var win= null;

function ForceTopFrameLoad(pageName, str)
{
	var sURL = "Frameset.aspx?pageName="+pageName+"&"+str;
	parent.window.location = sURL;
}

function SetHeaderAndAgencyInfo(hdrName, agencyName, logoPath)
{
		try
		{
			top.TopFrame.window.document.frmheader.txtPageHeader.value = hdrName;
			
			if (logoPath != "")
			{
				top.TopFrame.window.document.images[1].src = logoPath;
			}
			else
			{
				top.TopFrame.window.document.all.spanAgencyName.innerText = agencyName;		
			}
		}

		catch (e)
		{
			setTimeout ('SetHeaderAndAgencyInfo("' + hdrName + ',' + agencyName + ',' + logoPath + '")', 500);
		}

}


function FixChars(name)
{
	var newName = "";
	for (var i=0; i < name.length; i++)
	{
		if (name.substr(i,1) == "'")
		{
			newName = newName + "&#39;";
//			newName = newName + "\&#39;";
//			newName = newName + "<";
		}
		else
		{
			newName = newName + name.substr(i,1);
		}
	}
	
	return newName;
}

function set_agency_name(name)
{
		try
		{
			top.TopFrame.window.document.all.spanAgencyName.innerText = name;
		}

		catch (e)
		{
			setTimeout ('set_agency_name("' + name + '")', 500)
		}
}

function set_logo(path)
{
		try
		{
//			alert("getting logo");
//			var logoObject = top.TopFrame.window.document.getElementById(logo);
//			var logoObject = top.TopFrame.window.document.getElementById(Logo1);
//			var logoObject = top.TopFrame.document.getElementById(Logo1);
//			alert("got logo");
//			logoObject.src = path;
			
			top.TopFrame.window.document.images[1].src = path;
//			top.TopFrame.window.document.images[2].src = path;
//			top.TopFrame.window.document.Logo1.src = path;
		}

		catch (e)
		{
			setTimeout ('set_logo("' + path + '")', 500)
		}
}

function set_header(line)
	{
		try
		{
			top.TopFrame.window.document.frmheader.txtPageHeader.value = line;
		}

		catch (e)
		{
		setTimeout ('set_header("' + line + '")', 500)
		}
	}

function NewWindow(mypage,myname,w,h,scroll) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no'
	win=window.open(mypage,myname,settings)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

