var t=setTimeout("var t='loaded'",2000);

function setRegion(selItem, item) {
	if (window.location.href.indexOf(item.value) == -1) {
		window.location = item.value;	
	} else {
		var web_path = window.location.pathname.split("/");
		if (web_path[1] == "us" && item.value.indexOf("us") == -1) {
			// additional check for "us" slash
			window.location = item.value;			
		}
	}
}


function setCookieVal() {
    var currURL = location.href;
    var regionVal = readCookie("region");
    var URL_Refer = document.referrer;
    if(readCookie("region")!=null)
    {
        if((regionVal=="uk")&&(currURL.indexOf("objective.co.uk")==-1))
        {
            if(URL_Refer.indexOf("objective.co.uk")<0 && URL_Refer.indexOf("objective.com")<0){
                var newURL = "http://www.objective.co.uk";
                try{
                    document.getElementById('Click_UK').click();
                }catch(e){
                    location.href=newURL;
                }
            }else{
                createCookie("region","au",30);   
            }
        }
        if(regionVal=="au" && currURL.indexOf("objective.com")<0)
        {
            if(URL_Refer.indexOf("objective.co.uk")<0 && URL_Refer.indexOf("objective.com")<0){
                var newURL = "http://www.objective.com";
                try{
                    document.getElementById('Click_AU').click();
                }catch(e){
                    location.href=newURL;
                }
            }else{
                createCookie("region","uk",30);
            }
        }
    }
}


function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name) {
    createCookie(name,"",-1);
}

