// JavaScript Document

function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }
 
function switchTab(tabName, divName, tabClass, divClass){
	$('.' + divClass).hide();
	$('#' + divName).show();
	
	$('.' + tabClass).removeClass('active');
	$('#' + tabName).addClass('active');
}

function resizeWindow(){
    var h = $(window).height();
	var w = $(window).width();
	var w2 = $(window).width() - 139;
	var ratio = (w2 / h);
	var vML = (w2 / 2);
	var hML = ((h * 1.42) / 2);
	
	$().add('.wrap').css( "min-height", h );
	$().add('.landing-col').css( "height", h );
	$().add('.home-wrap').css( "height", h );
	$().add('.home-wrap').css( "width", w2 );
	$().add('.content-wrap').css( "min-height", h );
	$().add('.background').css( "height", h );
	$().add('.exp-item').css( "height", h );
	$().add('.exp-item').css( "width", w2 );
	$().add('.exp-nav img').css( "padding-top", (h / 2) - 34 );
	
	if ( ratio < 1.42 )
	{
		$('.exp-img').removeClass("h-stretch");
		$('.exp-img').addClass("v-stretch");
	}
	else 
	{
		$('.exp-img').removeClass("v-stretch");
		$('.exp-img').addClass("h-stretch");
	}
}

$(document).ready(function() {
	resizeWindow();
});

$(window).resize(function() {	
	resizeWindow();
});

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	
	return null;
}

function setCookie(c_name,value,exdays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function oc(a)
{
    var o = {};
    for(var i=0;i<a.length;i++)
    {
        o[a[i]]='';
    }
    
    return o;
}	

function checkNALanguage(){
    if (readCookie('country_code') == null){
        try{
            if(google.loader.ClientLocation){
                visitor_country = google.loader.ClientLocation.address.country;
                visitor_countrycode = google.loader.ClientLocation.address.country_code;
                setCookie('country_code', visitor_countrycode, 7);            
            }  
        }
        catch(e){ }      
    }
    
    if (readCookie('country_code') in oc (['CA','MX','US', null])){
        return true;
    }
    
    return false;
}
