
/* Begin TC Popup */
var newwindow;

function PopUp(url) {
	newwindow=window.open(url,'name','height=400,width=850,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
/* End TC Popup */

/* Begin Invoice Auto Fill */
var InvoiceName="";
var InvoiceAdd1="";
var InvoiceAdd2="";
var InvoiceCity="";
var InvoiceState="";
var InvoiceZip="";

function InitSaveVariables(form) {
	InvoiceName = form.InvoiceName.value;
	InvoiceAdd1 = form.InvoiceAdd1.value;
	InvoiceAdd2 = form.InvoiceAdd2.value;
	InvoiceCity = form.InvoiceCity.value;
	InvoiceState = form.InvoiceState.value;
	InvoiceZip = form.InvoiceZip.value;
}

function InvoiceToShip(form) {
	if(form.copy.checked) {
		InitSaveVariables(form);
		form.InvoiceName.value = form.ShipName.value;
		form.InvoiceAdd1.value = form.ShipAdd1.value;
		form.InvoiceAdd2.value = form.ShipAdd2.value;
		form.InvoiceCity.value = form.ShipCity.value;
		form.InvoiceState.value = form.ShipState.value;
		form.InvoiceZip.value = form.ShipZip.value;
	}  else {
		form.InvoiceName.value = InvoiceName;
		form.InvoiceAdd1.value = InvoiceAdd1;
		form.InvoiceAdd2.value = InvoiceAdd2;
		form.InvoiceCity.value = InvoiceCity;
		form.InvoiceState.value = InvoiceState;
		form.InvoiceZip.value = InvoiceZip;
	}
}
/* End Invoice Auto Fill */

/* Begin Item Description Auto Fill */
var item = new Array();
item[0] = ""; 															/* Default and Subheadings */
item[1] = "Reader device for 16-channel sensor chips."; 				/* Cyrus Chip Reader */
item[2] = "Full-featured Potentiostat for electrochemical detection."; 	/* Athena Chip Reader */
item[3] = "Modular robotic system. Automatic incubation."; 				/* Proteus Robotic System */
item[4] = "Multi-channel microfluidics cartidge system.";				/* Asklepios Cartridge System */
item[5] = "Bare Au Surface Chips (5 per order)"; 						/* Sensor Chip SC1000-16-B */
item[6] = "Low Density MH Coated Chips (5 per order)"; 					/* Sensor Chip SC1000-16-L */

function ItemChoice1(form) {
	form.desc1.value = item[form.item1.value];	
}
function ItemChoice2(form) {
	form.desc2.value = item[form.item2.value];	
}
function ItemChoice3(form) {
	form.desc3.value = item[form.item3.value];	
}
/* End Item Description Auto Fill */

function CheckForm() {
   var cphone, cShipAdd1, cShipCity, cShipState, cShipZip, cInvoiceAdd1, cInvoiceCity, cInvoiceState, cInvoiceZip;
   
   with(window.document.form) {
		cphone = phone;
		cemail = email;
		cShipAdd1 = ShipAdd1;
		cShipCity = ShipCity;
		cShipState = ShipState;
		cShipZip  = ShipZip;
        cInvoiceAdd1 = InvoiceAdd1;
		cInvoiceCity = InvoiceCity;
		cInvoiceState = InvoiceState;
		cInvoiceZip = InvoiceZip;
   }

   if(trim(cphone.value) == '') {
      alert('Please enter your phone number.');
      cphone.focus();
      return false;
   }
   else if(trim(cemail.value) == '') {
      alert('Please enter your email.');
      cemail.focus();
      return false;
   }  else if(!isEmail(trim(cemail.value))){
	  alert('Email address is not valid.');
	  cemail.focus();
	  return false;
   }
   else if(trim(cShipAdd1.value) == '') {
      alert('Please enter your ship address.');
      cShipAdd1.focus();
      return false;
   }
   else if(trim(cShipCity.value) == '') {
      alert('Please enter your ship city.');
      cShipCity.focus();
      return false;
   }
   else if(trim(cShipState.value) == '') {
      alert('Please enter your ship state.');
      cShipState.focus();
      return false;
   }
   else if(trim(cShipZip.value) == '') {
      alert('Please enter your ship zip.');
      cShipZip.focus();
      return false;
   }
   else if(trim(cInvoiceAdd1.value) == '') {
      alert('Please enter your invoice address.');
      cInvoiceAdd1.focus();
      return false;
   }
   else if(trim(cInvoiceCity.value) == '') {
      alert('Please enter your invoice city.');
      cInvoiceCity.focus();
      return false;
   }
   else if(trim(cInvoiceState.value) == '') {
      alert('Please enter your invoice state.');
      cInvoiceState.focus();
      return false;
   }
   else if(trim(cInvoiceZip.value) == '') {
      alert('Please enter your invoice zip.');
      cInvoiceZip.focus();
      return false;
   }
   else if(window.document.form.tcagreement.checked == false) {
      alert('You must agree to the Terms & Conditions and check the box to submit a request.');
	  return false;
   }
   else{
      cphone.value = trim(cphone.value);  
	  cemail.value = trim(cemail.value);
	  cShipAdd1.value = trim(cShipAdd1.value);
	  cShipCity.value = trim(cShipCity.value);
	  cShipState.value = trim(cShipState.value);
	  cShipZip.value = trim(cShipZip.value);
	  cInvoiceAdd1.value = trim(cInvoiceAdd1.value);
	  cInvoiceCity.value = trim(cInvoiceCity.value);
	  cInvoiceState.value = trim(cInvoiceState.value);
	  cInvoiceZip.value = trim(cInvoiceZip.value);
      return true;
   }
}

function trim(str) {
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str) {
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   return regex.test(str);
}
