﻿// JScript File

function changeDirection(strCtrClicked,strOtherGrpCtrls,strhidCtl,logictoExecute,strValueSelected,divReturns,strhidServerPathCtl)
{
    try{
        
        var thisCtrl = document.getElementById(strCtrClicked);
        logictoExecute = logictoExecute.toLowerCase();
        imgString = thisCtrl.src.toLowerCase();
        strNotSelectedConst = "NotSelected".toLowerCase();
        if(logictoExecute.indexOf("direction") != -1)
        {
           //alert(document.getElementById(strhidCtl).value);
           document.getElementById(strhidCtl).value=strValueSelected;
           
           var OtherGrpCtrls = document.getElementById(strOtherGrpCtrls);
           if(imgString.indexOf(strNotSelectedConst) != -1)
           {
               thisCtrl.src = document.getElementById(strhidServerPathCtl).value + "/App_Themes/KissTheme/Images/ChkBxSelected.gif";
               OtherGrpCtrls.src = document.getElementById(strhidServerPathCtl).value + "/App_Themes/KissTheme/Images/ChkBxNotSelected.gif";
               
           }
           else
           {
                thisCtrl.src = document.getElementById(strhidServerPathCtl).value + "/App_Themes/KissTheme/Images/ChkBxNotSelected.gif";
                OtherGrpCtrls.src = document.getElementById(strhidServerPathCtl).value + "/App_Themes/KissTheme/Images/ChkBxSelected.gif";
            }
            
            //If One way direction then return date must be hidden
            if(strValueSelected=="1")
            {   
                document.getElementById(divReturns).style.display="none";
                document.getElementById("DurationPanel").style.height="11%";
            }
            else
            {
                //document.getElementById(divReturns).style.visibility="visible";
                document.getElementById(divReturns).style.display="block";
                document.getElementById("DurationPanel").style.height="22%";
            }    
            
              
        }
        else
        {
            if(strOtherGrpCtrls.indexOf(",")!= -1)
            {
            }
        }
    }
    catch(e)
    {
        alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);    
    }
}

function disCalender(strCtr) {
    //alert(strCtr);
   thisCtrl=document.getElementById(strCtr);  
   thisCtrl.style.visibility="visible";
}

