// function to pop up a separate window
function popUp(aURL, aName, aSpec) {
		open(aURL, aName, aSpec);
	}

// function to check invalid characters
function invChar(aValue) {
	invalidChars = " /:,;";
	for (i = 0; i < invalidChars.length; i++) {
		badChar = invalidChars.charAt(i);
		if (aValue.indexOf(badChar,0) > -1) {return false;}
	}
	return true;
}

// function to check blanks (less than 2 chars)
function blankCheck(aValue) {
	if (aValue.length < 2) {return false;}
	return true;
}

function verify() {
	if (!blankCheck(document.theForm.Your_Name.value)) {
		alert("Please enter your name");
		document.theForm.Your_Name.focus();
	} else if (!blankCheck(document.theForm.Telephone.value)) {
		alert("Please enter your phone number");
		document.theForm.Telephone.focus();
	} else if (!validEmail(document.theForm.Email.value)) {
		alert("Please enter your valid email");
		document.theForm.Email.focus();
		document.theForm.Email.select();
	} else if (!blankCheck(document.theForm.Comments.value)) {
		alert("Please enter your comment");
		document.theForm.Comments.focus();
	} else {
		document.theForm.action = "/cgi/gdform.cgi";
		document.theForm.submit();
	}
}
		
// function to validate serial number type
function validSNType(snType) {
	if (snType == "0") {return false;}
	return true;
}

// function to validate serial number
function validSN(sn) {
	// checking for an invalid character
	if (!invChar(sn)) {return false;}
	
	// checking for non empty field
	if (sn.length < 11) {return false;}
	if (sn.length == 11) {
		for (i=0; i<11; i++) {if (sn.charAt(i) == "-") {return false;}}
		// putting sn into the proper form
		newSN = "";
		for (i = 0; i < 12; i++) {
			if (i==4) {newSN = newSN + "-";}
			newSN = newSN + sn.charAt(i);
		}
		document.theForm.SN.value = newSN;
	} else {
		// the length is 12 so checking the dashes
		if (sn.charAt(4) == "-") {
			for (i=0; i<4; i++) {if (sn.charAt(i) == "-") {return false;}}
			for (i=5; i<12; i++) {if (sn.charAt(i) == "-") {return false;}}
		} else {return false;}
	}
	return true;
}

// checking for valid email
function validEmail(email) {
	// checking for an invalid character
	if (!invChar(email)) {return false;}
		
	atPos = email.indexOf("@", 1);
	if (atPos == -1) {return false;}
	if (email.indexOf("@", atPos+1) > -1) {return false;}
	
	periodPos = email.indexOf(".", atPos);
	if (periodPos == -1) {return false;}
	if (periodPos + 3 > email.length) {return false;}
	
	return true;
}

// checking for valid phone number
function validPhone(phone) {
	var valid = "0123456789-";
	if (phone.length == 0) {return false;}
	for (i=0; i < phone.length; i++) {
		if (valid.indexOf(phone.charAt(i)) == "-1") {return false;}
	}
	return true;
}

// checking for valid date
function validDate(aDate) {
	if (aDate.length <8) {return false;}
	if (aDate.length == 9) {return false;}
	valid = "0123456789/"
	// checking for invalid characters
	for (i=0; i<aDate.length; i++) {if (valid.indexOf(aDate.charAt(i)) == "-1") {return false;}}
	valid = "0123456789"
	if (aDate.length == 10) {
		for (i=0; i<2; i++) {if (valid.indexOf(aDate.charAt(i)) == "-1") {return false;}}
		for (i=3; i<5; i++) {if (valid.indexOf(aDate.charAt(i)) == "-1") {return false;}}
		for (i=6; i<9; i++) {if (valid.indexOf(aDate.charAt(i)) == "-1") {return false;}}
	} else {
		newDate = "";
		for (i=0; i<8; i++) {
			if ((i==2) || (i==4)) {newDate += "/";}
			newDate += aDate.charAt(i);
		}
		document.theForm.DatePurch.value = newDate;
	}
	return true;
}

