/************************************* Flight Result Specific Scripts ****************************************/
/****** Created By: Surabhi Gupta ******/
/****** Dated: 5th September 2007 ******/
/****** Purpose: This Javacript file contains all the functions related to Flight Search & Results ******/

/************************************* Flight Result Specific Scripts Starts ****************************************/
var iFilesLoaded = 0
var strSessionId = ""
var bFirstResult = true
var objMergeXML;   
var strQry
var totAirlines
var arrAirLines = new Array();
var bool;
var sIndex;
var nColumns = 4;
var startAirlineIndex = 1; endAirlineIndex = 5;
var faresearch;
var currencyCode;
var showFareSource = false;
var totalFlight;
var xu = new XML();
var spnTotalResults = document.getElementById("spnTotalResults");
var dom = new DOM();
var globalSortId;
var showClassDiv;
var iBEReply;
var Allresultsload = false;
var compId = "UK";
var searchCompId;
var jType;

//Paging releated variables
var TotalResultCount;
var pages;
var PagingCounter =50;
var xmlPagerFlightResult;
var xmlOrigFlightResult;
var xmlOrigCalcFlightResult;
var startIndex =1;
var endIndex = (parseInt(PagingCounter) +1);

function SearchFlightMain() 
{
    
  var hdnJourneyType = getElement("hndJourneyType", false).value;
  var hdnFlightMode = getElement("hdnFlightMode", false).value;
  var hndFirstJourneyType = getElement("hndFirstJourneyType", false).value;
  
  var flag = true;
  if (hndFirstJourneyType != "ID") 
  {
    flag = false;
    GetFlightCount()
  }
  if (flag == true) 
  {
    SearchFlight();
  }
}

var xmlHttp;
function GetFlightCount() 
{
  xmlHttp = new GetXmlHttpObject();
  //var xmldom = xu.GetXMLDocument();
  if (xmlHttp) 
  {
    var webServiceURL;
    // Commented temporarily because Mozilla debugging only works for local requests.
    var wsPath = new DOM().$("ctl00_contentMain_hdnDomain").value;
    wsPath = (wsPath == "http://localhost/") ? "http://localhost/online_1/ASPX/" : wsPath;
    webServiceURL = wsPath + "Online/ASPX/Validations.aspx?Validate=flightsearch";
    
     if (new BrowserSniffer().GetBrowserType() == "ie")
        xmlHttp.open("POST", webServiceURL, true);
    else
        xmlHttp.open("GET", webServiceURL, true);

    xmlHttp.onreadystatechange = fnFlightCount;
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(null);
    
  }
}

function fnFlightCount() 
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') 
  {
    if (xmlHttp.status == 200) 
    {

      totalFlight = xmlHttp.responseText;
			// Check re-added to check for Threads returned = 0.
      // Someone removed this check !!!
      if (totalFlight == "0")
      {
				RedirectToStartPage();
				return;
      }
      getElement("hndFilesToLoad", false).value = totalFlight;
      var hdnJourneyType = getElement("hndJourneyType", false).value;
      var hdnFlightMode = getElement("hdnFlightMode", false).value;
      var hndFirstJourneyType = getElement("hndFirstJourneyType", false).value;

      if (hdnFlightMode == "I") 
      {
				// Do nothing?
      }
      else 
      {
        if (hdnFlightMode == "D") 
        {
          if (hdnJourneyType == "R") 
          {
            iBEReply = getElement("hndFilesToLoad", false).value;
            iBEReply = parseInt(iBEReply) / 2
            getElement("hndFilesToLoad", false).value = iBEReply;
          }
        }
        else 
        {
          if (hndFirstJourneyType == "ID") 
          {
            iBEReply = getElement("hndFilesToLoad", false).value;
            iBEReply = parseInt(iBEReply) / 2
            getElement("hndFilesToLoad", false).value = iBEReply;
          }
        }
      }
      SearchFlight();
    }
  }
}

function SearchFlight() 
{
//debugger
    
  if (strSessionId == "") 
  {
		// Commented temporarily because Mozilla debugging only works for local requests.
    strSessionId = getElement("hndSessionId", false).value
    //strSessionId = "OD-xtk4wd55ghmghmfnd0liamj3"
    
  }
  xmlHttp = new GetXmlHttpObject();
	
  if (xmlHttp) 
  {
    var webServiceURL;
   
    if (getElement("hdnISLCCRT", false).value == "True")
    {
        strSessionId = strSessionId.replace("OD","IN");
    }

    if (bFirstResult == true) 
    {
      strQry = "<QryXML><SessionId>" + strSessionId + "</SessionId><FirstHit>true</FirstHit><AllAtOnce>" + dlFaresAtOnce + "</AllAtOnce><FilesToLoad>" + getElement("hndFilesToLoad", false).value + "</FilesToLoad><numOfAdults>" + getElement("numFLAdults", false).value + "</numOfAdults><numOfChildren>" + getElement("numFLChildren", false).value + "</numOfChildren><numOfInfants>" + getElement("numFLInfants", false).value + "</numOfInfants></QryXML>"
    }
    else 
    {
      strQry = "<QryXML><SessionId>" + strSessionId + "</SessionId><FirstHit>false</FirstHit><AllAtOnce>" + dlFaresAtOnce + "</AllAtOnce><numOfAdults>" + getElement("numFLAdults", false).value + "</numOfAdults><numOfChildren>" + getElement("numFLChildren", false).value + "</numOfChildren><numOfInfants>" + getElement("numFLInfants", false).value + "</numOfInfants></QryXML>"
    }
   
    // Commented temporarily because Mozilla debugging only works for local requests.
    var XChangeOnlineService = getElementWithSeparator('hdnSvcXChange', false, '', '_').value;
    //var XChangeOnlineService = "http://localhost/XChangeOnlineService/XChangeOnlineService.asmx"
    webServiceURL = XChangeOnlineService + '/GetFareDetails?strInputXML=' + strQry;

    xmlHttp.onreadystatechange = ServiceResponseHandler;
    xmlHttp.open("GET", webServiceURL, true);
    xmlHttp.send(null);

  }
  else 
  {
    alert("Error! Your browser does not seem to support Ajax!");//Error! Your browser does not seem to support Ajax!
  }
}

