var browserVer=parseInt( navigator.appVersion );
var cookieval;
function totup( num )
{
  if( browserVer <= 2 ) return;
  qty=eval( "document.forms[0].Qty"+num+".value" );
  uct=eval( "document.forms[0].UVal"+num+".value" );
  tot=eval( "document.forms[0].STVal"+num);
  tot.value=qty*uct;
  fulltot();
}
function fulltot()
{
  if( browserVer <= 2 ) return;
  var vtot=0;
  var ptot=0;
  for(i=1;i<=8;i++)
  {
    v=parseInt( eval( "document.forms[0].STVal"+i+".value") );
    p=eval( "document.forms[0].Desc"+i+".value");
    q=parseInt(eval( "document.forms[0].Qty"+i+".value") );
    if( !isNaN( v ) ) vtot+=v;
    if( p != "" || !isNaN( v )  || !isNaN( q ) ) ptot+=q;
  }
  document.forms[0].TotVal.value=eval( vtot );
  document.forms[0].NumPcs.value=eval( ptot );
}
function getCookie(Name)
{
  var search = Name + "="
  if (0 < document.cookie.length)
  {
    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))
    } 
  }
  return "";
}
function setCookie(name, value, expire) {
  document.cookie = name + "=" + escape(value)
    + ((expire == null) ? "" : ("; expires=" + expire))
}
function form_sub( theform )
{
  sbcname=theform.SBCname.value;
  sbdept=theform.SBDept.value;
  sbaddr=theform.SBAddr.value;
  sbpcode=theform.SBPcode.value;
  sbcount=theform.SBCount.value;
  sbpnum=theform.SBPnum.value;
  sbvatnum=theform.SBVATnum.value;

  value="SBCname="+sbcname+"|"+
    "SBDept="+sbdept+"|"+
    "SBAddr="+sbaddr+"|"+
    "SBPcode="+sbpcode+"|"+
    "SBCount="+sbcount+"|"+
    "SBPnum="+sbpnum+"|"+
    "SBVATnum="+sbvatnum+"|";

  setCookie( "PROFORMA", value, "Friday, 31-Dec-99 23:59:59 GMT" );

  if( theform.newwin.checked == true )
  {
    win=window.open( "", "DHL_INVOICE", "directories=0,location=0,menubar=0,status=0,toolbar=1,scrollbars=1" );
    theform.target="DHL_INVOICE";
  }
}
function getBit( name )
{
  ind1=cookieval.indexOf( name+"=" );
  ind2=cookieval.indexOf( "|", ind1 );
  return cookieval.substring( ind1+name.length+1, ind2 );
}
function initForm()
{
  theform=document.forms[0];

  today = new Date();
  st=today.getDate()+"/"+(today.getMonth()+1)+"/"+today.getYear();
  theform.SgnDat.value=st;
  theform.PlcDat.value=st;

  cookieval=getCookie( "PROFORMA" );
  if( cookieval == "" ) return;

  theform.SBCname.value=getBit( "SBCname" );
  theform.SBDept.value=getBit( "SBDept" );
  theform.SBAddr.value=getBit( "SBAddr" );
  theform.SBPcode.value=getBit( "SBPcode" );
  theform.SBCount.value=getBit( "SBCount" );
  theform.SBPnum.value=getBit( "SBPnum" );
  theform.SBVATnum.value=getBit( "SBVATnum" );
}

