
// load the theme system and replace text as necessary 
// ===================================================

	function GetTheURLparms( name ) {
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return unescape(results[1]); }

	$(document).ready(function(){
		var TheTheme = "";
		var TheTheme = GetTheURLparms('theme');
		if (TheTheme != "") {
			$('span.TheTheme').html(TheTheme);
		}
	})	







// Validate contact info fields and submit the form.
// =================================================
// Currently this is only used to validate the 3rd step of the 1 page survey. RL 2009.06.23

function validateContactInfo() {

	// collect the validity
	
	var FirstNameIsValid				= ( $('#FirstName')		.val().length != '' );
	var LastNameIsValid					= ( $('#LastName')		.val().length != '' );
	var gEmailExpression				= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var EmailAddressIsValid 			= gEmailExpression.test( $('#EmailAddress').val() );
		var gNumbersOnly 				= /^[0-9]+$/;
		var AreaCodeIsCorrectLength 	= $('#areaCode').val().length == 3;
		var AreaCodeIsNumbersOnly		= gNumbersOnly.test( $('#areaCode').val() );
		var PrefixIsCorrectLength 		= $('#prefix').val().length == 3;
		var PrefixIsNumbersOnly			= gNumbersOnly.test( $('#prefix').val() );
		var numberIsIsCorrectLength		= $('#PhoneNumber').val().length == 4;
		var numberIsNumbersOnly			= gNumbersOnly.test( $('#PhoneNumber').val() );
	var areaCodeIsValid					= AreaCodeIsCorrectLength	&& AreaCodeIsNumbersOnly ;
	var prefixIsValid					= PrefixIsCorrectLength		&& PrefixIsNumbersOnly ;
	var numberIsValid					= numberIsIsCorrectLength	&& numberIsNumbersOnly ;
	var CompanyNameIsValid				= ( $('#CompanyName')	.val().length != '' );
	var Address1IsValid					= ( $('#Address1')		.val().length != '' );
	var CityIsValid						= ( $('#City')			.val().length != '' );
	var stateIsValid					= ( $('#StateId')		.val() != -1 );
	var gZipExpression					= /(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/;
	var zipIsValid 						= gZipExpression.test( $('#zip').val() );
	var allInfoIsValid					= ( FirstNameIsValid + LastNameIsValid + EmailAddressIsValid + areaCodeIsValid + prefixIsValid + numberIsValid + CompanyNameIsValid + Address1IsValid + CityIsValid + stateIsValid + zipIsValid == 11 )

	// submit the form or inform the visitor

	if (allInfoIsValid) {
		return true;
	} else {
		$('#wrapper #content .contactInfo').css({ backgroundColor:'#fff'});	// reset colors in case the visitor comes through more than once.
		var messageToTheVisitor		= "Please check your input. The following information is not complete:\n\n";
		if (!FirstNameIsValid) 		{ messageToTheVisitor	+= "First Name\n"; 		$("#FirstName")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!LastNameIsValid) 		{ messageToTheVisitor	+= "Last Name\n"; 		$("#LastName")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!EmailAddressIsValid) 	{ messageToTheVisitor	+= "Email Address\n"; 	$("#EmailAddress")	.css({ backgroundColor:"#f6d9a4"}); }
		if (!areaCodeIsValid) 		{ messageToTheVisitor	+= "Area Code \n"; 		$("#areaCode")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!prefixIsValid) 		{ messageToTheVisitor	+= "Phone prefix\n"; 	$("#prefix")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!numberIsValid) 		{ messageToTheVisitor	+= "Phone number\n"; 	$("#PhoneNumber")	.css({ backgroundColor:"#f6d9a4"}); }
		if (!CompanyNameIsValid) 	{ messageToTheVisitor	+= "Company Name\n"; 	$("#CompanyName")	.css({ backgroundColor:"#f6d9a4"}); }
		if (!Address1IsValid) 		{ messageToTheVisitor	+= "Street Address\n";	$("#Address1")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!CityIsValid) 			{ messageToTheVisitor	+= "City\n";			$("#City")			.css({ backgroundColor:"#f6d9a4"}); }
		if (!stateIsValid) 			{ messageToTheVisitor	+= "State\n";			$("#StateId")		.css({ backgroundColor:"#f6d9a4"}); }
		if (!zipIsValid) 			{ messageToTheVisitor	+= "ZIP\n";				$("#zip")			.css({ backgroundColor:"#f6d9a4"}); }
		alert(messageToTheVisitor);
		return false;
	}

}



function setupThreePartSurvey() {

	//Initialization
	$("#step-2").hide();
	$("#step-3").hide();
	// the submit is actually available while step 1 and 2 are onscreen (It's just hidden while the first two steps on on screen.) and it's not appropriate.  
	// Disable it until we put step 3 onscreen.
	$('input#getQuotes').attr({ disabled : 'disabled'});
	
	// step one submit button
	$("#continue-1").click(function () { 
		// validate step 1
		var q1IsValid = $("input[name='rbAnswer_1']:checked").length;
		var q2IsValid = $("input[name='rbAnswer_3']:checked").length;
		if ( (q1IsValid + q2IsValid) < 2) {
			var messageToTheVisitor = 'We need more information. Please tell us: \n\n';
			if ( !q1IsValid ) { messageToTheVisitor += '* how do you plan on using your office trailer\n'			}
			if ( !q2IsValid ) { messageToTheVisitor += '* approximately how much total square footage you need\n'	}
			alert(messageToTheVisitor);
			return false;
		} else {
			// show step 2
			$("#step-1").hide();
			$("#step-2").show();
			$("#step-3").hide();
		}
	});
	
	// step two submit button
	$("#continue-2").click(function () { 
		// validate step 1
		var q1IsValid = $("input[name='rbAnswer_4']:checked").length;
		var q2IsValid = $("input[name='rbAnswer_5']:checked").length;
		var q3IsValid = 0;
		var zipCodeEntry = $("#txtZipCode").val().length;
		if (zipCodeEntry < 5) {
			q3IsValid = 0;
		} else {
			q3IsValid = 1;
		}

		if ( (q1IsValid + q2IsValid + q3IsValid) < 3) {
			var messageToTheVisitor = 'We need more information. Please tell us:\n\n';
			if ( !q1IsValid ) { messageToTheVisitor += '* approximately how long will you need the office trailer(s)\n'	}
			if ( !q2IsValid ) { messageToTheVisitor += '* when would you like to have your office trailer(s) delivered\n'	}
			if ( !q3IsValid ) { messageToTheVisitor += '* the ZIP code(s) for your office trailer delivery location(s)\n'	}
			alert(messageToTheVisitor);
			return false;
		} else {
			// show step 3, contact details
			$("#step-1").hide();
			$("#step-2").hide();
			$("#step-3").show();
			// Enable the submit button. It was disabled while either of the first 2 steps were showing.
			// The visitor can use it when contact details are onscreen.
			$('input#getQuotes').removeAttr('disabled');

		}
	});

	// step 3, contact details, are validated in a separate function via the submit handler.
}



