var firstr = true;
var usd2gry = 7.8;
var eur2gry = 9.8;
var rur2gry = 0.24;

function changeCurrency(tocur)
{
	var conversion = 1;
	var n = 0;
	if(tocur == 'usd')
	{
		n = 2;
		conversion = usd2gry;
		document.getElementById('currnav').innerHTML = "<b><nobr><a href=\"#currency\" onClick=\"changeCurrency('gry');\">&nbsp; грн. \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<span class=\"nf\">долл. США</span>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('rur');\">рублей РФ \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('eur');\">евро \&gt;\&gt;</a></nobr></b>";
	}
	else if(tocur == 'eur')
	{
		n = 2;
		conversion = eur2gry;
		document.getElementById('currnav').innerHTML = "<b><nobr><a href=\"#currency\" onClick=\"changeCurrency('gry');\">&nbsp; грн. \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('usd');\">долл. США \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('rur');\">рублей РФ \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<span class=\"nf\">евро</span></nobr></b>";
	}
	else if(tocur == 'rur')
	{
		n = 2;
		conversion = rur2gry;
		document.getElementById('currnav').innerHTML = "<b><nobr><a href=\"#currency\" onClick=\"changeCurrency('gry');\">&nbsp; грн. \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('usd');\">долл. США \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<span class=\"nf\">рублей РФ</span>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('eur');\">евро \&gt;\&gt;</a></nobr></b>";
	}
	else
	{
		n = 2;
		document.getElementById('currnav').innerHTML = "<b><nobr><span class=\"nf\">&nbsp;грн.</span>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('usd');\">долл. США \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('rur');\">рублей РФ \&gt;\&gt;</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"#currency\" onClick=\"changeCurrency('eur');\">евро \&gt;\&gt;</a></nobr></b>";
	}
	fromcur = tocur;
	var list = [];
	var elem = document.getElementsByTagName('*');
	for(var i = 0; i < elem.length; i++) if(elem[i].className == 'tvalue') list.push(elem[i]);
	var ind = -1;
	for(var i = 0; i < list.length; i++)
	{
		if(list[i].innerHTML != '----')
		{
			var array;
			var temp;
			var br;
			if(firstr)
			{
				array = splitContent(list[i].innerHTML);
				var c = 0;
				while(list[i].firstChild)
				{
					if(list[i].firstChild.nodeType === 1)
					{
						if(list[i].firstChild.className == 'burn') ind = list[i].firstChild.innerHTML;
					}
					list[i].removeChild(list[i].firstChild);
				}
				var hidval;
				for(var j = 0; j < array.length; j++)
				{
					if(navigator.appName == 'Microsoft Internet Explorer') hidval = document.createElement('td');
					else hidval = document.createElement('tr');
					hidval.setAttribute('value',array[j]);
					if(array[j] == ind) list[i].setAttribute('name','burn');
					list[i].appendChild(hidval);
					temp = document.createElement('font');
					if(j == 0)
					{
						if(array[j] === ind)
						{
							temp.setAttribute('name','burn');
							temp.setAttribute('color','#C01000');
							temp.setAttribute('style','font-weight: bold;');
							temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
						}
						else
						{
							if(ind !== -1) temp.style.textDecoration = 'line-through';
							temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
						}
					}
					else
					{
						if(array[j] === ind)
						{
							temp.setAttribute('name','burn');
							temp.setAttribute('color','#C01000');
							temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
						}
						else
						{
							if(ind !== -1) temp.style.textDecoration = 'line-through';
							temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
							temp.setAttribute('color','#009900');
						}
						temp.setAttribute('style','font-weight: bold;');
					}
					hidval.appendChild(temp);
				}
			}
			for(var j = 0; j < list[i].childNodes.length; j++)
			{
				if(list[i].getAttribute('name') == 'burn') ind = -2;
				else ind = -1;
				while(list[i].childNodes[j].firstChild)
				{
					if(list[i].childNodes[j].firstChild.nodeType === 1)
					{
						if(list[i].childNodes[j].firstChild.getAttribute('name') == 'burn') ind = list[i].childNodes[j].getAttribute('value');
					}
					list[i].childNodes[j].removeChild(list[i].childNodes[j].firstChild);
				}
				temp = document.createElement('font');
				if(j == 0)
				{
					if(list[i].childNodes[j].getAttribute('value') === ind)
					{
						temp.setAttribute('color','#C01000');
						temp.setAttribute('name','burn');
						temp.setAttribute('style','font-weight: bold;');
					}
					else if(ind !== -1) temp.style.textDecoration = 'line-through';
					temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
				}
				else if(list[i].childNodes[j].getAttribute('value') === ind)
				{
					temp.setAttribute('color','#C01000');
					temp.setAttribute('name','burn');
					temp.setAttribute('style','font-weight: bold;');
					temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
				}
				else
				{
					temp.setAttribute('color','#009900');
					//temp.setAttribute('size','1');
					temp.setAttribute('style','font-weight: bold;');
					if(ind !== -1) temp.style.textDecoration = 'line-through';
					temp.innerHTML = (list[i].childNodes[j].getAttribute('value')/conversion).toFixed(n).replace('.',',');
				}
				list[i].childNodes[j].appendChild(temp);
			}
		}
	}
	firstr = false;
	return;
}

function replaceAfterComment(str,srch,repl)
{
	if(str.indexOf('-->') == -1) return str.replace('>'+srch+'<','>'+repl+'<');
	else
	{
		var temp = str.substring(str.indexOf('-->')+3,str.length-1);
		temp = temp.replace('>'+srch+'<','>'+repl+'<');
		str = str.substring(0,str.indexOf('-->')+3)+temp;
		return str;
	}
}

function splitContent(str)
{
	var strin;
	if(str.indexOf('<!--') != -1)
	{
		strin = str.replace(str.substring(str.indexOf('-->')-1,str.length-1),'');
		strin = strin.replace('<!--','');
		strin = strin.replace(/<\/?[^>]+(>|$)/g," ");
	}
	else strin = str.replace(/<\/?[^>]+(>|$)/g," ");
	strin = strin.replace(/^\s+|\s+$/g,"");
	var array = strin.split(/\s+/);
	return array;
}