function checkMail(s){
// var emailFilter=/^.+@.+\..{2,3,4,5,6}$/;
 var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
 var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;

 if (s.match(illegalChars)){
  window.alert("The email address contains illegal characters.\n");
  return false;
 }
 else if (!(emailFilter.test(s))) { 
  window.alert("Can\'t use "+s+".\nPlease enter a valid email address.\n");
  return false;
 }
 else
  return true;
}

function checkText(field){
 var error="";
 if (field.value==error){
  window.alert(field.name+" is blank.\n\nPlease enter a value for "+field.name+".");
  field.focus();
  return false;
 }
 else
  return true;
}

function getHtm(location,docId,src){
 document.getElementById(docId).src="http://activmarks.com/getpage.php?page="+location+"/"+src+".htm";
 return true;
}

function showWindow(hwnd,url,x,y,resize) {
 if(url == null) { 
 url = "/help/general/";
 } 
 if(x==null || y==null){
 x = 620;
 y = 300;
 } 
 if (resize==null)
  resize="yes";
 var str = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable="+resize+",left=0,top=0,width="+x+",height="+y; 
 win = window.open(url,hwnd,str);
  this.win.focus();
 return true;
}

function dateTime(){
 today = new Date();
 now = today.getHours()+":"+today.getMinutes()+":"+today.getSeconds();
 return today+" "+now;
}

function costOf(v1,v2){
 var v=Math.round(v1); 

 if (isNaN(v)) 
   v1=1; 
 else 
   v1=v; 

 v=v1*v2; 

 return(v.toFixed(2));
}

function getBookCost(doc){
 var v=1.0;

 if (1.00*doc.qty.value>1.00*doc.qtybreak4.value)
  v=1.00*doc.pricebreak4.value;
 else if (1.00*doc.qty.value>1.00*doc.qtybreak3.value)
  v=1.00*doc.pricebreak3.value;
 else if (1.00*doc.qty.value>1.00*doc.qtybreak2.value)
  v=1.00*doc.pricebreak2.value;
 else if (1.00*doc.qty.value>1.00*doc.qtybreak1.value)
  v=1.00*doc.pricebreak1.value;
 else
  v=1.00*doc.basecost.value;

 if (1.00*v<1.00*doc.basecost.value){
  var d=Math.round(100.00*(1.00-(v/(1.00*doc.basecost.value))));
  doc.discounts.value="<p>&nbsp;&nbsp;&nbsp;<font face=\"Verdana\" size=\"2\"><b>Note</b>: Unit Cost shown reflects a "+d.toFixed(0)+"% discount.</p></font>";
 }

 return(v);
}

function inState(stateString,s1,s2){
 var s=stateString.toLowerCase();

 s1=s1.toLowerCase();
 s2=" "+s2.toLowerCase();
// window.alert(stateString+'-'+s+'-'+s1+'-'+s2);

 return((s.indexOf(s1)>0)||(s.indexOf(s2)>0));
}

function toDecimal(value,fix){
 var v=1.00*value;
 return(v.toFixed(fix));
}

function trackDownload(filename){
 return("http://www.aasdt.com/cgi-bin/track/download.cgi?"+filename);
}