function ServiceResponseHandler() 
{
//debugger

  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') 
  {
    if (xmlHttp.status == 200) 
    {
   
		var aj = new Ajax();
		var strResult = aj.GetResponseText(xmlHttp);
		ToggleLayer(true);
		var xmlResult = xu.LoadXMLString(strResult);
		
     // prompt('strResult',strResult);;
//      debugger;
      if ( (xu.HasXML(xmlResult)) && (xmlResult.documentElement.nodeName != "Message") )
      {
        iFilesLoaded += parseInt(xu.SelectNodeValue(xmlResult, "FilesLoaded"))
        var strResult;
        strSalesChannel = getElement("hdnChannelType", false).value
        searchCompId= getElement("hdnCompId", false).value
        if (strSalesChannel.indexOf("Online") > 0)
        {
          strSalesChannel = "Online"
        }
        if (compId != searchCompId)
        {
            if (bFirstResult == true) 
            {
              ToggleComponents();
            }
        }
		mergeResultXML(xmlResult)
		xmlOrigFlightResult =objMergeXML;
		xmlPagerFlightResult =objMergeXML;
		if (compId != searchCompId)
        {
            if (bFirstResult == true) 
            {
              
                  document.getElementById("tdFilters").style.visibility = "visible"
                  document.getElementById("tdFilters").style.position = ""
                  init(true)
                  totAirlines = 0
                 bFirstResult = false
            }
            else 
            {
              init(false)
            }
          CreateAirlines(objMergeXML)
		 CreatePager(TotalResultCount);
        }
        bFirstResult = false;
      }
      else 
      {
        iFilesLoaded += parseInt(xu.SelectNodeValue(xmlResult, "FilesLoaded"))
      }
      var iTotalFiles = getElement("hndFilesToLoad", false).value
      if (parseInt(iFilesLoaded) < parseInt(iTotalFiles)) 
      {
        setTimeout(SearchFlight, 2000)
        //showClassDiv="false"
        if ( (xu.HasXML(xmlResult)) && (xmlResult.documentElement.nodeName != "Message") )
        {
            Allresultsload = true;
            if (compId != searchCompId)
            {
						// Only show results at once if ShowFaresAtOnce is True.
						if (!showFaresAtOnce)
						{
							sortAllResults(false, 'PR');
						}
            }
        }
      }
      else 
      {
        if (!xu.HasXML(objMergeXML)) 
				{
					//ObsoleteRedirectToStartPage();
					RedirectToStartPage();
				}
        else 
        {
        //debugger 
//			alert('Sorting Start')
//			alert(xu.SelectNodeValue(xmlOrigFlightResult, "/FCRep"))
			var xu1 = new XML();
			xu1.AddParameter("SortId", "Price")
			xu1.AddParameter("AddTags", "False")
			strResult = xu1.XSLTransform(xmlOrigFlightResult, "../XSLT/SortFlight.xslt", "xml");
//			alert(strResult)
			xmlOrigFlightResult = xu1.LoadXMLString(strResult);
			if (compId == searchCompId)
			{
				ToggleComponents();
				document.getElementById("tdFilters").style.visibility = "visible"
				document.getElementById("tdFilters").style.position = ""
				init(false)
				bFirstResult = false
				totAirlines = 0
				xmlPagerFlightResult =objMergeXML;
				CreatePager(TotalResultCount);
			}
			
//			alert(xu.SelectNodeValue(xmlOrigFlightResult, "/FCRep"))
			CreateAirlines(xmlOrigFlightResult) //pavangupta
//			alert('Sorting End')
			Allresultsload = true;
			sortAllResults(false, 'PR')
			document.getElementById("trProcessing").style.visibility = "hidden"
			document.getElementById("trProcessing").style.position = "absolute"
			if ((strSessionId.toString()).substr(0, 2) == 'IN') 
			{
	//            CreateFlightOptions(xmlResult)
				CreateFlightOptions()
			}
			Allresultsload = false;
			ToggleLayer(false);
        }
      }
    }
  }
}
function GetFlightResult()
{
//debugger
    xmlHttp = new GetXmlHttpObject();
  if (xmlHttp) 
  {
    var webServiceURL;
    var IDOdFlight = "false";
    var FileName = getElement("hdnDynamicSesiionId", false).value 
    var jDType =   getElement("hdnDynamicJourneytype", false).value
    if(getElement("hdnDomesticFileId", false)!=null)
    {
        if(getElement("hdnDomesticFileId", false).value=="ID")
        {
            IDOdFlight = "true"
        }
    }
    strSessionId = getElement("hndSessionId", false).value
    var wsPath = new DOM().$("ctl00_contentMain_hdnDomain").value;
    wsPath = (wsPath == "http://localhost/") ? "http://localhost/online_1/ASPX/" : wsPath;
    webServiceURL = wsPath + "Online/ASPX/Validations.aspx?Validate=LoadFlightResult&FileName="+FileName+"&jDType="+jDType+"&IDODFlight="+IDOdFlight;
     if (new BrowserSniffer().GetBrowserType() == "ie")
        xmlHttp.open("POST", webServiceURL, true);
    else
        xmlHttp.open("GET", webServiceURL, true);
    xmlHttp.onreadystatechange = fnGetFlightResultdynamicSearch;
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(null);
  }
}
function fnGetFlightResultdynamicSearch()
{
 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') 
  {
   
    if (xmlHttp.status == 200) 
    {
        var aj = new Ajax();
        
         var strResult = xmlHttp.responseText
       ToggleLayer(true);
        var xmlResult = xu.LoadXMLString(strResult);
		var strResult;
        strSalesChannel = getElement("hdnChannelType", false).value
        searchCompId= getElement("hdnCompId", false).value
        if (strSalesChannel.indexOf("Online") > 0)
        {
          strSalesChannel = "Online"
        }
        
            if (bFirstResult == true) 
            {
              ToggleComponents();
            }
        
        mergeResultXML(xmlResult)
        xmlOrigFlightResult =objMergeXML;
        xmlPagerFlightResult =objMergeXML;
		
            if (bFirstResult == true) 
            {
                  document.getElementById("tdFilters").style.visibility = "visible"
                  document.getElementById("tdFilters").style.position = ""
                  init(true)
                  totAirlines = 0
                 bFirstResult = false
            }
          
          
         CreateAirlines(objMergeXML) //pavangupta
         CreatePager(TotalResultCount);
         var xu1 = new XML();
        // debugger
             xu1.AddParameter("SortId", "Price")
             xu1.AddParameter("AddTags", "False")
             strResult = xu1.XSLTransform(xmlOrigFlightResult, "../XSLT/SortFlight.xslt", "xml");
             xmlOrigFlightResult = xu1.LoadXMLString(strResult);
             CreateAirlines(xmlOrigFlightResult) //pavangupta
          Allresultsload = true;
          sortAllResults(false, 'PR')
          document.getElementById("trProcessing").style.visibility = "hidden"
          document.getElementById("trProcessing").style.position = "absolute"
          if ((strSessionId.toString()).substr(0, 2) == 'IN') 
          {
//            CreateFlightOptions(xmlResult)
              CreateFlightOptions()
             
          }
           
            sortAllResults(false, 'PR');
			    Allresultsload = false;
			    ToggleLayer(false);
    }
    }
}
var chngeTd ="false";
function changeTdColor(control1,e)
{
 // prompt('changeTdColor', control1.style.backgroundColor);
    if((control1.style.backgroundColor == "#f1f3f8")|| (control1.style.backgroundColor == "rgb(241, 243, 248)"))
    {
        control1.style.backgroundColor="#2491ff";
        chngeTd = "true";
    }
    else
    {
        control1.style.backgroundColor="#2491ff";
        chngeTd = "false";
    }
}
function changeTdOutColor(control,evt)
{
    if(chngeTd == "true")
    {
        control.style.backgroundColor = "#f1f3f8";
    }
}
function RedirectToStartPage()
{
	window.location.href = "Errorpage.aspx?err=333";
}

function ObsoleteRedirectToStartPage()
{
	alert("No Fares are available for the return trip against the criteria chosen by you.. Please search again.");
	if (document.getElementById("ctl00_contentMain_hndchannelType") != null) 
	{
		if ((document.getElementById("ctl00_contentMain_hndchannelType").value == "1") || (document.getElementById("ctl00_contentMain_hndchannelType").value == "2")) 
		{
			if (document.getElementById("ctl00_contentMain_hndDomainName").value != "") 
			{
				if ((document.getElementById("ctl00_contentMain_hndDomainName").value == "DewanHolidays") || (document.getElementById("ctl00_contentMain_hndDomainName").value == "Saharaglobal")) 
				{
					window.location.href = '../' + document.getElementById("ctl00_contentMain_hndDomainName").value + '/FlightHome.aspx';
				}
				else 
				{
					if ((document.getElementById("ctl00_contentMain_hdnChannelName") != null) && ((document.getElementById("ctl00_contentMain_hdnChannelName").value.toLowerCase() == "bo-dc") || (document.getElementById("ctl00_contentMain_hdnChannelName").value.toLowerCase() == "bo-sa"))) 
					{
						window.location.href = '../' + document.getElementById("ctl00_contentMain_hndDomainName").value + '/Index.aspx?type=flight';
					}
					else 
					{
						// extra check for B2B2C website.
						if (((document.getElementById("ctl00_contentMain_hndchannelType").value == "2") || (document.getElementById("ctl00_contentMain_hndchannelType").value == "1")) && (document.getElementById("ctl00_contentMain_hndDomainName").value.toLowerCase() == "online")) 
						{
							window.location.href = '../main.aspx?type=flight';
						}
						else 
						{
							if (document.getElementById("ctl00_contentMain_hndDomainName").value == "Quadlabs") 
							{
								window.location.href = '../' + document.getElementById("ctl00_contentMain_hndDomainName").value + '/HomePage.aspx?type=flight';
							}
							else 
							{
								history.back();
							}
						}
					}
				}
			}
			else 
			{
				history.back();
			}
		}
		else 
		{
			if (document.getElementById("ctl00_contentMain_hndDomainName").value != "") 
			{
				window.location.href = '../' + document.getElementById("ctl00_contentMain_hndDomainName").value + '/Index.aspx?type=flight';
			}
			else 
			{
				history.back();
			}
		}
	}
}

