
var zind=0;
var div_id="";
var div_w=0;


	var isOver=false;
	var cont="";
	var left=0;
	var dk=0;
	var ready=false;

	function init() {
		cont=document.getElementById("content");
		left=parseInt(cont.style.left ? cont.style.left:0);
		window.status=left;
		ready=true;
	}
	function scroll(direct){
		if(ready!=true) return;
		var k=0; var flag=false;
		if(direct=='left') k=-(5+dk); else k=5+dk;
		try {
			if(left>0) left=0;
			else if(-left>cont.clientWidth-440) left=-(cont.clientWidth-440);
			if(-left<=cont.clientWidth-440 && left<=0) flag=true;
			if(cont && flag) {left+=k;cont.style.left=left;}
			if(isOver==true) setTimeout("scroll('"+direct+"')",50);
		}
		catch(e) {window.status="error"}
	}


	function repaint() {
		var tbody=document.getElementById("carttable");
		i=0;
		tr=tbody.firstChild;
		while(tr) {
			if(tr.className.indexOf("reg")!=-1) tr.className="reg_"+(i%2==0 ? "even":"odd");
			i++;
			tr=tr.nextSibling;
		}
	}
	function recalc_cart(id){
		var d=document,totalPrice=0,totalCost=0;
		var fst_num=parseInt(d.getElementById("fst_num").innerText);
		var totalId=parseInt(d.getElementById("total_id").innerText)-1;

		i=0;cyc=0;
		var inputs=d.forms["cartform"].elements;
		while(inputs[i] && cyc<1000 && fst_num<totalId) {
			fst=fst_num+1;
			cost2=d.getElementById("_cost"+fst);
			price2=d.getElementById("_price"+fst);
			if(cost2 && cost2.innerText!="0") {/**/} else {cyc++;if(cost2 && cost2.innerText=="0") i++; fst_num+=2;continue;}
			cost=parseFloat(d.getElementById("_cost"+fst_num).innerText);
			price=parseFloat(d.getElementById("_price"+fst_num).innerText);
			amount=price/cost;
			qty=parseInt(inputs[i].value);
			cost2.innerText=cost*qty;
			price2.innerText=cost*qty*amount;
			totalPrice+=cost*qty*amount;
			totalCost+=cost*qty;
			i++;fst_num+=2;
		}
		
		d.getElementById("_price"+totalId).innerText=totalPrice;
		d.getElementById("_cost"+totalId).innerText=totalCost;
		
		if(id!=0) d.getElementById("img"+id).src="images/accept_act.gif";
	}

	function chcurr(curcode){
		var arr=document.forms["curr"].getElementsByTagName("input");
		var n=arr.length;
		for(i=0;i<n;i++) {	//смена картинок
			try {
				if(arr[i].code==curcode) arr[i].src="images/"+curcode+"_act.gif";
				else arr[i].src="images/"+arr[i].code+".gif";
			}
			catch(e) {
				//window.status="error in for [replacing curr images]"
			}
		}
		
		for(i=0;i<200;i++) {
			try {
				elem=document.getElementById("_cost"+i)
				//window.status+=arr[i].innerHTML;
				cost=parseFloat(elem.innerText);
				sb=document.getElementById("_sb"+i);
				sa=document.getElementById("_sa"+i);
				price=document.getElementById("_price"+i);
	
				sb.innerText=currencies[curcode][2];
				sa.innerText=currencies[curcode][3];
				price.innerText=(currencies[curcode][0]*parseFloat(elem.innerText));//,currencies[curcode][1]
				//window.status+="|"+currencies[curcode][2]+"."+currencies[curcode][3]+"."+currencies[curcode][0]+"|";
			}
			catch(e) {
				//window.status="error in for [reading prices]"
			}
		}
		progress(0);
	}

function big_pix(w,h,img) {
	window.open('products/'+img,'w','width='+w+',height='+h+',scrolling=no,menubar=no,status=no');
}

function switch_(val,dsp) {
	if(typeof(dsp)=='undefined') dsp="block";
	if(val=='f') dsp="none";
	//else if(val=='u') dsp=dsp;
	var i=1;
	while(tr=document.getElementById("ur"+i)) {tr.style.display=dsp;i++;}
}

function gebi(id){
	return document.getElementById(id);
}

function progress(flag){
	var div=document.getElementById("wait");
	switch(flag) {
		case 0:
			div.style.display="none";
			break;
		case 1:
			div.style.display="block";
			div.style.top=document.documentElement.scrollTop+300;
			break;
	}
}

