// JavaScript Document
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
dom = (document.getElementById)? true:false

function OpenDetailsB(loc, nm)
	{
	/*firstone=self;*/
	page="../adm/detailsB.php?cid=" + loc + "&nm=" + nm;
    if (ns4)  window.open(page,"myadd","screenX=0,screenY=0,innerwidth=700,innerheight=580,scrollbars=no,resizable");
    else if (ie4)  window.open(page,"myadd","height=580,left=0,width=700,top=0,scrollbars=no,resizable");
    else _win=window.open(page,"myadd","width=700,height=580,scrollbars=no,resizable");
	}


function change_currency(myfile, mycurr, mysort, arg)
	{
	//alert(myfile+","+ mycurr+","+ mysort+","+ arg);
	if (arg=="not set")	my_attr="../"+myfile+".php?crcy_new=" + mycurr+"&sort_now="+mysort;
	else	my_attr="../"+myfile+".php?crcy_new=" + mycurr+"&sort_now="+mysort+"&ser="+arg;
	document.location=my_attr;
	}
function change_currency_allproducts(myfile, mycurr, mysort, arg)
	{
	my_attr="../"+myfile+".php?crcy_new=" + mycurr+"&sort_now="+mysort+"&suppl="+arg;
	document.location=my_attr;
	}

function open_cart()
	{
	if (ie4) qty=document.all.res2.innerHTML;
	if (dom) qty=document.getElementById("res2").innerHTML;
		if (qty=="&nbsp;&nbsp;&nbsp;позиций=0 шт.")
		{alert("Ваша корзина пуста!");
		return
		}
		else
		document.location="../main_pages/cart.php?del=no";
	}

function navbar()
	{
	var navStr= '';
	for (var i = 0; i < navURLs.length; i++) {
		if (location.href.indexOf(navURLs[i]) == -1) {	
			navStr += ' <B>&nbsp;&nbsp;&nbsp;<A class= "menu" HREF="' + navURLs[i] + '">' + pageText[i] + '</A>&nbsp;&nbsp;&nbsp;</B> '; 
			}
		}
	    document.writeln(navStr);
	}

function ShowImg(){
	document.write('<img src="'+pctr.src+'" align="right" border=0">');
}
function ShowImg2(){
	document.write('<img src="'+pctr.src+'" border=0">');
}

function adwin(loc){
     if (ns4)  window.open(loc,"","screenX=100,screenY=100,innerwidth=550,innerheight=500,scrollbars=no,resizable");
    else if (ie4)  window.open(loc,null,"height=500,left=100,width=550,top=100,scrollbars=no,resizable");
    else _win=window.open(loc,"","width=550,height=500,scrollbars=no,resizable");
}

function adwinsm(loc){
     if (ns4)  window.open(loc,"","screenX=100,screenY=100,innerwidth=350,innerheight=150,scrollbars=no,resizable");
    else if (ie4)  window.open(loc,null,"height=150,left=100,width=350,top=100,scrollbars=no,resizable");
    else _win=window.open(loc,"","width=350,height=150,scrollbars=no,resizable");
}

//--rollovers handling. start-----------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	parent.name=main;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//--rollovers handling. end-----------

//------cart handling. start----------
function putitem (dat1,dat2)
{
ie4 = (document.all)? true:false;
dom = (document.getElementById)? true:false;

dat1=eval(document.cart.summ.value)+dat1;
dat2=eval(document.cart.qty.value)+dat2;
document.cart.summ.value=dat1;
document.cart.qty.value=dat2;
dat1="&nbsp;&nbsp;&nbsp;сумма= "+dat1+" "+"руб.";
dat2="&nbsp;&nbsp;&nbsp;позиций= "+dat2+" "+"шт.";

	if (ie4) 
	{
	document.all.res1.innerHTML=dat1;
	document.all.res2.innerHTML=dat2 ;
	};
	if (dom) 
	{
	document.getElementById("res1").innerHTML=dat1;
	document.getElementById("res2").innerHTML=dat2;
	}
}

var itms_array= new Array();
var med;
var tovar_item;
var att;

function add_to_array(c,i,p,at)
{
n=document.cart.qty.value;
var fin='new';

for(var x=0; x<itms_array.length; x++)
	{
     if (itms_array[x].supplier==c && itms_array[x].goodid==i)
     	{
     	 itms_array[x].qty= itms_array[x].qty+1;
     	putitem(p,0);
     	at=at+"&pr="+p+"&cm="+c+"&it="+i+"&mode=edit";
		 fin='edit';
     	break
     	}
 	}
 
if(fin=='new')
	{	 
 	 itms_array[n] = new tovar_item(c,i,p,1);
 	 putitem(p,1);
 	 at=at+"&pr="+p+"&cm="+c+"&it="+i+"&mode=new";
 	}
	//alert(at) 
adwinsm(at);
//med=itms_array[n].price;
}

function tovar_item(supplier,goodid,price,qty){
this.supplier=supplier;
this.goodid=goodid;
this.price=price;
this.qty=qty;
}

function populate_array()
{
dat2=eval(document.cart.qty.value);
if (dat2==0)
return;
message="";
for(x=0; x<dat2; x++)
  	{
     c=eval("document.cart.cm"+x+".value");
     i=eval("document.cart.it"+x+".value");
     q=eval("document.cart.qty"+x+".value");
     p=eval("document.cart.pr"+x+".value");
	 itms_array[x] = new tovar_item(c,i,p,q);
	 //message=message+itms_array[x]["price"]+"\n";
  	}

//alert(message);
//alert (itms_array[0]["price"]);
return itms_array;
}
//------cart handling. end---------

function put_titles (razdel, page)
{
ie4 = (document.all)? true:false;
dom = (document.getElementById)? true:false;

	if (ie4) 
	{
	document.all.page_name.innerHTML=page;
	document.all.razdel_name.innerHTML=razdel ;
	};
	if (dom) 
	{
	document.getElementById("page_name").innerHTML=page;
	document.getElementById("razdel_name").innerHTML=razdel;
	}
}