function ToggleComponents() 
{
  // Hide the Wait DIV.
  var waitDiv = document.getElementById("divWait");
  if (waitDiv) 
  {
    waitDiv.style.visibility = "hidden"
    waitDiv.style.position = "absolute"
  }

  // Show the Results DIV.
  var resultsDiv = document.getElementById("divResults");
  resultsDiv.style.display = "block"

  // Show all - Header/HeaderImage/Footer/FooterImage/NavBar/PoweredBy
  var Headerfr = document.getElementById("ctl00_ifrmHeader");
  if (Headerfr) 
  {
    Headerfr.style.display = "block";
  }

  var imgHeader = document.getElementById("ctl00_imgHeader");
  if (imgHeader) 
  {
    imgHeader.style.display = "block";
  }

  var navBar = document.getElementById("tblNavigation");
  if (navBar != null) 
  {
    navBar.style.display = "";
  }

  var Footerfr = document.getElementById("ctl00_ifrmFooter");
  if (Footerfr) 
  {
    Footerfr.style.display = "block";
  }

  var tblFooter = document.getElementById("ctl00_tblFooter");
  if (tblFooter) 
  {
    tblFooter.style.display = "block";
  }

  var poweredBy = document.getElementById("ctl00_PoweredByCopyRight");
  if (poweredBy) 
  {
    poweredBy.style.display = "";
  }
}

function SelectAllAirlines(checked)
{

ToggleLayer(true);
    for (intCtr = 0; intCtr <= totAirlines - 1; intCtr++)
    {
      var id = "chkAirlines" + intCtr;
      document.getElementById(id).checked = checked;
    }
    
    var selectHTML = checked ? "Deselect All" : "Select All";
    document.getElementById("Select").innerHTML = selectHTML;
    commonFiltering()
    //FilterByAirlines();
   Flightsortresults('', '', '')
}
function CreateAirlines(xmlResult) 
{
	
	  // Set XSL params.s
	var numAdt, numChd, numInf, decFormat, showDecimals;
	numAdt = getElement("numFLAdults", false).value;
	numChd = getElement("numFLChildren", false).value;
	numInf = getElement("numFLInfants", false).value;
	
	var dom = new DOM();
	decFormat = dom.$("ctl00_hdnRegionCode").value;
	showDecimals = dom.$("ctl00_contentMain_hdnDecimalPreference").value.toLowerCase();
	xu.AddParameterArray("numAdt", numAdt, "numChd", numChd, "numInf", numInf, "decFormat", decFormat, "showDecimals", showDecimals);
	//debugger
	var xml = xu.XSLTransform(xmlResult, "../XSLT/UniqueAirlineNames.xsl.ay", "xml");
	objAirlineXML = xu.LoadXMLString(xml);
	
  var rowIndx = 1;
  var tdContainerTblAirlines= document.getElementById("tdContainerTblAirlines");
  tdContainerTblAirlines.innerHTML="<TABLE class='allborder' id='tblAirlines' cellSpacing='2' cellPadding='4' width='98%' border='0'></TABLE>"
  totAirlines = 0
  var root = objAirlineXML.documentElement;
  var count = xu.GetNodeCount(objAirlineXML, "Airline");
  var tblAirlines = document.getElementById("tblAirlines");
  var newRow = dom.InsertTableRow(tblAirlines, 0)
  var deselect = "Deselect All";
  
	newCell =  dom.InsertTableCell(newRow);
	newCell.width = "20";
	newCell.innerHTML = "<input type='checkbox' id='SelectOptions' checked='checked' onclick='SelectAllAirlines(this.checked);' />";
  
  newCell =  dom.InsertTableCell(newRow);
  newCell.colSpan= "3";
  newCell.width = "100px";
  newCell.align = "left";
  newCell.innerHTML = "<span id='Select' class='AirlineList' style='font-weight:600'>" + deselect + "</span>";
	
    
  for (i = 0; i <= count; i++) 
  {
    if(i==0)
    {
      if (xu.SelectNodeValue(objAirlineXML, "Airline[0]") != null)
      {
        count--;
        sIndex = 0;
        startAirlineIndex = 0;
        endAirlineIndex = 4;
      }
      else
      {
        i++;
        sIndex = 1;
        startAirlineIndex = 1;
        endAirlineIndex = 5;
      }
    }
		var airName = xu.SelectNodeValue(objAirlineXML, "Airline[" + i + "]/@name");
		var airLogo = xu.SelectNodeValue(objAirlineXML, "Airline[" + i + "]/@logo");
		var airAmt = xu.SelectNodeValue(objAirlineXML, "Airline[" + i + "]/@amt");


    newRow = dom.InsertTableRow(tblAirlines, rowIndx + totAirlines);
    newCell = dom.InsertTableCell(newRow);
    newCell.width = "20";
    newCell.innerHTML = "<input type=\"checkbox\" id=\"chkAirlines" + totAirlines + "\" checked=\"checked\" name=\"chkAirlines" + totAirlines + "\" value=\"" + airName + "\" OnClick=\"javascript:ToggleCheckAirLine(this.value);\" />";

    newCell = dom.InsertTableCell(newRow);
    newCell.innerHTML = "<a id=\"" + airName + "\" value=\"" + airName + "\"  href=\"javascript:AirfareRules('"+ totAirlines +"');\"><img src=" + airLogo + " border='0' alt=''  hspace='0' vspace='0' /></a>";

    newCell = dom.InsertTableCell(newRow);
    newCell.align = "left";
    newCell.innerHTML = "<a id=\"" + airName + "\" value=\"" + airName + "\"  href=\"javascript:AirfareRules('"+ totAirlines +"');\"><span class='AirlineList'>" + airName + "</span></a>";


    newCell = dom.InsertTableCell(newRow);
    newCell.align = "left";
    newCell.innerHTML = "<a id=\"" + airName + "\" value=\"" + airName + "\"  href=\"javascript:AirfareRules('"+ totAirlines +"');\"><span class='AirlineList' style='font-weight:600'>" + airAmt + "</span></a>";
    
    currencyCode = airAmt.toString().substring(0, 4);
    totAirlines++;
    arrAirLines.push(airName);
  }
}


function AirfareRules(totAirlines)
{
    
//    var test=''
//    test=document.getElementById("chkAirlines"+totAirlines).value
    if(document.getElementById("chkAirlines"+totAirlines).checked == true)
        {
            document.getElementById("chkAirlines"+totAirlines).checked=false;
        }
    else
        {
            document.getElementById("chkAirlines"+totAirlines).checked=true;
        }
        ToggleCheckAirLine(document.getElementById("chkAirlines"+totAirlines).value)
}


