function AddCookie(name, text, days){
  var StopDate = new Date();
  StopDate.setTime(StopDate.getTime() + days * 24*60*60*1000);
  if (text == "") {text= " ";}
  document.cookie = name  +  "=" + escape(text) + "; expires=" + StopDate.toGMTString() + ";domain=diamail.com.ua; path=/";

}

function AddCookies() {

var FIOV = document.prs.FIO.value;
if (FIOV=="") FIOV=" ";
if (document.getElementById('Firm') != null) {var FirmV = document.prs.Firm.value;}
if (FirmV=="") FirmV=" ";
var IndexV = document.prs.Index.value;
if (IndexV=="") IndexV=" ";
var CityV = document.prs.City.value;
if (CityV=="") CityV=" ";
var AddressV = document.prs.Address.value;
if (AddressV=="") AddressV=" ";
var PhoneV = document.prs.Phone.value;
if (PhoneV=="") PhoneV=" ";
var CellphoneV = document.prs.Cellphone.value;
if (CellphoneV=="") CellphoneV=" ";
var EmailV = document.prs.Email.value;
if (EmailV=="") EmailV=" ";


if (document.getElementById('Firm') != null) {AddCookie ("Firm",FirmV,1000);}
AddCookie ("Index",IndexV,100);
AddCookie ("City",CityV,1000);
AddCookie ("Address",AddressV,1000);
AddCookie ("Phone",PhoneV,1000);
AddCookie ("Cellphone",CellphoneV,1000);
AddCookie ("Email",EmailV,1000);
AddCookie ("FIO",FIOV,1000);



}

function FindCookie(name) {
var i=0;
var start=0;
var end=0;
var inform=document.cookie;
 while (i<=inform.length)
 {
 start=i;
 end=start+name.length;
  if(inform.substring(start,end) == name) 
  {
  start=end+1;
  end=document.cookie.indexOf(";",start);
     if (end<start) 
        end = document.cookie.length;
  return document.cookie.substring(start,end);
  break;
  }
 i++;
 }
return "";
}

function GetCookies (par) {
document.prs.FIO.value = unescape(FindCookie("FIO"));
if (document.getElementById('Firm') != null) {document.prs.Firm.value = unescape(FindCookie("Firm"));}
document.prs.Index.value = unescape(FindCookie("Index"));
if (document.prs.City.value == "" || document.prs.City.value == " ") {document.prs.City.value = unescape(FindCookie("City"));}
document.prs.Address.value = unescape(FindCookie("Address"));
document.prs.Phone.value = unescape(FindCookie("Phone"));
document.prs.Cellphone.value = unescape(FindCookie("Cellphone"));
document.prs.Email.value = unescape(FindCookie("Email"));

}


function Empty () {
document.prs.FIO.value = "";
if (document.getElementById('Firm') != null) {document.prs.Firm.value =""};
document.prs.Index.value ="";
document.prs.City.value ="";
document.prs.Address.value ="";
document.prs.Phone.value ="";
document.prs.Cellphone.value ="";
document.prs.Email.value ="";
}



function Sending() {
//Ref(parent.refer);
return Checking();
}
                                               



function AddOrder(code,quant,price,from) {

  quant=parseInt(quant, 10);
  var Store=unescape(FindCookie('order'));
  if (Store == "") {
   qp="code=" + code + "quant=" + quant +"price=" + price + "from=" + from + ":";
   AddCookie ('order',qp,1000);
  Htotb=parseInt(parent.header.document.forms[0].totb.value,10);
  Htotm=Math.round(parent.header.document.forms[0].totm.value*100)/100;
  Htotb=Htotb+quant;
  Htotm=Htotm+price;
  parent.header.document.forms[0].totb.value=Htotb;
  parent.header.document.forms[0].totm.value=Math.round(Htotm*100)/100;
  }

  else {

  qp="code=" + code + "quant=" + quant +"price=" + price +"from=" + from +":";
  qp=Store+qp;
  AddCookie ('order',qp,1000);
  Htotb=parseInt(parent.header.document.forms[0].totb.value,10);
  Htotm=Math.round(parent.header.document.forms[0].totm.value*100)/100;
  Htotb=Htotb+quant;
  Htotm=Htotm+price;
  parent.header.document.forms[0].totb.value=Htotb;
  parent.header.document.forms[0].totm.value=Math.round(Htotm*100)/100;
  parent.header.document.forms[0].disP.value=0;
  parent.header.document.forms[0].disH.value=0;
 
   if (Htotb>2 && Htotb<5) {
   parent.header.document.forms[0].disP.value=3;
   parent.header.document.forms[0].disH.value=Math.round(Htotm*100*0.03)/100;
   }

   if (Htotb>4 && Htotb<10) {
   parent.header.document.forms[0].disP.value=5;
   parent.header.document.forms[0].disH.value=Math.round(Htotm*100*0.05)/100;
   }

   if (Htotb>9) {
   parent.header.document.forms[0].disP.value=10;
   parent.header.document.forms[0].disH.value=Math.round(Htotm*100*0.10)/100;
   }

  }



}



