﻿function LoadCountry(culture) {

    if (culture == "en-nz") {
        window.location = "http://www.datacom.co.nz";
        return;
    } else if (culture == "en-au") {
        window.location = "http://www.datacom.com.au";
        return;
    }
    else {
        window.location = "http://www.datacom.com.au";
        return;
    }

    /*var exdate=new Date();
    exdate.setDate(exdate.getDate()+1);
	
    // override
    if(culture == "en-nz")
    {
    window.location = "http://www.datacom.co.nz";
    return;
    }
    
	
	location.href = "/default.aspx?ct=" + culture;
	document.cookie = "isNZ="+(culture == "en-nz") + ";expires="+exdate.toGMTString();*/
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

$(document).ready(function() {
    var auLocaleSwitchTrigger = $("#regionButton li a[id='locale-switch-au']");
    var nzLocaleSwitchTrigger = $("#regionButton li a[id='locale-switch-nz']");

    $(nzLocaleSwitchTrigger).unbind().click(function(e) {
        LoadCountry('en-nz');
        e.preventDefault();
    });

    $(auLocaleSwitchTrigger).unbind().click(function(e) {
        LoadCountry('en-au');
        e.preventDefault();
    });

    // if there's a cookie, set it to that value, else go by their location
    if (getCookie("isNZ") != "") {
        if (getCookie("isNZ") == "true") {
            $(nzLocaleSwitchTrigger).parent().addClass("active");
        } else {
            $(auLocaleSwitchTrigger).parent().addClass("active");
        }

    } else {
        if ((window.location.toString().indexOf(".co.nz") != -1 || window.location.toString().indexOf("datacom-nz") != -1)) {
            $(nzLocaleSwitchTrigger).parent().addClass("active");
        } else {
            $(auLocaleSwitchTrigger).parent().addClass("active");
        }
    }
    
    
    
	$(".headerTopNav ul :eq(0)").css('background','none');
	
	$(".headerTopNav a").wrapInner('<span class="topNavItemRight"><span class="topNavItemPadding"></span></span>').addClass(function() {
		return $(this).parent().has('ul').length > 0 ? "dropdown" : "single"
	});
	$(".headerTopNav ul li ul").append('<img src="/css/images/topnavDropDownBottom.png" />');
	
	/*$(".searchInput").val("Search Datacom").click(function () {
		if($(this).val() == "Search Datacom") {
			$(this).val("");
		}
	
	});*/
    
    
});




