// JavaScript Document
var exitviewed=false;
var formsubmit = false;
function ValidateForm()
{
	formsubmit = true;
	exitviewed=true;
	var n_regExpression = new RegExp("[^A-Za-z .'`,-]","gi");
	
	if(document.getElementById("Fname").value=="")
	{
		alert("First Name is required.");
		document.getElementById("Fname").focus();
		return false;
	}
	
	if(isValidData("theForm","FName","First name")==false)
	{
		return false;	
	}
	if(document.getElementById("LName").value=="")
	{
		alert("Last Name is required.");
		document.getElementById("LName").focus();
		return false;
	}
	if(isValidData("theForm","LName","Last name")==false)
	{
		return false;	
	}
	if(document.getElementById("Email").value=="")
	{
		alert("Email is required.");
		document.getElementById("Email").focus();
		return false;
	}
	if(isValidData("theForm","Email","Email")==false)
	{
		return false;	
	}
	if(document.getElementById("Zip").value=="")
	{
		alert("Zip is required.");
		document.getElementById("Zip").focus();
		return false;
	}
	if(isValidData("theForm","Zip","Zip")==false)
	{
		return false;	
	}
	
	var n_strAlphaOnly = document.getElementById("Fname").value;
	var n_strAlphaOnly = n_strAlphaOnly.replace(n_regExpression,"");
	
	if (n_strAlphaOnly != document.getElementById("Fname").value)
	{
		alert("First Name can only be alpha characters (A-Z), spaces, commas, apostrophes, hyphens and periods");
		document.getElementById("Fname").focus();
		return false;
	}
	
	var n_strAlphaOnly = document.getElementById("LName").value;
	var n_strAlphaOnly = n_strAlphaOnly.replace(n_regExpression,"");
	
	if (n_strAlphaOnly != document.getElementById("LName").value)
	{
		alert("Last Name can only be alpha characters (A-Z), spaces, commas, apostrophes, hyphens and periods");
		document.getElementById("LName").focus();
		return false;
	}
	
	var emailReg = "^[a-z|0-9]+([\-|_|\.]?[a-z|0-9|_]+)*@[a-z|0-9]+([\-|\.]+[a-z|0-9]+)+$";
	var regex = new RegExp(emailReg);
	
	if (!regex.test(document.getElementById("Email").value.toLowerCase()))
	{
		alert("Email is not a valid email address");
		document.getElementById("Email").focus();
		return false;
	}					
					
	if(!fncIsNumber(document.getElementById("Zip").value))
	{
		alert("Zip must be numeric.");
		document.getElementById("Zip").focus();
		return false;
		
	}
	
	if(document.getElementById("select").value=="")
	{
		alert("Please select a reason for your credit report");
		document.getElementById("select").focus();
		return false;
	}
/* removing phone javascript since we hid the input form
	if((document.theForm.phoneCode.value == "" || document.theForm.phonePrefix.value == "" || document.theForm.phoneSuffix.value == "") &&
		document.theForm.phoneCode.value != "" || document.theForm.phonePrefix.value != "" || document.theForm.phoneSuffix.value != "")
	{
		if(document.theForm.phoneCode.value == "")
		{
			alert("Phone code could not be empty.");
			document.theForm.phoneCode.focus();
			return false;
		}
		if(document.theForm.phonePrefix.value == "")
		{
			alert("Phone prefix could not be empty.");
			document.theForm.phonePrefix.focus();
			return false;
		}
		if(document.theForm.phoneSuffix.value == "")
		{
			alert("Phone suffix could not be empty.");
			document.theForm.phoneSuffix.focus();
			return false;
		}

		if(document.theForm.phoneCode.value != "" && document.theForm.phonePrefix.value != "" && document.theForm.phoneSuffix.value != "")
		{
			if(!fncIsNumber(document.theForm.phoneCode.value))
			{
				alert("Phone code must be numeric.");
				document.theForm.phoneCode.focus();
				return false;		
			}

			if(document.theForm.phoneCode.value.length != 3)
			{
				alert("Phone code must have 3 numbers.");
				document.theForm.phoneCode.focus();
				return false;		
			}

			if(document.theForm.phonePrefix.value.length != 3)
			{
				alert("Phone prefix must have 3 numbers.");
				document.theForm.phonePrefix.focus();
				return false;		
			}

			if(document.theForm.phoneSuffix.value.length != 4)
			{
				alert("Phone suffix must have 4 numbers.");
				document.theForm.phoneSuffix.focus();
				return false;		
			}
		}
	}
*/


	return true;
}

function fncIsNumber(n_strVal) {
	var digits="1234567890.";
	for (var i=0; i < n_strVal.length; i++)
		if (digits.indexOf(n_strVal.charAt(i)) == -1)
			return false;
	return true;
}
function resetvar()
{
  formsubmit = true;
  exitviewed=true;
  return true;
}