//alert("hi")
strIataArray = new Array (4);
for (i = 0; i < strIataArray . length; ++ i)
strIataArray [i] = new Array (2);
strIataArray [0] [0] = "";
strIataArray [0] [1] = "";
strIataArray [1] [0] = "";
strIataArray [1] [1] = "";

strIataArray1 = new Array (4);
strIataArray1 [0] = "";
	
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    //if (pair[0].toLowerCase() == variable) {
	if (pair[0].toUpperCase() == variable) {
      return pair[1];
    }
  } 
}

if(getQueryVariable("ES") == undefined)
{
	if ( Get_Cookie( 'ES' )  == null)
	{
		//Set_Cookie( 'ES', strIataArray1[0], '30', '/', '', '' );
	}
}
else
{
	if(Get_Cookie('ES') == getQueryVariable("ES"))
	{
	}
	else
	{
		//cookieval = Get_Cookie('strIATA');
		qsval = getQueryVariable("ES");
		/*cookieindex=0;
		qsindex=0;
		for (var i = 0; i < strIataArray1.length ; i++) 
		{
			if(cookieval==strIataArray1[i])
			{
				cookieindex=i;
			}
		}
		for (var i = 0; i < strIataArray1.length ; i++) 
		{
			if(qsval==strIataArray1[i])
			{
				qsindex=i;
			}
		}
		if(qsindex > cookieindex)
		{*/
			Set_Cookie( 'ES', qsval, '30', '/', '', '' );
		//}
	}
}
  
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


function redirectUrl(strUrl,strNewWindow)
{
	var txtUrl = strUrl;
	var txtNewWindow = strNewWindow;
	var flg,len,k;
	var strCookieValue;
	flg = true;
	
	if(Get_Cookie('ES') == null)
	{
	    strCookieValue = 'Thayer_AL_NATIONALHARBOR_3284';
	}
	else
	{
	    strCookieValue = Get_Cookie('ES');
	}
	
	if(txtUrl!=null)
	{
		len=txtUrl.length;
		for(k=0;k<len;k++)
		{
			if(txtUrl.substring(k,k+1) == "?")
			{flg=false;		
			break;		
			}
		}
	}
	/*if(flg==false)
	{
		if(txtNewWindow != '' && txtNewWindow=='newwindow')
		{
			window.open(txtUrl+"&ES="+strCookieValue+"&iATANumber="+strCookieValue)
		}
		else
		{
			window.location.href=txtUrl+"&ES="+strCookieValue+"&iATANumber="+strCookieValue
		}
	}
	if(flg==true)
	{
		if(txtNewWindow != '' && txtNewWindow=='newwindow')
		{
			window.open(txtUrl+"?ES="+strCookieValue+"&iATANumber="+strCookieValue)
		}
		else
		{
			window.location.href=txtUrl+"?ES="+strCookieValue+"&iATANumber="+strCookieValue
		}
	}	*/
	
	if(flg==false)
	{
		if(txtNewWindow != '' && txtNewWindow=='newwindow')
		{
			window.open(txtUrl+"&ES="+strCookieValue)
			//window.open(txtUrl)
		}
		else
		{
			window.location.href=txtUrl+"&ES="+strCookieValue
			//window.location.href=txtUrl
		}
	}
	if(flg==true)
	{
		if(txtNewWindow != '' && txtNewWindow=='newwindow')
		{
			window.open(txtUrl+"?ES="+strCookieValue)
			//window.open(txtUrl)
		}
		else
		{
			window.location.href=txtUrl+"?ES="+strCookieValue
			//window.location.href=txtUrl
		}
	}	
}
