function utf_win2(str){

	var u2koi = {
	"&#x430;": "а", "&#x410;": "А",
	"&#x431;": "б", "&#x411;": "Б",
	"&#x432;": "в", "&#x412;": "В",
	"&#x433;": "г", "&#x413;": "Г",
	"&#x434;": "д", "&#x414;": "Д",
	"&#x435;": "е", "&#x415;": "Е",
	"&#x451;": "ё", "&#x401;": "Ё",
	"&#x436;": "ж", "&#x416;": "Ж",
	"&#x437;": "з", "&#x417;": "З",
	"&#x438;": "и", "&#x418;": "И",
	"&#x439;": "й", "&#x419;": "Й",
	"&#x43A;": "к", "&#x41A;": "К",
	"&#x43B;": "л", "&#x41B;": "Л",
	"&#x43C;": "м", "&#x41C;": "М",
	"&#x43D;": "н", "&#x41D;": "Н",
	"&#x43E;": "о", "&#x41E;": "О",
	"&#x43F;": "п", "&#x41F;": "П",
	"&#x440;": "р", "&#x420;": "Р",
	"&#x441;": "с", "&#x421;": "С",
	"&#x442;": "т", "&#x422;": "Т",
	"&#x443;": "у", "&#x423;": "У",
	"&#x444;": "ф", "&#x424;": "Ф",
	"&#x445;": "х", "&#x425;": "Х",
	"&#x446;": "ц", "&#x426;": "Ц",
	"&#x447;": "ч", "&#x427;": "Ч",
	"&#x448;": "ш", "&#x428;": "Ш",
	"&#x449;": "щ", "&#x429;": "Щ",
	"&#x44A;": "ъ", "&#x42A;": "Ъ",
	"&#x44B;": "ы", "&#x42B;": "Ы",
	"&#x44C;": "ь", "&#x42C;": "Ь",
	"&#x44D;": "э", "&#x42D;": "Э",
	"&#x44E;": "ю", "&#x42E;": "Ю",
	"&#x44F;": "я", "&#x42F;": "Я","&#34;": "\"","&#171;": "«","&#187;": "»"};

	for (var k in u2koi) str = str.replace (new RegExp (k, "g"), u2koi [k]);

	return str;
}
function createXMLHttp ()
{
	if (typeof XMLHttpRequest != "undefined")
	{
		return new XMLHttpRequest ();
	}
	else if (window.ActiveXObject)
	{
		var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0",
		"MSXML2.XMLHttp.3.0","MSXML2.XMLHttp",
		"Microsoft.XMLHttp"];
		for (var i = 0; i < aVersions.length; i++)
		{
			try
			{
				var oXmlHttp = new ActiveXObject (aVersions[i]);
				return oXmlHttp;
			}
			catch (oError)
			{
			}
		}
	}
	throw new Error("Can not load XmlHttp");
}



function SubMenuOver(id)
{
	var div = document.getElementById('SubMenu'+id);
	if(id=='2')
	{
		var elems = document.getElementById('Menu').getElementsByTagName('td');
		var mleft = 50; // лажа конечно, но не нашел быстро, как сделать ссылку на смещение, описанное в .css
		for(var i=0; i<4; i++)
			if(elems[i].clientWidth!='')
				mleft += parseInt(elems[i].clientWidth);
		div.style.left = mleft;
	}
	div.style.display = 'block';
}
function SubMenuOut(id)
{
	document.getElementById("SubMenu"+id).style.display = 'none';
}