function NewWindowMaximized(mypage,myname) {
	win=window.open(mypage,myname)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

function NewWindowForceMaximized(mypage,myname) {
	settings='height='+(screen.availHeight-55)+',width='+ (screen.availWidth-10) +',top=0,left=0,screenX=0,screenY=0,scrollbars=yes,toolbar=no,location=no,status=yes,menubar=no,resizable=yes,dependent=no';
	win=window.open(mypage,myname,settings)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

function NewWindowResizable(mypage,myname,w,h,scroll) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no'
	win=window.open(mypage,myname,settings)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

function NewWindowResizableRawVerticalPlacement(mypage,myname,w,h,top,scroll) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-60);
	settings='height='+wint+',width='+w+',top='+top+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no'
	win=window.open(mypage,myname,settings)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

function displayLayer(layerName, imageObject) {
	var lyr = document.getElementById(layerName);
	
	if (lyr.style.display == 'block') {
		lyr.style.display = 'none';
		imageObject.src = 'graphics/sort_down.jpg';
	} else {
		lyr.style.display = 'block';
		imageObject.src = 'graphics/sort_up.jpg';
	}
}


function ShowSelectTravelerPopUp(url)
{/* For CSR234901P01 MTAMOnlineCheckin Rakesh/IGT/WSPN] */

	document.getElementById("hidURL").value = url;
}

function MoveOlciTravelerPopup(event)
{/* For CSR234901P01 MTAMOnlineCheckin Rakesh/IGT/WSPN] */

	var TravelerPopup = document.getElementById("SelectTravelerPopup");
	var w = 500;
	var h = 175;		
	
    var cursor = {x:0, y:0};
    if (event.pageX || event.pageY) {
        cursor.x = event.pageX;
        cursor.y = event.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = event.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = event.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	TravelerPopup.style.display = '';
	TravelerPopup.style.left = ((cursor.x-((w/2))-120));
	TravelerPopup.style.top = (cursor.y - h)-8;
	TravelerPopup.style.width = w;
	TravelerPopup.style.height = h;
}

function CallJumpPage()
{/* For CSR234901P01 MTAMOnlineCheckin Rakesh/IGT/WSPN] */
	var URL = document.getElementById("hidURL").value;
	var TravelerList = document.getElementById(targetField);
	var TravelerName = TravelerList[TravelerList.selectedIndex].text;
	var TravelerLastName= TravelerList[TravelerList.selectedIndex].value;
	if(TravelerName!="" && TravelerList.selectedIndex!=0)
	{	
		var Names = TravelerLastName.split("/");
		var LastName = Names[0] ;
		var FirstName = Names[1];
		
		document.getElementById("SelectTravelerPopup").style.display = 'none';
		URL = URL.replace("RFN",FirstName);
		URL = URL.replace("RLN",LastName);
		NewWindowForceMaximized(URL,"JumpPage");
		TravelerList.selectedIndex = 0;
	}
}

function ShowOnLineCheckInPopUp(vendorName,inactiveLinkText)
{/* For CSR234901P01 MTAMOnlineCheckin Rakesh/IGT/WSPN] */

	document.getElementById("checkinVendorName").innerHTML = vendorName;
	document.getElementById("checkinVendorText").innerHTML = inactiveLinkText;
}

function MoveOlciPopup(event)
{/* For CSR234901P01 MTAMOnlineCheckin Rakesh/IGT/WSPN] */

	var checkInPopup = document.getElementById("OnlineCheckinPopup");
	var w = 350;
	var h = 175;
		
	//e = window.event;
    var cursor = {x:0, y:0};
    if (event.pageX || event.pageY) {
        cursor.x = event.pageX;
        cursor.y = event.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = event.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = event.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	checkInPopup.style.display = '';
	checkInPopup.style.left = cursor.x - (w-50);
	checkInPopup.style.top = (cursor.y - h)-8;
	checkInPopup.style.width = w;
	checkInPopup.style.height = h;
}

function toggleStopOver(idStop)
{
    if (document.getElementById)
    {       
        var object = document.getElementById(idStop);             
        if (object != null)
        {         
          if( object.style.display == "none" )
          {        
            object.style.display = "";
          }
          else
          {        
            object.style.display = "none";
          }
        }
    }
}

// Sends _trackEvent for both pageTracker and rollupTracker, if they exist.
function gaTrackEvent(category, action, optional_label, optional_value)
{
      var bResult = false;

      if (isDefined("pageTracker"))
      {
            switch (arguments.length)
            {
                case 2:
                    bResult = trackEventWithTracker(pageTracker, category, action);
                    break;
                case 3:
                    bResult = trackEventWithTracker(pageTracker, category, action, optional_label);
                    break;
                case 4:
                    bResult = trackEventWithTracker(pageTracker, category, action, optional_label, Number(optional_value));
                    break
            }
      }

      if (isDefined("rollupTracker"))
      {
            switch (arguments.length)
            {
                case 2:
                    bResult = trackEventWithTracker(rollupTracker, category, action);
                    break;
                case 3:
                    bResult = trackEventWithTracker(rollupTracker, category, action, optional_label);
                    break;
                case 4:
                    bResult = trackEventWithTracker(rollupTracker, category, action, optional_label, Number(optional_value));
                    break;
            }
      }

      //alert("Tracking of : " + category + ", " + action + ", " + optional_label + ", " + optional_value + "\nResult : " + bResult);
}

// Wraps Google Analytics' pageTracker._trackEvent(category, action, optional_label, optional_value);
function trackEventWithTracker(gaTracker, category, action, optional_label, optional_value)
{
    try
    {
        if (arguments.length < 3)
        {
            return false;
        }
        
        if (gaTracker._trackEvent)
        {
            switch (arguments.length)
            {
                case 3:
                    return gaTracker._trackEvent(''+category, ''+action);
                    break;
                case 4:
                    return gaTracker._trackEvent(''+category, ''+action, ''+optional_label);
                    break;
                case 5:
                    return gaTracker._trackEvent(''+category, ''+action, ''+optional_label, optional_value);
                    break;
            }
        }
        else
        {
            return false;
        }
    }
    catch(err) { return false; }
}


// Pass in a string as the variable argument.
function isDefined(variable)
{
    var temp;
    if (variable === temp)
    {
      return false
    }
    else
    {
        if ( typeof (variable) == "string")
        {
              return (typeof( window[variable] ) !== "undefined");
        }
        else
        {
              return (typeof (variable) !== "undefined");
        }
    }
}

function ShowBaggageMessage()
{
   document.getElementById("dvETR").style.display = "none";
   document.getElementById("dvErrorBaggage").style.display = "";  
}

function ShowETR()
{
   document.getElementById("dvETR").style.display = "";
   document.getElementById("dvErrorBaggage").style.display = "none";
}

function ShowAirlineBaggage(baggageLink)
{
    win=window.open(baggageLink)
	if (parseInt(navigator.appVersion) >= 4){ 
		win.window.focus();
	}
}