function CreateFlightOptions() 
{
  var amt;
  
  if (getElement("hndJourneyType", false).value == 'R') 
  {
    xu.AddParameter("jType", 'R');
  }
  else 
  {
    xu.AddParameter("jType", 'O');
  }
///debugger
  var decFormat, showDecimals;
  decFormat = dom.$("ctl00_hdnRegionCode").value;
  showDecimals = dom.$("ctl00_contentMain_hdnDecimalPreference").value.toLowerCase();
  
  xu.AddParameter("decFormat", decFormat);
  xu.AddParameter("showDecimals", showDecimals);
  
	var result = xu.XSLTransform(xmlOrigFlightResult, "../XSLT/FlightOption.xsl.ay", "xml");
  objAirlineXML = xu.LoadXMLString(result);

  var ind = xu.GetNodeCount(objAirlineXML,"Airline")

  if (ind < nColumns) 
  {
    endAirlineIndex = ind + sIndex;
  }
  else 
  {
    if (endAirlineIndex < nColumns) 
    {
      endAirlineIndex = nColumns + sIndex;
      document.getElementById("ctl00_contentMain_flLink").style.visibility = "hidden";
    }
  }
  if (endAirlineIndex >= ind)  
  {
    endAirlineIndex = ind + sIndex;
    document.getElementById("ctl00_contentMain_flLink").style.visibility = "hidden";
  }
  else 
  {
    document.getElementById("ctl00_contentMain_flLink").style.visibility = "visible";
  }
  
  newrow = dom.InsertTableRow("tlbFlightOption",0);

  if ((endAirlineIndex - startAirlineIndex) < 4 && ind >= 4) 
  {
    startAirlineIndex -= 4 - (endAirlineIndex - startAirlineIndex)
  }
  
  if (startAirlineIndex <= sIndex) 
  {
    startAirlineIndex = sIndex;
    if ((endAirlineIndex < nColumns + sIndex) && (ind >= nColumns))
    {
      endAirlineIndex = nColumns + sIndex;
    }
    document.getElementById("ctl00_contentMain_flLink2").style.visibility = "hidden";
  }
  else 
  {
    document.getElementById("ctl00_contentMain_flLink2").style.visibility = "visible";
  }
   
 if (getElement("hdnISLCCRT", false).value == "false")
{ 
  newCell = dom.InsertTableCell(newrow, 0);
  newCell.style.width = "100px";
  newCell.style.borderTop = "none";
  newCell.style.borderlRight = "none";
  newCell.className ="flightIntOptionHeading"
newCell.align="Center"
  newCell.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

  for (intCtr = startAirlineIndex; intCtr <= endAirlineIndex - 1; intCtr++) 
  {
    newCell = dom.InsertTableCell(newrow);
    newCell.style.width = "100px";
    newCell.style.borderTop = "none";
    newCell.style.borderlRight = "none";
    newCell.style.borderLeft = "none";
    newCell.className ="flightIntOptionHeading"
        newCell.align="Center"
    if (intCtr == sIndex) 
    {
      newCell.innerHTML = "  <img src=" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Logo") + "   alt='' width='30px'    /> <br/>"

      newCell.innerHTML += "<a href =javascript:ToggleLayer(true);Flightoption('','','','true');><span class='lbl' ><u>" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name") + "</u></span></a>   "
    }
    else 
    {
      newCell.innerHTML = "  <img src=" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Logo") + "   alt='' width='30px'    /> <br/> "
      newCell.innerHTML += "<a href =javascript:ToggleLayer(true);Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "','','');><span   class='lbl' ><u>" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name") + "</u></span></a>  "
    }
  }

  newrow = dom.InsertTableRow("tlbFlightOption",1);

  newCell = dom.InsertTableCell(newrow,0);
  newCell.style.borderTop = "none";
  newCell.style.borderlRight = "none";
  newCell.style.borderLeft = "none";
  newCell.className ="flightIntOption"
newCell.align="Center"
  newCell.innerHTML = " <span   style='font-weight:bold;' class='lbl'>" + "Non Stop" + " </span> "

  for (intCtr = startAirlineIndex; intCtr <= endAirlineIndex - 1; intCtr++) 
  {
    newCell = dom.InsertTableCell(newrow);
    newCell.style.borderTop = "none";
    newCell.style.borderlRight = "none";
    newCell.style.borderLeft = "none";
    newCell.className ="flightIntOption"
newCell.align="Center"
    amt = xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/NonStop")
    if (amt == "") 
    {
      amt = "---   "
    }
    else 
    {
        if (intCtr == sIndex) 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','','true');javascript:Flightoption('All%20Results','" + replaceCommas(amt) + "','0','true');><span   style='font-weight:bold;' class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
        else 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "','" + replaceCommas(amt) + "','0');><span   style='font-weight:bold;  class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
      //amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "'," + amt.replace(/,/, '') + ",'0');><span   style='font-size: 8pt; font-weight:bold;  color:#1F5A97'><u>" + currencyCode + amt + "</u></span></a>   "
    }
    newCell.innerHTML = " " + amt
  }
  newrow = dom.InsertTableRow("tlbFlightOption",2);

  newCell = dom.InsertTableCell(newrow);
  newCell.style.borderTop = "none";
  newCell.style.borderlRight = "none";
  newCell.style.borderLeft = "none";
   newCell.className ="flightIntOption"
newCell.align="Center"
  newCell.innerHTML = "  <span   style='font-weight:bold;' class='lbl'>" + "1 Stop" + " </span>   "
  newCell.className ="flightIntOption"
  newCell.align="Center"
  for (intCtr = startAirlineIndex; intCtr <= endAirlineIndex - 1; intCtr++) 
  {
    newCell = dom.InsertTableCell(newrow);
    newCell.style.borderTop = "none";
    newCell.style.borderlRight = "none";
    newCell.style.borderLeft = "none";
    newCell.className ="flightIntOption"
newCell.align="Center"
    amt = xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/OneStop")
    if (amt == "") 
    {
      amt = "---   "
    }
    else 
    {
        if (intCtr == sIndex) 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','','true');javascript:Flightoption('All%20Results','" + replaceCommas(amt) + "','1','true');><span   style='font-weight:bold;' class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
        else 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "','" + replaceCommas(amt) + "','1');><span   style='font-weight:bold;' class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
      //amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "'," + amt.replace(/,/, '') + ",'1');><span   style='font-size: 8pt; font-weight:bold;  color:#1F5A97'><u>" + currencyCode + amt + "</u></span></a>   "
    }
    newCell.innerHTML = " " + amt
  }
  newrow = dom.InsertTableRow("tlbFlightOption",3);

  newCell = dom.InsertTableCell(newrow);
  newCell.style.borderTop = "none";
  newCell.style.borderlRight = "none";
  newCell.style.borderLeft = "none";
  newCell.style.borderBottom = "none";
  newCell.className ="flightIntOption"
newCell.align="Center"
  newCell.innerHTML = "<span   style='font-size: 10pt; font-weight:bold;' class='lbl'>" + "2+ Stop" + " </span> "
  newCell.className ="flightIntOption"
  newCell.align="Center"
  for (intCtr = startAirlineIndex; intCtr <= endAirlineIndex - 1; intCtr++) 
  {
    newCell = dom.InsertTableCell(newrow);
    newCell.style.borderTop = "none";
    newCell.style.borderlRight = "none";
    newCell.style.borderLeft = "none";
    newCell.style.borderBottom = "none";
    newCell.className ="flightIntOption"
newCell.align="Center"
    amt = xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/MoreStop")
    if (amt == "") 
    {
      amt = "---   "
    }
    else 
    {
        if (intCtr == sIndex) 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','','true');javascript:Flightoption('All%20Results','" + replaceCommas(amt) + "','2','true');><span   style='font-weight:bold;'  class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
        else 
        {
            amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "','" + replaceCommas(amt) + "','2');><span   style='font-weight:bold;' class='lbl'><u>" + currencyCode + amt + "</u></span></a>   "
        }
      //amt = " <a href =javascript:ToggleLayer(true);Flightoption('','','');javascript:Flightoption('" + xu.SelectNodeValue(objAirlineXML,"Airline[" + intCtr + "]/Name").replace(/ /gi, "%20") + "'," + amt.replace(/,/, '') + ",'2');><span   style='font-size: 8pt; font-weight:bold;  color:#1F5A97'><u>" + currencyCode + amt + "</u></span></a>   "
    }
    newCell.innerHTML = " " + amt
  }
  }
}

function mergeResultXML(objXML) 
{
//	alert("mergeResultXML Start")
	//debugger
	if (xu.HasXML(xmlOrigCalcFlightResult)) 
	{
		if (xu.GetNodeCount(objXML, "AirlineList/*") > 0)
		{
			var airlineList = xu.SelectNode(objXML, "/FCRep/AirlineList");
			xmlOrigCalcFlightResult.documentElement.appendChild(airlineList.cloneNode(true));
		}
	}
	else
	{
		xmlOrigCalcFlightResult = objXML;
	}
	//debugger
	objMergeXML = xmlOrigCalcFlightResult;
	
//	alert(xu.SelectNodeValue(objMergeXML, "/FCRep"))
	var xmlOutput = xu.XSLTransform(objMergeXML, "../XSLT/xsltMergeXML.xslt", "xml");
//	prompt('xmlOutput',xmlOutput);
//	alert("mergeResultXML End")
	objMergeXML = xu.LoadXMLString(xmlOutput);

	var totResults = xu.GetNodeCount(objMergeXML, "AirlineList/*");
	TotalResultCount = totResults;
        
	var endIndexText = PagingCounter;
	if (PagingCounter > TotalResultCount)
		endIndexText = TotalResultCount
        
	spnTotalResults = document.getElementById("spnTotalResults");
  spnTotalResults.innerHTML = "Displaying<b>"
  if(TotalResultCount==0)
    + "0"
  else
    + "1"
  
  + " - " 
  + endIndexText
  + "</b> of "
  + TotalResultCount.toString()
  + " Flight Options for <b>"
  + document.getElementById("ctl00_contentMain_numFLAdults").value
  + " Adult";

  if (document.getElementById("ctl00_contentMain_numFLChildren").value != '0') 
  {
    spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLChildren").value + ' Child';
  }
  if (document.getElementById("ctl00_contentMain_numFLInfants").value != '0') 
  {
    spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLInfants").value + ' Infant';
  }

}

function fnFlLink(opt) 
{
  if (opt == "Nxt") 
  {
    startAirlineIndex = endAirlineIndex;
    endAirlineIndex += 4;
  }
  if (opt == "Pre") 
  {
    endAirlineIndex = startAirlineIndex;
    startAirlineIndex -= 4;
  }

  tblLength = document.getElementById("tlbFlightOption").rows.length
  for (intCtr = 0; intCtr <= tblLength - 1; intCtr++) 
  {
    document.getElementById('tlbFlightOption').deleteRow(0)
  }
  CreateFlightOptions();
}

//new sort function

