// trackin debug flag

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

// cookie related
	var days2keepCookie = 365;
	var cookieName = "nikebasketballHomeLocation";
	var currentCookie = getCookie( cookieName );
	
	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));
	}
	
	// if the cooke has been set, redirect
	function redirectToRegion() {
	
		if (currentCookie != null && currentCookie != "") {
			if ( currentCookie.indexOf("?") > -1 ) {
				currentCookie = currentCookie + "&ref=bball_global_redirect";
			} else {
				currentCookie = currentCookie + "?ref=bball_global_redirect";
			}
			document.location.href = currentCookie;
		}
	}

// track first then redirct to another URL, setting cookie if needed
function trackAndGoToUrl( link, actionTag, referral, cookieOk ) {
	Tracker.track( actionTag );
	
	if (referral == null || referral == "")
		var referral = defaultHost;

	if (referral == null || referral == "")
		var referral = window.location.hostname;

	if( referral && referral != null && referral == "global_home" ) {
		referral = "bball_global_home" ;
	}
   
	//alert( "link: " + link + "\nactionTag: " + actionTag + "\nreferal: " + referral + "\ncookieOk: " + cookieOk );

	if (link != null && link != "") {
		if ( cookieOk != null && cookieOk == "true" ) {
			setCookie(cookieName,link,"/");
		}
		  	  
		if ( link.indexOf("?") > -1 ) {
			link = link + "&ref=" + referral;
		} else {
			link = link + "?ref=" + referral;
		}

		// If in Debug mode, display the link
		if( cmdebug && cmdebug !=null && cmdebug== "yes" ) {
			link += "&cmdebug=yes" ;
			alert("in debug mode link= "+ link) ;
		}

		// defined in common.js
		gotoOtherSite( link )
		
   	} else {
		// System.out.println("The javascript:goToUrl() function was called with either a null or empty 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;
}

//this functionality is exclusive for USA nikebasketball baller of the week
//create properties for baller of the week pop-up window 
var newWindow;

function bow_open ( quality ) {
	
	if ( quality == "lo" ) {
		newWindow = window.open("family/bow/bow_lo.html", "lo", "height=200, width=240");
		
	} else {
		newWindow = window.open("family/bow/bow_hi.html", "hi", "height=260, width=320");

	}
}

//open window from flash
function openNewWindow( URLtoOpen, windowName, windowFeatures ) {
	newWindow = window.open(URLtoOpen, windowName, windowFeatures); 
}

var surveyWindow;

//survey pop up window
function open_survey () {

	var fixWidth = 8;
	var fixHeight = 28;	
	var screenHeight = screen.availHeight-fixHeight;
	var screenWidth = screen.availWidth-fixWidth;

	if ( screenWidth < 900 || screenHeight < 650 ) {
		//popWindow = window.open( url, "pop_window", "height="+height+", width="+width+", resizable, scrollbars" );
		surveyWindow = window.open( "http://www.easeability.com/survey/18-12/invite.html", "pop_window", "height=350, width=300, resizable, scrollbars" );
	} else {
		surveyWindow = window.open( "http://www.easeability.com/survey/18-12/invite.html", "pop_window", "height=650, width=550, resizable, scrollbars" );
		
	}
}