function textBoxValidation( inputId )
{
	var input = document.getElementById( inputId );
	
	if( isEmpty( input.value ) )
	{
		input.style.backgroundColor="yellow";
		return false;
	}
	else
	{
		input.style.backgroundColor="white";
		return true;
	}
}

function dropDownValidation( inputId )
{
	var input = document.getElementById( inputId );
		
	if( input.value == "-- Select --" )
	{
		input.style.backgroundColor="yellow";
		return false;
	}
	else
	{
		input.style.backgroundColor="white";
		return true;
	}
}

//this is the function used to validate the contact form.
function validateProperty(property)
{
	var isValid = true;	
	var emailval = document.getElementById( "EmailVal" );
	
	if( textBoxValidation( property.email.id) == false )
		isValid = false;
	else if( isEmail( property.email.value ) == false)
	{
		emailval.style.display="block";
		isValid = false;
		property.email.style.backgroundColor="yellow";
	}
	else if (isEmail( property.email.value ) == true )
		emailval.style.display="none";		
		
	if( textBoxValidation( property.firstName.id ) == false )
		isValid = false;		
	if( textBoxValidation( property.lastName.id ) == false )
		isValid = false;		
	if( textBoxValidation( property.dateOfBirth.id ) == false )
		isValid = false;			
	if( textBoxValidation( property.occupation.id ) == false )
		isValid = false;			
		
	var spouseFirstName = document.getElementById('spouseFirstName');
	if( !isEmpty(spouseFirstName.value) )
	{
		if( textBoxValidation( property.spouseLastName.id ) == false )
			isValid = false;	
		if( textBoxValidation( property.spouseDateOfBirth.id ) == false )
			isValid = false;				
		if( textBoxValidation( property.spouseOccupation.id ) == false )
			isValid = false;	
	}	
	else
	{
		makeMeWhiteAgain(property.spouseLastName.id);
		makeMeWhiteAgain(property.spouseDateOfBirth.id);
		makeMeWhiteAgain(property.spouseOccupation.id);
	}
			
	if( textBoxValidation( property.areaCode.id ) == false )
		isValid = false;				
	if( textBoxValidation( property.phonePrefix.id ) == false )
		isValid = false;				
	if( textBoxValidation( property.phonePostfix.id ) == false )
		isValid = false;
		
						
	if( textBoxValidation( property.propertyAddress.id ) == false )
		isValid = false;				
	if( textBoxValidation( property.yearBuilt.id ) == false )
		isValid = false;				
	if( textBoxValidation( property.squareFootage.id ) == false )
		isValid = false;				
	if( textBoxValidation( property.numberStories.id ) == false )
		isValid = false;		
		
	var numDogs = document.getElementById('numberDogs');
	if (numDogs.value != "0" )
	{ 
		if (!isEmpty(numDogs.value)) {
			if (textBoxValidation(property.dogType.id) == false) 
				isValid = false;
		}
	}
	else {
		makeMeWhiteAgain(property.dogType.id);
	}
			
	if (getCheckedValue(property.patioCover) == "Yes") {
		if (textBoxValidation(property.patioCoverSize.id) == false) 
			isValid = false;
	}
	else {
		makeMeWhiteAgain(property.patioCoverSize.id);
	}
	
	if( textBoxValidation(property.dateRoofReplaced.id) == false)
		isValid = false;
	if( textBoxValidation(property.numberCars.id) == false)
		isValid = false;
	if( textBoxValidation(property.numberFireplaces.id) == false)
		isValid = false;
		
		
	if(getCheckedValue(property.alarmSystem) == "Yes")
	{
		if( textBoxValidation(property.alarmCompany.id) == false)
			isValid = false;		
	}
	else
	{
		makeMeWhiteAgain(property.alarmCompany.id);
	}
	
	if( property.plumbing.value == "Other")
	{
		if(textBoxValidation(property.otherPlumbing.id) == false)
			isValid = false;
	}
	else
	{
		makeMeWhiteAgain(property.otherPlumbing.id);
	}
		
	if( textBoxValidation(property.datePlumbingReplaced.id) == false)
		isValid = false;
		
	if( getCheckedValue(property.rewired) == "Yes")
	{
		if( textBoxValidation(property.rewireDate.id) == false)
		isValid = false;
	}
	else
	{
		makeMeWhiteAgain(property.rewireDate.id);
	}
	
	
	if( textBoxValidation(property.dateAirServiced.id) == false)
		isValid = false;
	
			
				
    var validator = document.getElementById( "BlanketValidator" );
	var validator2 = document.getElementById( "BlanketValidator2" );
	
	if( isValid == false )
	{
		validator.style.display = "block";
		validator2.style.display = "block";
	}
	else
	{
		validator.style.display = "none";
		validator2.style.display = "none";
	}
	
	return isValid;
}

