var lang;

function trim(str) {
    return str.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
}


var ie=document.all?1:0
var oDiv1 = document.createElement("DIV1");
var oDiv2 = document.createElement("DIV1");

function openWindow1(html, x_l, x_t){
	oDiv1.innerHTML=html;
	oDiv1.style.position="absolute";
	oDiv1.style.zIndex=301;
	if (ie==1){
		oDiv1.style.pixelLeft=x_l;
		oDiv1.style.pixelTop=x_t;
	}else{ 
		oDiv1.style.left=x_l;
		oDiv1.style.top=x_t;
	}
	document.body.appendChild(oDiv1);
}	
	
function openWindow2(html, x_l, x_t){
	oDiv2.innerHTML=html;
	oDiv2.style.position="absolute";
	oDiv2.style.zIndex=302;
	if (ie==1){
		oDiv2.style.pixelLeft=x_l;
		oDiv2.style.pixelTop=x_t;
	}else{ 
		oDiv2.style.left=x_l;
		oDiv2.style.top=x_t;
	}
	document.body.appendChild(oDiv2);
}	
	
function getString(x,f1,f2) {
	do {	
		tmp = x;
		x=tmp.replace(f1,f2);
		}
		while ( x != tmp);
 return x;
 }


function do_php(php,head,num,xd,yd) { 
	if(!(xd))xd=xx;
	if(!(yd))yd=yy;
	JsHttpRequest.query(php,{},
            // Function is called when an answer arrives. 
            function(result, errors) { 
                // Write the answer.
                if (result) { 
				if(result["str"]!='ok'){
					content=getString(result["str"],'``','<br/>');
					content=getString(content,'DO_SCRIPT','DO_SCR'+countscript);
					if(num ==0){
						//open_layer_d(content,head)
					} else { 
						showWindow(num,head,content,xd,yd)
					}
					layer=''; 
					if(obj=document.getElementById("DO_SCR"+countscript)){ 
						obj.onclick(); 
						countscript++;
					};
		
				}
				if(result["str"]=='close')hideMe(num)
	            }
            },
            true
        );
}

function do_del(php) { 
	JsHttpRequest.query(php,{},
            // Function is called when an answer arrives. 
            function(result, errors) { 
                if (result) {}
            },
            true
        );
}


function do_content(url,select_id) { 
	if(!(select_id)){select_id='content';}
	if(select_id=='content')document.getElementById("content").innerHTML='<center><img src="images/loading.gif" border="0" width="76" height="8" alt=""></center>';
	JsHttpRequest.query(url,{},
            function(result, errors) { 
                if (result) { 
				document.getElementById(select_id).innerHTML=result["str"];
				if(obj=document.getElementById("DO_SCRIPT")){ 
					obj.onclick(); 
				};
	            }
            },
            true
        );
}

function do_menu(n) { 
		//document.getElementById('main').style.display='none';
		//document.getElementById('content').innerHTML='';
		document.getElementById('content').style.display='';

		//if(document.getElementById('list').value!='') do_content("list_r.php?cat_id="+document.getElementById('list').value+"&rowshop="+document.getElementById('rowshop').value);
		//if(document.getElementById('act').value=='contact' && document.getElementById('list').value=='') document.getElementById('content').innerHTML=document.getElementById('plate').innerHTML;
		document.getElementById('content').style.backgroundColor='#FFFFFF';
		document.getElementById('orel').style.display='none';
		if(n=='1' && lang=='') read_news("read_news.php?file=files/news.html");
		if(n=='1' && lang=='2') read_news("read_news.php?file=files/news2.html");
		if(n=='2') do_content('categories_list_r.php?rowshop=1&lang='+lang);
		if(n=='3') do_content('categories_list_r.php?rowshop=2&lang='+lang);
		if(n=='4') do_content('categories_list_r.php?rowshop=7&lang='+lang);
		if(n=='5') do_send('',lang);
}
function read_news(url) { 
   JsHttpRequest.query(url,{},
            function(result, errors) { 
                if (result) { 
					document.getElementById('content').innerHTML='<table width="100%" height="90" cellpadding="0" cellspacing="0"><tr><td>'+result["str"]+'</td></tr></table>';
	            }
            },
            true  
        );
}

function do_send(act,lang) { 
   ymail='';if(obj=document.getElementById("ymail"))ymail=obj.value;
   name='';if(obj=document.getElementById("name"))name=obj.value;
   message='';if(obj=document.getElementById("message"))message=obj.value;
   JsHttpRequest.query("mail_kalinka.php",{
   'lang': lang,
   'act': act,
   'ymail': ymail,
   'name': name,
   'message': message
   },
            function(result, errors) { 
                if (result) { 
					document.getElementById('content').innerHTML=result["str"];
					initialize()
					//document.getElementById('content_map').style.display='';
	            }
            },
            true  
        );
}


