
function country_redirect(){
		var cr = gup('cr');
		if (cr == 'US' || cr == 'us'){
			// if cr is passed in, make sure a cookie is created
			var country_redirect = readCookie('country_redirect');
	        if(country_redirect == null)
	        	createCookie('country_redirect', 'false', 3);
		}
		
		// now use cookie to determine whether we do redirect or not
		var country_redirect = readCookie('country_redirect');
		if (country_redirect != null && country_redirect == 'false'){
			// skip the redirect
		}else{
		    asyncGet('/getcountry.php', 'handle_country_redirect', null);
		}

}

function handle_country_redirect(response, arg){
        response = response.replace(/^\s+|\s+$/g,"");
        if(response == 'JP'){
        	window.location = 'http://www.kidrobot.jp';
        }
        else if (response == 'US'){
        	// do nothing
        }else{
        	// need to decide whether we redirect to EU
        	// handle EU traffic as well. remove the redirect here
        	// asyncGet('/getcontinent.php', 'handle_country_redirect_2', null);
        }
        	
}

function handle_country_redirect_2(response, arg){
	 response = response.replace(/^\s+|\s+$/g,"");
     if(response == 'EU'){
     	window.location = 'http://www.kidrobot.eu/';
     }
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