function sortAllResults(AddTags, sortId) 
{
ToggleLayer(true);
//debugger
     var firstResult = true;
    if (typeof(globalSortId) != "undefined")
	firstResult = false;
    globalSortId = sortId;
    
   if (sortId == 'PR') 
  {
    document.getElementById("rbPrice").checked = true;
    document.getElementById("rbDeptTime").checked = false;
    document.getElementById("rbArrTime").checked = false;
    if ((document.getElementById("rbRetTime") != 'undefined') && (document.getElementById("rbRetTime")!= null))
    {
      document.getElementById("rbRetTime").checked = false;
    }
  }
  if (sortId == 'DT') 
  {
    document.getElementById("rbPrice").checked = false;
    document.getElementById("rbDeptTime").checked = true;
    document.getElementById("rbArrTime").checked = false;
    if ((document.getElementById("rbRetTime") != 'undefined') && (document.getElementById("rbRetTime")!= null))
    {
      document.getElementById("rbRetTime").checked = false;
    }
  }
  if (sortId == 'AT') 
  {
    document.getElementById("rbPrice").checked = false;
    document.getElementById("rbDeptTime").checked = false;
    document.getElementById("rbArrTime").checked = true;
    if ((document.getElementById("rbRetTime") != 'undefined') && (document.getElementById("rbRetTime")!= null))
    {
      document.getElementById("rbRetTime").checked = false;
    }
  }
  if (sortId == 'RT') 
  {
    document.getElementById("rbPrice").checked = false;
    document.getElementById("rbDeptTime").checked = false;
    document.getElementById("rbArrTime").checked = false;
    document.getElementById("rbRetTime").checked = true;
  }
  	
  var AirlineNames = getAirlineNames()
  xu.AddParameter("MinPrice", minPrice);
  xu.AddParameter("MaxPrice", maxPrice);

  xu.AddParameter("MinDepTTime", minFTLT);
  xu.AddParameter("MaxDepTTime", maxFTLT);

  xu.AddParameter("AirlineName", AirlineNames);

  xu.AddParameter("MinDepLTime", minFTLL)
  xu.AddParameter("MaxDepLTime", maxFTLL)

 if ((strSessionId.toString()).substr(0, 2) == 'IN' && getElement("hndJourneyType", false).value == 'R') 
  {
    xu.AddParameter("MinArrTTime", minFRLT)
    xu.AddParameter("MaxArrTTime", maxFRLT)

    xu.AddParameter("MinArrLTime", minFRLL)
    xu.AddParameter("MaxArrLTime", maxFRLL)
    
    xu.AddParameter("Journey", "R")
  }
  
  var RefNode;
  var dom = new DOM();
  if ((dom.$("chkRefundable").checked.toString() == "true") && (dom.$("chkNonRefundable").checked.toString() == "true"))
  {
    RefNode = "True,False,";
//		xu.AddParameter("ShowRefundableFares", dom.$("chkRefundable").checked.toString());
//    xu.AddParameter("ShowNonRefundableFares", dom.$("chkNonRefundable").checked.toString());
  }
  else if(dom.$("chkRefundable").checked.toString() == "true")
  {
        RefNode = "True,";
  }
  else if(dom.$("chkNonRefundable").checked.toString() == "true")
  {
        RefNode = "False,";
  }
    xu.AddParameter("Refundable", RefNode)
   
  	xu.AddParameter("SortId", sortId)
    xu.AddParameter("AddTags", AddTags)
    xu.AddParameter("startIndex", startIndex)
    xu.AddParameter("endIndex", (parseInt(endIndex)))
  	ROE = xu.SelectNodeValue(xmlPagerFlightResult, "/FCRep/CRC/ROE");
  	  xu.AddParameter("ROE",ROE)
  	  //debugger 
//	xu.AddParameterArray("SortId", sortId, "AddTags", AddTags, "startIndex", startIndex, "endIndex", endIndex);
	strResult = xu.XSLTransform(xmlPagerFlightResult, "../XSLT/SortFlight.xslt", "xml");
	
  objMergeXML = xu.LoadXMLString(strResult);
  //xmlPagerFlightResult = objMergeXML;
  

  if (AddTags == true) 
  {
		// ALAS, THIS CODE WILL NEVER BE EXECUTED!
		// The (un)concerned developer wrote it only because... Who knows!
		var  vAdt, vChd, vInf;
		
    if (getElement("hndJourneyType", false).value == 'R' && (strSessionId.substr(0, 2) == 'OD'))
      jType = strSessionId.substr(0, 2);
    else 
     jType = "";

    strSalesChannel = getElement("hdnChannelType", false).value
    if (strSalesChannel.indexOf("Online") > 0) 
    {
      strSalesChannel = "Online"
    }
    
    vAdt = getElement("numFLAdults", false).value;
    vChd = getElement("numFLChildren", false).value;
    vInf = getElement("numFLInfants", false).value;
		
		xu.AddParameter("JourneyType", jType);
		xu.AddParameter("SalesChannel", strSalesChannel);
		xu.AddParameter("VAdult", vAdt);
		xu.AddParameter("VChild", vChd);
		xu.AddParameter("VInfant", vInf);
		xu.AddParameter("TopLink2", "View Fare Details");
		//debugger
		if(document.getElementById("ctl00_contentMain_hdnDynamicSearch")!=null)
		{
		xu.AddParameter("isDynamic", document.getElementById("ctl00_contentMain_hdnDynamicSearch").value);
		    if(document.getElementById("ctl00_contentMain_hdnHotelAmount")!=null)
		    {
		    xu.AddParameter("HotelPrice", document.getElementById("ctl00_contentMain_hdnHotelAmount").value);
		    }
		    else
		    {	xu.AddParameter("HotelPrice", 0);}
		       if(document.getElementById("ctl00_contentMain_hdnFlightAmount")!=null)
		                {
		                xu.AddParameter("FlightPrice", document.getElementById("ctl00_contentMain_hdnFlightAmount").value);
		                }
		                else
		                {	xu.AddParameter("FlightPrice", 0);}
		}
		else
		{	
		xu.AddParameter("isDynamic", "False");
		xu.AddParameter("HotelPrice", 0);
		xu.AddParameter("FlightPrice", 0);
	    }
	//debugger
    strResult = xu.XSLTransform(objMergeXML, "../XSLT/FlightResults.xslt", "html");
    
  }
  else
  {
  if (getElement("hndJourneyType", false).value == 'R' && (strSessionId.substr(0, 2) == 'OD'))
      jType = strSessionId.substr(0, 2);
    else 
    jType = "";
    showClassDiv = getElement("hndshowClassDiv", false).value
	// Calls into FilterSlider.js
    //strResult = FilterResults();
   
  }
//	var dom = new DOM();
//	var tblResults = dom.$("tblResults");
//  tblLength = tblResults.rows.length
//  for (intCtr = 0; intCtr <= tblLength - 1; intCtr++) 
//  {
//		tblResults.deleteRow(0);
//  }

//  var dom = new DOM();
//  newrow = dom.InsertTableRow(tblResults);
//  newCell = dom.InsertTableCell(newrow);
//  newCell.innerHTML = strResult
  
  var numAirlines = xu.GetNodeCount(xmlPagerFlightResult, "AirlineList/*").toString();
  
  
  // Added for initially selecting all the Flight options : VB : 03/04/2009
  Flightsortresults('','','',firstResult);
  
    
    if (globalSortId == "PR" && showClassDiv=="true")
    {
        showTotalResult(totAirlines);
    }
    else
    {
      var numAirlines;
      if(getElement("hdnminTime",false).value == "0000")
				numAirlines = xu.GetNodeCount(objMergeXML,"AirlineList/*").toString();
			else
				numAirlines = document.getElementById('hndTotalAirline').value;
				    
	  var Tcount = new XML().GetNodeCount(xmlPagerFlightResult, "AirlineList/*");
	  var endIndexText = (parseInt(endIndex) -1);
    if ((parseInt(endIndex) -1) > Tcount)
        endIndexText = Tcount;
        
    var startIndexText = (parseInt(startIndex));
    if ((parseInt(Tcount)) == 0)
        startIndexText = 0;
        
	  
      spnTotalResults.innerHTML = 'Displaying <b>' + startIndexText.toString() + ' - ' + endIndexText + '</b> of <b>'+ Tcount.toString() +'</b> Flight Options for <b>' + document.getElementById("ctl00_contentMain_numFLAdults").value + ' Adult';
//      alert(spnTotalResults.innerHTML);
      if (document.getElementById("ctl00_contentMain_numFLChildren").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLChildren").value + ' Child';
      }
      if (document.getElementById("ctl00_contentMain_numFLInfants").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLInfants").value + ' Infant';
      }
     
      }

  }  
      var strDOMArrDeptDateTimeStatus=""
      var strDOMArrDeptTimeStatus=""

