/* ------------------------------------------------------------
   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];
		for(d=2;d<pairHalves.length;d++) {
			queryVars[pairHalves[0]] += "=" + pairHalves[d];
		}
	}
	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;
}

/* ------------------------------------------------------------
   Used for resizing objects when dealing with 100% Flash movies
   ------------------------------------------------------------ */

function getWinSize()
{
	var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' )
      {
         //Non-IE
         myWidth = window.innerWidth;
         myHeight = window.innerHeight;
      }
      else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
      {
          //IE 6+ in 'standards compliant mode'
          myWidth = document.documentElement.clientWidth;
          myHeight = document.documentElement.clientHeight;
      }
      else if(document.body && (document.body.clientWidth || document.body.clientHeight))
      {
          //IE 4 compatible
          myWidth = document.body.clientWidth;
          myHeight = document.body.clientHeight;
      }
      return {w:myWidth,h:myHeight}
      
}   
   
function adjustObjectSize(id,w,h)
{
      var winSizes = getWinSize();
      
      var tmpObject = document.getElementById(id);

      if(winSizes.w < w)
      {
         tmpObject.style.width = w + "px";
      }
      else
      {
         tmpObject.style.width = "100%";
      }
      if(winSizes.h < h)
      {
         tmpObject.style.height = h + "px";
      }
      else
      {
         tmpObject.style.height = (winSizes.h)-2 + "px";
      }
}

/* ------------------------------------------------------------
   Used for getting the users browser
   ------------------------------------------------------------ */

// browser detection
var _appName = navigator.appName;
var _appVersion = navigator.appVersion;
var _userAgent = navigator.userAgent.toLowerCase();

function getBrowser() {
      
      var browser = '';
      
      if ((_appName.indexOf('Microsoft') != -1) && (_userAgent.indexOf('mac') == -1)) {
		  browser = 'IE';
	  // We're treating MAC IE as a special case anymore
	  } else if ((_appName.indexOf('Microsoft') != -1) && (_userAgent.indexOf('mac') != -1)) {		
	      browser = 'Other';
	  } else if (_userAgent.indexOf('safari') != -1) {
		  browser = 'Safari';
	  } else if (_userAgent.indexOf('firefox') != -1) {
		  browser = 'Firefox';
	  } else {
		  browser = 'Other';
	  }
	  return browser;
}

/* ------------------------------------------------------------
   Used for setting a cookie
   ------------------------------------------------------------ */
function setCookie(name, value, path, domain) {
     var today = new Date();
	   var expires = new Date();
	   expires.setTime( today.getTime() + 3600000 * 24 * 365);
	   var curCookie = name + "=" + escape(value) +
		  ((expires) ? "; expires=" + expires.toGMTString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "");
		  //alert("name: " + name + ", value: " + value + ", path: " + path + ", domain: " + domain);
	   document.cookie = curCookie;
 } 
 
 function deleteCookie(name, path, domain) {
 		var today = new Date();
 		var expires = new Date();
 		expires.setTime (today.getTime() - (360000 * 24 * 365));
 		var curCookie = name + "=" + escape("") +
 		((expires) ? "; expires=" + expires.toGMTString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "");
		  document.cookie = curCookie;
}

function evalCookie(name,value) {
		var cookiestring = "" + document.cookie;
		var index1 = cookiestring.indexOf( name );
		if (index1 == -1 || name == "") return false;

		var index2=cookiestring.indexOf( ';', index1 );
		if ( index2 == -1 ) index2 = cookiestring.length;

		var cookieValue = unescape(cookiestring.substring( index1 + name.length + 1, index2 ));
		if (cookieValue == value){
			return true;
		} else {
			return false;
		}
	}

/* ------------------------------------------------------------
   Used for determining if we are on the live site
   ------------------------------------------------------------ */
		function isLiveSite() {
			var hostname = location.hostname;
	
			if (hostname.indexOf("nike-dev2") >= 0 || hostname.indexOf("env") >= 0) {
				return false;
			}
			else {
				return true;
			}
		}