var objWin;
function ShowHelp(bolWin) {
  if(!objWin == null) objWin.close();
  objWin = window.open('orderhelp.asp?js=1', 'newindow', 'scrollbars=yes,resizable=no,toolbar=no,menubar=no,location=no,status=no,width=450,height=300');
  objWin.focus();
}
function ShowCID() {
  if(!objWin == null) objWin.close();
  objWin = window.open('/scripts/content/shophelp/cid.asp?js=1', '_blank', 'scrollbars=yes,resizable=no,toolbar=no,menubar=no,location=no,status=no,width=550,height=300');
  objWin.focus();
}
function ShowOptIn() {
  if(!objWin == null) objWin.close();
  objWin =  window.open('/scripts/content/shophelp/optin.asp?js=1', '_blank', 'scrollbars=yes,resizable=no,toolbar=no,menubar=no,location=no,status=no,width=550,height=300');
  objWin.focus();
}
function GoShipFAQ(bolWin) {
  if(!objWin == null) objWin.close();
  objWin = window.open('/scripts/content/shipping/shipping_FAQ.asp?js=1', 'newindow', 'scrollbars=yes,resizable=no,toolbar=no,menubar=no,location=no,status=no,width=450,height=300');
  objWin.focus();
}
function DropShipTo(itemNum,manufName,prodtName,ptID){
  var strURL;
  strURL = "/scripts/dropshippop.asp?id=" + itemNum + "&manufName=" + manufName + "&prodtName=" + prodtName + "&ptID=" + ptID;
  if(!objWin == null) objWin.close();
  objWin = window.open(strURL,"newwindow","scrollbars=yes,toolbar=no,menubar=no,location=no,status=no,width=500,height=300");
  objWin.focus();
}
function SetChangeMade() {
  document.frmOrder.hdnChangeMade.value = 1;
}
function ClearShipTo(){
    document.frmOrder.txtShipFirstName.value        = "";
    document.frmOrder.txtShipMiddleName.value       = "";
    document.frmOrder.txtShipLastName.value         = "";
    document.frmOrder.txtShipCompany.value          = "";
    document.frmOrder.txtShipAttnTo.value           = "";
    document.frmOrder.txtShipAddr1.value            = "";
    document.frmOrder.txtShipAddr2.value            = "";
    document.frmOrder.txtShipCity.value             = "";
	 document.frmOrder.lstShipToState.value          = "";
	 document.frmOrder.lstShipToState.selectedIndex  = 0;
	 document.frmOrder.lstShipToCountry.selectedIndex  = 0;
	 document.frmOrder.txtShipZip.value              = "";
	 document.frmOrder.txtShipZip4.value             = "";
//    document.frmOrder.txtShipToIntlPhoneNo.value    = "";
}
function ClearBillTo(){
	 document.frmOrder.txtFirstName.value          = "";
	 document.frmOrder.txtMiddleName.value         = "";
	 document.frmOrder.txtLastName.value           = "";
	 document.frmOrder.txtCompany.value            = "";
	 document.frmOrder.txtAttnTo.value             = "";
	 document.frmOrder.txtAddr1.value              = "";
	 document.frmOrder.txtAddr2.value              = "";
	 document.frmOrder.txtCity.value               = "";
	 document.frmOrder.lstState.selectedIndex      = 0;
	 document.frmOrder.lstCountry.selectedIndex      = 0;
	 document.frmOrder.txtZip.value                = "";
	 document.frmOrder.txtZip4.value               = "";
//    document.frmOrder.txtPhone.value              = "";
}
function ClearShipToAddNum(){
	 document.frmOrder.hdnShipTo.value            = "";
}

function validateOrder(){

if(document.frmOrder.lstCreditCard.value ==""){alert('Please select a type of card.');return false}
if(document.frmOrder.lstCCMonth.value ==""){alert('Please give a complete expiration date for your card.');return false}
if(document.frmOrder.lstCCYear.value ==""){alert('Please give a complete expiration date for your card.');return false}
if(document.frmOrder.txtCCNumber.value ==""){alert('Please give us your credit card number.');return false}
if(document.frmOrder.txtCCCid.value ==""){alert('Please give us your card security code.');return false}
if(document.frmOrder.txtCompany.value ==""){alert('Please let us know your company name.');return false}
if(document.frmOrder.txtAttnTo.value ==""){alert('Please let us know to whose attention info will be sent.');return false}
if(document.frmOrder.txtFirstName.value ==""){alert('Please give us your first name.');return false}
if(document.frmOrder.txtLastName.value ==""){alert('Please give us your last name.');return false}
if(document.frmOrder.txtAddr1.value ==""){alert('Please give us your address.');return false}
if(document.frmOrder.txtZip.value ==""){alert('Please give us your zip code.');return false}
if(document.frmOrder.txtCity.value ==""){alert('Please let us know what city you are from.');v}
if(document.frmOrder.lstState.value ==""){alert('Please let us know what state you are from.');return false}
if(document.frmOrder.txtEmail.value ==""){alert('Please give us your email address.');return false}
}