var scrW;
var scrH;
scrW = screen.width / 2;
scrH = screen.height / 2;
/* ------------------------------------------------------------------------ */
/* [[[[[[[[[[[[[[[[[[[[[[[[[[[[  OKAY TO EDIT  ]]]]]]]]]]]]]]]]]]]]]]]]]]]] */
/* ------------------------------------------------------------------------ */

/* ----------------- Global Functions below --------------------------------------*/
/*--------------------------------------------------------------------------*/


function stripCharsInBag(str) {
	var chars = "()- ."
	var i;
	var returnString = "";

	for (i = 0; i < str.length; i++) {
		// Check that current character isn't whitespace.
		var c = str.charAt(i);
		if (chars.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

//------ phone number checking functions below ------------
function CheckPhoneNumber(TheNumber,vlength) {
	var valid = 1;
	var GoodChars = "0123456789().-+ "
	var i = 0;
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0;
	}
	if (stripCharsInBag(TheNumber).length != vlength) {
		//Return false if length in not correct
		valid = 0;
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
		// alert(TheNumber.charAt(i) + " is no good.")
			valid = 0;
		} // End if statement
	} // End for loop
	return valid;
}

function PhoneCheck(theField, validLength) {
	fData = theField.value;
	if(!CheckPhoneNumber(fData,validLength)) {
			alert("This phone field must be a 10 digit U.S. phone number (like 415.555.1212 or 4155551212).\n Please check it for accuracy.");
			theField.focus();
			return false;
	}
	else {
		if(validLength == 10) {
			theField.value = reformatUSPhone(stripCharsInBag(fData))
			return true;
		}
		else { 
				return true; 
		}
	}
}


function PhoneCheckSeven(theField, validLength) {
	fData = theField.value;
	if(fData != '') {
	if(!CheckPhoneNumber(fData,validLength)) {
			alert("This phone field must be a 7 digit U.S. phone number (like 555.1212 or 555-1212).\n Please check it for accuracy.");
			theField.focus();
			return false;
	}
	else {
		if(validLength == 7) {
			theField.value = reformatSevenDigitPhone(stripCharsInBag(fData))
			return true;
		}
		else { 
				return true; 
		}
	}
	}
}

// - - - - - - Change display format of the variable - - - - - -
function reformatUSPhone(USPhone) {
	return (reformat(USPhone, "(", 3, ") ", 3, "-", 4))
}

// - - - - - - Change display format of the variable - - - - - -
function reformatSevenDigitPhone(vcPhone) {
	return (reformat(vcPhone,"",3,"-",4))
}


function reformat(s) {
	var arg;
	var sPos = 0;
	var resultString = "";
	for (var i = 1; i < reformat.arguments.length; i++) {
		arg = reformat.arguments[i];

		if (i % 2 == 1)
			resultString += arg;
		else {
			resultString += s.substring(sPos, sPos + arg);
			sPos += arg;
		}
	}
	return resultString;
}
//----------------------------
//checks the proposed email name for illegal chars
function checkEname(name) {
	// are regular expressions supported?
	testStr = name;
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) 
			supported = 1;
	}
	if (supported) {
		validEname = new RegExp("([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}");
		return validEname.test(testStr);
	}
}
	
//-------------- email verification -------------------------
function verifyEmail(element){
	if(element.value!=""){
		var currentState = true;
		var newState = !isEmail(element.value);
		if (newState == currentState){
			alert("Please enter a valid email address.");
			element.focus();
			element.select();
			return false;
		}
	}
	}

function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
	}

function checkNumInput(element) {
	if (isNaN(element.value) == true){
		alert("Please enter only numbers.");
		element.focus();
		}
	}
