﻿/* **************************** */
/* ********* TOGGLE *********** */
/* **************************** */

function toggleVisibility(idImg, id, idHidden) 
{
  var img = document.getElementById(idImg);
  if (toggleDisplayStyle(id) == "none")
      img.src = "img/plus.gif";
  else
      img.src = "img/minus.gif";
      
  if(idHidden != '')
  {
    var elHidden = document.getElementById(idHidden);
    if(elHidden.value == "false")
      elHidden.value = "true";
    else
      elHidden.value = "false";
    return elHidden.value;  
  }
}

function toggleVisbilityOneWay()
{
  var sOneWay = toggleVisibility('imgOneWay', 'divReturnDate', 'hfOneWay');  
  var sOpenJaw = document.getElementById('hfOpenJaw').value;  
  
  if(sOneWay == "true")
  {
    if(sOpenJaw == "true")
      toggleVisibility('imgOpenJaw', 'divDifferentReturnFlight', 'hfOpenJaw');
    document.getElementById('pnOpenJaw').style.display = 'none';
  }
  else
  {    
    document.getElementById('pnOpenJaw').style.display = 'block';
  }
}

function toggleDisplayStyle(id)
{
  var el = document.getElementById(id);
  el.style.display = (el.style.display != 'none' ? 'none' : 'block' );
  return el.style.display;
}

function toggleExpertmode(idImg, idExpertmode, idStandardmode, idHiddenField) 
{
  toggleVisibility(idImg, idExpertmode, '');
      
  if (document.getElementById(idExpertmode).style.display == "block")
     document.getElementById(idStandardmode).style.display = "none";
  else
      document.getElementById(idStandardmode).style.display = "block";
      
  var elHidden = document.getElementById(idHiddenField);
  if(elHidden.value == "false")
    elHidden.value = "true";
  else
    elHidden.value = "false";
}

/* ********************************************************************* */
	    
function togglePanel(obj) {
    var el = document.getElementById(obj + 'panel');
    el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
}

/* ********************************************************************* */

function resetPanels(obj) {
    if(obj == 'toolbox')
        document.getElementById('pnQuickQuery').style.display = "none";
    else
        document.getElementById('toolboxpanel').style.display = "none";
    
    togglePanel(obj);
}

/* ********************************************************************* */

function toggleToolbox(obj, el) {
    if(document.getElementById(obj).style.display == "block") {
        document.getElementById(obj).style.display = "none";
        if(el.className == "mainactive")
            el.className = "maininactive";
        else
            el.className = "subinactive";
    } else {
        document.getElementById(obj).style.display = "block";
        if(el.className == "maininactive")
            el.className = "mainactive";
        else
            el.className = "subactive";
    }
}

/* ********************************************************************* */

function toggleTariffCalculation(tariffno, el) {
    if(document.getElementById('calc' + tariffno).style.display == "block") {
        document.getElementById('calc' + tariffno).style.display = "none";
        el.className = "inactive";
    } else {
        document.getElementById('calc' + tariffno).style.display = "block";
  
        var suchstring = document.getElementById('imgSF' + tariffno).src;
        var ergebnis = suchstring.search(/close.+/);
  	            
        /*if (ergebnis != -1) {
            document.getElementById('fee' + tariffno).style.visibility == "hidden"
        } else {
            document.getElementById('fee' + tariffno).style.visibility = "visible";
        } */               
        el.className = "active";
    }
}

/* ********************************************************************* */

function toggleFeeInTicketOrder() {	        
    var visibility = '';
    
    var tbl  = document.getElementById('gvCalculation');
    var rows = tbl.getElementsByTagName('tr');
    for (var row=0; row<rows.length; row++) 
    {
        var cells;
        if(row == 0)
            cells = rows[row].getElementsByTagName('th');
        else
            cells = rows[row].getElementsByTagName('td');
        
        if(visibility == '')
        {
            if(cells[2].style.visibility == 'hidden')
                visibility = 'visible';
            else
                visibility = 'hidden';
        }
        
        cells[2].style.visibility = visibility;        
        cells[3].style.visibility = visibility;
    }    

    if (visibility == 'hidden')
        document.getElementById('imgSF').src = "img/sf_closed.gif";
    else
        document.getElementById('imgSF').src = "img/sf_open.gif";
}

