/* ----------------------------------------------------
	open new window with cookie warning
------------------------------------------------------ */
function nikeGeneralCookieNotice() {
	nikeGeneralNoticeWindow("http://www.nike.com/usa/cookie/cookies_main.jhtml", 600, 400, "winCookie");
}







/* ----------------------------------------------------
	open new window with privacy notice
------------------------------------------------------ */
function nikeGeneralPrivacyNotice() {
	nikeGeneralNoticeWindow("http://www.nike.com/usa/cookie/privacy_main.jhtml", 600, 400, "winPrivacy");
}

/* ----------------------------------------------------
	open new window
------------------------------------------------------ */
function nikeGeneralNoticeWindow(filePath,width,height,windowName) {

	var win_x = (screen.width - width)/2;
	var win_y = (screen.height - height)/2;

	var features = 'toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+width+',height='+height+',screenX='+win_x+',screenY='+win_y+',top='+win_y+',left='+win_x;

	windowName = window.open(filePath, windowName, features);
	windowName.focus() ;

}

/* ----------------------------------------------------
	check if cookies are enabled and return true/false
------------------------------------------------------ */
function nikeGeneralCookiesEnabled(){ 
	document.cookie = "temp=test";
	readCookie = -1; 
	if(document.cookie.length > 0){
		readCookie = document.cookie.indexOf("temp=");
	}
	if (readCookie == -1){
		//got no cookies;
		return false;
	} else {
		//got cookies;
		document.cookie = "temp=test; expires=Thu, 01-Jan-70 00:00:01 GMT";
		return true;
	}
}

function isRetail()
{
	var cookieName = "NikeiDRetailCookie";
	var cookieValue = "";
	var nameEQ = cookieName + "=";
	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) cookieValue = c.substring(nameEQ.length,c.length);
	}
	
	return cookieValue.length > 0 ? "true" : "false";
}

function setCountryLocale( p_country, p_locale )
{
	if( p_country.indexOf( "," ) > -1 )
	{
		var temp = p_country.split( "," );
		p_country = temp[ 0 ];
		p_locale = temp[ 1 ];
	}
	setNikeCookie( "NIKEID_country", p_country );
	setNikeCookie( "NIKEID_locale", p_locale )
}

function setNikeCookie( name, value )
{
	var a = document.location.host.split(".");
	var domain = a[a.length-2] + "." + a[a.length-1];
	setCookie( name, value, domain );
}

function setCookie( name, value, domain )
{
	var expire = new Date();
	expire.setTime(expire.getTime()+( 1000*60*60*24*365) ); // 1 year
	if (domain == null) domain = document.location.host;
	document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; path=/; domain=" + domain;
}


