/* ------------------------------------------------------------
   Maintains the query string. Used to sublink into the site
   ------------------------------------------------------------ */
var queryVars = new Object();
var qloc = "";

function parseQuery( p_qstr ) {
	var pairHalves;
	var queryVars = {};
	var N_V_pairs = p_qstr.split("&");
	var l = N_V_pairs.length;
	for(i=0; i<l; i++){
		pairHalves = N_V_pairs[i].split("=");
		queryVars[pairHalves[0]] = pairHalves[1];
	}
	return queryVars;
}

function buildQString( p_queryVars )
{
	var results = "";
	for( var item in p_queryVars ){
		if ( results.length > 0 )
		{
			results += "&";
		}
		if ( item.length > 0 )
		{
			results += item + "=" + p_queryVars[ item ];
		}
	}
	
	return results;
}

function cleanupQString( p_qString )
{
	if( p_qString && p_qString != null && p_qString != "" ) {
	
		if( q_str.indexOf(";") > -1 ) {
			var temp_q_str = p_qString ;
			p_qString = temp_q_str.substring( 0, p_qString.indexOf(";") );
		}
		
		// remove the question mark
		p_qString = p_qString.substring( 1 );
	
	} else {
		p_qString = "";
	}
	
	return p_qString;
};

var windowId = "NIKEiD_" + new Date().getTime();	

function getWindowId()
{
	return windowId;
};

var hashFlag = false;

function setFlag(status)
{
	hashFlag = status;
};

function getFlag()
{
	return hashFlag;
};


function checkHash() {
	if ( parent.window )

	{
		if ( parent.window.location.hash != hashLoc )
		{
			if ( parent.window.getFlag() )
			{
				hashLoc = parent.window.location.hash;
				parent.window.setFlag(false);
				
			}
			else
			{
				parent.window.location.reload( false );
			}
		
		}
		parent.window.setFlag(false);
	}
};

function setHash( newHash, newTitle )
{
	var agent = navigator.userAgent.toLowerCase();
	if ( ( agent.indexOf("macintosh") < 0 && agent.indexOf("mac_") < 0 ) &&
		navigator.appName.toLowerCase().indexOf( "microsoft" ) >= 0 )
	{
		try{parent.window.setFlag(true);
		}catch(e){};
		
		if ( newHash != null )
		{
			parent.window.location.hash = newHash;
		}
		else
		{
			parent.window.location.hash = unescape( qloc );
		}
		
		if ( newTitle != null )
		{
			title = newTitle;
		}
		else if(queryVars.title && queryVars.title != null && queryVars.title != "" && unescape(queryVars.title) != "_root")
		{
			title = unescape(queryVars.title);
		}
		else
		{
			title = "NIKEiD";
		}
		parent.document.title = title;
	}
}
;

/* ------------------------------------------------------------
   Helper function for calling external scripts asynchronously
   example:		callAsyncScript('www.myhost.com','/path/myScript.js');
   ------------------------------------------------------------ */
function callAsyncScript(jsHost,jsPath){
	var u=(("https:" == document.location.protocol) ? "https://"+jsHost : "http://"+jsHost);
	var d=document,
		g=d.createElement('script'),
		s=d.getElementsByTagName('script')[0];
		g.type='text/javascript';
		g.defer=true;
		g.async=true;
		g.src=(jsHost)? u+jsPath : jsPath;
		s.parentNode.insertBefore(g,s);
};

/* ------------------------------------------------------------
   Helper function for calling Adobe Survey from s_code plugin 
   as dhtml or popup window[true] (second argument, null or false is dhtml)
   example:		initSurvey("49078",true|false);
   ------------------------------------------------------------ */
function initSurvey(surveyId,popupBool){
	try{if(typeof s.Survey.launch=="function") 
		{ 
		s.Survey.launch(surveyId,null,null,null,popupBool);
		}
		}
		catch(e){};
	};