function SubProduct(id)
{
	if(document.getElementById("SubProduct"+id))
	{
		var st = document.getElementById("SubProduct"+id).style.display;
		if(st=='none')
		{
			document.getElementById("SubProduct"+id).style.display = 'block';
		}
		else
		{
			document.getElementById("SubProduct"+id).style.display = 'none';
		}
	}
}
//запрос информации на сервере (запрашиваемый файл, место возврата информации,данные)
function GetInfo(file,back,quer)
{
	document.getElementById(back).innerHTML = "loading...";

	var oXmlHttp = createXMLHttp ();

	oXmlHttp.open ("post", file, true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");

	oXmlHttp.onreadystatechange = function ()
	{
		if (oXmlHttp.readyState == 4)
		{
			if (oXmlHttp.status == 200)
			{
				document.getElementById(back).innerHTML = utf_win2(oXmlHttp.responseText);
			}
			else
			{
				document.getElementById(back).innerHTML = "Error: " + utf_win2(oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send (quer);
}

function SendAsk()
{
    var send = "";
	if((comm = document.getElementById('comm').value) == "")
	{
		send = send +  "<b><font color=Red>Введите текст вопроса</font><b><br><br>";
	}

	if (send == "")
	{

		document.getElementById('RezLetter').innerHTML = "Идет отправка...";
		
		var oXmlHttp = createXMLHttp ();
		
		comm = escape(comm);

		var Quer = "comm=" + comm;
		
		oXmlHttp.open ("post", "../asks/send.php", true);
		
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");

		oXmlHttp.onreadystatechange = function ()
		{
			if (oXmlHttp.readyState == 4)
			{
				if (oXmlHttp.status == 200)
				{
					document.getElementById('RezLetter').innerHTML = oXmlHttp.responseText;
				}
				else
				{
					document.getElementById('RezLetter').innerHTML = "Error: " + oXmlHttp.statusText;
				}
			}
		};
		oXmlHttp.send (Quer);
	}
	else
	{
		document.getElementById('RezLetter').innerHTML = send;
	}
}

function Step2(file,back)
{
	var product1 = document.getElementsByName('product1');
	
	for(i=0;i<product1.length;i++)
	{
		if(product1[i].checked)
		{
			var product1_value = product1[i].value;
		}
	}
	
	var quer = "product1="+product1_value;
	
	GetInfo(file,back,quer)
}
function Step3(file,back)
{
	var product2 = document.getElementsByName('product2');
	
	for(i=0;i<product2.length;i++)
	{
		if(product2[i].checked)
		{
			var product2_value = product2[i].value;
		}
	}
	
	var product1_value = document.getElementById('product1').value;
	var quer = "product1="+product1_value + "&product2="+product2_value;
	
	GetInfo(file,back,quer)
}
function Step4(file,back)
{
	var product3 = document.getElementsByName('product3');
	var product3_value = '';
	for(i=0;i<product3.length;i++)
	{
		if(product3[i].checked)
		{
			product3_value = product3[i].value + "_" + product3_value;
		}
	}
	
	var product1_value = document.getElementById('product1').value;
	var product2_value = document.getElementById('product2').value;
	var quer = "product1="+product1_value + "&product2="+product2_value + "&product3="+product3_value;
	
	GetInfo(file,back,quer)
}
function Send()
{
	var send = "";
	var re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	if((comp = document.getElementById('comp').value) == "")
	{
		send = send +  "<b><font color=Red>Введите название компании</font><b><br><br>";
	}
	if((name = document.getElementById('name').value) == "")
	{
		send = send +  "<b><font color=Red>Введите ФИО</font><b><br><br>";
	}
	if((tel = document.getElementById('tel').value) == "")
	{
		send = send +  "<b><font color=Red>Введите контактный телефон</font><b><br><br>";
	}
	if((email = document.getElementById('email').value) == "")
	{
		send = send +  "<b><font color=Red>Введите e-mail</font><b><br><br>";
	}
	if((pl = document.getElementById('pl').value) == "")
	{
		send = send +  "<b><font color=Red>Введите плательщика</font><b><br><br>";
	}
	if((gr = document.getElementById('gr').value) == "")
	{
		send = send +  "<b><font color=Red>Введите грузополучателя</font><b><br><br>";
	}
	else
	{
		if(re.test(document.getElementById('email').value)==false)
		{
			send = send +  "<b><font color=Red>Некорректный e-mail</font><b><br><br>";
		}
	}
	if (send == "")
	{

		document.getElementById('RezLetter').innerHTML = "Идет отправка...";
		var oXmlHttp = createXMLHttp ();

		tel = escape(tel);
		name = escape(name);
		comp = escape(comp);
        pl = escape(pl);
        gr  = escape(gr);
        
		var product1 = document.getElementById('product1').value;
		var product2 = document.getElementById('product2').value;
		var product3 = document.getElementById('product3').value;
		
		var Quer = "name=" + name + "&tel=" + tel + "&email=" + email + "&comp=" + comp + "&product1=" + product1 + "&product2=" + product2 + "&product3=" + product3+ "&pl=" + pl + "&gr=" + gr;
		
		oXmlHttp.open ("post", "send.php", true);
		
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");

		oXmlHttp.onreadystatechange = function ()
		{
			if (oXmlHttp.readyState == 4)
			{
				if (oXmlHttp.status == 200)
				{
					document.getElementById('RezLetter').innerHTML = oXmlHttp.responseText;
				}
				else
				{
					document.getElementById('RezLetter').innerHTML = "Error: " + oXmlHttp.statusText;
				}
			}
		};
		oXmlHttp.send (Quer);
	}
	else
	{
		document.getElementById('RezLetter').innerHTML = send;
	}
}
function Registration()
{
	var send = "";
	var re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	
	if((mail = document.getElementById('mail').value) == "")
	{
		send = send +  "<b><font color=Red>Введите e-mail</font><b><br>";
	}
	else
	{
	    if(re.test(document.getElementById('mail').value)==false)
	    {
		   send = send +  "<b><font color=Red>Некорректен e-mail</font><b><br>";
	    }
	}
	if (send == "")
	{
		 var oXmlHttp = createXMLHttp ();
		 
		 var fio = document.getElementById('fio').value;
		 var dolzh = document.getElementById('dolzh').value;
		 var org = document.getElementById('org').value;
		 
		 fio = escape(fio);
		 dolzh = escape(dolzh);
		 org = escape(org);
		 
		 var Quer = "mail=" + mail + "&fio=" + fio + "&dolzh=" + dolzh + "&org=" + org;
	
	     oXmlHttp.open ("post", "../inc/main/registration.php", true);
		 oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		 
	     oXmlHttp.onreadystatechange = function ()
	     {
		    if (oXmlHttp.readyState == 4)
		    {
			   if (oXmlHttp.status == 200)
			   {
				  document.getElementById('RezZakaz').innerHTML = oXmlHttp.responseText;
			   }
		}
	 };
	 oXmlHttp.send (Quer);
	}
	else
	{
		document.getElementById('RezZakaz').innerHTML = send;
	}
}
function Forget()
{
	var send = "";
	var re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	if((mail = document.getElementById('mail').value) == "")
	{
		send = send +  "<b><font color=Red>Введите e-mail</font><b><br>";
	}
	else
	{
	    if(re.test(document.getElementById('mail').value)==false)
	    {
		   send = send +  "<b><font color=Red>Некорректен e-mail</font><b><br>";
	    }
	}
	if (send == "")
	{
		 var oXmlHttp = createXMLHttp ();
		 
		 var Quer = "mail=" + mail;
		 
	     oXmlHttp.open ("post", "../inc/main/forget.php", true);
		 oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		 
	     oXmlHttp.onreadystatechange = function ()
	     {
		    if (oXmlHttp.readyState == 4)
		    {
			   if (oXmlHttp.status == 200)
			   {
				  document.getElementById('RezZakaz').innerHTML = oXmlHttp.responseText;
			   }
		}
	 };
	 oXmlHttp.send (Quer);
	}
	else
	{
		document.getElementById('RezZakaz').innerHTML = send;
	}
}
function In()
{
	var send = "";
	if (send == "")
	{
		 var oXmlHttp = createXMLHttp ();
		 var log = document.getElementById('log').value;
		 var pass = document.getElementById('pass').value;
		 
		 var Quer = "log=" + log + "&pass=" + pass;
		 
	     oXmlHttp.open ("post", "../inc/main/in.php", true);
		 oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		 
	     oXmlHttp.onreadystatechange = function ()
	     {
		    if (oXmlHttp.readyState == 4)
		    {
			   if (oXmlHttp.status == 200)
			   {
				  document.getElementById('InId').innerHTML = oXmlHttp.responseText;
			   }
		}
	 };
	 oXmlHttp.send (Quer);
	}
	else
	{
		document.getElementById('InId').innerHTML = send;
	}
}
