function addCookie(szName,szValue,dtDaysExpires) {
 var dtExpires = new Date();
 var dtExpiryDate = "";
 dtExpires.setTime(dtExpires.getTime() + dtDaysExpires * 24 * 60 * 60 * 1000);
 dtExpiryDate = dtExpires.toGMTString();
 document.cookie = szName + "=" + szValue + "; expires=" + dtExpiryDate;
}

function findCookie(szName) {
 var i = 0;
 var nStartPosition = 0;
 var nEndPosition = 0;  
 var szCookieString = document.cookie;  
 while (i <= szCookieString.length) {
   nStartPosition = i;
   nEndPosition = nStartPosition + szName.length;
   if (szCookieString.substring(nStartPosition,nEndPosition) == szName) {
     nStartPosition = nEndPosition + 1;
     nEndPosition = document.cookie.indexOf(";",nStartPosition);
     if (nEndPosition < nStartPosition) {
       nEndPosition = document.cookie.length;
     }
     return document.cookie.substring(nStartPosition,nEndPosition);  
     break;    
   }
   i++;  
 }
 return "";
}

function mouseout(obj) {
  obj.style.backgroundColor='#FFFFFF';
}

function mouseover(obj,type) {
  obj.style.backgroundColor='#FFF8D0';
}

function validatesearch(){
 if (document.search.apt18search.value.length == 0 ||
     document.search.apt18search.value.replace(/ /gi,"").length < 3) {
  alert("Введите не менее 3-х символов!");
  document.search.apt18search.select();
  return false;
 }
}

function validatesubmit()
{
 if (document.formorder.ordername.value.length == 0 || 
     document.formorder.orderphone.value.length == 0 ||
     document.formorder.orderaddress.value.length == 0) {
  alert("Необходимо заполнить все поля помеченные звездочкой!");
  return false;
 }
 addCookie("ordername", document.formorder.ordername.value, 30);     
 addCookie("orderphone", document.formorder.orderphone.value, 30);
 addCookie("ordermail", document.formorder.ordermail.value, 30); 
 addCookie("orderaddress", document.formorder.orderaddress.value, 30);
}

function loadfield() {
 document.formorder.ordername.value=findCookie("ordername");
 document.formorder.orderphone.value=findCookie("orderphone");
 document.formorder.ordermail.value=findCookie("ordermail");
 document.formorder.orderaddress.value=findCookie("orderaddress");
}  
