/* *********************************************
FORM VALIDATION
********************************************* */
function fncShippingIsBilling(){
	var blnCopy = document.getElementById("billingIsShipping").checked;
	if(blnCopy == true) {
		document.getElementById("strNameBILL").value = document.getElementById("strName").value;
		document.getElementById("strAddressBILL").value = document.getElementById("strAddress").value;
		document.getElementById("strAddress2BILL").value = document.getElementById("strAddress2").value;
		document.getElementById("strCityBILL").value = document.getElementById("strCity").value;
		document.getElementById("strStateBILL").value = document.getElementById("strState").value;
		document.getElementById("strZipBILL").value = document.getElementById("strZip").value;
		document.getElementById("strPhoneBILL").value = document.getElementById("strPhone").value;
		document.getElementById("strEmailBILL").value = document.getElementById("strEmail").value;
	}
}



/* *********************************************
FORM VALIDATION
********************************************* */
function formValidator(){
	// Make quick references to our fields
	var name = document.getElementById('Name');
	var email = document.getElementById('EmailAddress');
	var phone = document.getElementById('Phone');

	// Check each input in the order that it appears in the form!
	if(notEmpty(phone, "Please enter a valid Phone.")){
		if(notEmpty(phone, "Please enter a valid Phone.")){
			if(notEmpty(phone, "Please enter a valid Phone.")){
				if(notEmpty(phone, "Please enter a valid Phone.")){
					if(notEmpty(phone, "Please enter a valid Phone.")){
						if(notEmpty(phone, "Please enter a valid Phone.")){
							if(notEmpty(phone, "Please enter a valid Phone.")){
								if(notEmpty(phone, "Please enter a valid Phone.")){
									return true;
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}


/* *********************************************
FORM VALIDATION
********************************************* */
function formValidatorPayment(){
	// Make quick references to our fields
	var name = document.getElementById('strName');
	var address = document.getElementById('strAddress');
	var city = document.getElementById('strCity');
	var state = document.getElementById('strState');
	var zip = document.getElementById('strZip');
	var phone = document.getElementById('strPhone');
	var email = document.getElementById('strEmail');

/* 20110920 ::: BILL TO */
	var nameBILL = document.getElementById('strNameBILL');
	var addressBILL = document.getElementById('strAddressBILL');
	var cityBILL = document.getElementById('strCityBILL');
	var stateBILL = document.getElementById('strStateBILL');
	var zipBILL = document.getElementById('strZipBILL');
	var phoneBILL = document.getElementById('strPhoneBILL');
	var emailBILL = document.getElementById('strEmailBILL');
/* 20110920 ::: BILL TO */

	var ccName = document.getElementById('strCCName');
	var ccNumber = document.getElementById('strCCNumber');
	var ccExpireMonth = document.getElementById('intExpireMonth');
	var ccExpireYear = document.getElementById('intExpireYear');
	var ccCCV = document.getElementById('strCCCVV');

	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Please enter a valid Name.")){
		if(notEmpty(address, "Please enter a valid Address.")){
			if(notEmpty(city, "Please enter a valid City.")){
				if(notEmpty(state, "Please enter a valid State.")){
					if(notEmpty(zip, "Please enter a valid Zip.")){
						if(notEmpty(phone, "Please enter a valid Phone.")){
							if(emailValidator(email, "Please enter a valid Email.")){

/* 20110920 ::: BILL TO */
								if(notEmpty(nameBILL, "Please enter a valid Bill To Name.")){
									if(notEmpty(addressBILL, "Please enter a valid Bill To Address.")){
										if(notEmpty(cityBILL, "Please enter a valid Bill To City.")){
											if(notEmpty(stateBILL, "Please enter a valid Bill To State.")){
												if(notEmpty(zipBILL, "Please enter a valid Bill To Zip.")){
													if(notEmpty(phoneBILL, "Please enter a valid Bill To Phone.")){
														if(emailValidator(emailBILL, "Please enter a valid Bill To Email.")){
/* 20110920 ::: BILL TO */
							
															if(notEmpty(ccName, "Please enter a valid Name on Card #.")){
																if(notEmpty(ccNumber, "Please enter a valid Phone.")){
																	if(notEmpty(ccExpireMonth, "Please enter a valid Expiration Month.")){
																		if(notEmpty(ccExpireYear, "Please enter a valid Expiration Year.")){
																			if(notEmpty(ccCCV, "Please enter a valid CCV.")){
																				return true;
																			}
																		}
																	}
																}
															}
/* 20110920 ::: BILL TO */
														}
													}
												}
											}
										}
									}
								}
/* 20110920 ::: BILL TO */

							}
						}
					}
				}
			}
		}
	}

	return false;

}





function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