function getXMLhttp() {
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	return req;

	//другая реализация, с intuit.ru
	if(typeof(XMLHttpRequest)!='undefined'){
	  var getXMLHttpObj = function(){ return new XMLHttpRequest(); }
	}
	else {
	  var getXMLHttpObj = function(){
		var activeXObjects = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0',	'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
		for(var i=0; i<activeXObjects.length; i++){
		  try{
			return new ActiveXObject(activeXObjects[i]);
		  }catch(err){}
		}
		return false;
	  }
	}
	return getXMLHttpObj();
}

function on_load_resize(){
	var nav=navigator.appName;
	try {
		var frm=parent.document.getElementById("oIframe");
		frm.style.width = 800;
//		alert(nav);
		if(nav=='Opera') dop=8;
		else if(nav=='Netscape') dop=40;
		else dop=2;
		frm.style.display="block";
		if(typeof(document.body.scrollWidth)!='undefined' && document.body.scrollWidth>0) frm.style.pixelWidth = document.body.scrollWidth;
		//frm.style.pixelwidth = frm.style.pixelWidth + dop;
		frm.style.height = document.body.scrollHeight;
		frm.style.left=(parent.document.body.scrollWidth-document.body.scrollWidth)/2;
		frm.style.top=parent.document.documentElement.scrollTop+200;
		
		parent.progress(0);
		parent.status=nav;
	}
	catch(e) {parent.status="error resizing"}
}

function backlink(){
	
}

function client_login(name) {
	try {
		document.getElementById("log_in_form").innerHTML="<div class=fl>Здравствуйте, <a href=\"cabinet.php\">"+name+"</a>!</div>";//&nbsp;<a href=\"?ng&amp;logout=true\" target=\"hfr\"><img src=\"images/logout.gif\" alt=\"Выход\"></a>";
	}
	catch(e) {}
}

function client_logout(cont){
	try {
		document.getElementById("log_in_form").innerHTML=(cont=="" ? "<b>Выход выполнен</b>":cont);
	}
	catch(e) {}
}

function showclik(level, pid)
{
//	progress(1);
	if(level=="") level='product_ttx.php?product_id=';
	var ff=navigator.appName;
//	alert(ff);
		if(ff!="Netscape") {
			oIframe.document.close();
			oIframe.document.write('Loading....');
		}
		var frm=document.getElementById("oIframe");
		//frm.style.top=document.body.scrollTop+130 ;
		//frm.style.display = 'block';
		frm.src=level+pid;
}

function menudiv_show(lev){
	if(document.all["image"+lev]) {
		source=document.all["image"+lev].src;
		src_path=source.substr(source.lastIndexOf("/")+1,source.length);
	}
	if(document.all["menudiv"+lev]) {
		if(document.all["menudiv"+lev].style.display!="block") {
			document.all["menudiv"+lev].style.display="block";
			if(src_path=="ul_arrow_inact.gif") document.all["image"+lev].src="admin/images/ul_arrow_act.gif";
			else if(src_path=="ul_list_inact.gif") document.all["image"+lev].src="admin/images/ul_list_act.gif";
		}
		else if(document.all["menudiv"+lev].style.display!="none") {
			document.all["menudiv"+lev].style.display="none";
			if(src_path=="ul_arrow_act.gif") document.all["image"+lev].src="admin/images/ul_arrow_inact.gif";
			else if(src_path=="ul_list_act.gif") document.all["image"+lev].src="admin/images/ul_list_inact.gif";
		}
	}
}

function validate_email(form,em_fld){
	if(em_fld=="") em_fld="email";

	//var email=eval('document.'+form_name+'.'+em_fld);
	var email=eval("form."+em_fld);
	var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
	if (!reg.test(email.value)) {
		//email.style.backgroundColor="red";
		//email.focus();
		return false;
	}
	else return true;
}

function hide(id){
	elem=document.getElementById(id);
	if(elem) elem.style.display="none";
}

function show(id,dsp){
	if(typeof(dsp)=='undefined') dsp="block";
	elem=document.getElementById(id);
	if(elem) elem.style.display=dsp;
}




function show_div(id){
	zind=zind+1;
	if(!document.all[id]) alert('Div "'+id+'" не найден');
	else {document.all[id].style.visibility="visible";document.all[id].style.zIndex=zind;}
}

function close_div(id){
	if(!document.all[id]) alert('Div "'+id+'" не найден');
	else document.all[id].style.visibility="hidden";
}

function check_form(form,em_fld){
	//alert('test');
	if(!validate_email(form,em_fld)) {alert('Email имеет неверный формат');return false;}
	return true;
}

function BsT()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function BsL()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getElementComputedStyle(elem, prop)	//получение свойства стиля, не определенного в css
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  
  return "";
}