﻿function submitFindConsultant() {

	if (!validateConsultantForm()) {
		return;
	}
	
	submitForm();
	
}

function submitFindConsultantShort() {

	if (!validateConsultantShortForm()) {
		return;
	}
	
	submitForm();
	
}

function submitFindConsultantShortZCL() {

	if (!validateConsultantShortForm()) {
		return;
	}
	
	submitFormZCL();
	
}

function validateConsultantForm() {
	
	var formObj = document.forms["findConsultant"];
	
	if (isEmpty(formObj.elements["leadContact.name.firstName"].value)) {
		alert("Please enter First Name.");
		formObj.elements["leadContact.name.firstName"].focus();
		return false;
	}
	
	if (formObj.elements["leadContact.name.lastName"].value.length < 3 ) {
		alert("Please enter at least 3 characters in the Last Name field.");
		formObj.elements["leadContact.name.lastName"].focus();
		return false;
	}
	
	if (isEmpty(formObj.elements["leadContact.name.lastName"].value)) {
		alert("Please enter Last Name.");
		formObj.elements["leadContact.name.lastName"].focus();
		return false;
	}
	
	if (isEmpty(formObj.elements["leadContact.homeAddress.streetAddress1"].value)) {
		alert("Please enter Street Address");
		formObj.elements["leadContact.homeAddress.streetAddress1"].focus();
		return false;
	}
	
	if (isEmpty(formObj.elements["leadContact.homeAddress.city"].value)) {
		alert("Please enter City.");
		formObj.elements["leadContact.homeAddress.city"].focus();
		return false;
	}
	
	if (isEmpty(formObj.elements["leadContact.homeAddress.state"].value)) {
		alert("Please select State.");
		formObj.elements["leadContact.homeAddress.state"].focus();
		return false;
	}
	
	// Check for value in siteRefer drop-down 
	if (isEmpty(formObj.elements["siteRefer"].value)) {
		alert("Please choose an option.");
		formObj.elements["siteRefer"].focus();
		return false;
	}
	if (isEmpty(formObj.elements["leadContact.homeAddress.postalCode"].value)) {
		alert("Please enter Zip Code.");
		formObj.elements["leadContact.homeAddress.postalCode"].focus();
		return false;
	}

	if (isEmpty(formObj.elements["leadContact.dayPhone.phoneNumber"].value) && 
	    //isEmpty(formObj.elements["leadContact.mobilePhone.phoneNumber"].value) && 
	    isEmpty(formObj.elements["leadContact.emailAddress.address"].value)) {
		alert("Please enter a phone number or an e-mail address, so we can follow up with your request.");
		formObj.elements["leadContact.dayPhone.phoneNumber"].focus();
		return false;
	}
	
	if (formObj.elements["interestedInCareer"].checked === false && 
	    formObj.elements["interestedInHosting"].checked === false &&
	    formObj.elements["interestedInPurchasing"].checked === false) {
		alert("Please select the information you would like to receive.");
		return false;
	}
	
	return true;
}

function validateConsultantShortForm() {
	
	var formObj = document.forms["findConsultant"];
	
	if (isEmpty(formObj.elements["leadContact.homeAddress.postalCode"].value)) {
		alert("Please enter a valid Zip Code.");
		formObj.elements["leadContact.homeAddress.postalCode"].focus();
		return false;
	}
	
	return true;
}

function submitForm() {

	var host = "www.myjockeyp2p.com";
	
	// Get host to post too, for testing purposes.
	if (location.host.match("localhost") == "localhost") {
		host = "localhost"; 
		
	} else if (location.host.match("10.0.12.162") == "10.0.12.162") {
		host = "dv.myjockeyp2p.com"; 
		
	} else if (location.host.match("testing.jockeyp2p.com") == "testing.jockeyp2p.com") {
		host = "qa.myjockeyp2p.com";
		 
	} else if (location.host.match("p2p-test-vm:3232") == "p2p-test-vm:3232"){
	    //host = "dv.myjockeyp2p.com";
	    
	}
	
	document.forms["findConsultant"].action = "http://" + host + "/locator";
	document.forms["findConsultant"].method = "POST";
	document.forms["findConsultant"].submit();
	
}

function submitFormZCL() {

	var host = "www.myjockeyp2p.com";
	
	// Get host to post too, for testing purposes.
	if (location.host.match("localhost") == "localhost") {
		host = "localhost"; 
		
	} else if (location.host.match("10.0.12.162") == "10.0.12.162") {
		host = "dv.myjockeyp2p.com"; 
		
	} else if (location.host.match("testing.jockeyp2p.com") == "testing.jockeyp2p.com") {
		host = "qa.myjockeyp2p.com"; 
	}
	
	// ORIGINAL 
	//document.forms["findConsultant"].action = "http://" + host + "/locator";
	
	// FINAL
	//document.forms["findConsultant"].action = "http://" + host + "/locator?landingPage=/productcatalog/catalog?systemRef=jockey_p2p_fall_2010_2&rfx_page=22";
	
	// TEST
	// GET THE PAGE VALUE FROM THE CATALOG
	if (location.search.match(/rfx_page=([^&=]*)(&|$)?/)) rfx_page=RegExp.$1;
	//var rfx_page = 10;

	//document.forms["findConsultant"].action = "http://" + host + "/locator?landingPage=" + escape('/productcatalog/catalog?systemRef=jockey_p2p_fall_2010&rfx_page=' + rfx_page);
	document.forms["findConsultant"].action = "http://" + host + "/locator?landingPage= ";
	//GOOD
	//document.forms["findConsultant"].action = "http://www.myjockeyp2p.com/locator?landingPage=" + escape('/productcatalog/catalog?systemRef=jockey_p2pfall_2010&rfx_page=' + rfx_page);
	
	document.forms["findConsultant"].method = "POST";
	// ADDED 1/23/2008: Villain Design
	//document.forms["findConsultant"].target = "_blank";
	document.forms["findConsultant"].submit();
	
	
}

function isEmpty(value) {
	return ((value === null) || (value.length === 0)); 
}


