function validateLandingForm(theForm) {

	if (theForm.first_name.value == "") {
		theForm.first_name.focus();
		alert("First Name is required");
		return false;
	}
	else if (theForm.last_name.value == "") {
		theForm.last_name.focus();
		alert("Last Name is required");
		return false;
	}
	else if (theForm.email.value == "") {
		theForm.email.focus();
		alert("Email is required");
		return false;
	}
	else if (theForm.title.value == "") {
		theForm.title.focus();
		alert("Title is required");
		return false;
	}
	else if (theForm.company.value == "") {
		theForm.company.focus();
		alert("Company is required");
		return false;
	}
	
	
	if (! validateEmail(theForm.email.value)) {
		return false;
	}

	return true;
}


function validateEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	return true;
}

function buildReturnURL() {
	
	if (document.getElementById("retURL")) {
			document.getElementById("retURL").value += "&email=" + document.getElementById("email").value + "&smartphones=" + document.getElementById("smartphones").value + "&company_billed=" + document.getElementById("company_billed").value + "&employee_billed=" + document.getElementById("employee_billed").value + "&negotiated_plans=" + ((document.getElementById("negotiated_plans_yes").checked) ? "1" : "0") + "&average_bill=" + document.getElementById("average_bill").value + "&voice_charges=" + document.getElementById("voice_charges").value + "&roaming_charges=" + document.getElementById("roaming_charges").value + "&oncampus_minutes=" + document.getElementById("oncampus_minutes").value + "&carriers_used=" + document.getElementById("carriers_used").value + "&actively_reviewed=" + ((document.getElementById("actively_reviewed_yes").checked) ? "1" : "0");
		
	}

}


function validateCalculatorLandingForm(theForm) {
	
	buildReturnURL();
	
	return validateLandingForm(theForm);
}

function preFilled(theFormField) {
	theFormField.value = "";
	theFormField.style.color = "#000000";
}



