var domPath	=	window.document.sendInfo; 	// be sure to change the form name
//step 1
var EmailObj = new InputCheck(domPath.email);
var PasswordObj = new InputCheck(domPath.password);
var NameObj = new InputCheck(domPath.name);
var Address1Obj = new InputCheck(domPath.address1);
var CityObj = new InputCheck(domPath.city);
var StateObj = new InputCheck(domPath.state);
var ZipObj = new InputCheck(domPath.zip);
var AreaCodeObj = new InputCheck(domPath.phAreaCode);
var PhoneObj = new InputCheck(domPath.phone);

// step 2
var CCnumberObj = new InputCheck(domPath.cc_number);
var CCnameObj = new InputCheck(domPath.cc_name);
var CCaddressObj = new InputCheck(domPath.cc_address);
var CCcityObj = new InputCheck(domPath.cc_city);
var CCstateObj = new InputCheck(domPath.cc_state);
var CCzipObj = new InputCheck(domPath.cc_zip);
var SubmitObj	=	new InputCheck();

function InputCheck(path,inputName){ 
	this.path = path;
	this.isEmail = emailCorrect;
	this.confirmEmail = checkConfirm;
	this.adjustValues = valueAdjust;
	this.step1Filled = checkStep1;
	this.someFilled = checkBox;
	return this;
}

var reqStep1Ary = new Array();
	reqStep1Ary[0]=new Array();
		reqStep1Ary[0][0]=EmailObj.path;
		reqStep1Ary[0][1]="an Email Address";
	reqStep1Ary[1]=new Array();
		reqStep1Ary[1][0]=PasswordObj.path;
		reqStep1Ary[1][1]="a Password";
	reqStep1Ary[2]=new Array();
		reqStep1Ary[2][0]=NameObj.path;
		reqStep1Ary[2][1]="a Name";
	reqStep1Ary[3]=new Array();
		reqStep1Ary[3][0]=Address1Obj.path;
		reqStep1Ary[3][1]="an Address";
	reqStep1Ary[4]=new Array();
		reqStep1Ary[4][0]=CityObj.path;
		reqStep1Ary[4][1]="a City";
	reqStep1Ary[5]=new Array();
		reqStep1Ary[5][0]=StateObj.path;
		reqStep1Ary[5][1]="a State";
	reqStep1Ary[6]=new Array();
		reqStep1Ary[6][0]=ZipObj.path;
		reqStep1Ary[6][1]="a Zip Code";
	reqStep1Ary[7]=new Array();
		reqStep1Ary[7][0]=AreaCodeObj.path;
		reqStep1Ary[7][1]="an Area Code";
	reqStep1Ary[8]=new Array();
		reqStep1Ary[8][0]=PhoneObj.path;
		reqStep1Ary[8][1]="a Phone Number";

var reqFieldsAry = new Array();
	reqFieldsAry[0]=new Array();
		reqFieldsAry[0][0]=CCnameObj.path;
		reqFieldsAry[0][1]="a Name";
	reqFieldsAry[1]=new Array();
		reqFieldsAry[1][0]=CCaddressObj.path;
		reqFieldsAry[1][1]="an Address";
	reqFieldsAry[2]=new Array();
		reqFieldsAry[2][0]=CCcityObj.path;
		reqFieldsAry[2][1]="a City";
	reqFieldsAry[3]=new Array();
		reqFieldsAry[3][0]=CCstateObj.path;
		reqFieldsAry[3][1]="a State or Province";
	reqFieldsAry[4]=new Array();
		reqFieldsAry[4][0]=CCzipObj.path;
		reqFieldsAry[4][1]="a Zip Code";

// global values used in setExpiration and checkDate functions to form the expiration date
var expYear = "";
var expMonth = "";		

/********* Method: checks if email address contains @ *********/
function emailCorrect(box){
	if (box.value!="" && box.value!=null){
		if (box.value.indexOf("@") == -1 || box.value.indexOf(".") == -1){
			alert("You must include a valid email address, Please correct your email address and re-submit this form.");
			box.value="";
			return false;
		}else{
			box.value=box.value.toLowerCase();
		}
	}
}

/********* METHOD: onSubmit checks if the email field is the same as the confirm email field *********/
function setExpiration(frmName){
	expYear = frmName.cc_year.selectedIndex;
	expYear = frmName.cc_year.options[expYear].value;
	expMonth = frmName.cc_month.selectedIndex;
	expMonth = frmName.cc_month.options[expMonth].value;
	frmName.cc_exp.value = expYear+"/"+expMonth+"/"+01;
}

/********* METHOD: onSubmit calls functions to adjust and check values within the form *********/
function valueAdjust(frmName){
	setExpiration(frmName);
}

/********* METHOD: onSubmit verifies that card number is valid *********/
function cardNumber(frmName){
	var creditCard = frmName.cc_number.value;
	if (creditCard != "" && creditCard != null){
		if (isNaN(creditCard) || creditCard.length != 16){
			alert("The Credit Card Number entered is incorrect.\n Please check the value entered and submit the form again.");
			return false;
		}else {
			return true;
		}
	}else{
		alert("You must enter a Credit Card Number. Please correct the information and re-submit this form.");
		return false
	}
}

/********* METHOD: onSubmit verifies that date has not yet passed *********/
function checkDate(frmName){
	var todayDateTemp = new Date();
	// getMonth() pulls from an array of months so January is 0 and December is 11. Add 1 to the getMonth() value to compare to the expDate
	var todayMonth = todayDateTemp.getMonth() + 1;
	var todayDate = todayMonth+"/1/"+todayDateTemp.getYear();
		todayDate = new Date(todayDate);
	var expDate = new Date(expMonth+"/"+01+"/"+expYear);
	if (todayDate > expDate){
		alert("The Credit Card has expired.");
		return false;
	}else{
		return true;
	}
}

/********* METHOD: onSubmit checks if the input box has a value *********/
function checkBox(frmName){
	var cardValue = cardNumber(frmName);
	if (!cardValue) return false;
	var dateValue = checkDate(frmName);
	if (!dateValue) return false;
	for (var i = 0; i < reqFieldsAry.length; i++){
		if (reqFieldsAry[i][0].value=="" || reqFieldsAry[i][0].value==null || reqFieldsAry[i][0].value==" "){
			alert("You must enter "+reqFieldsAry[i][1]+". Please correct the information and re-submit this form.");
			return false;
		}
	}
	return true;
}

/********* METHOD: onSubmit checks if the email field is the same as the confirm email field *********/
function checkConfirm(frmName){
	if (frmName.email.value != frmName.confirmEmail.value) {
		alert("The e-mail address entered is not the same as the confirmed e-mail address.\nPlease check the values and submit the form again.");
		return false;
	}
	if (frmName.password.value != frmName.confirmPassword.value) {
		alert("The password entered is not the same as the confirmed password.\nPlease check the values and submit the form again.");
		return false;
	}
	return true;
}

/********* METHOD: onSubmit checks if the input box has a value *********/
function checkStep1(frmName){
	var checkFields = checkConfirm(frmName);
	if (!checkFields) return false;
	for (var j = 0; j < reqStep1Ary.length; j++){
		if (reqStep1Ary[j][0].value=="" || reqStep1Ary[j][0].value==null || reqStep1Ary[j][0].value==" "){
			alert("You must enter "+reqStep1Ary[j][1]+". Please correct the information and re-submit this form.");
			return false;
		}
	}
	return true;
}