//this is the function used to validate the contact form.
function validateBusinessLife(businessLife)
{
	var isValid = true;	
	var emailval = document.getElementById( "bEmailVal" );
				
	if( textBoxValidation( businessLife.bFirstName.id ) == false )
		isValid = false;
		
	if( textBoxValidation( businessLife.bLastName.id ) == false )
		isValid = false;
			
	if( textBoxValidation( businessLife.bEmail.id) == false )
		isValid = false;
	else if( isEmail( businessLife.bEmail.value ) == false)
	{
		emailval.style.display="block";
		isValid = false;
		businessLife.bEmail.style.backgroundColor="yellow";
	}
	else if (isEmail( businessLife.bEmail.value ) == true )
		emailval.style.display="none";
			
	if( textBoxValidation( businessLife.bAddress.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bCity.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bState.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bZip.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bAreaCode.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bPhonePrefix.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bPhonePostfix.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bEveAreaCode.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bEvePhonePrefix.id ) == false )
		isValid = false;
				
	if( textBoxValidation( businessLife.bEvePhonePostfix.id ) == false )
		isValid = false;
					
	
    var validator = document.getElementById( "bBlanketValidator" );
	var validator2 = document.getElementById( "bBlanketValidator2" );
	
	if( isValid == false )
	{
		validator.style.display = "block";
		validator2.style.display = "block";
	}
	else
	{
		validator.style.display = "none";
		validator2.style.display = "none";
	}
	
	return isValid;
}

