    $(function() {
    homeRollover();
    videoPlayer();

    //Functions for new windows.
    newWindow();
    popWindow();
});

function homeRollover(){
	$("#home a").hover(function(){
		
	});
}

function newWindow() {
    // test links with rel of external
    var $external = $('a[rel="external"]').newWindow();
    var numTargetBlanks = 0;
    $external.each(function() {
        if (this.target = "_blank") numTargetBlanks++;
    });
}

function popWindow() {
    $('a.pop').popup();
}

function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}



function validate(form, mode) {
    var errmsg;           
    if (mode == 1) {
        errmsg = $("p.valid-text1");
    } else if (mode == 2) {
        errmsg = $("p.valid-text2");
    }
    $("p.valid-text1").removeClass("error");
    $("p.valid-text2").removeClass("error");

    if ((form.zipcode.value == "") || (form.zipcode.value.length != 5) || (!IsNumeric(form.zipcode.value))) {
        errmsg.addClass("error");
    } else {
    if (mode == 1) {
            _hbPageView('Find_an_Agent','/ingoodhands.com/allstate-insurance-agent/Contact')
        } else if (mode == 2) {
            _hbPageView('Get_A_Quote','/ingoodhands.com/allstate-insurance-agent/Contact')
        }
        return true;
    }
    return false;
}       

function videoPlayer(){
	/* Testimonials */
    $("#jeremy-clip, #jeremy-thumb").click(function(e) {
        _hbLink('Testimonial-View-Jeremy');
        e.preventDefault();
        $("#playWindow").load("../../Video-Snippets/Testim_Jeremy.aspx");
    });
    $("#diane-clip, #diane-thumb").click(function(e) {
        _hbLink('Testimonial-View-Diane');
        e.preventDefault();
        $("#playWindow").load("../../Video-Snippets/Testim_Diane.aspx");
    });
    $("#ed-clip, #ed-thumb").click(function(e) {
        _hbLink('Testimonial-View-Ed');
        e.preventDefault();
        $("#playWindow").load("../../Video-Snippets/Testim_Ed.aspx");
    });		
	
	/* Video Spots */
	$("#b2b-clip, #b2b-thumb").click(function(e){
	    _hbLink('Commercial-View-b2b')
		e.preventDefault();
		$("#playWindow").load("../../Video-Snippets/Spots_B2B60.aspx");
	});	
	$("#lessons60-clip, #lessons60-thumb").click(function(e){
        _hbLink('Commercial-View-Lessons')
		e.preventDefault();
		$("#playWindow").load("../../Video-Snippets/Spots_Lessons60.aspx");
	});	
}

function doHbxPageView(pageName) {
    var pathname = window.location.pathname;
    pathname = pathname.substring(0, pathname.length - 1);
    var cc = "/ingoodhands.com" + pathname;
    // alert(pageName + ", " + cc);
    _hbPageView(pageName, cc);
}

// bind HBX hbPageView calls to external links to allstate
$("#find_an_agent_ext").live("click", function() { doHbxPageView('allstateagencies.com') });
$("#get_a_quote_ext").live("click", function() { doHbxPageView('allstate.com') });
// main
$("#goodhandscommunity_ext").live("click", function() { doHbxPageView('goodhandscommunity.org') });
$("#garage_ext").live("click", function() { doHbxPageView('allstategarage.com') });
// footer
$("#rss").live("click", function() { doHbxPageView('allstate.com') });
$("#forums").live("click", function() { doHbxPageView('goodhandscommunity.org') });
$("#vehiclevibes").live("click", function() { doHbxPageView('vehiclevibes.com') });
$("#updates").live("click", function() { doHbxPageView('allstate.com') });
// bottom footer
$("#privacy_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#terms_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#underwriting_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#about_allstate_ext").live("click", function() { doHbxPageView('allstate.com') });
// insure more
$("#insure_more_auto_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_atv_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_boat_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_condo_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_home_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_renters_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_motorcycle_ext").live("click", function() { doHbxPageView('allstate.com') });
$("#insure_more_motorhome_ext").live("click", function() { doHbxPageView('allstate.com') });
// wmv links
$("#home_inventory_video_ext").live("click", function() { _hbLink('Home_Inventory_Video') });
$("#gap_insurance_auto_video_ext").live("click", function() { _hbLink('Gap_Insurance_Video') });
// leadfusion links
$("#leadfusion_car_ext").live("click", function() { doHbxPageView('leadfusion.com') });
$("#leadfusion_house_ext").live("click", function() { doHbxPageView('leadfusion.com') });
$("#car_new_or_used_ext").live("click", function() { doHbxPageView('leadfusion.com') });
// auto insurance discounts discounts
$("#auto_insurance_discounts_ext").live("click", function() { doHbxPageView('allstate.com') });

// attach to body.onload for specific page post load handling
jQuery(document).ready(function() {
    var curLoc = window.location.href;
    var frm = null;
    if ((curLoc.indexOf("/allstate-insurance-agent/") > 0) || (curLoc.indexOf("/allstate-get-a-quote/"))) {
        // Assign event to window.onload
        jQuery(window).load(function() {
            var curLoc = window.location.href;
            var frm = null;
			var elem = null;
            if (curLoc.indexOf("/allstate-insurance-agent/") > 0) {
                frm = document.forms["findanagentform"];
				elem = "zip1";
            } else {
                frm = document.forms["getaquoteform"];
				elem = "zip2";
            }
			var zipBox = null;
			zipBox = document.getElementById(elem);
			if (zipBox != null) {
				zipBox.focus();
			}
        });
    }
});



