function GeoCode()
{
    //get the country code
    var countrycode = getCookie("geolocator:countrycode");
    
    //if it doesn't exist, set it
    if (countrycode.length == 0)
    {
        //var url = 'http://localhost/QAService/Service.asmx/GeoCode';
        //var url = 'http://service.dev.clockfour.net/Service.asmx/GeoCode';
        var url = 'http://service.clockfour.net/Service.asmx/GeoCode';
        if (url.indexOf("?") > -1)
        {
            url += "&type=jsonp";
        }
        else
        {
            url += "?type=jsonp";
        }
        
        var script = document.createElement("script");        
        script.setAttribute("src", url);
        script.setAttribute("type", "text/javascript");     
        var tagheader = document.getElementsByTagName("head")[0];
        tagheader.appendChild(script);  
       
		//delay
		var date = new Date();
		var curDate = null;
		do { curDate = new Date(); }
		while(curDate-date < 10000);
    }
}

function WriteCookie(JSONResults)
{
    //write cookies
    setCookie('geolocator:IP', JSONResults.IP);
    setCookie('geolocator:countrycode', JSONResults.countrycode);
    setCookie('geolocator:country', JSONResults.country);
    setCookie('geolocator:regioncode', JSONResults.regioncode);
    setCookie('geolocator:region', JSONResults.region);
}

//set the cookie
//c_name is the cookie name
//value is the value of the cookie
//expiredays is the number of days to let the cookie live
function setCookie(c_name, value, expiredays)
{
    expiredays = 365;
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

//get the value of the cookie
//c_name is the cookie to search for
function getCookie(c_name)
{
    //check if there are any cookies
    if (document.cookie.length > 0)
    {
        //get the cookie
        c_start = document.cookie.indexOf(c_name + "=");
        //if it exists, get the value
        if (c_start != -1)
        { 
            //parse the cookie to find the value
            c_start = c_start + c_name.length + 1; 
            //find the expiration date
            c_end = document.cookie.indexOf(";", c_start);
            //if there is none, use the length
            if (c_end == -1)
            {
                c_end = document.cookie.length;
            }
            //return the value
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}