function fnContinue(strJourneyType, strIndex, minTime, minDate) 
{


//alert("Application Code Name :" +  navigator.appCodeName)
//alert("Application Name :" + navigator.appName)
//alert("Application Version :" + navigator.appVersion)

    var strHotelDetailFlag="False"
    var strJourneyTypetemp=""
    var Hindex =""
    var Jtype=""
 if(document.getElementById("ctl00_contentMain_hdninputFields").value!='')
 {
    Hindex = document.getElementById("ctl00_contentMain_hdninputFields").value
 }


var Hotelprice,FlightPrice,FlightPriceID
if(document.getElementById("ctl00_contentMain_hdnHotelAmount")!=null)
{Hotelprice = document.getElementById("ctl00_contentMain_hdnHotelAmount").value;}
else
{Hotelprice = 0;}

if(document.getElementById("hndAvgPriceFlight" + strIndex + "")!=null)
{
        if(document.getElementById("hndAvgPriceFlight" + strIndex + "").value=="")
        {FlightPrice=  0;}
        else
        { FlightPrice=  document.getElementById("hndAvgPriceFlight" + strIndex + "").value;}
 }
else
{  FlightPrice=  0;}

//if(document.getElementById("hndAvgPriceFlightID" + strIndex + "")!=null)
//{  FlightPriceID=  document.getElementById("hndAvgPriceFlightID" + strIndex + "").value;}
//else
//{  FlightPriceID=  0;}
 // alert(strSessionId)
 Jtype = strSessionId.toString().substr(0, 2) 
 //alert(Jtype)
if(document.getElementById("ctl00_contentMain_hdnDynamicSearch").value=='True')
{
    if(document.getElementById("ctl00_contentMain_hdnDHSFlag").value=='True')
    {
        if(strJourneyType=="")
         {
                 
            strSessionId=document.getElementById("ctl00_contentMain_hndSessionId").value;
            if (document.getElementById("ctl00_contentMain_hdnISLCCRT").value == "True")
            //if (getElement("hdnISLCCRT", false).value == "True")
            {
                strSessionId = strSessionId.replace("OD","IN");
            }
             strJourneyType= strSessionId.toString().substr(0, 2);
             
         }
 
            if (strJourneyType == "ID" || strJourneyType == "IN") 
            {
               //alert("ID or IN:   " + strJourneyType)
             
                if(strJourneyType=="ID")
                {strJourneyTypetemp="OD"}
                else
                {strJourneyTypetemp="IN"}
                GetDynamicHotelFile(strJourneyTypetemp,strIndex,Hindex)
                // call validation page method through AJAX
                if (strHotelIndex=="")
                {
                    window.location.href = 'DynamicResult.aspx?IsHotel='+strIndex+'&isDynamic=true&FlightPrice='+FlightPrice+'&DynamicHit=CAH';
                    return ;
                }
                else
                {
                     document.aspnetForm.action = 'Review.aspx?Index='+strIndex+'&HIndex='+Hindex+'&FlightPrice='+FlightPrice+"&DynamicHit=CAFOD"
                     document.aspnetForm.submit()
                    
                }
            }
      }
}
 
    
  if (strJourneyType == "OD") 
  {
            //for roundtrip (OD)
            var strODIndex=getElement("hdnODIndex", false).value
            CheckFlightTransitTime(strODIndex,strIndex,Jtype)
            if(strDOMArrDeptTimeStatus=="True")
            {
               getElement("hdnDomesticFileId", false).value ="ID"
               document.aspnetForm.action = 'FlightResult.aspx?JourneyType=ID&Index='+strIndex+'&minTime=' + minTime + '&minDate=' + minDate+'&Dynamic='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice+"&DynamicHit=CAFOD"
               document.aspnetForm.submit()
            }  
            else
            {
               var agree=confirm("Transit time more than 4 hours. Are you sure you wish to continue?")
                if(agree)
                  {
                       getElement("hdnDomesticFileId", false).value ="ID"
                       document.aspnetForm.action = 'FlightResult.aspx?JourneyType=ID&Index='+strIndex+'&minTime=' + minTime + '&minDate=' + minDate+'&Dynamic='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice+"&DynamicHit=CAFOD"
                       document.aspnetForm.submit()
                 }
                 else
                 {
                       return ;
                 }
              
            }
  
  }
  else
  {
   
  //debugger
        if ((strSessionId.toString()).substr(0, 2) == 'ID' && getElement("hndJourneyType", false).value == 'R') 
        {
           //for roundtrip(ID) 
           // alert("roundtrip ID")
            var strODIndex=getElement("hdnODIndex", false).value
            CheckDomesticArrivalDepartureDateTime(strODIndex,strIndex)
            CheckFlightTransitTime(strODIndex,strIndex,Jtype)  //&& strDOMArrDeptDateTimeStatus  alert("Transit time more than xxx hours")
            
        //    alert("90 minutest" + strDOMArrDeptDateTimeStatus)
        //    alert("Transit time" + strDOMArrDeptTimeStatus)
            if(strDOMArrDeptDateTimeStatus=="True" &&  strDOMArrDeptTimeStatus=="True")
            {   document.aspnetForm.action = 'Review.aspx?Index='+strIndex+'&HIndex='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice
                document.aspnetForm.submit()
            }
            else
            {
                if(strDOMArrDeptDateTimeStatus == "True" && strDOMArrDeptTimeStatus == "False")
                {
                
                 var agree= confirm("Transit time more than 4 hours. Are you sure you wish to continue?")
                //alert(agree)
                
                        if(agree)
                         {
                           document.aspnetForm.action = 'Review.aspx?Index='+strIndex+'&HIndex='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice
                           document.aspnetForm.submit()
                         }
                         else
                         {
                             return;
                         }
                }
                else
                {
                    alert("There should be 90 Minute Difference Between Outbound and Inbound Flight time. !!");
                        return;
                }
            
            }

        }
        else
        {
          //for one-way(OD) & for internation round-trip
            //alert("OD else ------" + jType)
            var strODIndex=getElement("hdnODIndex", false).value
             //alert("strODIndex" + strODIndex)
             //alert("strIndex" + strIndex)
             
            CheckFlightTransitTime(strODIndex,strIndex,Jtype)
            if(strDOMArrDeptTimeStatus=="True")
            {
        
            document.aspnetForm.action = 'Review.aspx?Index='+strIndex+'&HIndex='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice
            document.aspnetForm.submit()
            }
            else
            {
             var agree=confirm("Transit time more than 4 hours. Are you sure you wish to continue?")
             // alert(agree)
            //  alert(navigator.appVersion.indexOf("MSIE 9.0"))
             
              if(agree)
                   {
//                       
                        document.aspnetForm.action = 'Review.aspx?Index='+strIndex+'&HIndex='+Hindex+'&HotelPrice='+Hotelprice+'&FlightPrice='+FlightPrice
                        document.aspnetForm.submit()
                       // return;
                  }
                  else
                  {
                      return;
                  }
                   
              
            }
        
        }
  }
  
}


function CheckDomesticArrivalDepartureDateTime(strODIndex,strIDIndex)
{
    xmlHttp = new Ajax().GetXmlHttpObject();
    var xmldom=new Ajax().GetXmlHttpObject();
    if (xmlHttp)
    {
        var webServiceURL;
       
        webServiceURL= "FlightValidations.aspx?Validate=CheckDomesticArrivalDepartureDateTime&Index="+strODIndex+"&IDIndex="+strIDIndex;
        if (new BrowserSniffer().GetBrowserType() == "ie")
            xmlHttp.open("POST", webServiceURL, false);
        else
            xmlHttp.open("GET", webServiceURL, false);
        //xmlHttp.open("POST", webServiceURL, false);
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlHttp.send(null);
        GetDomesticArrivalDepartureDateTimeResult();
    }
        
}

function GetDomesticArrivalDepartureDateTimeResult()
{
//debugger
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{   
		    strDOMArrDeptDateTimeStatus=xmlHttp.responseText   
		}
	}
}

