// Javascript functions for use throughout Alnpete Press website
// 

function AP_insertyear() { //v1.0
var today = new Date();
var year  = today.getFullYear() - 2000;
document.write('-' + year);
}

function AP_MAddress(Erecip) { //v1.0
  wibble=Erecip;
  wibble=(wibble + '&#064;');
  wibble=(wibble + 'alnpetepress.co.uk');
  wobble='a href="mai';
  document.write('<' + wobble + 'lto:' + wibble + '" class="link">' + wibble + '</a>');
}

function AP_CalculateField(price,qty,cost) { //v1.0 (c)1998 Alnpete - all rights reserved
  var field,theNum,errors='';
    field = eval(qty);
    field.name = (field.name)?field.name:qty;
    if (field.value) { //If not an empty field
        theNum = parseInt(field.value);
        if (field.value != ''+theNum) errors += '- quantity must contain a whole number.\n';
       }
     else qty.value = "0";  // else empty so make zero
    if (errors) {alert('The cost cannot be calculated due to the following error(s):\n'+
                    errors+'\nPlease make changes to the value.');
               cost.value = "";
               }
  else { // All okay so calculate
        cost.value = eval(price.value +'*'+ qty.value); 
        AP_CalculateTotal();
		}
  document.MM_returnValue = (errors == '')
}

function AP_CalculateTotal() { //v1.3 (c)1998,2007 Alnpete - all rights reserved
  var fldStr,fldStrq,fldStrp,fldStra,fldStrh,runTot='0';
// Subtotal
  fldStr = 'document.orderform.LotSprice.value';
  if (eval(fldStr) != "") runTot += '+'+eval(fldStr);
  fldStr = 'document.orderform.DSprice.value';
  if (eval(fldStr) != "") runTot += '+'+eval(fldStr);
  fldStr = 'document.orderform.AEprice.value';
  if (eval(fldStr) != "") runTot += '+'+eval(fldStr);
  document.orderform.subtotal.value = eval(runTot);
// P and p
  runTot='0';
  fldStrq = 'document.orderform.LotSqty.value';
  fldStrp = 'document.orderform.LotSpp.value';
  fldStra = 'document.orderform.LotSppadd.value';
  if (eval(fldStrq) != "0") 
     {runTot += '+'+eval(fldStrp);
      runTot += '+'+eval(fldStrq +'*'+ fldStra);}
  fldStrq = 'document.orderform.DSqty.value';
  fldStrp = 'document.orderform.DSpp.value';
  fldStra = 'document.orderform.DSppadd.value';
  if (eval(fldStrq) != "0") 
     {runTot += '+'+eval(fldStrp);
      runTot += '+'+eval(fldStrq +'*'+ fldStra);}
  fldStrq = 'document.orderform.AEqty.value';
  fldStrp = 'document.orderform.AEpp.value';
  fldStra = 'document.orderform.AEppadd.value';
  if (eval(fldStrq) != "0") 
     {runTot += '+'+eval(fldStrp);
      runTot += '+'+eval(fldStrq +'*'+ fldStra);}
  fldStrh = 'document.orderform.handling.value';
  if (eval(runTot) != "0") runTot += '+'+eval(fldStrh);
  document.orderform.PP.value = eval(runTot);
// Total
  runTot='0';
  fldStr = 'document.orderform.subtotal.value';
  if (eval(fldStr) != "") runTot += '+'+eval(fldStr);
  fldStr = 'document.orderform.PP.value';
  if (eval(fldStr) != "") runTot += '+'+eval(fldStr);
  document.orderform.total.value = eval(runTot);
}

function AP_MakeVisibleCQ(trigger,divhid) { //v1.0 (c)2007 Alnpete - all rights reserved
  if (trigger.value == "Yes") divhid.type = "text"
  else divhid.type = "hidden";
}

function AP_MakeInitCQ() { //v1.1 (c)2007 Alnpete - all rights reserved
  AP_MakeVisibleCQ(document.orderform.LotSos0,document.orderform.LotSos1);
  AP_MakeVisibleCQ(document.orderform.DSos0,document.orderform.DSos1);
  AP_MakeVisibleCQ(document.orderform.AEos0,document.orderform.AEos1);
}

function AP_MakeVisibleCC(trigger,divhid,divname) { //v1.0 (c)2007 Alnpete - all rights reserved
  if (trigger.value == "Signed") {divhid.type = "text";divhid.value = "Name to be included in message";divname.value = "Signed to"}
  else {divhid.type = "hidden";divhid.value = "";divname.value = ""}
}
function AP_MakeInitCC() { //v1.0 (c)2007 Alnpete - all rights reserved
  AP_MakeVisibleCC(document.LotSform.os2,document.LotSform.os1,document.LotSform.on1);
  AP_MakeVisibleCC(document.DSform.os2,document.DSform.os1,document.DSform.on1);
  AP_MakeVisibleCC(document.AEform.os2,document.AEform.os1,document.AEform.on1);
  AP_MakeVisibleCC(document.CdVform.os2,document.CdVform.os1,document.CdVform.on1);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}