	function escapeToWin1251(str){
		str=str.replace(/&/g, '&');
		str=str.replace(/ /g, ' ');
		str=str.replace(/=/g, '=');
		str=str.replace(/\+/g, '+');
		str=str.replace(/№/g, '№');
		str=str.replace(/\;/g, ';');
		str=str.replace(/Ё/g, 'Ё');
		str=str.replace(/ё/g, 'ё');
		str=str.replace(/©/g, '©');
		str=str.replace(/[А-Яа-я]/g, function(symbol){return '%'+Number(symbol.charCodeAt(0)-0x0350).toString(16);});
		return str;
	}	
	
	function open_window(link,w,h) //opens new window
	{
		var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'newWin',win);
		newWin.focus();
	}

	function open_printable_version(link) //opens new window
	{
		var win = "menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'perintableWin',win);
		newWin.focus();
	}

	function confirmDelete(id, ask, url) //confirm order delete
	{
		temp = window.confirm(ask);
		if (temp) //delete
		{
			window.location=url+id;
		}
	}

	

	function confirmUnsubscribe() //unsubscription confirmation
	{
		temp = window.confirm('Вы уверены, что хотите отменить регистрацию в магазине?');
		if (temp) //delete
		{
			window.location="index.php?killuser=yes";
		}
	}

	function validate() // newsletter subscription form validation
	{
		if (document.subscription_form.email.value.length<1)
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		if (document.subscription_form.email.value == 'Email')
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		return true;
	}
	function validate_disc() // review form verification
	{
		if (document.formD.nick.value.length<1)
		{
			alert("Пожалуйста, введите Ваш псевдоним");
			return false;
		}

		if (document.formD.topic.value.length<1)
		{
			alert("Пожалуйста, введите тему сообщения");
			return false;
		}

		return true;
	}
	function validate_search()
	{

		if (document.Sform.price1.value!="" && ((document.Sform.price1.value < 0) || isNaN(document.Sform.price1.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}
		if (document.Sform.price2.value!="" && ((document.Sform.price2.value < 0) || isNaN(document.Sform.price2.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}

		return true;
	}
	
	////////////////// POPUP window
	
	function popup(target,id){
     var vis = 0;
     var     mouse_x, mouse_y;
	 var podskazka = document.getElementById('podskazka');
          
     Handler.add(target, "mousemove", moveHandler);
     Handler.add(target, "mouseout", outHandler);     
     	 
	 url = 'includes/description.php?id=';
     HTTP.getText(url+id, callbackText);
     	 
	 function callbackText(txt){
          var to = 'podskazka';
          podskazka.innerHTML=unescape(txt); 
          if (vis) {          
              podskazka.style.visibility="visible";
          }
     }
     
     function outHandler(e){
		  Handler.remove(target, "mousemove", moveHandler);
          Handler.remove(target, "mouseout", outHandler);
          vis=0;     
          podskazka.style.visibility="hidden";
     }
     
     function moveHandler(e){
          mouse_x=e.clientX;
          mouse_y=e.clientY;
          vis=1;
          podskazka.style.left=mouse_x-50+"px";
          podskazka.style.top=mouse_y+20+document.body.scrollTop+"px";
		  	
			/*			
		  document.getElementById('x').value = mouse_x;
		  document.getElementById('y').value = mouse_y;
		  document.getElementById('z').value = document.documentElement.scrollTop;
		  */
     }
	}

	
		function showTree(expand,parentkey,id){  
		
		var url="";
		if(expand == null || id == null)
		url = 'includes/menu.php';
					
		else
		url = 'includes/menu.php?id='+id+'&expand='+expand+"&key="+parentkey;
		HTTP.getText(url, callbackshowTree);
		
		function callbackshowTree(txt){
		var to = 'tree';
		var d = document.getElementById(to);
		d.innerHTML=unescape(txt);      
		}
		contactShow();	
		}
		
		
		
		function priceShow(expand,parentkey,id){  
			 
			 showTree(expand,parentkey,id);	 
			 url = 'includes/price.php?id=';
			 HTTP.getText(url+id, callbackPriceShow);
			 
			function callbackPriceShow(txt){
			 var to = 'price';
			 var d = document.getElementById(to);
			 var m = document.getElementById('main');
			 var b1 = document.getElementById("google_banner1");
			 var b2 = document.getElementById("google_banner2");
			 
			 d.innerHTML=unescape(txt);      
			 d.style.visibility="visible";   
			 m.style.display="none";  
			 b1.style.display="none";
			 b2.style.display="block";
			}	
		}
		
		function contactShow(){  
			 url = 'includes/contact.php';
			 HTTP.getText(url, callback);
			 
			function callback(txt){
			 var to = 'contact';
			 var d = document.getElementById(to);
			 
			 d.innerHTML=txt;      
			 d.style.visibility="visible";   
			}	
		}	
		
		function addtoCart(params)
		{
		var url="";
		url = 'includes/add_to_cart.php?'+params;
		HTTP.getText(url, callbackFormShow);
		
			function callbackFormShow(txt){
			 var to = 'addcart';
			 var d = document.getElementById(to);
			 
			 d.innerHTML=unescape(txt);      
			}
			
				
			if(document.getElementById('oncart') && params == 'id=-1')
			{
				document.getElementById('oncart').style.visibility='hidden'; 
				return false;
			}		
		
		}
		
		function viewonCart(e,type)
		{
			var url="";
			var mouse_x, mouse_y;
			if(e)
			{
				mouse_x=e.clientX;
				mouse_y=e.clientY;
			}
			
			if(type==0) url = 'includes/view_on_cart.php';
			if(type==1) url = 'includes/buy_form.php?send=0';
			
			
			
			if(type==2) 
			{
				var name = document.getElementById('name');
				var phone = document.getElementById('phone');
				var mail = document.getElementById('mail');
				var addres = document.getElementById('addres');
				var comment = document.getElementById('comment');
				var key = document.getElementById('key');
				
				url = 'includes/buy_form.php?send=1&name='+name.value+'&phone='+phone.value+'&mail='+mail.value+'&addres='+addres.value+'&comment='+comment.value+'&keystring='+key.value;
			}
			
			HTTP.getText(url, callbackFormShow);
			
				function callbackFormShow(txt){
				 var to = 'oncart';
				 var d = document.getElementById(to);
				 
				 d.innerHTML=unescape(txt); 
					if(e){
					d.style.left=mouse_x-100+"px";
					d.style.top=mouse_y+10+document.body.scrollTop+"px";
					d.style.visibility="visible"; 
				 }
				 popupWin("title");
				}
		}
		
		function formShow(id)
		{
		var url="";
		url = 'includes/buy_form.php?id='+id;
		HTTP.getText(url, callbackFormShow);
		
			function callbackFormShow(txt){
			 var to = 'buyform';
			 var d = document.getElementById(to);
			 
			 d.innerHTML=unescape(txt);      
			 d.style.visibility="visible";   
	 
			}
		}
		
		 function popupWin(title){
		 var win = document.getElementById("oncart");
		 var t = document.getElementById(title);
		 Handler.add(t, "mousedown", downHandler);     
		 function downHandler(e){          
			  drag(win, e);
		 } 
	}
		 
		 function plus_minus(pm,sess)
		{
		addtoCart('id='+sess+'&pm='+pm);
		setTimeout ('viewonCart(null,0)',200);
		}	
		
		function close_window(target)
		{
		alert(target);
		var d = document.getElementById(target);
			d.style.visibility="hidden";   
		}
		
		function buttonSwitch(buttonID, evt){
		if (evt == "mouseover"){
			document.getElementById(buttonID).firstChild.className = "C_hover";
		}else if (evt == "mouseout"){
			document.getElementById(buttonID).firstChild.className = "C_normal";
		}
		}
		
