
/*
jQuery(document).ready(function() {
    if(jQuery("#movFlashCore").size()>0){
        jQuery(".gBodyContainer").css("background-image","none");
    }
});
*/

var model = 'unknown';
if (location.pathname.indexOf('/ex/') == 0) 
    model = 'EX';
else 
    if (location.pathname.indexOf('/fx/') == 0) 
        model = 'FX';
    else 
        if (location.pathname.indexOf('/qx/') == 0) 
            model = 'QX';
        else 
            if (location.pathname.indexOf('/g_coupe/') == 0) 
                model = 'G_Coupe';
            else 
                if (location.pathname.indexOf('/g_sedan/') == 0) 
                    model = 'G_Sedan';
                else 
                    if (location.pathname.indexOf('/m/') == 0) 
                        model = 'M_Sedan';

var zipHasFocus = false;

function ShowZipToolTip(){
    if ($('zipToolTip')) {
        //$('zipToolTip').style.display = "";
        jQuery("#zipToolTip").fadeIn("slow");
        //$("div").fadeIn('fast');
        
        if (!zipHasFocus) {
            $('zipcode').focus();
            $('zipcode').select();
        }
        
        setTimeout('HideZipToolTip()', 2000);
    }
}

function HideZipToolTip(){
    if ($('zipToolTip')) {
        //$('zipToolTip').style.display = "none";
        jQuery("#zipToolTip").fadeOut("slow");
    }
}

function getIEVersion(){
    var version = 0
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        temp = navigator.appVersion.split("MSIE")
        version = parseFloat(temp[1])
    }
    return version
}

function isIE(){
    var version = 0
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        temp = navigator.appVersion.split("MSIE")
        version = parseFloat(temp[1])
    }
    return (version > 0);
}

function writeZipInput(zipInput){
    zipHasFocus = false;
    if (zipInput.value == '') {
        zipInput.maxLength = "20";
        zipInput.value = 'Enter Zip Code';
    }
}

function clearZipInput(zipInput){
    zipHasFocus = true;
    if (zipInput.value == 'Enter Zip Code') {
        zipInput.value = '';
        zipInput.maxLength = "5";
    }
    zipInput.select();
}

function checkZip(){
    //alert("in checkZip");
    if (!$('zipcode')) 
        return false;
    
    if ($('zipcode').value.length < 5) {
        ShowZipToolTip();
        return false;
    }
    
    var validZip = /^[0-9]{1,5}$/;
    if (validZip.test($('zipcode').value)) {
        return true;
    }
    else {
        ShowZipToolTip();
        return false;
    }
}

function onlyNumbers(evt, zipInput){
    zipInput.maxLength = "5";
    
    var e = evt;
    
    if (isIE()) 
        var charCode = e.which || e.keyCode;
    else 
        var charCode = e.which;
    
    //alert("charCode: " + charCode + '\ne.which = ' + e.which + '\ne.keyCode = ' + e.keyCode);
    
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //    ShowZipToolTip();
        return false;
    }
    
    if (charCode == 13) {
        zipHasFocus = false;
        submitZip();
        return false;
    }
    
    HideZipToolTip();
    
    return true;
}

function locateRetailer(myObj, myEvent){
    showDhtmlPop('locateretailer', myEvent, myObj, 'belowTallPage');
}

function RedirectFromCookie(){
    var zip = crmGetCookie("ZipCode");
    //alert('submitZip ' + zip);
    
    var url = '/tools/locate?zipCode=' + zip + '&next=' + model + '_accessories.locate';
    //crmEvent6();
    window.location = url;
}

function submitZip(){
    var zip = $('zipcode').value;
    //alert('submitZip ' + zip);
    
    var url = '/tools/locate?zipCode=' + zip + '&next=' + model + '_accessories.locate';
    if (checkZip()) {
        //crmEvent6();
        window.location = url;
    }
}

// adjust position of zip tooltip
function adjustZipToolTipPosition(){
    if (getIEVersion() < 7) {
        if ($('zipToolTip')) {
            jQuery('#zipToolTip').css("top", "60");
        }
    }
}

//jQuery(document).ready(adjustZipToolTipPosition);

jQuery(function(){
	if (jQuery('#gTabs').length > 0) {
		setTab();
		setHref();
	}
});


function setTab(){
    if (window.location.search.indexOf('g25') != -1) {
        jQuery('.tabContent').hide();
        jQuery('.tabContent').eq(0).show();
        jQuery('#gTabs a').eq(0).addClass('active');
        
    }
    else if (window.location.search.indexOf('g37') != -1) {
            jQuery('.tabContent').hide();
            jQuery('.tabContent').eq(1).show();
            jQuery('#gTabs a').eq(1).addClass('active');
            
    }
    else {
        jQuery('.tabContent').hide();
        jQuery('.tabContent').eq(0).show();
        jQuery('#gTabs a').eq(0).addClass('active');
        
    }
}

function setHref (){
	
	if (jQuery('#gTabs').length > 0) {
		var rel = jQuery('#gTabs a.active').attr('rel');
		
		jQuery('#secondaryMenu a').each(function(){
			var href = jQuery(this).attr('href');
			if (href === '#') {
			//do nothing
			}
			else 
				if (href != "#" && href.indexOf('?') == -1) {
					var newHref = href + '?vehicle=' + rel;
					jQuery(this).attr('href', newHref);
				}
				else 
					if (href != "#" && href.indexOf('?') != -1) {
						href = href.substring(0, href.length - 4);
						var newHref = href + '?vehicle=' + rel;
						jQuery(this).attr('href', newHref);
					}
		});
	}
}