function CheckFlightTransitTime(strODIndex,strIDIndex,filetype)
{
  //alert(filetype)
    xmlHttp = new Ajax().GetXmlHttpObject();
    var xmldom=new Ajax().GetXmlHttpObject();
    if (xmlHttp)
    {
        var webServiceURL;
       
        webServiceURL= "FlightValidations.aspx?Validate=CheckFlightTransitTime&Index="+strODIndex+"&IDIndex="+strIDIndex+"&filetype=" + filetype;
        //xmlHttp.open("POST", webServiceURL, false);
        if (new BrowserSniffer().GetBrowserType() == "ie")
            xmlHttp.open("POST", webServiceURL, false);
        else
            xmlHttp.open("GET", webServiceURL, false);
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlHttp.send(null);
        GetFlightTransitTimeResult();
    }
        
}

function GetFlightTransitTimeResult()
{
//debugger
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{   
		    strDOMArrDeptTimeStatus=xmlHttp.responseText   
		   
		}
	}
}


function GetDynamicHotelFile(strJourneyType,strIndex,Hindex)
{
    xmlHttp = new Ajax().GetXmlHttpObject();
    var xmldom=new Ajax().GetXmlHttpObject();
    if (xmlHttp)
    {
        var webServiceURL;
       
        webServiceURL= "Validations.aspx?Validate=GetDynamicHotelFile&JourneyType="+strJourneyType+"&Index="+strIndex+"&Dynamic="+Hindex;
        xmlHttp.open("POST", webServiceURL, false);
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlHttp.send(null);
        GetDynamicHotelFileResult();
    }
        
}
var strHotelIndex=""
function GetDynamicHotelFileResult()
{
//debugger
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{   
		    strHotelIndex=xmlHttp.responseText   
		}
	}
}

function LoadFlexi(channelName)
{

	var channelName = channelName
	var validationResult = false;
	
	if(document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_hdnFlightMode"))
	{
		if(document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_hdnFlightMode").value == "I")
		{
			document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_FlexidateIntchk").checked = true;
			validationResult = fnSearch(channelName,'MI','');
			if (!validationResult)
				document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_FlexidateIntchk").checked = false;
		}
	}
	else
	{
		document.getElementById("ctl00_contentMain_ModifyFlightSearch1_FlexidateDomchk").checked = true;
		validationResult =  fnSearch(channelName,'MD','');
		 
		if (!validationResult)
		 document.getElementById("ctl00_contentMain_ModifyFlightSearch1_FlexidateDomchk").checked = false;
	}
	
	return validationResult;
}
/************************************* Flight Result Specific Scripts Ends ****************************************/

function showHideNett(inputPos)
{
    if(document.getElementById('spn'+inputPos) != null)
    {
        if(document.getElementById('a'+inputPos).innerText=="+")
        {
            document.getElementById('a'+inputPos).innerText = "-";
            document.getElementById('spn'+inputPos).style.visibility = "visible";
        }
        else
        {
            document.getElementById('a'+inputPos).innerText = "+";
            document.getElementById('spn'+inputPos).style.visibility = "hidden";
        }
    }
}

function showDiv(AirCode)
{

    if (document.getElementById("hdn"+AirCode).value == "+")
    {
         var divTables = dom.$Name(AirCode);
         for (var _i=1; _i < divTables.length; _i++)
         {
            divTables[_i].style.display="block";
         }
         document.getElementById("hdn"+AirCode).value = "-";
        dom.SetElementInnerText(("spn"+AirCode),"- all fares for this flight");
        
        var totalFilghtDisplay = document.getElementById("hndTotalAirline").value;
        totalFilghtDisplay = parseInt(totalFilghtDisplay) + parseInt(document.getElementById("hdnAirLine" + AirCode).value)
        showTotalResult(totalFilghtDisplay);
    }
    else
    {
        var divTables = dom.$Name(AirCode);
         for (var _i=1; _i < divTables.length; _i++)
         {
            divTables[_i].style.display="none";
         }
         document.getElementById("hdn"+AirCode).value = "+";
         dom.SetElementInnerText(("spn"+AirCode),"+ show all fares for this flight");
        
        var totalFilghtDisplay = document.getElementById("hndTotalAirline").value;
        totalFilghtDisplay = parseInt(totalFilghtDisplay) - parseInt(document.getElementById("hdnAirLine" + AirCode).value)
        showTotalResult(totalFilghtDisplay);
    }
}

function showTotalResult(totalFilghtDisplay)
{
      document.getElementById("hndTotalAirline").value = totalFilghtDisplay;
      var numAirlines;
      if(getElement("hdnminTime",false).value == "0000")
				numAirlines = xu.GetNodeCount(objMergeXML, "AirlineList/*").toString();
			else
				numAirlines = xu.GetNodeCount(xmlPagerFlightResult, "AirlineList/*").toString();
				
        var endIndexText = (endIndex -1);
//        if ((endIndex -1) < numAirlines)
//             endIndexText = (endIndex -1)

  var startIndexText = (parseInt(startIndex));
    if ((parseInt(numAirlines)) == 0)
        startIndexText = 0;
			
      spnTotalResults.innerHTML = 'Displaying <b>' + startIndexText.toString() + ' - ' + endIndexText + '</b> Flight Options for <b>' + document.getElementById("ctl00_contentMain_numFLAdults").value + ' Adult';
//     alert(spnTotalResults.innerHTML);
      if (document.getElementById("ctl00_contentMain_numFLChildren").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLChildren").value + ' Child';
      }
      if (document.getElementById("ctl00_contentMain_numFLInfants").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLInfants").value + ' Infant';
      }
}
function CreatePager(totResults)
{
    var localtblLength=document.getElementById("tblPaging").rows.length
    for(intCtr=0;intCtr<=localtblLength-1;intCtr++)
    {
      document.getElementById('tblPaging').deleteRow(0)
    }
    localtblLength=document.getElementById("tblPagingbottom").rows.length
    for(intCtr=0;intCtr<=localtblLength-1;intCtr++)
    {
      document.getElementById('tblPagingbottom').deleteRow(0)
    }
        
     var rowIndx=document.getElementById("tblPaging").rowIndex;
      newRow = dom.InsertTableRow("tblPaging", rowIndx + 1);
      
      var rowIndxbottom=document.getElementById("tblPagingbottom").rowIndex;
      var newRowbottom = dom.InsertTableRow("tblPagingbottom", rowIndxbottom + 1);
      var newCellbottom;
      
      var counPage = parseFloat(totResults / PagingCounter).toString().split('.')
      if (counPage.length == 2)
      {
         pages = parseInt(counPage[0]) + 1;
      }
      else
      {
         pages = counPage[0];
      }
      var FirstPage = 1;
      var NextPage;
      
      if(pages ==1)
      {
      NPage = parseInt(FirstPage) + PagingCounter
      
       newCell = dom.InsertTableCell(newRow);
        newCellbottom = dom.InsertTableCell(newRowbottom);
        newCell.innerHTML ="<a id='pg"+pages.toString()+"><span id='spnPageAll"+pages.toString()+"' style='color:black; cursor:pointer; font-weight:bold;text-decoration:none;'> "+ "Page found 1 of 1" +"</span></a>&nbsp;"
                 newCellbottom.innerHTML ="<a href='#pg"+pages.toString()+"><span id='spnPageAllbottom"+pages.toString()+"' style='color:black; cursor:pointer; font-weight:bold;text-decoration:none;'> "+ "Page found 1 of 1"+"</span></a>&nbsp;"
         }
                   
      if(pages>1)
      for (var _iPage=1; _iPage<=pages; _iPage++)
      {
        newCell = dom.InsertTableCell(newRow);
        newCellbottom = dom.InsertTableCell(newRowbottom);
        
        NextPage = parseInt(FirstPage) + PagingCounter;
        
        if (_iPage != pages)
        {
            if(_iPage == 1)
            {
                   newCell.innerHTML ="<a id='pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ NextPage +","+ _iPage +")'><span id='spnPageAll"+_iPage.toString()+"' style='color:black; cursor:pointer; font-weight:bold'> "+ _iPage.toString() +"</span></a>&nbsp;|"
                   newCellbottom.innerHTML ="<a href='#pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ NextPage +","+ _iPage +")'><span id='spnPageAllbottom"+_iPage.toString()+"' style='color:black; cursor:pointer; font-weight:bold'> "+ _iPage.toString() +"</span></a>&nbsp;|"
            }
            else
            {
                   newCell.innerHTML ="<a id='pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ NextPage +","+ _iPage +")'><span id='spnPageAll"+_iPage.toString()+"' style='color:blue;cursor: pointer'> "+ _iPage.toString() +"</span></a>&nbsp;|"
                   newCellbottom.innerHTML ="<a href='#pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ NextPage +","+ _iPage +")'><span id='spnPageAllbottom"+_iPage.toString()+"' style='color:blue;cursor: pointer'> "+ _iPage.toString() +"</span></a>&nbsp;|"
            }
        }
        else
        { 
           var totalres = totResults +1;
            if(_iPage == 1)
            {
                 newCell.innerHTML ="<a id='pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ totalres +","+ _iPage +")'><span id='spnPageAll"+_iPage.toString()+"' style='color:black; cursor:pointer; font-weight:bold'> " + "Page  1 of "+ _iPage.toString() +"</span></a>&nbsp;"
                 newCellbottom.innerHTML ="<a href='#pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ totalres +","+ _iPage +")'><span id='spnPageAllbottom"+_iPage.toString()+"' style='color:black; cursor:pointer; font-weight:bold'> " + "Page  1 of "+ _iPage.toString() +"</span></a>&nbsp;"
            }
            else
            {
                 newCell.innerHTML ="<a id='pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ totalres +","+ _iPage +")'><span id='spnPageAll"+_iPage.toString()+"' style='color:blue;cursor: pointer'> "+ _iPage.toString() +"</span></a>&nbsp;"
                 newCellbottom.innerHTML ="<a href='#pg"+_iPage.toString()+"' onclick='javascript:ShowPaging("+FirstPage+","+ totalres +","+ _iPage +")'><span id='spnPageAllbottom"+_iPage.toString()+"' style='color:blue;cursor: pointer'> "+ _iPage.toString() +"</span></a>&nbsp;"
            }
        }
        FirstPage =parseInt(FirstPage) + PagingCounter;
      }
}