function SaveOrder(tmp) {
var incookies="";
var incookiesCQ="";
var incookiesP="";
var incookiesF="diamail";
var totb=0;
var code="";
var price=0;
var key='false';


 for( i = 0; i < document.forms[0].length; i++ ) {

        if( ( document.forms[0].elements[ i ].name.substring( 0, 5 ) == "totb-" ) &&
            ( document.forms[0].elements[ i ].value) > 0 )
          {                 totb = Math.round(document.forms[0].elements[ i ].value);
                            code = document.forms[0].elements[ i ].name.substring(5);
          incookiesCQ = "code=" + code + "quant=" + totb;
          key = 'true';
          }


        if( ( document.forms[0].elements[ i ].name.substring( 0, 3 ) == "pr-" ) &&
            ( document.forms[0].elements[ i ].value) > 0  && key == "true")
          {                 price = Math.round(document.forms[0].elements[ i ].value*100)/100;
          incookiesP = "price=" + price;
          key = 'true';
          }


        if( ( document.forms[0].elements[ i ].name.substring( 0, 5 ) == "from-" ) &&
            ( document.forms[0].elements[ i ].value) != ""  && key == "true")
          {                 from = document.forms[0].elements[ i ].value;
          incookiesF = "from=" + from + ":";
          key = 'false';
          }


        if( document.forms[0].elements[ i ].name.substring( 0, 4 ) == "del-") 
            { 
             if (document.forms[0].elements[ i ].checked == false)
            incookies=incookies + incookiesCQ + incookiesP + incookiesF;
            incookiesCQ="";
            incookiesP=""; 
            incookiesF="diamail";
            }



  }

 AddCookie ('order',incookies,1000);
 this.location.reload();

 if (window.opener) { 
  if( window.opener.name == 'header' && window.opener.closed == false && tmp == null) {
  window.open('../top.htm','header');
  }
 }

}


function clearbasket(tmp) {
 if (confirm("Очистить корзину?")) {
  AddCookie ("order",' ', -1);
  this.location.reload();

  if (window.opener) { 
   if (window.opener.name == 'header' && window.opener.closed == false && tmp == null) {
   window.open('../top.htm','header');
   }
  }
 }
}

function clearbasket2() {
AddCookie ("order",' ', -1);
}


function RegButtonShow(){
document.all.label1.innerHTML = '';
document.all.label2.innerHTML = '';
document.all.label1.innerHTML = '<p align=center><span style="font-size:11px;color:#600000" title="Для оформления заказа нажмите кнопку &laquo;Оформить заказ&raquo;"><b>Книга добавлена в корзину</b></span> <p><table width=135 border=0 cellspacing="0" cellpadding="0"><tr><td background="mb.gif" width=10><img src="mu.gif" width=10 height=27 vspace=0 hspace=0></td><td background="mb.gif" width=125><a onmouseover=\'window.status="Перейти к оформлению заказа";return true\' onmouseout=\'window.status="";return true\' title="Перейти к оформлению заказа" href="cgi-bin/register.cgi"><b><font color="#CC0000"><nobr>Оформить заказ</nobr></font></b></a></td></tr></table>';
document.all.label2.innerHTML = '<p><font color="#600000"><b>Книга в корзине. Для оформления заказа нажмите кнопку &laquo;Оформить заказ&raquo; под избражением обложки.</b></font>';
}

function DelCookie(){

if (confirm("Удалить куки-файл? Будет потеряна сохраненная на Вашем ПК информация о заказе и заказчике!")) {
AddCookie("FIO",' ', -1);
if (document.getElementById('Firm') != null) {AddCookie ("Firm",' ', -1);}
AddCookie ("Index",' ', -1);
AddCookie ("City",' ', -1);
AddCookie ("Address",' ', -1);
AddCookie ("Code",' ', -1);
AddCookie ("Phone",' ', -1);
AddCookie ("Cellphone",' ', -1);
AddCookie ("Fax",' ', -1);
AddCookie ("Email",' ', -1);
AddCookie ("FIO",' ', -1);
AddCookie ("Transfer",' ', -1);
AddCookie ("order",' ', -1);
alert('Файл \"куки\" удален!');
}

}




function SwitchImg (imgname, width) {
if (imgname != ""){
var width=width+0;

var imgsrc=document.images[imgname].src;
var imgalt=document.images[imgname].alt;
var imgtitle=document.images[imgname].title;

  if (imgsrc.indexOf("/big/",0)<0) {
//обычное изображение - увеличить
   var imgsrcnew=imgsrc.replace(/bimages\//,"bimages/big/");  
   var imgaltnew=imgalt.replace(/увеличить/,"уменьшить");  
   var imgtitlenew=imgtitle.replace(/увеличить/,"уменьшить");  
   document.images[imgname].width=width;
  }

  else {
//увеличенное изображение - уменьшить
   var imgsrcnew=imgsrc.replace(/bimages\/big\//,"bimages/");  
   var imgaltnew=imgalt.replace(/уменьшить/,"увеличить");  
   var imgtitlenew=imgtitle.replace(/уменьшить/,"увеличить");  
   document.images[imgname].width=150;
  }


   document.images[imgname].src=imgsrcnew;
   document.images[imgname].alt=imgaltnew;
   document.images[imgname].title=imgtitlenew;

}
}
