//global variables
var FlashCookieName = "FlashEnabled"
var FlashDetectedCookieName = "FlashDetected"

//ExpiresDays and Path are optional.
//ExipiresDays = the number of days this cookie should live for
//set ExipiresDays = 0 if you want it to expire after this session (the default)
//The default Path is "/"
function SetCookie(Name, Value, ExpiresDays, Path)
{
	var CookieString = new String(Name +"="+ Value + ";");
	if ((arguments.length >= 3) && 
		(ExpiresDays != 0))
	{	// add the expiresMS
		var ExpiresDate = new Date();
		ExpiresDate.setTime(ExpiresDate.getTime() + ExpiresDays * 24 * 60 * 60 * 1000);
		CookieString += "expires=" + ExpiresDate.toGMTString() + ";";
	}

	if (arguments.length >= 4)
	{	//set the path
		CookieString += "path=" + Path + ";";
	}
	else
	{	//the default path
		CookieString += "path=/;";
	}
	document.cookie = CookieString;
}

function GetCookie(Name)
{
	var CookieString = new String(document.cookie);
	var ReturnValue = "";
	var NameHeader = new String(Name +"=");
	
	var Start = CookieString.indexOf(NameHeader);
	
	if (Start != -1)
	{
		Start += NameHeader.length;
		var End = CookieString.indexOf(";", Start);
		if (End != -1)
		{
			ReturnValue = CookieString.substring(Start, End);
		}
		else
		{
			ReturnValue = CookieString.substr(Start);
		}
	}
	return ReturnValue;
}


//go to the FlashURL if Enabled
// otherwise goto the NonFlashURL
function FlashNavigate(FlashURL, NonFlashURL)
{
	if (IsFlashEnabled())
	{
		window.location = FlashURL;
	}
	else
	{
		window.location = NonFlashURL;
	}
	return false;
}

//Go to this url if flash is enabled.
//Returns false if it navigates (to cancel a <a> onclick event)
//or True if it doesn't
function GoIfFlash(FlashURL)
{
	if (IsFlashEnabled())
	{
		window.location = FlashURL;
		return false; //cancel the OnClick event
	}
	else
	{
		return true;
	}
}

function IsFlashEnabled()
{
	return (GetCookie(FlashCookieName)=="True")?true:false;
}

function IsFlashDetected()
{
	return (GetCookie(FlashDetectedCookieName)=="True")?true:false;
}

function IsFlashDisabled()
{
	return (GetCookie(FlashCookieName)=="False")?true:false;
}

function SetFlashEnabled(Enabled)
{
	SetCookie(FlashCookieName, (Enabled)?"True":"False", 365);
}

function SetFlashDetectedEnabled(Enabled)
{
	SetCookie(FlashDetectedCookieName, (Enabled)?"True":"False", 365);
}

function ToggleFlash(){
	if (IsFlashEnabled()){
		SetFlashEnabled(false);
	}else{
		if (IsFlashDetected()) {
			SetFlashEnabled(true);
		} else {
			if (confirm("Flash 5 has not been detected on your system. \n By enabling Flash content, you will not be able to navigate through the site properly. Are you sure you want to do this?")) {
				SetFlashEnabled(true);
			}
		}
	}
}

function WriteFlashCheckBox()
{	
	urlString = new String(document.location);
	if (urlString.indexOf('secure02') == -1){
		document.write('<input type="CheckBox" name="FlashEnabled" onClick="ToggleFlash();" ')
		if (IsFlashEnabled())
		{
			document.write(' checked ');
		}
		document.write('>Enable Flash');
	}	
}

//Disable flash and navigate to a URL
function DisableFlash(NonFlashURL)
{
	SetFlashEnabled(false);
	window.location = NonFlashURL;
	return false;
}

//Enable flash and navigate to a URL
function EnableFlash(FlashURL)
{
	SetFlashEnabled(true);
	window.location = FlashURL;
	return false;
}


function GoIfFlashBreakout(FlashURL)
{
	if (IsFlashEnabled())
	{
		top.location = FlashURL;
		return false; //cancel the OnClick event
	}
	else
	{
		return true;
	}
}





//macromedia 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;
  window.status='';
  return true;
}

function MM_findObj(n, d) { //v3.0
  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); 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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function SetStatusbar(msg){
	window.status=msg;
	return true;
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}