// WWW_file sign-up.js, Version , Updated 2009-03-10 11:13:15
function SetCursor() { document.signupform.users_X_usergivenname.focus() }
function checkInfo(thisForm) {
	var i;
	if ( ! checkNumChars(thisForm.suName.value.length,4,64,'Full Name') ) {return false}      //safe name
	if ( ! checkEmail(thisForm.suEmail)) {return false}
	if ( ! checkNumChars(thisForm.suPhone.value.length,10,18,'10-digit Phone Number') ) {return false}      //safe name
	return true;
}

function dupe (orig,fld) {
	var fldObj = document.getElementById(fld);
	if (fldObj.value.length < 2) {fldObj.value = orig.value}
}

function checkFreeSafe() {
	var i;
	// alert ("want to go on?");
	if ( ! checkNumChars(document.signupform.QB_company_name.value.length,4,64,'Company Name') ) {return false}   
	if ( ! checkNumChars(document.signupform.users_X_usergivenname.value.length,4,64,'Contact\'s Name') ) {return false}  
	if ( ! checkNumChars(document.signupform.QB_contact_title.value.length,4,64,'Contact\'s Title') ) {return false}      
	if ( ! checkEmail(document.signupform.QB_contact_email)) {return false}
	if ( ! checkNumChars(document.signupform.QB_contact_addr1.value.length,3,64,'Contact\'s Street Address for Contact') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.QB_contact_city.value.length,3,40,'Contact\'s City Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.QB_contact_state.value.length,2,40,'Contact\'s State or Province Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.QB_contact_zip.value.length,5,15,'Contact\'s Postal Code') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.QB_contact_phone.value.length,5,15,'Contact\'s Phone Number') ) {return false}      //safe name

	if (document.signupform.billing_info_X_billing_cardno.value.length < 15)  {alert ("Please enter a credit card number of 15 (Amex) or 16 (VISA, MC) digits."); return false}
	if (document.signupform.billing_info_X_billing_cardno.value == '000000000000000')  {alert ("Please enter a real credit card number."); return false}
	if (document.signupform.billing_info_X_billing_cardno.value == '0000000000000000')  {alert ("Please enter a real credit card number."); return false}
	if (checkLuhn(document.signupform.billing_info_X_billing_cardno.value) != 0) {alert ("The credit card number does not appear to be valid.  Please check."); return false}
	if (document.signupform.billing_info_X_billing_cardexpmo.value == 'month') {alert ("Please select a credit card expiration month."); return false}
	if (document.signupform.billing_info_X_billing_cardexpyr.value == 'year') {alert ("Please select a credit card expiration year."); return false}
	var index = document.signupform.billing_info_X_billing_cardexpmo.selectedIndex;
	var CCExMo = document.signupform.billing_info_X_billing_cardexpmo.options[index].value;
	index = document.signupform.billing_info_X_billing_cardexpyr.selectedIndex;
	var CCExYr = document.signupform.billing_info_X_billing_cardexpyr.options[index].value;
	var CurrDt = new Date();
	if (CCExYr < CurrDt.getFullYear() || (CCExYr == CurrDt.getFullYear() && CCExMo < CurrDt.getMonth()+1)) {
			alert("Please pick a credit card expiration date in the future."); return false;}
	if ( ! checkNumChars(document.signupform.billing_info_X_Account_billingname.value.length,4,64,'Billing Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_addr.value.length,3,64,'Street Address (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_city.value.length,3,40,'City Name (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_state.value.length,2,40,'State or Province Name (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_zip.value.length,5,15,'Postal Code (Zip, as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_amount.value.length,1,10,'Please enter at least one digit in the Billing Amt Field.') ) {return false}      //safe name


	if ( ! checkNumChars(document.signupform.account_info_X_Account_commonname.value.length,3,64,'Safe Long Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.account_info_X_Account_login_id.value.length,3,64,'Safe Short Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.account_info_X_Admin_userid.value.length,3,64,'User Account ID') ) {return false}  // user ID and Admin ID
	if ( ! checkNumChars(document.signupform.users_X_userpass.value.length,8,64,'User Account Password') ) {return false}  // user password and Admin password

	// if ( ! checkNumChars(document.signupform.billing_info_X_billing_cardccv.value.length,3,4,'CCV2 Number') ) {return false}  // user password and Admin password
	if ( ! checkEmail(document.signupform.users_X_emailaddr)) {return false}
	return true;
}

function checkNewSafe() {
	var i;
	if ( ! checkNumChars(document.signupform.users_X_usergivenname.value.length,4,64,'Full Name') ) {return false}      //safe name
	if ( ! checkEmail(document.signupform.users_X_emailaddr)) {return false}
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_addr.value.length,3,64,'Street Address (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_city.value.length,3,40,'City Name (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_state.value.length,2,40,'State or Province Name (as on credit card bill)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_zip.value.length,5,15,'Postal Code (Zip)') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.billing_info_X_billing_phone.value.length,10,18,'10-digit phone number') ) {return false}      //safe name

	if ( ! checkNumChars(document.signupform.account_info_X_Account_commonname.value.length,3,64,'Safe Long Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.account_info_X_Account_login_id.value.length,3,64,'Safe Short Name') ) {return false}      //safe name
	if ( ! checkNumChars(document.signupform.account_info_X_Admin_userid.value.length,3,64,'User Account ID') ) {return false}  // user ID and Admin ID
	if ( ! checkNumChars(document.signupform.users_X_userpass.value.length,8,64,'User Account Password') ) {return false}  // user password and Admin password

	return true;
}

function checkPhone(phone) {
	var phonum = phone.value;
	phonum = phonum.replace(/\D/g, "");
	if (phonum.length < 10) {alert ("Need 10-digit phone number.")}
}

function checkNumChars (sLength,low,high,fname) {
	if (sLength<low || sLength>high) {
		alert (fname + " must contain from " + low + " to " + high + " characters.");
		return false
	} else { return true }
}

 function checkLuhn(purportedCC) {
     var sum = 0;
     var nDigits = purportedCC.length;
     var parity = nDigits % 2;
     for (i=0; i<nDigits; i++) {
         var digit = purportedCC.substr(i,1) - 0;  // Subtract 0 to make number.  Don't use plus because it concatenates strings
         if ((i % 2) == parity) {digit = digit * 2}
         if (digit > 9) {digit = digit - 9}
         sum = sum + digit;
     }
     var retVal = (sum % 10);
     return retVal;
 }
function CCCheck(field) {
	var CCNbr = field.value;
	CCNbr = CCNbr.replace(/\D/g, "");
//  document.signupform.Ecom_Payment_Card_Number.value = CCNbr;
	document.signupform.billing_info_X_billing_cardno.value = CCNbr;
	var firstDigit = document.signupform.billing_info_X_billing_cardno.value.substr(0,1);
	if (firstDigit > 5 || firstDigit < 3) {alert ("Sorry, we only accept Visa, Mastercard, or American Express"); return false} 
	if (checkLuhn(document.signupform.billing_info_X_billing_cardno.value) != 0) {alert ("The credit card number does not appear to be valid.  Please check."); return false}
  if (CCNbr.length < 15) {alert("Need a 15 or 16 digit Credit Card Number"); return false}
  return true;
}
//  -->
function show_CCV2(cards_accepted) {
	var CCV2 = window.open('', 'What_is_CCV2', 'width=450,height=600,fullscreen=no,scrollbar=0,menubar=1,statusbar=yes');
	 CCV2.document.writeln('<HTML><HEAD><TITLE> What is CCV2?</TITLE>');
	 CCV2.document.writeln('</HEAD><BODY BGCOLOR=WHITE>');
	 CCV2.document.writeln(top);
	 if (cards_accepted.indexOf('amex') > -1) {CCV2.document.writeln (amex)}
	 if (cards_accepted.indexOf('discover') > -1) {CCV2.document.writeln (discover)}
	 if (cards_accepted.indexOf('mc') > -1) {CCV2.document.writeln (mc)}
	 if (cards_accepted.indexOf('visa') > -1) {CCV2.document.writeln (visa)}
	 CCV2.document.writeln('</BODY></HTML>');
	 CCV2.document.close();
	CCV2.window.moveTo(250,100);
	CCV2.window.focus();
	return;
}
var top ='<table border="0" cellspacing="0" cellpadding="0" width="380">';
var amex = '<TR><TD><img src="/pics/credit_cards/amex.gif"><br><STRONG><U>AMEX<BR></U></STRONG>A 4-digit non-embossed number on the <STRONG>face</STRONG> of the card printed above the account number.</td></tr>';
var discover = '<TR><TD><img src="/pics/credit_cards/discover.gif"><br><STRONG><U>Discover<BR></U></STRONG>A 3-digit non-embossed number on the <STRONG>back</STRONG> of the card printed within the signature panel immediately following the account number.</td></tr>';
var mc = '<TR><TD><img src="/pics/credit_cards/mc.gif"><br><STRONG><U>Mastercard<BR></U></STRONG>A 3-digit non-embossed number on the <STRONG>back</STRONG> of the card printed within the signature panel.<BR></td></tr>';
var visa = '<TR><TD><img src="/pics/credit_cards/visa.gif"><br><STRONG><U>VISA<BR></U></STRONG>A 3-digit non-embossed number on the <STRONG>back </STRONG>of the card printed within the signature panel immediately following the account number.</td></tr>';

function checkSafeShort(shortname)
{
	var sN = shortname.value;
	sN = sN.replace(/\W/g, ""); 
	shortname.value = sN;
}

function checkLong(longname)
{
	var lN = longname.value;
	lN = lN.replace(/'|"/g, ""); 
	longname.value = lN;
}

function checkEmail(EmAddr)
{
	var Em = EmAddr.value;
 Em = Em.replace(/(\.\.)/g, ".");      // multiple period to one
 Em = Em.replace(/(\@\@)/g, "\@");    // multiple at-signs to one
 Em = Em.replace(/\\+/g, "");        // change backslash to null
 Em = Em.replace(/[\s]+/g, "");     // mult blanks/tabs/newline/cr/ff to nul
 EmAddr.value = Em;
 if (Em.length <= 5) {alert("This email address is too short.  Need full email address, such as joe@ibm.com"); return false}
 if (Em.search(  /,|\/\\|(@.*@)|(\.\.)|(\.$)/  ) != -1) {alert("Email address has Illegal characters, or characters out of order"); return false} 
 if (Em.search(  /^[\w\-\.]+[\%\+]?[\w\-\.]*\@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/  ) != -1) {
  	 return true;
 } else {
     alert("The Email Address has an error."); 
     return false;
 }
}

function checkPass(field) {
	var fval= field.value;
	fval = fval.replace(/ /g, "");
	fval = fval.replace (/"|'|`|\+|\\|<|>/g, "");
	if (fval != field.value) {alert("Passwords can't have spaces or &quot;, &squo;, `, +, \, <, >.  These have been removed.  Make sure you still have an 8 character password.")}
	field.value = fval;
}

function fixUID(thisForm) {
	var fval= thisForm.user_first.value;
	var orig_fval
	fval = fval.toLowerCase();
	fval = fval.replace(/ /g, "");
	fval = fval.replace (/\W/g, "x");
	if (fval.match(/^\d/) ) {fval = "a"+fval}
	thisForm.user_first.value = fval;
	if (fval != orig_fval) {
		alert("User names must begin with a lowercase letter and contain only lowercase letters and digits.  User name has been modified."); 
		return false
	}else {
		return true
	}
}


function lower(field) {
	var fval= field.value;
	fval = fval.toLowerCase();
	fval = fval.replace(/ /g, "");
	fval = fval.replace (/\W/g, "x");
	if (fval.match(/^\d/) ) {fval = "a"+fval}
	if (fval != field.value) {alert("User names must begin with a lowercase letter and contain only lowercase letters and digits.")}
	field.value = fval;
}

/*
  Ecom_BillTo_Online_Email            b_email
  Ecom_BillTo_Postal_City             b_city
  Ecom_BillTo_Postal_CountryCode      b_country
  Ecom_BillTo_Postal_Name_First       b_fname
  Ecom_BillTo_Postal_Name_Last        b_lname
  Ecom_BillTo_Postal_Name_Middle      b_mname
  Ecom_BillTo_Postal_Name_Prefix      b_title
  Ecom_BillTo_Postal_Name_Suffix      b_name_suffix
  Ecom_BillTo_Postal_PostalCode       b_zip
  Ecom_BillTo_Postal_StateProv        b_state
  Ecom_BillTo_Postal_Street_Line1     b_address1
  Ecom_BillTo_Postal_Street_Line2     b_address2
  Ecom_BillTo_Postal_Street_Line3     b_address3
  Ecom_BillTo_Telecom_Phone_Number    b_phone_day
  Ecom_ConsumerOrderID                mv_order_number
  Ecom_Payment_Card_ExpDate_Day       mv_credit_card_exp_day
  Ecom_Payment_Card_ExpDate_Month     mv_credit_card_exp_month
  Ecom_Payment_Card_ExpDate_Year      mv_credit_card_exp_year
  Ecom_Payment_Card_Name              c_name
  Ecom_Payment_Card_Number            mv_credit_card_number
  Ecom_Payment_Card_Protocol          payment_protocols_available
  Ecom_Payment_Card_Type              mv_credit_card_type
  Ecom_Payment_Card_Verification      mv_credit_card_verify
  Ecom_ReceiptTo_Online_Email         r_email
  Ecom_ReceiptTo_Postal_City          r_city
  Ecom_ReceiptTo_Postal_CountryCode   r_country
  Ecom_ReceiptTo_Postal_Name_First    r_fname
  Ecom_ReceiptTo_Postal_Name_Last     r_lname
  Ecom_ReceiptTo_Postal_Name_Middle   r_mname
  Ecom_ReceiptTo_Postal_Name_Prefix   r_title
  Ecom_ReceiptTo_Postal_Name_Suffix   r_name_suffix
  Ecom_ReceiptTo_Postal_PostalCode    r_zip
  Ecom_ReceiptTo_Postal_StateProv     r_state
  Ecom_ReceiptTo_Postal_Street_Line1  r_address1
  Ecom_ReceiptTo_Postal_Street_Line2  r_address2
  Ecom_ReceiptTo_Postal_Street_Line3  r_address3
  Ecom_ReceiptTo_Telecom_Phone_Number r_phone
  Ecom_SchemaVersion                  ecml_version
  Ecom_ShipTo_Online_Email            email
  Ecom_ShipTo_Postal_City             city
  Ecom_ShipTo_Postal_CountryCode      country
  Ecom_ShipTo_Postal_Name_Combined    name
  Ecom_ShipTo_Postal_Name_First       fname
  Ecom_ShipTo_Postal_Name_Last        lname
  Ecom_ShipTo_Postal_Name_Middle      mname
  Ecom_ShipTo_Postal_Name_Prefix      title
  Ecom_ShipTo_Postal_Name_Suffix      name_suffix
  Ecom_ShipTo_Postal_PostalCode       zip
  Ecom_ShipTo_Postal_StateProv        state
  Ecom_ShipTo_Postal_Street_Line1     address1
  Ecom_ShipTo_Postal_Street_Line2     address2
  Ecom_ShipTo_Postal_Street_Line3     address3
  Ecom_ShipTo_Telecom_Phone_Number    phone
  Ecom_TransactionComplete            end_transaction_flag
*/
