var combowidth='';
var comboheight='';

// Месага о добавлении товара в корзину
function initialize(){
if (document.all){
combowidth=cartwindow.offsetWidth;
comboheight=cartwindow.offsetHeight;
setInterval("staticit_ie()",50);
try{
cartwindow.filters.revealTrans.Apply();
cartwindow.filters.revealTrans.Play();
cartwindow.style.visibility="visible";
}
catch(e){}
}
else if (document.layers){
combowidth=document.cartwindow.document.width;
comboheight=document.cartwindow.document.height;
setInterval("staticit_ns()",50);
document.cartwindow.visibility="show";
}
}

function initialize_off(){
if (document.all){
combowidth=cartwindow.offsetWidth;
comboheight=cartwindow.offsetHeight;
setInterval("staticit_ie()",50);
cartwindow.style.visibility="hidden";
}
else if (document.layers){
combowidth=document.cartwindow.document.width;
comboheight=document.cartwindow.document.height;
setInterval("staticit_ns()",50);
document.cartwindow.visibility="hide";
}
}

function staticit_ie(){
cartwindow.style.pixelLeft=document.body.scrollLeft+document.body.clientWidth-combowidth-30;
cartwindow.style.pixelTop=document.body.scrollTop+document.body.clientHeight-comboheight;
}

function staticit_ns(){
document.cartwindow.left=pageXOffset+window.innerWidth-combowidth-30;
document.cartwindow.top=pageYOffset+window.innerHeight-comboheight;
}


function setCookie(name, value)
{
   var today = new Date()
   var expires = new Date()
   expires.setTime(today.getTime() + 1000*24*60*60)
   document.cookie = name + "=" +escape(value)+ ((expires == null) ? "" : ("; expires=" +expires))+";path=/";
}



function getCookie(Name)
{
   var search = Name + "="
   if (document.cookie.length > 0)
   { // если есть какие-либо куки
      offset = document.cookie.indexOf(search)
      if (offset != -1)
      { // если кука существует
         offset += search.length
         // установить индекс начала значения
         end = document.cookie.indexOf(";", offset)
         // установить индекс конца значения куки
         if (end == -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
      else return(false);
   }
}




function addorder(pagelink,modname,formname)
{
  var i=0,str,tempstr,newstr="",isorder="false",calc=0,num=0,price,j=1,temp,getprice,qwert
  var massive=""
  var f
  var tkan1,tkan2
// if(confirm("Добавить товар в корзину?")) {

  var options = new Array();
  var present, option_str="";

  if (document.all('order_present').value) {
  	present = document.all('order_present').value;
  }

  tempstr=pagelink.split(",")
  if(tempstr[1]=="k")
  {
    if(document[formname].sizenum.value) temp=document[formname].sizenum.value
    temp-=0
    temp+=1
    tempstr[4]=temp
    pagelink=tempstr[0]
    while(tempstr[j])
    {
      pagelink+=","+tempstr[j]
      j+=1
    }
  }
  if(tempstr[1]=="m")
  {

    tempstr[3]=document.all('sel_tgr').value
    tempstr[4]=document.all('szn').value
    tempstr[5]=document.all('mht').value

    pagelink=tempstr[0]

    for(j=1;j<6;j++)
    {
      if(tempstr[j]==""){ tempstr[j] = ""}
      pagelink+=","+tempstr[j]
    }

  }

  // дополнительные опции
  if (document[formname]['order_option[]']) {
  	if (document[formname]['order_option[]'].length) {
	  	for (var i=0; i < document[formname]['order_option[]'].length; i++) {
	  		if (document[formname]['order_option[]'][i].value) {
	  			option_str += ':'+document[formname]['order_option[]'][i].value;
	  		}
	  	}
	}
  	else option_str = document[formname]['order_option[]'].value;

  	pagelink+=","+option_str;
  }

  str=getCookie(cookiname)
  if(str)
  {
        massive=str.split(";")
        while(massive[i])
        {
          tempstr=massive[i].split("|")
          if(pagelink==tempstr[0])
          {
            tempstr[2]-=0
            tempstr[2]+=1
            isorder="true"
            massive[i]=tempstr.join("|")
          }
          i+=1
        }
        newstr=massive.join(";")
        if(isorder!="true")
        {
          getprice=document[formname].cost_value.value.split(" ")
              try{
	            tkan1=document.all('main_tk').value
				tkan2=document.all('dop_tk').value
			  }
			  catch(e){}
          	newstr+=";"+pagelink+"|"+modname+"|1|"+getprice[0]+"|"+tkan1+"|"+tkan2+"|"+option_str+"|"+present
        }
        setCookie(cookiname,newstr)
  }
  else
  {
  	getprice=document[formname].cost_value.value
  	qwert=getprice.split(" ")
   			try{
              	tkan1=document.all('main_tk').value
			  	tkan2=document.all('dop_tk').value
			}catch(e){}
          	str=pagelink+"|"+modname+"|1|"+qwert[0]+"|"+tkan1+"|"+tkan2+"|"+options+"|"+present
  	setCookie(cookiname,str)
  }
  i=0
  str=getCookie(cookiname)
  massive=str.split(";")
  while(massive[i])
  {
    tempstr=massive[i].split("|")
    tempstr[2]-=0
    price=tempstr[3].split(" ")
    price[0]-=0
    num+=tempstr[2]
    calc+=tempstr[2]*price[0]
    i+=1
  }
  //document.write(getCookie("order"))
  colvo.innerHTML=num+" предм."
  summa.innerHTML="Сумма: "+calc+" руб."
  //initialize()
  //setTimeout("initialize_off()",3000)
//} // конец confirm





// открываем окно с корзиной
window.open('/rec_window.php?'+num+calc,'_blank','width=500, height=350, scrollbars=yes, resizable=no, location=0, left=200, top=150');

}
