//
// Copyright ByTheJob Inc. All Rights Reserved
// Unauthorized use or duplication of this content or program code is a
// violation of applicable laws and subject to prosecution thereunder.
//
//------------------------------------------------------------------------------------------
//	Website Customer Attribute edits.
//------------------------------------------------------------------------------------------
function checkName(fName,lName) {
	if (isBlank(fName)) {
		alert('Please enter required First Name.');
		fName.select();
		fName.focus();
		return false; 
	}

	if (isBlank(lName)) {
		alert('Please enter required Last Name.');
		lName.select();
		lName.focus();
		return false; 
	}
	return true;
}

function checkCVV2Number(fld) {
	if (!isBlank(fld)) {
		if((fld.value.length < 3) || (new Number(fld.value) == 0)) {
			alert('Please enter 3 numeric digits for CVV2 code.');
			fld.select();
			fld.focus();
			return false; 
		}
	}
	return true;
}

function checkAcctNumber(acct) {
	if (isBlank(acct)) {
		alert('Please enter required Card Account Number.');
		acct.select();
		acct.focus();
		return false; 
	}
	if (!isNumeric(acct) || (acct.value.length < 16) || (new Number(acct.value) == 0)) {
		alert('Please enter 16 numeric digits for Card Account Number.');
		acct.select();
		acct.focus();
		return false; 
	}
	return true;
}

function checkQty(quantity) {
	if (isNaN(quantity.value) || new Number(quantity.value) < 0) {
		return false; 
	}
	return true;
}

function checkValue(cst) {
	if (isNaN(cst.value) || new Number(cst.value) < 0) {
		alert('Please enter valid numeric value.');
		cst.select();
		cst.focus();
		return false; 
	}
	return true;
}

function checkEmail(eMail) {
	if (isBlank(eMail)) {
		alert('Please enter required Email Address.');
		eMail.select();
		eMail.focus();
		return false; 
	}

	if (!isEmail(eMail)) { 
		alert('Please specify full domain in E-mail Address (Ex:  joe@abc.com).');
		eMail.select();
		eMail.focus();
		return false; 
	}
	return true;
}

function checkAccount(aName) {
	if (isBlank(aName)) {
		alert('Please enter required Account Name.');
		aName.focus();
		aName.select();
		return false; 
	}

	if (aName.value.substr(0,1) == " " || aName.value.substr(aName.value.length,1) == " ") {
		alert('Please remove leading and trailing spaces from Account Name.');
		aName.focus();
		aName.select();
		return false;
	}
	return true;
}

function checkPassword(passWd) {
	if (passWd.value.length < 6 ) {
		alert('Password must be between 6 and 20 characters in length.');
		passWd.focus();
		passWd.select();
		return false; 
	}

	if (isBlank(passWd)) {
		alert('Please enter Password.');
		passWd.focus();
		passWd.select();
		return false; 
	}

	if (passWd.value.substr(0,1) == " " || passWd.value.substr(passWd.value.length,1) == " ") {
		alert('Please remove leading and trailing spaces from password.');
		passWd.focus();
		passWd.select();
		return false;
	}

	return true;
}

function checkAccountAndEmail(aName,eMail) {
	emailInt = eMail.value.indexOf("@");
	emailInt = (emailInt < 0) ? eMail.value.length : emailInt;

	if (isBlank(aName)) {
		alert('Please enter required Account Name.');
		aName.focus();
		aName.select();
		return false; 
	}

	if (aName.value.substr(0,1) == " " || aName.value.substr(aName.value.length,1) == " ") {
		alert('Please remove leading and trailing spaces from account name.');
		aName.focus();
		aName.select();
		return false;
	}

	if (eMail.value.substr(0,emailInt) == aName.value.substr(0,emailInt)) {
		alert('Please do not use your email userid in your account name.');
		aName.focus();
		aName.select();
		return false;
	}
	return true;
}

function checkAddress(post1,ci,zp,zps) {
	if (isBlank(post1)) {
		alert('Please enter Required Mailing Address Line 1.');
		post1.select();
		post1.focus();
		return false; 
	} 

	if (isBlank(ci)) {
		alert('Please enter Required City.');
		ci.select();
		ci.focus();
		return false; 
	}

	if (isBlank(zp)) {
		alert('Please enter Required Zip Code.');
		zp.select();
		zp.focus();
		return false; 
	}

	if (!isNumeric(zp) || zp.value.length < 5) {
		alert('Please enter 5 numeric digits for Zip Code.');
		zp.select();
		zp.focus();
		return false; 
	} 

	if (!isBlank(zps)) {
		if (!isNumeric(zps) || zps.value.length < 4) {
			alert('Please enter 4 numeric digits for Zip Code Suffix.');
			zps.select();
			zps.focus();
			return false; 
		}
	}
	return true;
}

