var url_formAction_newQuote = "";

$(document).ready(function(){
	/* jquery commands here */
	url_formAction_newQuote = "https://" + location.hostname + "/TGRV2/EntryGateway.gen?zipCode=";
	$('a[rel="ext"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	$('a[rel="external"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	$('#free-quote input').autoclear();
	$('#free-quote').validate({
		errorClass: "error",
		errorElement: "div",
		rules: {
			// simple rule, converted to {required:true}
			"zipCode": {
				required: true,
				minlength: 5,
				maxlength: 5
			}
		},
		messages: {
			"zipCode": "Please enter a valid ZIP code."
		}
	});
	$('#retrieve-quote input').autoclear();
	$("#contact").validate({
		errorClass: "error",
		errorElement: "div",
		rules: {
			// simple rule, converted to {required:true}
			name: "required",
			// compound rule
			email: {
				required: true,
				email: true
			},
			phone: "required",
			subject: "required",
			comment: "required"
		},
		messages: {
			name: "Please provide your name, so we know what to call you.",
			email: {
				required: "Please provide an e-mail so that we may return the favor.",
				email: "Your email address must be in the format of name@domain.com"
			},
			phone: "Please provide a number where you can be reached.",
			subject: "What do you want to talk about?",
			comment: "Tells us about it, we're listening."
		}

	});
	$("#phone").mask("(999) 999-9999");
	
	$('#retrieve-quote').validate({
		errorClass: "error",
		errorElement: "div",
		rules: {
			// simple rule, converted to {required:true}
			"quoteNumber": {
				required: true,
				digits: true
			}
		},
		messages: {
			"quoteNumber": "Please enter a valid quote number."
		}
	});
	
	$('#video-cycle').jCarouselLite({
	    btnNext: '#next',
	    btnPrev: '#back',
		visible: 3
	});
	$('#info-cells').cycle({
		fx: 'scrollLeft', 
	    	speed: 'fast', 
	    	timeout: 0, 
	    	pager: '#dot-pagi' 
	});
	$('#tagline-cycle').cycle({
		fx: 'scrollLeft', 
    	speed: 'fast', 
    	timeout: 3000
	});
	$('#fs-retrieve-quote-faux-password input').focus(function() {
		$('#fs-retrieve-quote-password').show().children('input').val('').focus();
		$(this).parents('fieldset').hide();
	});
	$('#free-quote-menu').change(function() { setFreeQuoteFormAction(); });
	$('#free-quote-zip').keyup(function() { setFreeQuoteFormAction(); });
});


/**
 * This is a rewritten version of the setInfo() function from the old site
 * @param void
 * @return void
 * @author Jonathan Kelly
 **/
function setFreeQuoteFormAction() {

	var strFormAction = 'http://thegeneral.com/thegeneral_landingIndex.jsp';
	var strSelectedOptionValue = $('#free-quote-menu option:selected').val();
	var strZip = $('#free-quote-zip').val();
	var urlBase = "http://"
	if (document.URL.substring(0, 5) == "https" ) {
		urlBase = "https://"
	}
	switch(strSelectedOptionValue) {
		case 'AU':
			strFormAction = url_formAction_newQuote + strZip;
			break;
		case 'MO':
			strFormAction = urlBase + "www.progressive.com/insurance/thegeneral/partnership-motorcycle.aspx?code=8013000002&zipCode=" + strZip;
			break;
		case 'BO':
			strFormAction = urlBase + "www.progressive.com/insurance/thegeneral/partnership-boat.aspx?code=8013000002&zipCode=" + strZip;
			break;
		case 'MH':
			strFormAction = urlBase + "www.progressive.com/insurance/thegeneral/partnership-rv.aspx?code=8013000002&zipCode=" + strZip;
			break;
		case 'TT':
			strFormAction = urlBase + "www.progressive.com/insurance/thegeneral/partnership-travel-trailer.aspx?code=8013000002&zipCode=" + strZip;
			break;
		case 'CA':
			strFormAction = urlBase + "www.progressivecommercial.com/web-promos/thegeneral/thegeneral.aspx?zipCode=" + strZip;
			break;
		case 'HO':
			strFormAction = "/partners/homeowner/surehits/?0=0&zipcode=" + strZip;
			break;
		case 'LI':
			strFormAction = "/partners/lifeinsurance/surehits/?0=0&zipcode=" + strZip;
			break;
		case 'HE':
			strFormAction = urlBase + "www.ehealthinsurance.com/ehi/Alliance?allid=Pga26077&zip=" + strZip;
			break;
		default:
			strFormAction = url_formAction_newQuote + strZip;
	}
	
	$('#free-quote').attr('action', strFormAction);
	
	return;

}