function validateAuto(auto)
{
	var isValid = true;	
	var emailval = document.getElementById( "aEmailVal" );
	
	if( textBoxValidation( auto.aEmail.id) == false )
		isValid = false;
	else if( isEmail( auto.aEmail.value ) == false)
	{
		emailval.style.display="block";
		isValid = false;
		auto.aEmail.style.backgroundColor="yellow";
	}
	else if (isEmail( auto.aEmail.value ) == true )
		emailval.style.display="none";
	
	if( textBoxValidation( auto.aHomeAddress.id ) == false )
		isValid = false;				
	if( textBoxValidation( auto.aAreaCode.id ) == false )
		isValid = false;				
	if( textBoxValidation( auto.aPhonePrefix.id ) == false )
		isValid = false;				
	if( textBoxValidation( auto.aPhonePostfix.id ) == false )
		isValid = false;					
	if( textBoxValidation( auto.aFirstName.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aLastName.id ) == false )
		isValid = false;	
	if( textBoxValidation( auto.aDateOfBirth.id ) == false )
		isValid = false;				
	if( textBoxValidation( auto.aDriversLicence.id ) == false )
		isValid = false;				
	if( textBoxValidation( auto.aLicenceAge.id ) == false )
		isValid = false;			
	if( textBoxValidation( auto.aLicWhere.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aOccupation.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aHowLong.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aEmployer.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aDistanceToWork.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aEmployerAddress.id ) == false )
		isValid = false;		
	if( textBoxValidation( auto.aEmployerCity.id ) == false )
		isValid = false;	
		
	var spouseFName = document.getElementById('aSpouseFirstName');
	
	if (!isEmpty(spouseFName.value)) 
	{
		if (textBoxValidation(auto.aSpouseFirstName.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseLastName.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseDateOfBirth.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseDriversLicence.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseLicenceAge.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseLicWhere.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseOccupation.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseHowLong.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseEmployer.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseDistanceToWork.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseEmployerAddress.id) == false) 
			isValid = false;
		if (textBoxValidation(auto.aSpouseEmployerCity.id) == false) 
			isValid = false;
	}	
	else
	{
		makeMeWhiteAgain(auto.aSpouseFirstName.id);
		makeMeWhiteAgain(auto.aSpouseLastName.id);
		makeMeWhiteAgain(auto.aSpouseDateOfBirth.id);
		makeMeWhiteAgain(auto.aSpouseDriversLicence.id);
		makeMeWhiteAgain(auto.aSpouseLicenceAge.id);
		makeMeWhiteAgain(auto.aSpouseLicWhere.id);
		makeMeWhiteAgain(auto.aSpouseOccupation.id);
		makeMeWhiteAgain(auto.aSpouseHowLong.id);
		makeMeWhiteAgain(auto.aSpouseEmployer.id);
		makeMeWhiteAgain(auto.aSpouseDistanceToWork.id);
		makeMeWhiteAgain(auto.aSpouseEmployerAddress.id);
		makeMeWhiteAgain(auto.aSpouseEmployerCity.id);
	}
		
	if( textBoxValidation( auto.aYear1.id ) == false )
		isValid = false;	
	if( textBoxValidation( auto.aMake1.id ) == false )
		isValid = false;	
	if( textBoxValidation( auto.aModel1.id ) == false )
		isValid = false;	
	if( textBoxValidation( auto.aVin1.id ) == false )
		isValid = false;	
	if( textBoxValidation( auto.aMiles1.id ) == false )
		isValid = false;
	if( textBoxValidation( auto.aPurch1.id ) == false )
		isValid = false;
					
	if(getCheckedValue(auto.aInsuranceNow) == "Yes" )
	{
		if( textBoxValidation( auto.aHowLongHadInsurance.id) == false )
			isValid = false;
		if( textBoxValidation(auto.aNameOfInsCo.id) == false )
			isValid = false;
	}
	else
	{
		makeMeWhiteAgain(auto.aHowLongHadInsurance.id);
		makeMeWhiteAgain(auto.aNameOfInsCo.id);
	}
	
    var validator = document.getElementById( "aBlanketValidator" );
	var validator2 = document.getElementById( "aBlanketValidator2" );
	
	if( isValid == false )
	{
		validator.style.display = "block";
		validator2.style.display = "block";
	}
	else
	{
		validator.style.display = "none";
		validator2.style.display = "none";
	}
	
	return isValid;
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function makeMeWhiteAgain( inputId )
{
	var input = document.getElementById( inputId );
	
	//if( !isEmpty( input.value ) )
		input.style.backgroundColor="white";
}



function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
     return false;   
 
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function showProperQuote()
{
	var quoteType = document.getElementById('quoteType');
	var propertyQuoteForm = document.getElementById('propertyQuote');
	var autoQuoteForm = document.getElementById('autoQuote');
	var businessLifeQuoteForm = document.getElementById('businessLifeQuote');
	
	
	if( quoteType.selectedIndex == 1 )
	{
		//show property quote.
		if (window.location == "http://localhost/centralcityinsurance/asp/propertyForm.asp" || window.location == "http://www.centralcityinsurance.com/asp/propertyForm.asp") {
		}
		else{			
			window.location = "http://www.centralcityinsurance.com/asp/propertyForm.asp";
		}

	}
	else if( quoteType.selectedIndex == 2 )
	{
		//show auto quote.
		if (window.location == "http://localhost/centralcityinsurance/asp/autoForm.asp" || window.location == "http://www.centralcityinsurance.com/asp/autoForm.asp") {
		}
		else{			
			window.location = "http://www.centralcityinsurance.com/asp/autoForm.asp";
		}
	}
	else if( quoteType.selectedIndex == 3 || quoteType.selectedIndex == 4)
	{
		//show business life quote
		if (window.location == "http://localhost/centralcityinsurance/asp/businessLifeForm.asp" || window.location == "http://www.centralcityinsurance.com/asp/businessLifeForm.asp") {
		}
		else{			
			window.location = "http://www.centralcityinsurance.com/asp/businessLifeForm.asp";
		}
	}
	else if( quoteType.selectedIndex == 0 )
	{
		//don't show any quote forms.
		if (window.location == "http://localhost/centralcityinsurance/form/QuoteForm.html" || window.location == "http://www.centralcityinsurance.com/form/QuoteForm.html") {
		}
		else{			
			window.location = "http://www.centralcityinsurance.com/form/QuoteForm.html";
		}
	}
	
	var propertyForm = document.getElementById('property');
	var autoForm = document.getElementById('auto');
	var businessLifeForm = document.getElementById('businessLife');
	propertyForm.reset();
	autoForm.reset();
	businessLifeForm.reset();
}

/* setFocus is used to automatically change the focus from one text control
 * to another. This is useful, for instance, in the case of 4-box cc entry
 * or 3-box phone entry
 * 
 * id: the id of the control that will recieve focus
 * input: a reference to the current text box
 * keyCode: the last key pressed
 * len: if the text in input exceeds len, change the focus to id.
 */
function setFocus( id, input, keyCode, len )
{
	//do not set focus if the key is a tab, shift, arrow key, etc.		
	if ((keyCode < 32) ||
		(keyCode >= 37 && keyCode <= 40))
	{
		return;
	}
	else if( input.value.length == len && id != input.id )
	{
		var textbox = document.getElementById(id);
		textbox.focus();
		textbox.select();
	}
}

function SelectAll(input)
{
	input.select();
}