function fillFlightsTo(obj,strhidFlightTo,strFlightTo,strhidFlightToSelected) 
{
    /*alert(strhidFlightTo);
    alert(document.getElementById(strhidFlightTo).value);
    alert(document.getElementById(strFlightTo).value);*/
    var arrFlightsto = document.getElementById(strhidFlightTo).value.split("*");
    document.getElementById(strFlightTo).options.length = 0;
    cnt=0; 
    for(var i=0;i<arrFlightsto.length;i++)
    {
        if(arrFlightsto[i].indexOf(obj.value + ",",0) != -1 )
        {   
            var arrSubFlightsto = arrFlightsto[i].split(",");
            newOpt=new Option; 
            newOpt.value=arrSubFlightsto[1].replace(/\"/g,"");
            newOpt.text=arrSubFlightsto[2].replace(/\"/g,"");
            document.getElementById(strFlightTo).options[cnt]=null;
            document.getElementById(strFlightTo).options[cnt]=newOpt;cnt++;
            /*alert("inside loop");*/
         }
         else{}
     }
     document.getElementById(strFlightTo).options[0].selected = true;
     document.getElementById(strhidFlightToSelected).value = document.getElementById(strFlightTo).value;
     /*alert(document.getElementById(strFlightTo).value);
     alert(document.getElementById(strhidFlightTo).value);*/
 }

function flightsToSelected(obj,strhidFlightToSelected) 
{
    document.getElementById(strhidFlightToSelected).value = obj.value;
}

function link_popup(url,width,height,scrollbar)
{
    window.open(url,'Register','menubar=0,status=0,location=0,toolbar=0,width=' + width + ',height=' + height + ',scrollbars=' + scrollbar );
}

function close_popup()
{
    window.close();
}

function validateSearchFor(ddlDepDay,ddlDepMon,ddlDepYear,ddlRtnDay,ddlRtnMon,ddlRtnYear,hidDirection,ddlAdult,ddlChild,ddlInfant)
{
    //var sDepDate = new Date(document.getElementById(ddlDepDay).value + "/" + document.getElementById(ddlDepMon).value + "/" + document.getElementById(ddlDepYear).value;
    var dDepDate = new Date(document.getElementById(ddlDepYear).value,document.getElementById(ddlDepMon).value - 1, document.getElementById(ddlDepDay).value);
    var dRtnDate = new Date(document.getElementById(ddlRtnYear).value,document.getElementById(ddlRtnMon).value - 1, document.getElementById(ddlRtnDay).value);
    
    //If its return flight then do the check of dates for departs and Returns
    if(document.getElementById(hidDirection).value=="2")
    {
        if(dRtnDate <= dDepDate)
        {
            alert("The return date must be at least a day after the departure date.");
            return false;
        }
    }
    
    var iNoOfAdult = parseInt(document.getElementById(ddlAdult).value);
    var iNoOfChild = parseInt(document.getElementById(ddlChild).value);
    var iNoOfInfant = parseInt(document.getElementById(ddlInfant).value);
    
    if((iNoOfAdult+iNoOfChild) >= 10)
    {
            alert("To check pricing and availability for bookings of 10 or more passengers, group bookings, please contact the Kiss Flights Reservations team on 0871 737 4155.");
            return false;
    }
    
    if(iNoOfInfant > iNoOfAdult)
    {
            alert("The number of Infants cannot be greater than the number of Adults on the booking.");
            return false;
    }
    
    return true;
}

function setReturnsDate(ddlDepDay,ddlDepMon,ddlDepYear,ddlRtnDay,ddlRtnMon,ddlRtnYear,hidDepDate,hidRtnDate)
{
    //alert("Dep Year" + document.getElementById(ddlDepYear).value);
    //alert("Dep Mon" + document.getElementById(ddlDepMon).value - 1);
    //alert("Dep Day" + document.getElementById(ddlDepDay).value);
    
    var dDepDate = new Date(document.getElementById(ddlDepYear).value,document.getElementById(ddlDepMon).value - 1, document.getElementById(ddlDepDay).value);
    
    var dRtnDate = new Date(dDepDate.getTime() + 7*24*60*60*1000 ) 
    //alert(dDepDate);
    //alert(dRtnDate);
    
    //Populate and Set Departure Days
    PopulateDays(ddlDepDay,ddlDepMon,ddlDepYear,hidDepDate,dDepDate);
    
    //Populate and Set Return Days
    PopulateDays(ddlRtnDay,ddlRtnMon,ddlRtnYear,hidRtnDate,dRtnDate);
    
}

function PopulateDays(ddlDay,ddlMon,ddlYear,hidDate,dDate)
{
    
    if(!dDate){  
        dDate = new Date(document.getElementById(ddlYear).value,document.getElementById(ddlMon).value - 1, document.getElementById(ddlDay).value);
    }
        
    var ileapYear = dDate.getYear() % 4;
    var icurMon = dDate.getMonth() + 1;
        
    removeAllOptions(document.getElementById(ddlDay));
    
    document.getElementById(hidDate).value = dDate.getDate() + "/" + icurMon + "/" + dDate.getFullYear();
    
    //alert("hidDate in Populate Days" + document.getElementById(hidDate).value);
    for (var intDay = 1; intDay <= 31; intDay++)
    {
         if (icurMon == 4 || icurMon == 6 || icurMon == 9 || icurMon == 11)
         {
             if (intDay <= 30)
             {
		        newOpt=new Option; 
	            newOpt.value= "" + intDay;
		        newOpt.text="" + intDay;	
            	document.getElementById(ddlDay).options[intDay - 1]=null;
	            document.getElementById(ddlDay).options[intDay - 1]=newOpt;
	         }
         }
         if (icurMon == 2)
         {
            if (ileapYear == 0)
            {
                 if (intDay <= 29)
                 {
		            newOpt=new Option; 
	                newOpt.value="" + intDay;
		            newOpt.text="" + intDay;	
            	    document.getElementById(ddlDay).options[intDay - 1]=null;
	                document.getElementById(ddlDay).options[intDay - 1]=newOpt;
    		    }

            }
            else
            {
                 if (intDay <= 28)
                 {
		            newOpt=new Option; 
	                newOpt.value="" + intDay;
		            newOpt.text="" + intDay;	
            	    document.getElementById(ddlDay).options[intDay - 1]=null;
	                document.getElementById(ddlDay).options[intDay - 1]=newOpt;
	             }    
		    }

         }
                
         if (icurMon == 1 || icurMon == 3 || icurMon == 5 || icurMon == 7 || icurMon == 8 || icurMon == 10 || icurMon == 12)
	    {
		     newOpt=new Option; 
	         newOpt.value="" + intDay;
		     newOpt.text="" + intDay;	
             document.getElementById(ddlDay).options[intDay - 1]=null;
	         document.getElementById(ddlDay).options[intDay - 1]=newOpt;
	    }
	   }
	   
	   document.getElementById(ddlDay).value = dDate.getDate();
       document.getElementById(ddlMon).value = dDate.getMonth() + 1;
       document.getElementById(ddlYear).value = dDate.getYear();
}

function removeAllOptions(selectbox)
{
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
        selectbox.remove(i);
    }
}

function CalculateTotalCost(objSelected,optionalExtras,totalCost,hidCostExtras,hidTotalCost,hidExtrasSelected,objPriceSelected)
{
    var strClickedValue;
    var sExtrasSelected = document.getElementById(hidExtrasSelected).value;
    var strPriceSelected = "0";
    var stroptionalExtrasRef = document.getElementById(optionalExtras);
    var stroptionalExtrasValue = getLabelValue(stroptionalExtrasRef);
    
    stroptionalExtrasValue = stroptionalExtrasValue.replace(/£/gi, "");
    
    var stroptionalExtrasFinalValue;
    var strtotalCostRef = document.getElementById(totalCost);
    var strtotalCostValue = getLabelValue(strtotalCostRef);
    var strtotalCostFinalValue;
    strtotalCostValue = strtotalCostValue.replace(/£/gi, "");
    
    if(objSelected.type == "select-one")
    {
        strClickedValue = objSelected.options[objSelected.selectedIndex].text;
        strClickedValue = strClickedValue.substring(strClickedValue.indexOf("£") + 1,strClickedValue.indexOf(")"));
        
        if(strClickedValue == "" )
            strClickedValue = "0";
            
        strPriceSelected = document.getElementById(objPriceSelected).value;        
        
        //Reduce the old price value from optional extras/Total Cost and add the new value to optional Extras/Total Cost
        stroptionalExtrasFinalValue = parseFloat(stroptionalExtrasValue) - parseFloat(strPriceSelected) + parseFloat(strClickedValue);
        strtotalCostFinalValue = parseFloat(strtotalCostValue) - parseFloat(strPriceSelected) + parseFloat(strClickedValue);
            
        //Set the Selected Price Value
        document.getElementById(objPriceSelected).value =  strClickedValue.replace(/£/gi, "");
        
    }
    else
    {
        //alert(objSelected.id.replace(/chk/gi, "hid"));
        var sTempValSel="";
        if(document.getElementById(objSelected.id.replace(/chk/gi, "hid")) != null)
            sTempValSel = document.getElementById(objSelected.id.replace(/chk/gi, "hid")).value;
            
        strClickedValue = getLabelValue(document.getElementById(objSelected.id.replace(/chk/gi, "lbl"))); 
        strClickedValue = strClickedValue.replace(/£/gi, "");  
        if(strClickedValue == "" )
            strClickedValue = "0";
            
        if(objSelected.checked == true)
        {
            //alert(sTempValSel);
            //alert(sTempValSel.substring(0,sTempValSel.indexOf(".")));
            //alert(sExtrasSelected.indexOf(sTempValSel.substring(0,sTempValSel.indexOf("."))));
//            if(sTempValSel!="" && sTempValSel.indexOf("BAG")!=-1)
//            {
//                if(sExtrasSelected != "" && sExtrasSelected.indexOf(sTempValSel.substring(0,sTempValSel.indexOf("."))) != -1)
//                {
//                    alert("You can't select two different baggage options for the same flight");
//                    objSelected.checked = false;
//                    return false;
//                }
//            }

            stroptionalExtrasFinalValue = parseFloat(stroptionalExtrasValue) + parseFloat(strClickedValue);
            strtotalCostFinalValue = parseFloat(strtotalCostValue) + parseFloat(strClickedValue);
            sExtrasSelected = sExtrasSelected + ";" + document.getElementById(objSelected.id.replace(/chk/gi, "hid")).value; 
        }
        else
        {
            stroptionalExtrasFinalValue = parseFloat(stroptionalExtrasValue) - parseFloat(strClickedValue) - parseFloat(strPriceSelected);
            strtotalCostFinalValue = parseFloat(strtotalCostValue) - parseFloat(strClickedValue);
            var tmpIndex = sExtrasSelected.indexOf(sTempValSel);
            //alert(tmpIndex);
            //alert(sExtrasSelected.replace(sTempValSel,""));
            if( tmpIndex != -1) 
            {
                sExtrasSelected = sExtrasSelected.replace(sTempValSel,""); 
            }
        }
        //alert(sExtrasSelected);
    }    
    
    setLabelValue(document.getElementById(optionalExtras),"£" + (stroptionalExtrasFinalValue).toFixed(2));
    setLabelValue(document.getElementById(totalCost),"£" + (strtotalCostFinalValue).toFixed(2));
    
    document.getElementById(hidCostExtras).value = "£" + stroptionalExtrasFinalValue;
    document.getElementById(hidTotalCost).value = "£" + strtotalCostFinalValue;
    document.getElementById(hidExtrasSelected).value = sExtrasSelected;
}

function CalculateTotalCostForVikingGold(objSelected,optionalExtras,
        totalCost,hidCostExtras,hidTotalCost,hidExtrasSelected,hidTotalVikingGoldPrice)
{
    var strClickedValue;
    var sExtrasSelected = document.getElementById(hidExtrasSelected).value;
    var strPriceSelected = "0";
    var stroptionalExtrasRef = document.getElementById(optionalExtras);
    var stroptionalExtrasValue = getLabelValue(stroptionalExtrasRef);
    
    //alert(stroptionalExtrasValue);
    stroptionalExtrasValue = stroptionalExtrasValue.replace(/£/gi, "");
    
    var stroptionalExtrasFinalValue;
    var strtotalCostRef = document.getElementById(totalCost);
    var strtotalCostValue = getLabelValue(strtotalCostRef);
    
    //alert(strtotalCostValue);
    var strtotalCostFinalValue;
    strtotalCostValue = strtotalCostValue.replace(/£/gi, "");
    
    var strTotalVikingGoldPrice = document.getElementById(hidTotalVikingGoldPrice).value;        
    var sTempValSel="VIK.GOLD";
    
    if(objSelected.checked == true)
    {
        stroptionalExtrasFinalValue = parseFloat(stroptionalExtrasValue) + parseFloat(strTotalVikingGoldPrice);
        strtotalCostFinalValue = parseFloat(strtotalCostValue) + parseFloat(strTotalVikingGoldPrice);
        sExtrasSelected = sExtrasSelected + ";" + sTempValSel;         
    }    
    else
    {        
        stroptionalExtrasFinalValue = parseFloat(stroptionalExtrasValue) - parseFloat(strTotalVikingGoldPrice);
        strtotalCostFinalValue = parseFloat(strtotalCostValue) - parseFloat(strTotalVikingGoldPrice);
        var tmpIndex = sExtrasSelected.indexOf(sTempValSel);
        if( tmpIndex != -1) 
        {
            sExtrasSelected = sExtrasSelected.replace(sTempValSel,""); 
        }
    }
    
    setLabelValue(document.getElementById(optionalExtras),"£" + (stroptionalExtrasFinalValue).toFixed(2));
    setLabelValue(document.getElementById(totalCost),"£" + (strtotalCostFinalValue).toFixed(2));
    
    document.getElementById(hidCostExtras).value = "£" + stroptionalExtrasFinalValue;
    document.getElementById(hidTotalCost).value = "£" + strtotalCostFinalValue;
    document.getElementById(hidExtrasSelected).value = sExtrasSelected;
}
       
function getLabelValue(Ref)
{
    if ( Ref.textContent )
    {
        // Firefox...
        sValue = Ref.textContent;
        //alert("FireFox" + stroptionalExtrasValue);
    }
    else if ( Ref.innerText )
    {
        // IE...
        sValue = Ref.innerText;
        //alert("IE" + stroptionalExtrasValue);
    }
    else
    {
        // Default...
        sValue = Ref.innerHTML;
        var regExp = /<\/?[^>]+>/gi;
        sValue = sValue.replace(regExp, '');
        //alert("default" + stroptionalExtrasValue);
    }
    
    return sValue;
 }        
 
function CalculateTotalCost2(objSelected,optionalExtras,optionalExtras2,totalCost,hidCostExtras,hidTotalCost,hidExtrasSelected,objPriceSelected)
{
    var strClickedValue;
    var sExtrasSelected = document.getElementById(hidExtrasSelected).value;
    var strPriceSelected = "0";
    var stroptionalExtrasRef = document.getElementById(optionalExtras);
    var stroptionalExtrasValue = getLabelValue(stroptionalExtrasRef);
    
    stroptionalExtrasValue = stroptionalExtrasValue.replace(/£/gi, "");
    
    var stroptionalExtrasRef2 = document.getElementById(optionalExtras2);
    var stroptionalExtrasValue2 = getLabelValue(stroptionalExtrasRef2);
    
    stroptionalExtrasValue2 = stroptionalExtrasValue2.replace(/£/gi, "");
    
    var stroptionalExtrasFinalValue;
    var strtotalCostRef = document.getElementById(totalCost);
    var strtotalCostValue = getLabelValue(strtotalCostRef);
    var strtotalCostFinalValue;
    strtotalCostValue = strtotalCostValue.replace(/£/gi, "");
    
    var sTempValSel="";
    if(document.getElementById(objSelected.id.replace(/chk/gi, "hid")) != null)
        sTempValSel = document.getElementById(objSelected.id.replace(/chk/gi, "hid")).value;
        
    strClickedValue = getLabelValue(document.getElementById(objSelected.id.replace(/chk/gi, "lbl"))); 
    strClickedValue = strClickedValue.replace(/£/gi, "");  
    if(strClickedValue == "" )
        strClickedValue = "0";
        
    if(objSelected.checked == true)
    {
        //alert(stroptionalExtrasValue + " - " + strClickedValue + " - " + stroptionalExtrasValue2);
        
        setLabelValue(document.getElementById(optionalExtras2),strClickedValue);    
        stroptionalExtrasFinalValue = (parseFloat(stroptionalExtrasValue) - stroptionalExtrasValue2) + parseFloat(strClickedValue);
        strtotalCostFinalValue = (parseFloat(strtotalCostValue) - stroptionalExtrasValue2) + parseFloat(strClickedValue);
        sExtrasSelected = sExtrasSelected + ";" + document.getElementById(objSelected.id.replace(/chk/gi, "hid")).value; 
    }
    
    setLabelValue(document.getElementById(optionalExtras),"£" + (stroptionalExtrasFinalValue).toFixed(2));
    setLabelValue(document.getElementById(totalCost),"£" + (strtotalCostFinalValue).toFixed(2));
    
    document.getElementById(hidCostExtras).value = "£" + stroptionalExtrasFinalValue;
    document.getElementById(hidTotalCost).value = "£" + strtotalCostFinalValue;
    document.getElementById(hidExtrasSelected).value = sExtrasSelected;
}

function setLabelValue(Ref, sValue)
{
    if ( Ref.textContent )
    {
        // Firefox...
        Ref.textContent = sValue;
        //alert("FireFox" + stroptionalExtrasValue);
    }
    else if ( Ref.innerText )
    {
        // IE...
        Ref.innerText = sValue;
        //alert("IE" + stroptionalExtrasValue);
    }
    else
    {
        // Default...
        Ref.innerHTML = sValue;
        /*var regExp = /<\/?[^>]+>/gi;
        sValue = sValue.replace(regExp, '');
        //alert("default" + stroptionalExtrasValue);*/
    }
    
    return sValue;
 }      
                  
/* Date Picker*/ 
var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('S', 'M', 'T', 'W', 'T', 'F', 'S');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 
// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
// and defaultDateFormat variables either here or on your HTML page.
var defaultDateSeparator = "/";        // common values would be "/" or "."
var defaultDateFormat = "mdy"    // valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/**
This is the main function you'll call from the onClick event of a button.
Normally, you'll have something like this on your HTML page:

Start Date: <input name="StartDate">
<input type=button value="select" onclick="displayDatePicker('StartDate');">

That will cause the datepicker to be displayed beneath the StartDate field and
any date that is chosen will update the value of that field. If you'd rather have the
datepicker display beneath the button that was clicked, you can code the button
like this:

<input type=button value="select" onclick="displayDatePicker('StartDate', this);">

So, pretty much, the first argument (dateFieldName) is a string representing the
name of the field that will be modified if the user picks a date, and the second
argument (displayBelowThisObject) is optional and represents an actual node
on the HTML document that the datepicker should be displayed below.

In version 1.1 of this code, the dtFormat and dtSep variables were added, allowing
you to use a specific date format or date separator for a given call to this function.
Normally, you'll just want to set these defaults globally with the defaultDateSeparator
and defaultDateFormat variables, but it doesn't hurt anything to add them as optional
parameters here. An example of use is:

<input type=button value="select" onclick="displayDatePicker('StartDate', false, 'dmy', '.');">

This would display the datepicker beneath the StartDate field (because the
displayBelowThisObject parameter was false), and update the StartDate field with
the chosen value of the datepicker using a date format of dd.mm.yyyy
*/

function displayDatePicker(dateFieldName, displayBelowThisControl, dtFormat, dtSep, dateComboFields)
{
  
  var targetDateField = document.getElementById(dateFieldName);
  
  var displayBelowThisObject = document.getElementById(displayBelowThisControl);
  // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
 
  // if a date separator character was given, update the dateSeparator variable
  if (dtSep)
    dateSeparator = dtSep;
  else
    dateSeparator = defaultDateSeparator;
 
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
    dateFormat = defaultDateFormat;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
 
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }
 
  drawDatePicker(targetDateField, x, y, dateComboFields);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y, dateComboFields)
{
  var dt = getFieldDate(targetDateField.value);
  
  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
 
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
 
  // draw the datepicker table
  refreshDatePicker(dateComboFields,targetDateField.id, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateComboFields,dateFieldName, year, month, day)
{
  //alert("refreshDatePicker:" + dateComboFields );
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
 
 
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_CloseButton = "<tr class='dpCloseButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleTD'>";
  var TD_buttons = "<td class='dpButtonTD'>";
  var TD_CloseButton = "<td colspan=7 class='dpCloseButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";
 
  // start generating the code for the calendar table
  var html = TABLE;
 
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;", dateComboFields) + xTD;
  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;", dateComboFields) + xTD;
  html += xTR;
  
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
 
  // now we'll start populating the table with days of the month
  html += TR;
 
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;
 
  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + dateComboFields + "','" + getDateString(thisDay) + "');\">";
    
    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
 
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
 
  // add a button to allow the user to easily return to today, or close the calendar
  //var today = new Date();
  //var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
  html += TR_CloseButton + TD_CloseButton;
  //html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", \"" + dateComboFields + "\");'>this month</button> ";
  html += "<button class='clsKissButton' onClick='updateDateField(\"" + dateFieldName + "\", \"" + dateComboFields + "\");'>close</button>";
  html += xTD + xTR;
 
  // and finally, close the table
  html += xTABLE;
    
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label, dateComboFields)
{
  var newMonth = (dateVal.getMonth () + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
  
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateComboFields + "\",\"" + dateFieldName + "\", " + newYear + "," + newMonth + ");'>" + label + "</button>";
}


/**
Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
 
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal;
  var dArray;
  var d, m, y;
 
  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else if (dateString) {
      dateVal = new Date(dateString);
    } else {
      dateVal = new Date();
    }
  } catch(e) {
    dateVal = new Date();
  }
 
  return dateVal;
}


/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
 
  return dArray;
}

/**
Update the field with the given dateFieldName with the dateString that has been passed,
and hide the datepicker. If no dateString is passed, just close the datepicker without
changing the field value.

Also, if the page developer has defined a function called datePickerClosed anywhere on
the page or in an imported library, we will attempt to run that function with the updated
field as a parameter. This can be used for such things as date validation, setting default
values for related fields, etc. For example, you might have a function like this to validate
a start date field:

function datePickerClosed(dateField)
{
  var dateObj = getFieldDate(dateField.value);
  var today = new Date();
  today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
 
  if (dateField.name == "StartDate") {
    if (dateObj < today) {
      // if the date is before today, alert the user and display the datepicker again
      alert("Please enter a date that is today or later");
      dateField.value = "";
      document.getElementById(datePickerDivID).style.visibility = "visible";
      adjustiFrame();
    } else {
      // if the date is okay, set the EndDate field to 7 days after the StartDate
      dateObj.setTime(dateObj.getTime() + (7 * 24 * 60 * 60 * 1000));
      var endDateField = document.getElementsByName ("EndDate").item(0);
      endDateField.value = getDateString(dateObj);
    }
  }
}

*/

function datePickerClosed(dateField,dateComboFields)
{
  var dateObj = getFieldDate(dateField.value);
  var arrDateComboFields = dateComboFields.split("*");
     
  //If 8 the its Departure Date is clicked
  if(arrDateComboFields.length == 8){
    PopulateDays(arrDateComboFields[0],arrDateComboFields[1],arrDateComboFields[2],arrDateComboFields[6],dateObj);
    setReturnsDate(arrDateComboFields[0],arrDateComboFields[1],arrDateComboFields[2],arrDateComboFields[3],arrDateComboFields[4],arrDateComboFields[5],arrDateComboFields[6],arrDateComboFields[7]);
  }
  else
    PopulateDays(arrDateComboFields[0],arrDateComboFields[1],arrDateComboFields[2],arrDateComboFields[3],dateObj);
}


function updateDateField(dateFieldName,dateComboFields,dateString)
{
  
  var targetDateField = document.getElementById(dateFieldName);
  
  if (dateString)
    targetDateField.value = dateString;
    
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  //targetDateField.focus();
 
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField,dateComboFields);
}


/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDiv, iFrameDiv)
{
  // we know that Opera doesn't like something about this, so if we
  // think we're using Opera, don't even try
  var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  if (is_opera)
    return;
  
  // put a try/catch block around the whole thing, just in case
  try {
    if (!document.getElementById(iFrameDivID)) {
      // don't use innerHTML to update the body, because it can cause global variables
      // that are currently pointing to objects on the page to have bad references
      //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
      var newNode = document.createElement("iFrame");
      newNode.setAttribute("id", iFrameDivID);
      newNode.setAttribute("src", "javascript:false;");
      newNode.setAttribute("scrolling", "no");
      newNode.setAttribute ("frameborder", "0");
      document.body.appendChild(newNode);
    }
    
    if (!pickerDiv)
      pickerDiv = document.getElementById(datePickerDivID);
    if (!iFrameDiv)
      iFrameDiv = document.getElementById(iFrameDivID);
    
    try {
      iFrameDiv.style.position = "absolute";
      iFrameDiv.style.width = pickerDiv.offsetWidth;
      iFrameDiv.style.height = pickerDiv.offsetHeight ;
      iFrameDiv.style.top = pickerDiv.style.top;
      iFrameDiv.style.left = pickerDiv.style.left;
      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
      iFrameDiv.style.visibility = pickerDiv.style.visibility ;
      iFrameDiv.style.display = pickerDiv.style.display;
    } catch(e) {
    }
 
  } catch (ee) {
  }
 
}