function checkPasswordAndConfirm(passWd,cpassWd,aName,eMail) {
	emailInt = eMail.value.indexOf("@");
	emailInt = (emailInt < 0) ? eMail.value.length : emailInt;

	if (passWd.value.length < 6 ) {
		alert('Password must be between 6 and 20 characters in length.');
		passWd.focus();
		passWd.select();
		return false; 
	}

	if (isBlank(passWd) || isBlank(cpassWd)) {
		alert('Please enter Password AND Confirm Password.');
		passWd.focus();
		passWd.select();
		return false; 
	}

	if (eMail.value.substr(0,emailInt) == passWd.value.substr(0,emailInt)) {
		alert('Please do not use your email address in your password.');
		passWd.focus();
		passWd.select();
		return false;
	} 

	if (aName == passWd.value.substr(0,aName.value.length) ) {
		alert('Please do not use your account name in your password.');
		passWd.focus();
		passWd.select();
		return false;
	} 

	if (passWd.value.substr(0,1) == " " || passWd.value.substr(passWd.value.length,1) == " ") {
		alert('Please remove leading and trailing spaces from password.');
		passWd.focus();
		passWd.select();
		return false;
	}

	if (passWd == cpassWd) {
	}
	else {
		alert('Password and Confirm Password do not match.  Please re-enter.');
		passWd.focus();
		passWd.select();
		return false;
	} 
	return true;
}

function checkPhone(dCode,dPfx,dExch,dPext,eCode,ePfx,eExch,ePext) {
	return checkMandatoryDay(dCode,dPfx,dExch,dPext) && checkOptionalEvening(eCode,ePfx,eExch,ePext);
}
		
function checkMandatoryDay(dCode,dPfx,dExch,dPext) {
	if (isBlank(dCode)) {
		alert('Please enter required Daytime Phone Area code.');
		dCode.select();
		dCode.focus();
		return false; 
	}
	if (!isNumeric(dCode) || (dCode.value.length < 3) || (new Number(dCode.value) == 0)) {
		alert('Please enter 3 numeric digits for Daytime Phone Area Code.');
		dCode.select();
		dCode.focus();
		return false; 
	}
	if (isBlank(dPfx)) {
		alert('Please enter required Daytime Phone Prefix.');
		dPfx.select();
		dPfx.focus();
		return false; 
	}
	if (!isNumeric(dPfx) || (dPfx.value.length < 3) || (new Number(dPfx.value) == 0)) {
		alert('Please enter 3 numeric digits for Daytime Phone Prefix.');
		dPfx.select();
		dPfx.focus();
		return false; 
	}
	if (isBlank(dExch)) {
		alert('Please enter required Daytime Phone Exchange.');
		dExch.select();
		dExch.focus();
		return false; 
	}
	if (!isNumeric(dExch) || (dExch.value.length < 4) || (new Number(dExch.value) == 0)) {
		alert('Please enter 4 numeric digits for Daytime Phone Exchange.');
		dExch.select();
		dExch.focus();
		return false; 
	}
	if (!isBlank(dPext) && !isNumeric(dPext)) {
		alert('Please enter numeric digits for Daytime Phone Extension.');
		dPext.select();
		dPext.focus();
		return false; 
	}
	return true;
}

function checkOptionalEvening(eCode,ePfx,eExch,ePext) {
	if (!isBlank(eCode)) {
		if (!isNumeric(eCode) || (eCode.value.length < 3) || (new Number(eCode.value) == 0)) {
			alert('Please enter 3 numeric digits for Evening Phone Area Code.');
			eCode.select();
			eCode.focus();
			return false; 
		}
	}

	if (!isBlank(ePfx)) {
		if (!isNumeric(ePfx) || (ePfx.value.length < 3) || (new Number(ePfx.value) == 0)) {
			alert('Please enter 3 numeric digits for Evening Phone Prefix.');
			ePfx.select();
			ePfx.focus();
			return false; 
		}
	}

	if (!isBlank(eExch)) {
		if (!isNumeric(eExch) || (eExch.value.length < 4) || (new Number(eExch.value) == 0)) {
			alert('Please enter 4 numeric digits for Evening Phone Exchange.');
			eExch.select();
			eExch.focus();
			return false; 
		}
	}

	if (!isBlank(ePext) && !isNumeric(ePext)) {
		alert('Please enter numeric digits for Evening Phone Extension.');
		ePext.select();
		ePext.focus();
		return false; 
	}
	return true;
}

function checkMandatoryEvening(eCode,ePfx,eExch,ePext) {
	if (isBlank(eCode)) {
		alert('Please enter required Evening Phone Area code.');
		eCode.select();
		eCode.focus();
		return false; 
	}
	if (!isNumeric(eCode) || (eCode.value.length < 3) || (new Number(eCode.value) == 0)) {
		alert('Please enter 3 numeric digits for Evening Phone Area Code.');
		eCode.select();
		eCode.focus();
		return false; 
	}
	if (isBlank(ePfx)) {
		alert('Please enter required Evening Phone Prefix.');
		ePfx.select();
		ePfx.focus();
		return false; 
	}
	if (!isNumeric(ePfx) || (ePfx.value.length < 3) || (new Number(ePfx.value) == 0)) {
		alert('Please enter 3 numeric digits for Evening Phone Prefix.');
		ePfx.select();
		ePfx.focus();
		return false; 
	}
	if (isBlank(eExch)) {
		alert('Please enter required Evening Phone Exchange.');
		eExch.select();
		eExch.focus();
		return false; 
	}
	if (!isNumeric(eExch) || (eExch.value.length < 4) || (new Number(eExch.value) == 0)) {
		alert('Please enter 4 numeric digits for Evening Phone Exchange.');
		eExch.select();
		eExch.focus();
		return false; 
	}
	if (!isBlank(ePext) && !isNumeric(ePext)) {
		alert('Please enter numeric digits for Evening Phone Extension.');
		ePext.select();
		ePext.focus();
		return false; 
	}
	return true;
}