//--------zip formater ----------------
function regExpSupported(){
	var supported = false;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = true;
	}
	return(supported);
}
function stripZip(element){
	if(regExpSupported){
		var r1,re1;
		var ss=element.value;
//		re1=/\D/g;
		re1=new RegExp("[^0-9]","g");
		r1=ss.replace(re1,"");
		element.value=r1.substr(0,9);
	}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Script for the Residential Dialup sign up  page

function ResSignupForm(theForm) {
	var errMsg = '';
	if (theForm.vcFirstName.value == "")
		errMsg += "\n    - Your First Name";
	if (theForm.vcLastName.value == "")
		errMsg += "\n    - Your Last Name";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Your Address";
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Your Daytime Contact Number";
	if (theForm.service.options[theForm.service.options.selectedIndex].value == "")
		errMsg += "\n    - Your Desired Dial-up Service";
	if (theForm.vcSpeed.options[theForm.vcSpeed.options.selectedIndex].value == "")
		errMsg += "\n    - Your Desired Dial-up Billing";
	if (theForm.vcOS.options[theForm.vcOS.options.selectedIndex].value == "")
		errMsg += "\n    - Your Computer's Operating System";
	if (theForm.vcEmailPri1.value == "")
		errMsg += "\n    - Your Desired Primary Email Address with opusnet.com";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Your Zipcode";
	if (theForm.city.value == "")
		errMsg += "\n    - Your City";
	if (theForm.State.options[theForm.State.options.selectedIndex].value == -1)
		errMsg += "\n    - Your State";
	if (errMsg) {
		errMsg = "Please fill out the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} 
}
//---------------------------------------------------------------------------
// Script for the Residential DSL page

function accessForm(phoneVal, stateVal, type) {
	var destinate = ""
	if (phoneVal == "" || stateVal == "") {
		alert('Please select BOTH a phone carrier and state to continue');
	} else if (phoneVal == "a4" || stateVal == "b3") {
	 	destinate = type + "_dsl_sorry.asp";
	 } else if (phoneVal == "a2" && stateVal == "b2") {
	 	destinate = type + "_dsl_sorry.asp";
	} else if (phoneVal == "a5") {
	 	destinate = type + "_dsl_qwest.asp";
	} else if (phoneVal == "a1") {
		destinate = type + "_dsl_qwest.asp";
	} else if (phoneVal == "a2") {
		destinate = type + "_dsl_ctel.asp";
	} else if (phoneVal == "a3") {
		destinate = type + "_dsl_verizon.asp";
	}

	if (destinate != "") {
		location.href = destinate;
	}
}


// ------------------------------------------------------------------------------
// Script for the CTel Application Form Checking

function ctelForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Your address";
	if (theForm.vcCity.value == "")
		errMsg += "\n    - Your City";
	if (theForm.vcState.options[theForm.vcState.options.selectedIndex].value == -1)
		errMsg += "\n    - Your State";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Your Zipcode";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Your phone number for DSL service";
	if (!CheckPhoneNumber(theForm.vcPhone.value,7))
		errMsg += "\n    - Your phone number for DSL service is invalid";
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Your daytime contact number";
	if (!CheckPhoneNumber(theForm.vcContact.value,7))
		errMsg += "\n    - Your contact phone is invalid";
	if (theForm.vcOS.options[theForm.vcOS.options.selectedIndex].value == 0)
		errMsg += "\n    - Your computer's operating system";
	if (theForm.intRPID.options[theForm.intRPID.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired DSL plan";
	if (theForm.vcHardware.options[theForm.vcHardware.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired hardware";
	//if (theForm.vcBillOption.options[theForm.vcBillOption.options.selectedIndex].value == 0)
		//errMsg += "\n    - Your desired billing option";
	if (theForm.vcEmailPri1.value == "")
		errMsg += "\n    - Your desired primary email address with Opus";
	if (errMsg) {
		errMsg = "Please fill out the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}

// ------------------------------------------------------------------------------
// Script for the Qwest Application Form Checking

function qwestForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Your address";
	if (theForm.vcCity.value == "")
		errMsg += "\n    - Your City";
	if (theForm.vcState.options[theForm.vcState.options.selectedIndex].value == -1)
		errMsg += "\n    - Your State";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Your Zipcode";
	if (!theForm.rblStandAlone.checked){
		if (theForm.vcPhone.value == "")
			errMsg += "\n    - Your phone number for DSL service";
		if (!CheckPhoneNumber(theForm.vcPhone.value,7))
			errMsg += "\n    - Your phone number for DSL service is invalid";
	}
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Your daytime contact number";
	if (!CheckPhoneNumber(theForm.vcContact.value,7))
		errMsg += "\n    - Your contact phone is invalid";
	if (theForm.vcOS.options[theForm.vcOS.options.selectedIndex].value == 0)
		errMsg += "\n    - Your computer's operating system";
	if (theForm.intRPID.options[theForm.intRPID.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired DSL plan";
	if (theForm.vcHardware.options[theForm.vcHardware.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired hardware";
	if (theForm.vcDSL[1].checked && theForm.priorISP.value == 0)
		errMsg += "\n    - Please select your prior ISP";
	if (theForm.vcEmailPri1.value == "")
		errMsg += "\n    - Your desired primary email address with Opus";
	if (errMsg) {
		errMsg = "Please fill out or edit the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}

// ------------------------------------------------------------------------------
// Script for the Oregon Telecom Application Form Checking

function ortelecomForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcEmail.value == "")
		errMsg += "\n    - Your email address";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Your address";
	if (theForm.vcCity.value == "")
		errMsg += "\n    - Your City";
	if (theForm.vcState.options[theForm.vcState.options.selectedIndex].value == -1)
		errMsg += "\n    - Your State";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Your Zipcode";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Your phone number for DSL service";
	if (!CheckPhoneNumber(theForm.vcPhone.value,7))
		errMsg += "\n    - Your phone number for DSL service is invalid";
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Your daytime contact number";
	if (!CheckPhoneNumber(theForm.vcContact.value,7))
		errMsg += "\n    - Your contact phone is invalid";
	if (theForm.vcOS.options[theForm.vcOS.options.selectedIndex].value == 0)
		errMsg += "\n    - Your computer's operating system";
	if (theForm.vcInstall.options[theForm.vcInstall.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired installation option";
	if (theForm.intRPID.options[theForm.intRPID.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired DSL plan";
	if (theForm.vcHardware.options[theForm.vcHardware.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired hardware";
	if (theForm.vcDSL[1].checked && theForm.priorISP.value == 0)
		errMsg += "\n    - Please select your prior ISP";
	if (theForm.orContact[0].checked && theForm.orContactName.value == "")
		errMsg += "\n    - The Oregon Telecom contact, or check no to the contact question";
	if (errMsg) {
		errMsg = "Please fill out or edit the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}

// ------------------------------------------------------------------------------
// Script for the OTI Form Added around 2/2/2005 JPB

function OTIForm(theForm) {
	var errMsg = '';
	if (theForm.vcOrTeleContactName.value == "")
		errMsg += "\n    - Please enter Oregon Telecome contact name";
	/*if (theForm.vcOrTeleSalesName.value == "")
		errMsg += "\n    - Please enter Oregon Telecome sales name";*/
	if (theForm.vcOrTeleContactEmail.value == "")
		errMsg += "\n    - Please enter Oregon Telecome contact email address";
	/*if (theForm.vcOrTeleSalesEmail.value == "")
		errMsg += "\n    - Please enter Oregon Telecome sales email address";*/
	if (theForm.orSalesRep.options[theForm.orSalesRep.options.selectedIndex].value == -1)
		errMsg += "\n    - Select Oregon Telecom Sales Rep";
	if (theForm.orPartnerCode.options[theForm.orPartnerCode.options.selectedIndex].value == -1)
		errMsg += "\n    - Select Oregon Telecom Partner Code";
	if (theForm.vcFirstName.value == "")
		errMsg += "\n    - Customer First Name";
	if (theForm.vcLastName.value == "")
		errMsg += "\n    - Customer Last Name";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Customer Address";
	if (theForm.vcCity.value == "")
		errMsg += "\n    - Customer City";
	if (theForm.vcState.options[theForm.vcState.options.selectedIndex].value == -1)
		errMsg += "\n    - Customer State";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Customer Zipcode";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Customer phone number for DSL service";
	if (!CheckPhoneNumber(theForm.vcPhone.value,7))
		errMsg += "\n    - Customer phone number for DSL service is invalid";
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Customer daytime contact number";
	if (!CheckPhoneNumber(theForm.vcContact.value,7))
		errMsg += "\n    - Customer contact phone is invalid";
	if (theForm.intRPID.options[theForm.intRPID.options.selectedIndex].value == 0)
		errMsg += "\n    - Customer's DSL plan";
	if (theForm.vcDSL[1].checked && theForm.priorISP.value == 0)
		errMsg += "\n    - Please select customer's prior ISP";
	if (theForm.HostingMove.checked && theForm.Domain.value == "")
		errMsg += "\n    - The domain to be hosted.";
	if (theForm.HostingMove.checked && theForm.HostingPackage.options[theForm.HostingPackage.options.selectedIndex].value == "")
		errMsg += "\n    - Your desired Hosting plan.";	
	if (errMsg) {
		errMsg = "Please fill out or edit the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}


function hideShowDSLModem(element)
{
	if (element.checked)
	{
	var bi = document.getElementById("trDSLModem");

	bi.style.display = "";

	}
	else
	{
	var bi = document.getElementById("trDSLModem");

	bi.style.display = "none";

	}
}

function hideShowSA(element)
{
	if (element.checked)
	{
	var bi = document.getElementById("trShipAddress");

	bi.style.display = "";

	}
	else
	{
	var bi = document.getElementById("trShipAddress");

	bi.style.display = "none";

	}
}



function hideShowEM(element)
{
	if (element.checked)
	{
	var bi = document.getElementById("trEmailDomain");
	bi.style.display = "";


	}
	else
	{
	var bi = document.getElementById("trEmailDomain");
	bi.style.display = "none";


	}
}

function hideShowEMH()
{
	var bi = document.getElementById("HostingInfo");
	var cdInfo = document.getElementById("cdInfo");
	if (document.dslForm.EmailDomainName.options[document.dslForm.EmailDomainName.options.selectedIndex].value == "opusnet.com"){
		bi.style.display = "none";
		cdInfo.style.display = "none";
		}		
	else{
		bi.style.display = "";
		cdInfo.style.display = "";
		document.dslForm.HostingMove.checked = true;
		document.dslForm.Domain.focus();
		}	
}



function hideShowIPS(element)
{
	if (element.checked)
	{
	var bi = document.getElementById("trStaticIPs");

	bi.style.display = "";

	}
	else
	{
	var bi = document.getElementById("trStaticIPs");

	bi.style.display = "none";

	}
}

function hideShowEHO(element)
{
	if (element.checked)
	{
	var bi = document.getElementById("trEHO");

	bi.style.display = "";

	//var bi = document.getElementById("trEHO2");

	//bi.style.display = "inline";
	//var bi = document.getElementById("trEHO3");

	//bi.style.display = "inline";
	//var bi = document.getElementById("trEHO4");

	//bi.style.display = "inline";

	}
	else
	{
	var bi = document.getElementById("trEHO");

	bi.style.display = "none";
	//var bi = document.getElementById("trEHO2");

	//bi.style.display = "none";
	//var bi = document.getElementById("trEHO3");

	//bi.style.display = "none";
	//var bi = document.getElementById("trEHO4");

	//bi.style.display = "none";

	}
}


function hideShowHI(element)
{
	if (element.checked)
	{
		// show ta area
		enableHI();
	}
	else
	{
		// hide ta area
		disableHI();
	}
}

function enableHI(){
	var bi = document.getElementById("HostingInfo");

	bi.style.display = "";
}

function disableHI(){
	var bi = document.getElementById("HostingInfo");

	bi.style.display = "none";
}

function enableOISP(element){
	var bi = document.getElementById("ISPOther");
	if (document.dslForm.newISP.options[document.dslForm.newISP.options.selectedIndex].value == "Other"){
		bi.style.display = "";}
	else{
		bi.style.display = "none";}
}


function enableYSC(element){
	var bi = document.getElementById("YSCterms");
	if (document.dslForm.vcBillOption.options[document.dslForm.vcBillOption.options.selectedIndex].text == "1 Year"){
		bi.style.display = "";}
	else{
		bi.style.display = "none";}
}


// ------------------------------------------------------------------------------
// Script for the Verizon Application Form Checking

function verizonForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcAddress1.value == "")
		errMsg += "\n    - Your address";
	if (theForm.vcCity.value == "")
		errMsg += "\n    - Your City";
	if (theForm.vcState.options[theForm.vcState.options.selectedIndex].value == -1)
		errMsg += "\n    - Your State";
	if (theForm.zipcode.value.length < 5)
		errMsg += "\n    - Your Zipcode";
	if (!theForm.rblStandAlone.checked){
		if (theForm.vcPhone.value == "")
			errMsg += "\n    - Your phone number for DSL service";
		if (!CheckPhoneNumber(theForm.vcPhone.value,7))
			errMsg += "\n    - Your phone number for DSL service is invalid";
	}
	if (theForm.vcContact.value == "")
		errMsg += "\n    - Your daytime contact number";
	if (!CheckPhoneNumber(theForm.vcContact.value,7))
		errMsg += "\n    - Your contact phone is invalid";
	if (theForm.vcOS.options[theForm.vcOS.options.selectedIndex].value == 0)
		errMsg += "\n    - Your computer's operating system";
	if (theForm.intRPID.options[theForm.intRPID.options.selectedIndex].value == 0)
		errMsg += "\n    - Your desired DSL plan";
	//if (theForm.vcBillOption.options[theForm.vcBillOption.options.selectedIndex].value == 0)
		//errMsg += "\n    - Your desired billing option";
	if (theForm.vcEmailPri1.value == "")
		errMsg += "\n    - Your desired primary email address with Opus";
	if (errMsg) {
		errMsg = "Please fill out or edit the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}

// ------------------------------------------------------------------------------
// Script for the Verizon Application Form Checking

function dslQualForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your Full Name";
	if (theForm.vcEmail.value == "")
		errMsg += "\n    - Your Email address";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Your phone number for DSL service";
	if (!CheckPhoneNumber(theForm.vcPhone.value,7))
		errMsg += "\n    - Your phone number for DSL service is invalid";		
	if (errMsg) {
		errMsg = "Please fill out or edit the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}


// ------------------------------------------------------------------------------
// Script for the Contact Us Request Form Checking

function contactRequest(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcEmail.value == "")
		errMsg += "\n    - Your email address";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Your contact phone number";
	if (errMsg) {
		errMsg = "Please fill out the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return true;
	}
}

// ------------------------------------------------------------------------------
// Script for the Secure Payment Form Checking

function paymentForm(theForm) {
	var errMsg = '';
	if (theForm.vcName.value == "")
		errMsg += "\n    - Your name";
	if (theForm.vcPhone.value == "")
		errMsg += "\n    - Your Phone Number";
	if (theForm.vcShowMeTheMoney.value == "")
		errMsg += "\n    - Payment Amount";
	if (theForm.vcCCType.options[theForm.vcCCType.options.selectedIndex].value == "")
		errMsg += "\n    - Credit Card Type";
	if (theForm.vcCCExpMonth.value == "" || theForm.vcCCExpYear.value == "")
		errMsg += "\n    - Credit Card Expiration Date";

	var checkMyMessage = document.theForm.vcComments.value;
	var checkNum = checkMyMessage.length;
	if (checkNum > 250) {		
		errMsg += '\n    Comments are too long (' + checkNum + ')';
		errMsg += '\n      maximum length is 250 characters';
	}		
		
	if (errMsg) {
		errMsg = "Please fill out the following information before you continue:\n" + errMsg;
		alert (errMsg);
		return false;
	} else {
		return checkCredit();
	}
}

function checkCredit() {

	var errMsg = "";
	if (document.theForm.vcCCNum.value == "")
		errMsg += '\n   Please enter a credit card number';

	if (!errMsg) {
		var checkIt = validatecard(document.theForm.vcCCNum.value,document.theForm.vcCCType.options[document.theForm.vcCCType.selectedIndex].value);
		if (!checkIt) errMsg += '\n   Please enter a valid credit card number';
	}

	if (errMsg) {
		errMsg = 'Please complete the following before you continue:\n' + errMsg;
		alert(errMsg);
		return false;
	} else {
		return true;
	}
}

function validatecard (whoKnew,youKnew) {
	result = validatecardfunc(whoKnew,youKnew);
	if (result == true) {
		Num = stripNonNumbers(whoKnew);
		ret = cardcheck (Num)
		if (ret == "VALID") {
			return true;
		} else {
//			canSubmit[1] = "yes"
			return false;
		}
	} else {
//		canSubmit[1] = "yes"
		return false;
	}
}

function validatecardfunc (theyKnew,weKnew) {
	validcard = false;
	ret = stripNonNumbers (theyKnew);
	result = weKnew;
	if (result == "MasterCard") {
		if (ret.length == 16)
			validcard = true;
		if ((ret.substring (0, 2) >= "51") && ("56" > ret.substring (0, 2) ))
			validcard = true;
		else
			validcard = false;
	}
	if (result == "VISA") {
		if ((ret.length == 16)  || (ret.length ==13))
			validcard = true;
		if (ret.substring (0, 1) != "4")
			validcard = false;
	}
	if (result == "AMEX") {
		if (ret.length == 15)
			validcard = true;
		if ((ret.substring (0, 2) != "34") && (ret.substring (0, 2) != "37"))
			validcard = false;
	}
	if (result == "Discover") {
		if (ret.length == 16)
			validcard = true;
		if (ret.substring (0, 4) != "6011")
			validcard = false;
	}
	return (validcard);
}

function cardcheck (Num) {
	CardType=""
	mask = "2121212121212121"
	if (Num=="")  {
		CardType="BLANK"
		return (CardType)
	}
	if ( Num.length == 13 )
		Num = "000" + Num;
	else if ( Num.length == 14 )
		Num = "00" + Num;
	else if (Num.length == 15 )
		Num = "0" + Num;
	if (Num.length == 16)
		Num = Num;
	else
		CardType="INVALID" ;

	CheckSum = 0;
	for (count = 1; count<= 16; count++) {
		ProdVal = Num.charAt(count-1) * mask.charAt(count-1)
		if (ProdVal > 9)
			ProdVal = ProdVal - 9
		CheckSum = CheckSum + ProdVal
	}
	CheckSum = CheckSum % 10
	if (CheckSum != 0)
		CardType="INVALID"
	else
		CardType="VALID"
	return (CardType)
}

function stripNonNumbers (InString)  {
	OutString="";

	for (Count=0; InString.length >= Count; Count++)  {
		TempChar=InString.substring (Count, Count+1);
		Strip = false;
		CharString="0123456789";
		for (Countx = 0; CharString.length >= Countx; Countx++) {
			StripThis = CharString.substring(Countx, Countx+1)
			if (TempChar == StripThis) {
				Strip = true;
				break;
			}
		}
		if (Strip)
			OutString=OutString+TempChar;
	}
	return (OutString);
}

/* ------------------------------------------------------------------------ */
/* [[[[[[[[[[[[[[[[[[[[[[[[[[[[  DO NOT EDIT  ]]]]]]]]]]]]]]]]]]]]]]]]]]]]] */
/* ------------------------------------------------------------------------ */
// Script for the opening up any window

function newWin(URLVar,nameVar,winW,winH) {
	window.open(URLVar,nameVar,'width=' + winW + ',height=' + winH + ',top=' + (scrH-(winH/2)) + ',left='+ (scrW-(winW/2)) +',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}

// Global glossary popup function
function GlossaryPop(term) {
var winl = (screen.width-340)/2;
var wint = (screen.height-200)/2;
termsWin = window.open( term, "termswin", "status=0,toolbars=0,scrollbars=1,resizable=1,menubar=0,width=380,height=200,left="+winl+",top="+wint+"");
if(parseInt(navigator.appVersion) >= 4){termsWin.window.focus();}
}


/*------------------------------------------------------------------*/
/*      Functions to remember values in the Webmail login form      */
/*------------------------------------------------------------------*/

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var usr;
var pw;
var sv;

function getIngredients()
{
usr = document.Login.username;
pw = document.Login.password;
sv = document.Login.rememberMe;
	if (GetCookie('username') != null)
	{
		usr.value = GetCookie('username')
		pw.value = GetCookie('password')
		if (GetCookie('save') == 'true')
		{
			sv.checked = true;
		}
	}
}
function saveIngredients()
{
usr = document.Login.username;
pw = document.Login.password;
sv = document.Login.rememberMe;
	if (usr.value.length != 0 && pw.value.length != 0)
	{
		if (sv.checked)
		{
			expdate = new Date();
			expdate.setTime(expdate.getTime()+(365 * 18 * 60 * 60 * 1000));
			SetCookie('username', usr.value, expdate);
			SetCookie('password', pw.value, expdate);
			SetCookie('save', 'true', expdate);
		}
		else if (!sv.checked)
		{
			DeleteCookie('username');
			DeleteCookie('password');
			DeleteCookie('save');
		}
	}
		else
	{
		alert('You must enter a username/password.');
		return false;
	}
}

function rememberMessage() {
	alert("If you check the Remember Me option, your webmail login information will be stored" +
				" on your computer in a small, harmless file called a cookie, so that you will"+
				" not need to enter that information on your next visit.  You should check this" +
				" option ONLY IF this is your own private computer, or if you are logged into a" + 
				" shared computer with a secure user account. UNCHECKING this option will cause your login information" +
				" to NOT be saved (i.e. if you have previously saved your login it will remove the cookie). If you have trouble with this "+
				"feature, make sure your browser options are set to accept cookies.")
}


/*---------------- end Webmail login functions ------------*/
//-->