function MultipleFieldsValidatorEvaluateIsValid(val) {
 
    controltovalidateIDs = val.controlstovalidate.split(',');
    //alert(controltovalidateIDs);
    switch (val.condition) {
        case 'OR':
            for(var controltovalidateIDIndex in controltovalidateIDs) {
                var controlID = controltovalidateIDs[controltovalidateIDIndex];
                if (ValidatorTrim(ValidatorGetValue(controlID)) != '') {
                    return true;
                } 
            }
            return false;
        break;
        case 'XOR':
            for(var controltovalidateIDIndex in controltovalidateIDs) {
                var controlID = controltovalidateIDs[controltovalidateIDIndex];
                if (controltovalidateIDIndex == '0') {
                    var previousResult = !(ValidatorTrim(ValidatorGetValue(controlID)) == '');
                    continue;
                }
                var currentResult = !(ValidatorTrim(ValidatorGetValue(controlID)) == '');
                if (currentResult != previousResult) {
                    return true;
                }
                previousResult != currentResult;
            }
            return false;
        break;
        case 'AND':
            for(var controltovalidateIDIndex in controltovalidateIDs) {
                var controlID = controltovalidateIDs[controltovalidateIDIndex];
                if (ValidatorTrim(ValidatorGetValue(controlID)) == '') {
                    return false;
                } 
            }
            return true;
        break;
        case 'CUSTOM':
            for(var controltovalidateIDIndex in controltovalidateIDs) {
                var controlID = controltovalidateIDs[controltovalidateIDIndex];
                var control;
                var chkControlChecked;
                var otherControlEmpty;
                control = document.getElementById(controlID);
                
                if (control.type == "checkbox" )
                {
                    //alert(controlID);
                    if (control.checked)
                        chkControlChecked = true;
                        //return true;
                }
                if (ValidatorTrim(ValidatorGetValue(controlID)) == '') {
                    otherControlEmpty = true
                    
                } 
            }
            if(chkControlChecked && otherControlEmpty) 
                return false;
            else
                return true;
        break;
       case 'MANDATORYCHECKBOX':
            for(var controltovalidateIDIndex in controltovalidateIDs) {
                var controlID = controltovalidateIDs[controltovalidateIDIndex];
                var control;
                var chkControlChecked;
                var otherControlEmpty;
                control = document.getElementById(controlID);
                
                if (control.type == "checkbox" )
                {
                    if (control.checked){
                        return true;
                     }
                     return false;
                }
               
            }
            
        break;
    }
    return false;
}

        var xmlHttp;

		function createXMLHttpRequest() {
			if (window.ActiveXObject) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			else if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
			}
		}

		function SetFlightTimeTable(sb) {
				//document.getElementById("LoadingTimeTable").innerHTML = '<strong>Loading Time Table...</strong>';
				/*var to = document.getElementById("ddl_ajax").options[document.getElementById("ddl_ajax").selectedIndex].value;
				var season = document.getElementById("Select1").options[document.getElementById("Select1").selectedIndex].value;
				var from = document.getElementById("ddl").options[document.getElementById("ddl").selectedIndex].value;*/
				//alert("SetFlightTimeTable");
				createXMLHttpRequest();
				xmlHttp.onreadystatechange = handleStateChange;
				//xmlHttp.open("GET", "../FlightOffersAjax.asp?origin=" + from + "&destination=" + to + "&BrochureCode=" + season + "&sortby=" + sb, true);
				xmlHttp.open("GET", "../FlightOffersAjax.aspx", true);
				xmlHttp.send(null);
				//document.getElementById("LoadingTimeTable").innerHTML = '';
		}

		function handleStateChange() {
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					document.getElementById("divOffers").innerHTML = xmlHttp.responseText;
				}
			}
		}
		
		function validateCC(idddlCardType,idddlStartDateMonth,
                             idddlStartDateYear, idtxtIssueNumber)
       {
            
            var sCardType= document.getElementById(idddlCardType).value;
            var sddlStartDateMonth= document.getElementById(idddlStartDateMonth).value;
            var sddlStartDateYear= document.getElementById(idddlStartDateYear).value;
            var stxtIssueNumber= document.getElementById(idtxtIssueNumber).value;
            
            
            if(sCardType=="MAE")
            {
                
                if((sddlStartDateMonth!= "" && sddlStartDateYear != "") 
                            || stxtIssueNumber != "")
                {
                    return true;
                }
                else
                {
                    alert("If your card type is Maestro/Switch, then either start month/year or Issue No should be provided");
                    return false;
                }
            }
            
            return false;
       }
       
       function AddCreditCardCharge(idddlCardType,    
                                    idlblSubTotal,
                                    idlblAuthoriseAmount,
                                    idhidCCChargeAdded,
                                    idhidTotalPax,
                                    idhidOrigSubTotal,
                                    iddivlblCardCharge,
                                    idlblTotalCardCharge)
       {
            
            //var slblSubTotal= getLabelValue(idlblSubTotal);
            //var slblAuthoriseAmount= getLabelValue(idlblAuthoriseAmount);
            //var shidCCChargeAdded= document.getElementById(idhidCCChargeAdded).value;
            var sCardType= document.getElementById(idddlCardType).value;
            var shidTotalPax= document.getElementById(idhidTotalPax).value;
            var shidOrigSubTotal= document.getElementById(idhidOrigSubTotal).value;
            
            //alert(slblSubTotal);
            //alert(slblAuthoriseAmount);
            //alert(shidOrigSubTotal);
            
            if(sCardType=="MAS" || sCardType=="VIS")
            {
                var stempAmt = (parseFloat(shidOrigSubTotal) + ((5)*  parseFloat(shidTotalPax))).toFixed(2);
                
                setLabelValue(document.getElementById(idlblSubTotal),"£" + stempAmt);
                setLabelValue(document.getElementById(idlblAuthoriseAmount),"£" + stempAmt);
                
                setLabelValue(document.getElementById(idlblTotalCardCharge),"£" + ((5)* parseFloat(shidTotalPax)).toFixed(2));
                
                document.getElementById(iddivlblCardCharge).style.display="block";
                document.getElementById(iddivlblCardCharge).style.visibility="visible";
            }
            else
            {
                setLabelValue(document.getElementById(idlblSubTotal),"£" + shidOrigSubTotal);
                setLabelValue(document.getElementById(idlblAuthoriseAmount),"£" + shidOrigSubTotal);
                
                setLabelValue(document.getElementById(idlblTotalCardCharge),"£" + "0");
                
                document.getElementById(iddivlblCardCharge).style.display="none";
                document.getElementById(iddivlblCardCharge).style.visibility="hidden";
            }
       }
       

