var cmdebug = getValue(location.search,"cmdebug") ;

function goToUrl() {
}


function setCookieThenRedirect( name, value, path, inURL, domain, secure ) {
	//alert("setCookieThenRedirect="+inURL);
	var today = new Date();
	var expires = new Date();
	if (days2keepCookie==null || days2keepCookie==0) days2keepCookie=1;
	expires.setTime( today.getTime() + 3600000 * 24 * days2keepCookie);
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;

	if ((inURL!="")&&(inURL!=undefined)){
		document.location = inURL;
	}
}


function setCookie( name, value, path, domain, secure ) {
	var today = new Date();
	var expires = new Date();
	if (days2keepCookie==null || days2keepCookie==0) days2keepCookie=1;
	expires.setTime( today.getTime() + 3600000 * 24 * days2keepCookie);
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return "";
	} else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

var days2keepCookie = 365;
var cookieName = "mynikehomepage";
var currentCookie = getCookie( cookieName );

if( currentCookie == "usa/" ) {
	var ref = document.referrer ;
	ref = "global_home" ;
	var to_url = "/usa/" ;
	if( ref && ref != null && ref != "" ) {
		to_url += "index.html?ref=" + ref ;
	}
	window.location = to_url ;
	
}



// pass it the queryString and the variable name
// it will return the value of that parameter or it does not exist, null
function getValue ( queryString, parameterName ) {
        if ( queryString.charAt( 0 ) == "?" ) queryString = queryString.substr(1);
        var query_array = queryString.split("&");
        for (var i=0; i< query_array.length; i++ ) {
                query_array[ i ] = query_array[ i ].split("=");
                if ( query_array[ i ][ 0 ] == parameterName ) {
                        return query_array[ i ][ 1 ];
                        break;
                }
        }
        return null;
}


