function SetCookie(name, value, expiredays)
{
  var todayDate = new Date();
  todayDate.setDate(todayDate.getDate() + expiredays);
  document.cookie = name + "=" + value + "; expires=" +
                    todayDate.toGMTString() + "; path=/;" 
}


function saveptltools()
{
  var isimg,isimggrp,store,transit,order,srttp,qty;

  if(ptltools.needimg.checked)    isimg = "Y";    else isimg = "N";  
  if(ptltools.needimggrp.checked) isimggrp = "Y"; else isimggrp = "N";  
  if(ptltools.onstore.checked)    store = "Y";    else store = "N";
  if(ptltools.ontransit.checked)  transit = "Y";  else transit = "N";
  if(ptltools.onorder.checked)    order = "Y";    else order = "N";

  srttp = ptltools.srttp.value;
  qty = ptltools.qty.value;

  SetCookie("PSPISIMGGRP", isimggrp, 1000);
  SetCookie("PSPISIMG", isimg, 1000);
  SetCookie("PSPSTORE", store, 1000);
  SetCookie("PSPTRANSIT", transit, 1000);
  SetCookie("PSPORDER", order, 1000);
  SetCookie("PSPSRTTP", srttp, 1000);
  if(qty==0) SetCookie("PSPROWS",'', 1000);
  else       SetCookie("PSPROWS",qty, 1000);

  if (urlpage)
  {
    url = urlpage;
    url = url + "&prm=" + srttp + isimg + isimggrp + store + transit + order;
    if (qty!=0) url = url + qty;
    url = url.toLowerCase()
  }
  else
  {
    rnd = getRandom();
    url = window.location.href;
    if (url.indexOf("&seed=")>=0) url = url.substring(0,url.indexOf("&seed="));
    if (url.indexOf("&prm=")>=0) url = url.substring(0,url.indexOf("&prm="));
    url = url + "&prm=" + srttp + isimg + isimggrp + store + transit + order;
    if (qty!=0) url = url + qty;
    url = url + "&seed="+String(rnd);
    url = url.toLowerCase()
  }

  window.location = url;

}


function saveadress() 
{  
 SetCookie("PSPADR", escape(ptlshoporder.adress.value), 1000);
}


function saverows(qty)
{
  if(qty==0) SetCookie("PSPROWS",'', 1000);
  else       SetCookie("PSPROWS",qty, 1000);
  
  rnd = getRandom();

  url = document.ptltvtoolsp.urlback.value;
  if (url.indexOf("seed=")>=0) url = url.substring(0,url.indexOf("seed=")-1);
  if (url.indexOf("prm=")>=0)  { if (qty!=0) url = url + qty }
  url = url + "&seed="+String(rnd);
  url = url.toLowerCase()
  window.location = url;
}


function savesrttp(srttp, prmnosrt)
{
  SetCookie("PSPSRTTP", srttp, 1000);

  rnd = getRandom();

  url = document.ptltvtoolsp.urlsort.value;
  if (url.indexOf("seed=")>=0) url = url.substring(0,url.indexOf("seed=")-1);
  if (url.indexOf("?")>=0) url = url + "&prm="+srttp.toLowerCase()+prmnosrt;
  else url = url + "?prm="+srttp.toLowerCase()+prmnosrt;
  url = url + "&seed="+String(rnd);
  url = url.toLowerCase()
  window.location = url;
}


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))      
     }    
   }
}


