// Roll-Over Functions
// ****************************************************************************************

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Javascript Cookie Functions
******************************************************************************************

setTheCookie('cookie_name','valuename:value','days to expire','path','domain'); 
expires -> enter ('-1') to Kill cookie

readCookie(cookie name, nested value ('') returns the entire value)	

modCookie('cookie_name','valuename','new_value','days to expire','path','domain'); 
new_value -> ('') deletes nested name/value
	
******************************************************************************************
*/

function expDate(days) // returns a UTC date
	{
	var today = new Date();
	var expDate = new Date( today.setDate( today.getDate() + (days) ) );
	expDate = expDate.toGMTString();
	return expDate;
	}

function setTheCookie(name,value,expires,path,domain) // sets a cookie
	{
	var cookie = name + '=' + escape(value);
	if (expires != '')
		{
		cookie = cookie + ';expires=' + expDate(expires);
		}
	if (path != '')
		{
		cookie = cookie + ';path=' + path;
		}
	if (domain != '')
		{
		cookie = cookie + ';domain=' + domain;
		}
	document.cookie = cookie;
	}

function nestedValue(name_value,prop)  // finds a value nested in the cookie value
	{
	name_value = unescape(name_value);
	var separated_values = name_value.split("&"); // Split it into an array
	var property_value = "";

	for (var loop = 0; loop < separated_values.length; loop++)
		{
		property_value = separated_values[loop];
		var broken_info = property_value.split(":");
		//alert(property_value);
	
		if (prop == broken_info[0])   // Compare to the substring (prop) we are looking for
			{ 
			var the_property = broken_info[0];
			var the_value = broken_info[1];
			return the_value; // return prop' value
			break;
			}
		}
	return false;
	}

function readCookie(name,prop) // Reads a coookie and/or a nested value
	{
    if (document.cookie == '')
    	{ 
		return false; // there's no cookie, so go no further
    	} 
    else   // there is a cookie
    	{ 
		var firstChar, lastChar;
		var theBigCookie = unescape(document.cookie);
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) // if you found the cookie
			{ 
		    firstChar += name.length + 1; // skip 'name' and '='
		    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
		  	if(lastChar == -1) lastChar = theBigCookie.length;
		  	
	    	var name_value = theBigCookie.substring(firstChar,lastChar); // Get it's value string
	    	
			if (prop != '') // looking for a nested value
				{
			    return nestedValue(name_value,prop);
				}
			else
				{	
				return name_value; // return entire cookie value
				}
			} 
		else 
			{ 
			return false;  // If there was no cookie of that name, return false.
			}
		}	
	}
	
function modCookie(name,nested,newvalue,expires,path,domain)  // modifies a existing cookie
	{
	var mainVal = readCookie(name , '');
	var nestVal = nestedValue(mainVal,nested);
	var addVal = '';
	
	if ( (mainVal != '') && (nestVal != false || nestVal != '') )  // modifies a existing nested value
		{
		if (newvalue == '')   // && (nestVal != false || nestVal != '' ) // deletes nested value
			{
			var separated_values = mainVal.split('&'); // Split it into an array
			var property_value = "";

			for (var loop = 0; loop < separated_values.length; loop++)
				{
				property_value = separated_values[loop];
				if (property_value.indexOf(nested) == (-1))
					{
					if (loop > 0)
						{
						addVal = addVal + '&';
						}
					addVal = addVal + property_value;
					}
				}
			}
		else    // changes nested value
			{
			var str1 = nested + ':' + nestVal;
			var str2 = nested + ':' + newvalue;
			addVal = mainVal.replace(str1,str2);
			}
		setTheCookie(name,addVal,expDate(expires),path,domain);
		}
	else if ( (mainVal != '') && (newvalue != '') )  // adds a nested value
		{
		addVal = mainVal + '&' + nested + ':' + newvalue;
		setTheCookie(name,addVal,expDate(expires),path,domain);
		}
	}


// Javascript Browser Functions
// *****************************************************************************

function chkPlatform()
	{
	if (navigator.platform.indexOf('Mac') != "-1") 
		{
    	return 'mac';
		} 
	else 
		{ // Assume PC
    	return 'pc';
    	}
	}
	
function chkBroType()
	{
	var broVer = navigator.appVersion.substring(0,3);
	
	if ( navigator.appName.indexOf("Netscape") != "-1" ) 
		{
	    if (broVer.indexOf("5") == "0") 
	    	{
	        return "Mo";
	    	} 
	    else 
	    	{   
	        return "Nav";
	    	} 
		}
	else 
		{
	    return "IE";
		}	
	}

function chkBrowser() // A friendly redirect to those who are using older browsers.
	{
	var redirect = "/message_browser.asp";
		
	var broType = chkBroType();
	var version = navigator.appVersion.substring(0,3);
	var cookie_name = 'broChk';
	var cookie_fail = escape('chk:1&pass:0');
	var cookie_pass = escape('chk:1&pass:1');
	
	if ( (broType == 'Nav') && (version < 5) )
		{
		setTheCookie(cookie_name,cookie_fail,'5','/','');
		document.location = redirect;
		}
	else if (broType == 'Mo' && version < 5)
		{
		setTheCookie(cookie_name,cookie_fail,'5','/','');
		document.location = redirect;
		} 
	else if (broType == 'IE' && version < 4)
		{
		setTheCookie(cookie_name,cookie_fail,'5','/','');
		document.location = redirect;
		}
	else 
		{
		setTheCookie(cookie_name,cookie_pass,'30','/','');
		}
	}
	

// Various Pop Up window Functions
// ****************************************************************************************

function winPop(url)
	{
	self.window.name = "homeWin";
	pWin = window.open(url,'searchWin','width=400,height=400,scrollbars=auto,resizable=no,top=50,left=50');
	pWin.focus();
	}
	
function winEmail(url)
	{
	self.window.name = "homeWin";	
	eWin = window.open(url,'Email','width=420,height=400,scrollbars=yes,resizable=yes,top=50,left=50');
	eWin.focus();
	}

function expWide(url) // Landscape format Experience Pop-up
	{
	var scBrs,reSize,width,height;
	if( url.indexOf("no3_nc_food") != -1 || url.indexOf("no4_nc_fallcolor") != -1 )
		{
		width  = 620;
		height = 410;
		scBrs  = "yes";
		reSize = "yes";
		}
	else
		{
		width  = 600;
		height = 400;
		scBrs  = "no";
		reSize = "no";
		}

	self.window.name = "homeWin";
	var pos_x = ((screen.availWidth - width)/2);
	var pos_y = ((screen.availHeight - (height + 50))/2);
	var ewfeatures = "width="+width+",height="+height+",scrollbars="+scBrs+",resizable="+reSize+",top="+pos_y+",left="+pos_x;
	ewWin = window.open(url,'expWide',ewfeatures);
	self.location = "/experience/exp_bkg.asp";
	ewWin.focus();
	}

function expTall(url) // Portrait format Experience Pop-up
	{
	self.window.name = "homeWin";
	var pos_x = ((screen.availWidth - 300)/2);
	var pos_y = ((screen.availHeight - 450)/2);
	var etfeatures = "width=300,height=400,scrollbars=no,resizable=no,top="+pos_y+",left="+pos_x;
	
	etWin = window.open(url,'expTall',etfeatures);
	self.location = "/experience/exp_bkg.asp";
	etWin.focus();
	}
	
	
// End Functions	
// *****************************************************************************

var broChk = readCookie('broChk','chk'); // Check Browser Version
if ( broChk == 1) {
	// been checked
} else {
	chkBrowser();
} 





