

// Global Constants
var COOKIE_NAME = 'ASAMIndex';
var COOKIE_DURATION = '15'; 			//number of days cookie lives till expires.
var COOKIE_DEFAULT_IMAGE = '1'; 		//first image to show on the page.(value represents index of Img Array)

// Global Variables
var ChartSelected = COOKIE_DEFAULT_IMAGE;	//Variable is remember which chart was selected. Used for those who don't have cookies enabled. 
//This function sets cookie to hold the index value of Img Array and changes the image.  
 var Img = new Array(6);
Img[0] = new Image(); Img[0].src = "/images/spacer.gif";
Img[1] = new Image(); Img[1].src = "/images/home/missionimg.jpg";
Img[2] = new Image(); Img[2].src = "/images/home/missionimg1.jpg";
Img[3] = new Image(); Img[3].src = "/images/home/missionimg2.jpg";
Img[4] = new Image(); Img[4].src = "/images/home/missionimg3.jpg";
Img[5] = new Image(); Img[5].src = "/images/home/missionimg4.jpg";


//Algorithm: If the cookie is not set yet, try to load the default image 
//If cookie is set, try to load the selected image. 
function updateFlash1(loop)
{
	
 if(loop){

	var flashCookie = getcookie(COOKIE_NAME);

	if(!flashCookie) {
			//eval('document.mission.src = "' + Img[1].src + '"');
			 //document.getElementById("mission").src=Img[1].src
			// window.document.fs.SetVariable("visits",1);
			
			 setcookie(COOKIE_NAME,1,COOKIE_DURATION);
			 return 1;
				
	}else {

		
flashCookie++;
		
		if(flashCookie==9){
		flashCookie=1;
		} 
		
		if(flashCookie==5){
		img=1;
		}
		else if(flashCookie==6){
		img=2;
		}else if(flashCookie==7){
		img=3;
		}else if(flashCookie==8){
		img=4;
		}else{
		img=flashCookie;
		}
		
		
	     


setcookie(COOKIE_NAME,flashCookie,COOKIE_DURATION);
	 
return flashCookie;
			
					
	}
   }
}
//This function will open a pop-up window depending on which Chart is currently Selected.
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// STANDARD COOKIE FUNCTIONS 
//////////////////////////////////////////////////////////////////////////////////////////////////////////

function getexpirydate(nodays)
{
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);	//computation is done in milliseconds
	UTCstring = Today.toUTCString();
	return UTCstring;
}

//escape method here is used to replace special characters by corresponding HEX values
function setcookie(name,value,duration)
{
	document.cookie=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	
	return getcookie(name); 		//we return getcookie here to be sure cookies are enabled on that computer		
}




//The function is passed one parameter cookiename. This is the cookie we want to retrieve. 
//We use document.cookie to retrieve all the cookie/value pairs set for our domain. The 
//function indexOf(cookiename) finds the position in the string of the first occurrence of 
//the cookiename we are looking for. If the string is not found index1 is set to -1. If it 
//doesn't find it an empty string is returned. If it finds the cookie it searches for the 
//first occurrence of ";" starting from the position of index1.The final line extracts the 
//cookie value as a substring of cookiestring and then uses unescape to translate any hex 
//coded characters back into a readable form
function getcookie(cookiename)
{	
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") {
		return ""; 
	}		
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1)	{
		index2=cookiestring.length;
	}	
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}