function AddCreditCardCharge(idddlCardType,    
                            idlblSubTotal,
                            idlblAuthoriseAmount,
                            idhidCCChargeAdded,
                            idhidTotalPax,
                            idhidOrigSubTotal,
                            iddivlblCardCharge,
                            idlblTotalCardCharge)
{
    
    //var slblSubTotal= getLabelValue(idlblSubTotal);
    //var slblAuthoriseAmount= getLabelValue(idlblAuthoriseAmount);
    //var shidCCChargeAdded= document.getElementById(idhidCCChargeAdded).value;
    var sCardType= document.getElementById(idddlCardType).value;
    var shidTotalPax= document.getElementById(idhidTotalPax).value;
    var shidOrigSubTotal= document.getElementById(idhidOrigSubTotal).value;
    
    //alert(slblSubTotal);
    //alert(slblAuthoriseAmount);
    //alert(shidOrigSubTotal);
    
    if(sCardType=="MAS" || sCardType=="VIS")
    {
        var stempAmt = (parseFloat(shidOrigSubTotal) + ((5)*  parseFloat(shidTotalPax))).toFixed(2);
        
        setLabelValue(document.getElementById(idlblSubTotal),"£" + stempAmt);
        setLabelValue(document.getElementById(idlblAuthoriseAmount),"£" + stempAmt);
        
        setLabelValue(document.getElementById(idlblTotalCardCharge),"£" + ((5)* parseFloat(shidTotalPax)).toFixed(2));
        
        document.getElementById(iddivlblCardCharge).style.display="block";
        document.getElementById(iddivlblCardCharge).style.visibility="visible";
    }
    else
    {
        setLabelValue(document.getElementById(idlblSubTotal),"£" + shidOrigSubTotal);
        setLabelValue(document.getElementById(idlblAuthoriseAmount),"£" + shidOrigSubTotal);
        
        setLabelValue(document.getElementById(idlblTotalCardCharge),"£" + "0");
        
        document.getElementById(iddivlblCardCharge).style.display="none";
        document.getElementById(iddivlblCardCharge).style.visibility="hidden";
    }
}