
//step will keep track of what step we are on
var step = 1;
var totalStep = 3;

function step1() {
	var okay = 1;

	for (x=0; x<document.captureForm.elements.length; x++){

		try{
			var ElementName =  document.captureForm.elements[x].name;
			var AlertElement = document.captureForm.elements[x].name + "Text";
			var AlertText = document.getElementById(AlertElement).value;
		}catch(ex){
			//alert(AlertElement)
			var AlertText = "";
		}

		if(document.captureForm.elements[x].id == "agree"){
			if(!checkDisClaimer(ElementName, "Please click the checkbox to continue.")){
				return bSubmitted = okay = false;
			}
		}

        if (document.captureForm.elements[x].id == "firstname"){
			if ((document.getElementById("firstname").value == "Jane" || document.getElementById("firstname").value == "John") &&  document.getElementById("lastname").value == "Doe"){
			    alert("Please enter a valid first and last name");
			    return bSubmitted = okay = false;
			}
			if (document.getElementById("firstname").value == document.getElementById("lastname").value){
			    alert("Please enter a valid first and last name");
			    return bSubmitted = okay = false;
			}
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid first name");
			    return bSubmitted = okay = false;
			}
        }

		if (document.captureForm.elements[x].id == "lastname"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid last name");
			    return bSubmitted = okay = false;
			}
		}
		
		if (document.captureForm.elements[x].id == "email"){
			if(document.getElementById("confirmemail")){
				if (document.captureForm.email.value != document.captureForm.confirmemail.value) {
					alert("Your email addresses do not match!  Please try again.");
					document.captureForm.confirmemail.value = '';
					document.captureForm.confirmemail.focus();
					return bSubmitted = okay = false;
				}
			}
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid email address.");
			    return bSubmitted = okay = false;
			}
		}
		if (document.captureForm.elements[x].id == "area_code"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid phone number");
			    return bSubmitted = okay = false;
			}
		}
		if (document.captureForm.elements[x].id == "phone1"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid phone number");
			    return bSubmitted = okay = false;
			}
		}
		if (document.captureForm.elements[x].id == "phone2"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid phone number");
			    return bSubmitted = okay = false;
			}
		}

	}
	var okay = 1;
	var iValidateAddress = 0;

    if (document.getElementsByName("area_code") ||
         document.getElementsByName("phone")  && !(iValidateAddress & 1)){
         iValidateAddress += 1;
    }

    if (document.getElementsByName("firstname") && document.getElementsByName("lastname")  && !(iValidateAddress & 2)){
         iValidateAddress += 2;
    }

  if(okay == true){
    //hide the submit button
        $('submit1').style.display = "none";
        //show the loader
        if ($('loadingGraphic')){
            $('loadingGraphic').style.display = "block";
        }
        //do an ajax post
        validateAddress2(iValidateAddress);
	}

}

function step2() {
	var okay = 1;
	var iValidateAddress = 0;
   
    if (document.getElementsByName("area_code") ||
         document.getElementsByName("phone")  && !(iValidateAddress & 1)){
         iValidateAddress += 1;
    }

    if (document.getElementsByName("firstname") && document.getElementsByName("lastname")  && !(iValidateAddress & 2)){
         iValidateAddress += 2;
    }

	for (x=0; x<document.captureForm.elements.length; x++){
        try{
            var ElementName =  document.captureForm.elements[x].name;
            var AlertElement = document.captureForm.elements[x].name + "Text";
            var AlertText = document.getElementById(AlertElement).value;
        }catch(ex){
        //alert(AlertElement)
            var AlertText = "";
        }
        if(document.captureForm.elements[x].id == "agree"){
    			if(!checkDisClaimer(ElementName, "Please click the checkbox to continue.")){
    				return bSubmitted = okay = false;
    			}
        }

		if(document.captureForm.elements[x].name == "address"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid address");
			    return bSubmitted = okay = false;
			}
		    if (okay == true && !(iValidateAddress & 4)){
		        iValidateAddress += 4;
		    }
		}else if(document.captureForm.elements[x].name == "city"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid city");
			    return bSubmitted = okay = false;
			}
		    if (okay == true && !(iValidateAddress & 8)){
		        iValidateAddress += 8;
		    }
		}else if(document.captureForm.elements[x].id == "selectReq"){
			varSelect = new RegExp("Select");
			if(document.captureForm.elements[x].name == "state"){
				if(!checkSend(document.captureForm.elements[x])){
					alert("Please select a state");
				    return bSubmitted = okay = false;
				}
				if (okay == true && !(iValidateAddress & 16)){
				    iValidateAddress += 16;
				}
			}
		}else if(document.captureForm.elements[x].name == "zipcode"){
			if(!checkSend(document.captureForm.elements[x])){
				alert("Please enter a valid postal code");
			    return bSubmitted = okay = false;
			}
			if (okay == true && !(iValidateAddress & 32)){
		        iValidateAddress += 32;
		    }
		}
	}
	
    if(okay == true && iValidateAddress > 0){
        //hide the submit button
        $('submit2').style.display = "none";
        //show the loader
        if ($('loadingGraphic')){
            $('loadingGraphic').style.display = "block";
        }
        //do an ajax post
        validateAddress2(iValidateAddress);
    }

}