/* ********************************************************************* */
	    
function toggleGeneral(obj, lnk) {
    var el = document.getElementById(obj);
    el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
    
    if(obj == "bookedflight")
        lnk.className = (lnk.className != 'bookedflightopen' ? 'bookedflightopen' : 'bookedflightclosed');
    else if (obj == "gds" || obj == "lblFfnPnr" || obj == "lblSeatMapPnr" || obj == "lblOsiPnr" || obj == "lblSsrPnr" || obj == "lblRemarkPnr")
        lnk.className = (lnk.className != 'gdsopen' ? 'gdsopen' : 'gdsclosed');
    else if(obj == "bookinghistory")
        lnk.className = (lnk.className != 'historyflightsopen' ? 'historyflightsopen' : 'historyflightsclosed');
    
    if(obj == "travellersummary") {
        if(document.getElementById("travellersummary").style.display == "block")
            document.getElementById('travarr').src = "img/PassInfo_arrow-close.gif";
        else
            document.getElementById('travarr').src = "img/PassInfo_arrow-open.gif";
    }       
}

/* ********************************************************************* */
	    
function toggleSearch() {
    var el = document.getElementById('advancedsearch');
    el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
    
    var el2 = document.getElementById('ctl00_cphContent_btnSearchQuick');
    el2.style.display = (el2.style.display != 'none' ? 'none' : 'block' );
}

/* ********************************************************************* */

function toggleFlightControlPanel() {
    var el = document.getElementById('fcpContent');
    el.style.display = (el.style.display != 'none' ? 'none' : 'block');

    if (document.getElementById('fcpContent').style.display == "block")
        document.getElementById('imgFlightControlPanel').src = "/img/minus.gif";
    else
        document.getElementById('imgFlightControlPanel').src = "/img/plus.gif";
}

/* ********************************************************************* */

function toggleFaresSection() {
    var el = document.getElementById('fsContent');
    el.style.display = (el.style.display != 'none' ? 'none' : 'block');

    if (document.getElementById('fsContent').style.display == "block")
        document.getElementById('imgFaresSection').src = "/img/minus.gif";
    else
        document.getElementById('imgFaresSection').src = "/img/plus.gif";
}

/* ********************************************************************* */

function toggleAvailabilitySection() {
    var el = document.getElementById('asContent');
    el.style.display = (el.style.display != 'none' ? 'none' : 'block');

    if (document.getElementById('asContent').style.display == "block")
        document.getElementById('imgAvailabilitySection').src = "/img/minus.gif";
    else
        document.getElementById('imgAvailabilitySection').src = "/img/plus.gif";

}

/* ********************************************************************* */

function CutAirlineText(source, eventArgs) {
    var sCurrentValue = eventArgs.get_text();
    source.get_element().value = sCurrentValue.substring(0, sCurrentValue.lastIndexOf('-')) + ",";
}

/* ******************************* */
/* ********* PRINT GDS *********** */
/* ******************************* */

function OpenGDSPrintPreview(){
    o = window.open('PrintGds.aspx','GDS','width=600, height=800, scrollbars=yes');
    o.focus();
}


/* *************************************************** */
/* ********* FLIGHT DETAILS / FLIGHT RULES *********** */
/* *************************************************** */

function OpenFlightDetails(id, outboundIndex, inboundIndex) {
    var newWin = window.open('FlightDetails.aspx?Id=' + id + '&OutboundIndex=' + outboundIndex + '&InboundIndex=' + inboundIndex,
      'Details', 'left=400,top=100,height=650,width=585,status=no,resizable=no,scrollbars=yes,toolbar=no,location=no,menubar=no');
    newWin.focus();
}

