
/*
* we have this function because portal allows only one <body>
* however, we need onload in different place, like
* need checkCookie() in homepage
* need datecheck in QuickFinder pages
*/
function doOnLoad()
{
//Home page
var home_prod = "http://www.bcaa.com/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_MD/_s.7_0_A/7_0_MD";
var home_test = "http://aerostar.bcaa.bc.ca/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_G5/_s.7_0_A/7_0_G5";

//Quick Search - Hotels
var hotel_prod = "http://www.bcaa.com/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_M8/_s.7_0_A/7_0_M8";
var hotel_test = "http://aerostar.bcaa.bc.ca/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_FQ/_s.7_0_A/7_0_FQ";
var hotel_myprod = "http://www.bcaa.com/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_M8/_s.7_0_A/7_0_M8";
var hotel_mytest = "http://aerostar.bcaa.bc.ca/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_FQ/_s.7_0_A/7_0_FQ";

//Quick Search - Flights
var flight_prod = "http://www.bcaa.com/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_M3/_s.7_0_A/7_0_M3";
var flight_test = "http://aerostar.bcaa.bc.ca/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_FR/_s.7_0_A/7_0_FR";
var flight_myprod = "http://www.bcaa.com/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_M3/_s.7_0_A/7_0_M3";
var flight_mytest = "http://aerostar.bcaa.bc.ca/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_FR/_s.7_0_A/7_0_FR";

//Quick Search - Car
var car_prod = "http://www.bcaa.com/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_N6/_s.7_0_A/7_0_N6?NewPageAptrixContext=http://www.bcaa.com/ilwwcm/connect/BCAA/Home/Take+a+Trip/Air+Travel/IDX+-+Air+Travel+-+Car+-+QuickFinder";
var car_test = "http://aerostar.bcaa.bc.ca/wps/portal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_GU/_s.7_0_A/7_0_GU?NewPageAptrixContext=http://sienna.bcaa.bc.ca:9080/content/connect/BCAA/Home/Take+a+Trip/Air+Travel/IDX+-+Air+Travel+-+Car+-+QuickFinder";
var car_myprod = "http://www.bcaa.com/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_N6/_s.7_0_A/7_0_N6?NewPageAptrixContext=http://www.bcaa.com/ilwwcm/connect/BCAA/Home/Take+a+Trip/Air+Travel/IDX+-+Air+Travel+-+Car+-+QuickFinder";
var car_mytest = "http://aerostar.bcaa.bc.ca/wps/myportal/!ut/p/.cmd/cs/.ce/7_0_A/.s/7_0_GU/_s.7_0_A/7_0_GU?NewPageAptrixContext=http://sienna.bcaa.bc.ca:9080/content/connect/BCAA/Home/Take+a+Trip/Air+Travel/IDX+-+Air+Travel+-+Car+-+QuickFinder";

//There is no onload function for Quick Search ¨C Cruise as yet.
	var here = location;
	if ( here == home_prod || here == home_test )
	{
		checkUserIdCookie();
	}
	else if ( here == hotel_prod || here == hotel_myprod || here == hotel_test || here == hotel_mytest )
	{
		SettingHotelDates();
	}
	else if ( here == flight_prod || here == flight_myprod || here == flight_test || here == flight_mytest )
	{
		SettingAirDates();
	}
	else if ( here == car_prod || here == flight_mytest || here == car_test || here == car_mytest )
	{
		SettingCarDates();
	}
	else
	{
	}
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function checkCookie()
{
	var here = location ;
	if ( /myportal/.test(here) )
	{
	}
	else
	{
		var uname = readCookie("cookie_username") ;
		var pwd = readCookie("cookie_password") ;
		if ( uname != "" && pwd != "" )
		{
			MM_setTextOfTextfield("userid","",uname);
			MM_setTextOfTextfield("password","",pwd);
			MM_setCheckboxfield("rememberMe",true);
			document.LoginPage.submit();
		}
	}
}

function checkUserIdCookie()
{
	var here = location ;
	if ( /myportal/.test(here) )
	{
	}
	else
	{
		var uname = readCookie("USERIDCOOKIE") ;
		if ( uname != "" )
		{
			MM_setTextOfTextfield("userid","",uname);
			MM_setCheckboxfield("rememberMe",true);
		}
	}
}


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_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

function MM_setCheckboxfield(objName,bool) { //v3.0
  var obj = MM_findObj(objName);
  if (obj)
  {
	obj.checked = bool;
  }
}