function step3() {
	var okay = 1;
	bSubmitted = true;

	for (x=0; x<document.captureForm.elements.length; x++){

		try{
			var ElementName =  document.captureForm.elements[x].name;
			var AlertElement = document.captureForm.elements[x].name + "Text";
			var AlertText = document.getElementById(AlertElement).value;
		}catch(ex){
			//alert(AlertElement)
			var AlertText = "";
		}

		if(document.captureForm.elements[x].id == "agree"){
			if(!checkDisClaimer(ElementName, "Please click the checkbox to continue.")){
				return bSubmitted = okay = false;
			}
		}

		if(document.captureForm.elements[x].id == "hiddenReq"){
			if (document.captureForm.elements[x].value == ""){
				if(AlertText != ""){
					alert(AlertText);
				}else{
					alert("Please enter a value for this field.");
				}
				return bSubmitted = okay = false;
				break
			}
		}

		if(document.captureForm.elements[x].id == "selectReq"){
			varSelect = new RegExp("Select");

			if (document.captureForm.elements[x].value.match(varSelect) || document.captureForm.elements[x].value == ""){
				if(AlertText != ""){
					alert(AlertText);
				}else{
					alert("Please Select an Option for this Field");
				}
				document.captureForm.elements[x].focus();
				return bSubmitted = okay = false;
				break
			}

		}

		if(document.captureForm.elements[x].id == "checkReq"){
			if (document.captureForm.elements[x].checked == false){
				if(AlertText != ""){
					alert(AlertText);
				}else{
					alert("The checkbox must be checked to continue.");
				}
			document.captureForm.elements[x].focus();
			return bSubmitted = okay = false;
			break
			}
		}
		if(document.captureForm.elements[x].id == "YN1"){
			var xx = x++;
			if (document.captureForm.elements[x].checked == false && document.captureForm.elements[xx].checked == false){
				if(AlertText != ""){
					alert(AlertText);
				}else{
					alert("Please Answer all of the Yes/No Questions.");
				}
				document.captureForm.elements[x].focus();
				return bSubmitted = okay = false;
				break
			}
		}
		if(document.captureForm.elements[x].id == "ccNum"){
			var aCCSplit = document.captureForm.elements[x].value.split(" ");
			var vCCNum = aCCSplit.join("");
			var aCCSplit = vCCNum.split("-");
			var iCCNum = aCCSplit.join("");
			document.captureForm.elements[x].value = iCCNum;
			var expDate = document.getElementById("ccMonth").value + "/" + document.getElementById("ccYear").value;
			//alert(iCCNum);

			if(!checkCC(iCCNum, expDate))	{
				alert ("Please enter valid credit card information");
				return bSubmitted = okay = false;
				break
			}
		}
		if(document.captureForm.elements[x].id == "checkStart"){
			if(!oneOrMore(x)){
				alert("Please select at least 1 interest.");
				return bSubmitted = okay = false;
				break
			}
		}

	}

	if(okay == true){
	    //hide the submit button
        $('submitButton').style.display = "none";
        //show the loader
        $('loadingGraphic').style.display = "block";
        
        //do the ajax post
		validateAddress2(0);
	}

}