function OpenFlightRules(fareId, fareType, itenaryType) {
    var nIndexOutbound = GetSelectedRadioButtonItem('ctrlFareDisplay$radioOutbound' + fareId);
    var nIndexInbound = GetSelectedRadioButtonItem('ctrlFareDisplay$radioInbound' + fareId);     
    var newWin = window.open('FlightRules.aspx?FareId=' + fareId + '&FareType=' + fareType + '&ItenaryType=' + itenaryType +
        '&OutboundIndex=' + nIndexOutbound + '&InboundIndex=' + nIndexInbound, 'Rules', 
        'left=400,top=100,height=650,width=585,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
    newWin.focus();
}

function GetSelectedRadioButtonItem(name)
{
    var arElements = document.getElementsByName(name);
    for (var n = 0; n < arElements.length; n++) {
        if (arElements[n].checked) {
            return n;
        }
    }
    return 0;
}

function OpenQuotedFareRules(fareId, bookingId, fareType) {
    var newWin = window.open('FlightRules.aspx?IsFareQuote=1&FareId=' + fareId + '&BookingId=' + bookingId + '&FareType=' + fareType,
      'Rules', 'left=400,top=100,height=650,width=585,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
    newWin.focus();
}

function OpenBookedFlightRules(bookingId, fareType) {
    var newWin = window.open('FlightRules.aspx?BookingId=' + bookingId + '&FareType=' + fareType,
      'Rules', 'left=400,top=100,height=650,width=585,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
    newWin.focus();
}


/* ********************************** */
/* ********* SCROLL FARES *********** */
/* ********************************** */

function scrollDiv(strId, intSpd) {
    if (objScrll = document.getElementById(strId)) {
        var left = parseInt(objScrll.style.left);
        if (intSpd > 0 ? left < 0 : parseInt(objScrll.parentNode.style.width) - left <= objScrll.offsetWidth)
            objScrll.style.left = (left + intSpd) + "px";
        eval('tvar' + strId + '= setTimeout("scrollDiv(\'' + strId + '\',' + intSpd + ')",50)');
        if (objSelf = scrollDiv.arguments[2])
            objSelf.onmouseup = objSelf.onmouseout = new Function('fx', 'clearTimeout(tvar' + strId + ')');
    }
}


/* ********************************* */
/* ********* AIRPORTLIST *********** */
/* ********************************* */

function ListAirports(parentFieldId, updateMethod) 
{
    window.open('AirportSearch.aspx?ParentFieldId=' + parentFieldId + '&UpdateMethod=' + updateMethod, 
        'Airports', 'resizable=yes,status=yes,scrollbars=yes,width=680,height=640,left=0,top=0').focus();
}

/* ***************************** */
/* ********* TOOLBAR *********** */
/* ***************************** */

var an = "";
var aus = "";
var fix = 0;
var version=navigator.appVersion;


function showPanel(pnlName) 
{
    window.clearTimeout(aus);
    
    // iFrame unter der Toolbox einblenden (nur für IE6 User)    
    if (version.indexOf ("MSIE 6")!=-1) { 
        document.getElementById('ifTB').style.visibility = "visible";
    }
    
    // wenn Quick query auf der Seite verfügbar UND noch offen ist, zunächst schliessen
    var o = document.getElementById('pnQuickQuery');
    if (o) {
        if (o.style.display == "block") {
            o.style.display = "none"; 
        }
    }
    // dann anderes Panel anzeigen
	document.getElementById(pnlName).style.display = "block";
} 

function hidePanel(pnlName) 
{	
    window.clearTimeout(an);
    
	if(fix == 0) 
	{
	    document.getElementById(pnlName).style.display = "none";
	    
	    // iFrame unter der Toolbox ausblenden (nur für IE6 User)
	    if (version.indexOf ("MSIE 6")!=-1 && document.getElementById('ifTB').style.visibility == "visible") { 
	        document.getElementById('ifTB').style.visibility = "hidden";
	    }
	}	
}

function fixPanel() {
    if (fix == 0) 
    {
        fix = 1;
        document.getElementById('pin').src = "img/pin_fix.gif";
    }        
    else
    {
        fix = 0;
        document.getElementById('pin').src = "img/pin.gif";
    }
}

/* ***************************** */
/* ********* AIRPORT COMBO *********** */
/* ***************************** */

function ValidateAirport(source, args)
{
    if(args.Value.length == 3 && args.Value.match(/[A-Za-z]{3}/))
        args.IsValid = true;
    else
        args.IsValid = args.Value.match(/\[[A-Za-z]{3}\]/) != null;
}   
function ShowAutoComplete(source, eventArgs)
{
    source.get_completionList().style.width = 350;
}
  
/* ***************************** */
/* ********* CALENDAR *********** */
/* ***************************** */
  
function checkDateOutbound() 
{     
    var date = document.getElementById('calOutboundDepartureDate_TextBox').value;
    if (date.length != 10)
        HitchHiker.Agent.DateHelper.CheckDate(date,  Sys.CultureInfo.CurrentCulture.dateTimeFormat.AbbreviatedMonthNames, 
            true, onCompleteOutbound);
    else
        addDays();
}         
function onCompleteOutbound(result)
{
    if(document.getElementById('calOutboundDepartureDate_TextBox').value != result)
        document.getElementById('calOutboundDepartureDate_TextBox').value = result;
    addDays();
}   
function addDays()
{
    HitchHiker.Agent.DateHelper.AddDays(document.getElementById('calOutboundDepartureDate_TextBox').value, 14, onCompleteAddDays);
}
function onCompleteAddDays(result)
{
    var calInbound = document.getElementById('calInboundDepartureDate_TextBox');
    if(calInbound != null)
    {
        if(calInbound.value != result)
        {
            calInbound.value = result;
            Page_ClientValidate();
        }
    }
}  

function checkDateOutboundQQ() 
{     
    var date = document.getElementById('calOutboundDepartureDate_TextBox').value;
    if (date.length != 10)
        HitchHiker.Agent.DateHelper.CheckDate(date,  Sys.CultureInfo.CurrentCulture.dateTimeFormat.AbbreviatedMonthNames, 
            true, onCompleteOutboundQQ);
    else
        addDaysQQ();
} 
function onCompleteOutboundQQ(result)
{
    if(document.getElementById('calOutboundDepartureDate_TextBox').value != result)
        document.getElementById('calOutboundDepartureDate_TextBox').value = result;
    addDaysQQ();
} 
function addDaysQQ()
{
    HitchHiker.Agent.DateHelper.AddDays(document.getElementById('calOutboundDepartureDate_TextBox').value, 14, onCompleteAddDaysQQ);
}
function onCompleteAddDaysQQ(result)
{
    var calInbound = document.getElementById('calInboundDepartureDate_TextBox');
    if(calInbound != null)
    {
        if(calInbound.value != result)
        {
            calInbound.value = result;
            Page_ClientValidate();
            document.getElementById('calInboundDepartureDate_TextBox').blur();
            document.getElementById('calInboundDepartureDate_TextBox').focus();
        }
    }
}
function checkDateInbound() 
{
    var date = document.getElementById('calInboundDepartureDate_TextBox').value;
    if (date.length != 10)
        HitchHiker.Agent.DateHelper.CheckDate(date,  Sys.CultureInfo.CurrentCulture.dateTimeFormat.AbbreviatedMonthNames, 
            true, onCompleteInbound);
}          
function onCompleteInbound(result)
{        
    if(document.getElementById('calInboundDepartureDate_TextBox').value != result)
    {
        document.getElementById('calInboundDepartureDate_TextBox').value = result;
        Page_ClientValidate();
    }
}  
function ValidateInboundDate(ctl, args)
{            
    var inboundText = args.Value.split('.');
    var inboundDate = new Date(inboundText[2], inboundText[1] - 1, inboundText[0]);
    
    var outboundText = document.getElementById('calOutboundDepartureDate_TextBox').value.split('.');
    var outboundDate = new Date(outboundText[2], outboundText[1] - 1, outboundText[0]);
    
    args.IsValid = inboundDate >= outboundDate;
}

function SetDebitedAmountOtherValidator() 
{
    document.getElementById('valReqDebitAmountOther').enabled = document.getElementById('rbDebitedAmountOther').checked;
}