function ShowPaging(startpos,endpos,currposCount)
{
    window.setTimeout('ShowPagingMain'+'(\''+startpos+'\',\''+endpos+'\',\''+currposCount+'\')',1);
    // window.setTimeout(''+funName+''+'(\''+Parm+'\')',1);
    ToggleLayer(true);
}

function ShowPagingMain(start,end,posCount)
{
     for (var _iPage=1; _iPage<=pages; _iPage++)
     {
        if(document.getElementById("spnPageAll" + _iPage))
        {
            if(_iPage == posCount)
            {
                document.getElementById("spnPageAll" + _iPage).style.color='black';
                document.getElementById("spnPageAll" + _iPage).style.fontWeight= "bold"
                document.getElementById("spnPageAllbottom" + _iPage).style.color='black';
                document.getElementById("spnPageAllbottom" + _iPage).style.fontWeight= "bold"
            }
            else
            {
                document.getElementById("spnPageAll" + _iPage).style.color='blue';
                document.getElementById("spnPageAll" + _iPage).style.fontWeight= "normal"
                document.getElementById("spnPageAllbottom" + _iPage).style.color='blue';
                document.getElementById("spnPageAllbottom" + _iPage).style.fontWeight= "normal"
            }
        }
     }
    
    startIndex = start;
    endIndex = end;
    
    //sortAllResults(false, globalSortId)
    
    
    xu = new XML();
  var AirlineNames = getAirlineNames()
  xu.AddParameter("MinPrice", minPrice);
  xu.AddParameter("MaxPrice", maxPrice);

  xu.AddParameter("MinDepTTime", minFTLT);
  xu.AddParameter("MaxDepTTime", maxFTLT);

  xu.AddParameter("AirlineName", AirlineNames);

  xu.AddParameter("MinDepLTime", minFTLL)
  xu.AddParameter("MaxDepLTime", maxFTLL)

 if ((strSessionId.toString()).substr(0, 2) == 'IN' && getElement("hndJourneyType", false).value == 'R') 
  {
    xu.AddParameter("MinArrTTime", minFRLT)
    xu.AddParameter("MaxArrTTime", maxFRLT)

    xu.AddParameter("MinArrLTime", minFRLL)
    xu.AddParameter("MaxArrLTime", maxFRLL)
    
     xu.AddParameter("Journey", "R")
  }
  
    var count = new XML().GetNodeCount(xmlOrigFlightResult, "AirlineList/*");
   
   // endIndex = count.toString();
    xu.AddParameter("SortId", "P")
    var AddTag = false;
    xu.AddParameter("AddTags", AddTag)
    xu.AddParameter("startIndex", startIndex)
    xu.AddParameter("endIndex", (parseInt(endIndex) -1).toString())
    xu.AddParameter("JourneyType", jType);
    
      var RefNode;
  var dom = new DOM();
  if ((dom.$("chkRefundable").checked.toString() == "true") && (dom.$("chkNonRefundable").checked.toString() == "true"))
  {
    RefNode = "True,False,";
  }
  else if(dom.$("chkRefundable").checked.toString() == "true")
  {
        RefNode = "True,";
  }
  else if(dom.$("chkNonRefundable").checked.toString() == "true")
  {
        RefNode = "False,";
  }
    xu.AddParameter("Refundable", RefNode)
    
    strResult = xu.XSLTransform(xmlOrigFlightResult, "../XSLT/SortFlight.xslt", "xml");
    xmlPagerFlightResult = xu.LoadXMLString(strResult);
    
   var count = new XML().GetNodeCount(xmlPagerFlightResult, "AirlineList/*");
    xu = new XML();
    xu.AddParameter("startIndex", startIndex);
    xu.AddParameter("endIndex", (parseInt(endIndex)).toString());
    xu.AddParameter("SortId", globalSortId);
    xu.AddParameter("AddTags", false);
      
  var AirlineNames = getAirlineNames()
  xu.AddParameter("MinPrice", minPrice);
  xu.AddParameter("MaxPrice", maxPrice);

  xu.AddParameter("MinDepTTime", minFTLT);
  xu.AddParameter("MaxDepTTime", maxFTLT);

  xu.AddParameter("AirlineName", AirlineNames);

  xu.AddParameter("MinDepLTime", minFTLL)
  xu.AddParameter("MaxDepLTime", maxFTLL)

 if ((strSessionId.toString()).substr(0, 2) == 'IN' && getElement("hndJourneyType", false).value == 'R') 
  {
    xu.AddParameter("MinArrTTime", minFRLT)
    xu.AddParameter("MaxArrTTime", maxFRLT)

    xu.AddParameter("MinArrLTime", minFRLL)
    xu.AddParameter("MaxArrLTime", maxFRLL)
  }
    
    xu.AddParameter("JourneyType", jType);
    
      var RefNode;
  
  if ((dom.$("chkRefundable").checked.toString() == "true") && (dom.$("chkNonRefundable").checked.toString() == "true"))
  {
    RefNode = "True,False,";
  }
  else if(dom.$("chkRefundable").checked.toString() == "true")
  {
        RefNode = "True,";
  }
  else if(dom.$("chkNonRefundable").checked.toString() == "true")
  {
        RefNode = "False,";
  }
    xu.AddParameter("Refundable", RefNode)
    //debugger 
    strResult =xu.XSLTransform(xmlPagerFlightResult, "../XSLT/SortFlight.xslt", "html");
    objMergeXML = xu.LoadXMLString(strResult);
    strResult=FilterResults();
    
    tblLength=document.getElementById("tblResults").rows.length
    for(intCtr=0;intCtr<=tblLength-1;intCtr++)
    {
        document.getElementById("tblResults").deleteRow(0)
    }
    newrow = dom.InsertTableRow("tblResults",0)
    newCell = dom.InsertTableCell(newrow,0);
    strResult = strResult.replace(/#####/g, '');
    newCell.innerHTML=strResult
    
     var numAirlines;
      if(getElement("hdnminTime",false).value == "0000")
		    numAirlines = xu.GetNodeCount(objMergeXML,"AirlineList/*").toString();
	    else
		    numAirlines = document.getElementById('hndTotalAirline').value;
    
    var count = new XML().GetNodeCount(xmlPagerFlightResult, "AirlineList/*");
    
     var endIndexText = (endIndex -1);
    if ((endIndex -1) > count)
        endIndexText = count

  var startIndexText = (parseInt(startIndex));
    if ((parseInt(count)) == 0)
        startIndexText = 0;
    
      spnTotalResults.innerHTML = 'Displaying <b>' + startIndexText.toString() + ' - ' + endIndexText + '</b> of <b>'+ count.toString() +'</b> Flight Options for <b> ' + document.getElementById("ctl00_contentMain_numFLAdults").value + ' Adult';
      if (document.getElementById("ctl00_contentMain_numFLChildren").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLChildren").value + ' Child';
      }
      if (document.getElementById("ctl00_contentMain_numFLInfants").value != '0') 
      {
        spnTotalResults.innerHTML += '<b>,' + document.getElementById("ctl00_contentMain_numFLInfants").value + ' Infant';
      }
    
    ToggleLayer(false);
}



