﻿
var SkipField = null;
var SelectedField = null;
var UpdateList = true;
var GroupsList = null;
var RegionsList = null;
var OperatorsList = null;
var PostedFields = null;
var SendForm = true;
var ResortsList = null; 
var AllResortsList = null;
var AirportGroups = null; //new Array('STN-LTN-LHR-LGW:Any London airport');
var ExcludedGroups = ''; //string of ('10012','10000',...);
var IncludeGroups = ''; // string of ('10012','10000',...);
var DestinationAirports = null;
var NewDate = false;
var InsurancePrice = 0;
var InsuranceOption=null;
var CardCharge = 0;
var PackagePrice = 0;
var DefaultAirport = null;
var LastDepStart = 0;
var LastRetStart = 0;
var LastDepMonth = 0;
var LastRetMonth = 0;
var WaitLeft = 300;
var WaitTop= 200;
var WaitWidth = 284;
var WaitHeight= 96;
var Booking = false;
var BackToSearch=null;
var BackToRegions=null;
var BackToHotels=null;
var BookingIDs = new Array();
var CachedOffers = null;
var WaitForCallBack = false;
var AllResortsChanged = false;
var ExcludedOperators = "";
/*************************** Mouse actions over images **********************************/
function MouseOver(img)
{
    var image = img.src.substring(0, img.src.lastIndexOf("_"));

    img.src = image + "_over.gif";
}

function MouseOut(img)
{
    var image = img.src.substring(0, img.src.lastIndexOf("_"));
        
    img.src = image + "_out.gif";
}

function MouseDown(img)
{
    var image = img.src.substring(0, img.src.lastIndexOf("_"));

    img.src = image + "_on.gif";
}
function MouseUp(btn)
{
    var Form = GetElementById('frmIBEMainForm');
    var secure = GetElementById("SecureSite");
    
    Form.reset();
    CheckFields();

    if(btn.id == "btn_book")
    {
        Booking = true;
        Form.action = secure.value.replace(/;/g, ':');     
        
        //Form.action = "http://localhost:8888/AEM%20IBE%20Secure/book.aspx";
    }
    if(btn.id == "btn_bookingrequest")
    {
        Booking = true;
        Form.action = secure.value.replace(/;/g, ':'); //.substring(0,secure.value.replace(/;/g, ':').lastIndexOf('/')) + "/SoftBooking.aspx";        
        
        //Form.action = "http://localhost:8888/AEM%20IBE%20Secure/softbooking.aspx";
    }
}
/***************************************************************************************/

/********************************** Navigation *****************************************/
function IndexOf(value, array)
{
    for(i=0; i<array.length; i++)
    {
        if(value.indexOf(array[i])>-1)
            return i;
    }
    return -1;
}
function Book(bookingid, operator, airport, selectedBoard, targetPage)
{
    if(WaitForCallBack)
        return false;
    var Form = GetElementById('frmIBEMainForm');
    var bAirport = GetElementById("BookingAirport");
    if(bAirport!=null)
        bAirport.value=airport;
    var secure = GetElementById("SecureSite");
    
    var OfferIndex = GetElementById('SelectedOfferIndex').value;
    var cache = GetElementById("a" + bookingid).innerHTML;
    offerGUID = cache.substring(cache.indexOf("&#91;OGUID&#93;") + "&#91;OGUID&#93;".length, cache.indexOf("&#91;&#47;OGUID&#93;"));
    var cachedOfferXml = cache.substring(cache.indexOf("[CachedOfferXml]")+"[CachedOfferXml]".length,cache.indexOf("[/CachedOfferXml]"));
    var cachedAvailXml = cache.substring(cache.indexOf("[CachedAvailXml]") + "[CachedAvailXml]".length, cache.indexOf("[/CachedAvailXml]"));
    var cachedFlightXml = GetElementById('FlightDataXML').value;
    var timeout = cache.substring(cache.indexOf("[TimeOut]") + "[TimeOut]".length, cache.indexOf("[/TimeOut]"));
    
    Form.reset();
    GetElementById("CachedOfferXml").value = cachedOfferXml;
    GetElementById("CachedAvailXml").value = cachedAvailXml;
    GetElementById('FlightDataXML').value = cachedFlightXml;
    var History = GetElementById("SearchHistory");
    History.value += "|BookingID:" + bookingid;
    History.value += "|BookingOperator:" + operator;
    History.value += "|BookingAirport:" + airport;
    History.value += "|SelectedBoard:" + selectedBoard;
    CheckFields();
    GetElementById("OfferGUID").value=offerGUID;
    Booking = true;
    Form.action = secure.value.replace(/;/g, ':');     
    GetElementById('SelectedOfferIndex').value = OfferIndex;
    if(window.CustomFunctions!=undefined)
        CustomFunctions();
    //Target Page
    var target = GetElementById("Target");
    if((target != null) && (targetPage != null))
        target.value = targetPage;
    // Timeout
    GetElementById("txtTimeout").value = timeout;
    return true;
}
function BookRequest(bookingid, operator, airport, selectedBoard, targetPage)
{
    return Book(bookingid, operator, airport, selectedBoard, targetPage);
}
function OpenPage(page)
{
    window.navigate(page);
}
function CloseWindow()
{
    window.open('','_parent','');
    window.close();
}
function Prev()
{
    var Form = GetElementById('frmIBEMainForm');
    Form.reset();
    CheckFields();

    var bookingId = GetElementById("BookingID");
    if(bookingId != null)
        bookingId.value = "";
    var action = GetElementById("Action");
    if(action != null)
        action.value = "Paging";
        
    var pageNum = GetElementById("PageNum");
    if(pageNum == null)
        return false;
        
    if(Form!=null)
    {
        if(pageNum.value!="")
            pageNum.value--;
        CleanAction();
        Form.submit();
    }
}

function Page(num)
{
    var Form = GetElementById('frmIBEMainForm');
    var pageNum = GetElementById("PageNum");
   
    Form.reset();
    CheckFields();

    var bookingId = GetElementById("BookingID");
    if(bookingId != null)
        bookingId.value = "";
    var action = GetElementById("Action");
    if(action != null)
        action.value = "Paging";
        
    if(pageNum == null)
        return false;
        
    if(Form!=null)
    {
        pageNum.value = num;
        CleanAction();
        Form.submit();
    }
}

function Next()
{
    var Form = GetElementById('frmIBEMainForm');

    Form.reset();
    CheckFields();

    var bookingId = GetElementById("BookingID");
    if(bookingId != null)
        bookingId.value = "";
    var action = GetElementById("Action");
    if(action != null)
        action.value = "Paging";
        
    var pageNum = GetElementById("PageNum");
  
    if(pageNum == null)
        return false;
        
    if(Form!=null)
    {
        if(pageNum.value!="")
            pageNum.value++;
        else
            pageNum.value = 2;
        CleanAction();
        Form.submit();
    }
}
function AgentLogin()
{
    var Form = GetElementById('frmIBEMainForm');
    var txtUID = GetElementById('AgentUID');
    var txtPWD = GetElementById('AgentPWD');
    var txtIsAgentLogin = GetElementById('IsAgentLogin');
    if(!txtUID)
    {
        alert("Agents' user name field is missing!");
        return false;
    }
    if(!txtPWD)
    {
        alert("Agents' password field is missing!");
        return false;
    }
    if(txtUID.value.length==0)
    {
        alert("Please enter the agents' user name!");
        txtUID.focus();
        return false;
    }
    if(txtPWD.value.length==0)
    {
        alert("Please enter the agents' password!");
        txtPWD.focus();
        return false;
    }
    txtIsAgentLogin.value = "True";
    return true;
}
function AgentLogout()
{
    agentName = document.getElementById('agentName');
    if(agentName){
        agentName.parentNode.removeChild(agentName);
        var Form = GetElementById('frmIBEMainForm');
        Form.action +="?LogOut=true";
        Form.submit();
    }
}
function UpdateHistory(count)
{
    var hist = GetElementById("History");
    if(hist!=null)
    {
        if(count < -1)
            hist.value = count - 1;
        else
            hist.value--;
    }
}

function Back()
{
    var hist = GetElementById("History");
    var h = "-1";
    
    if(hist != null)
    {
        if((hist.value.length > 0) && (parseInt(hist.value, 10) < 0))
            h = hist.value;
    }
    window.history.go(parseInt(h, 10));
}

function SetSearchPage()
{
    BackToSearch = GetElementById("SearchPageName").value;
}
function PopUp(target,width,height)
{
    url = ApplicationName + "?Target=" + target;
    var win = window.open(url,"","resizable=1,scrollbars=1,toolbar=no,menu=no,width="+width+",height="+height,true);
}
function BackTo( pageName )
{
    var Form = GetElementById('frmIBEMainForm');
    var action =GetElementById("Action");
    var target =GetElementById("Target");
    var searchPage =GetElementById("SearchPageName");
    var searchPageName = ""
    if(searchPage!=null)
        searchPageName = searchPage.value;
    var pageNum =GetElementById("PageNum");
    if(pageNum != null)
        pageNum.value = "1";

    //Action
    if(action != null)
        action.value = "Back";
                
    if(Form != null)
    {
        //Target page
        if(target != null)
            target.value = pageName;
        CleanAction()
        Form.submit();
    }
}
function GoTo( pageName )
{
    var Form = GetElementById('frmIBEMainForm');
    var action =GetElementById("Action");
    var target =GetElementById("Target");
    var iff =GetElementById("IFF");
    var searchPage =GetElementById("SearchPageName");
    var searchPageName = ""
    if(searchPage!=null)
        searchPageName = searchPage.value;
    var pageNum =GetElementById("PageNum");
    if(pageNum != null)
        pageNum.value = "1";

    //Action
    if(action != null)
        action.value = "";
    if(iff != null)
        iff.value = "";
                
    if(Form != null)
    {
        //Target page
        if(target != null)
            target.value = pageName;
        CleanAction()
        Form.submit();
    }
}

function BackToSearch()
{
    var Form = GetElementById('frmIBEMainForm');
    var action =GetElementById("Action");
    var pageNum =GetElementById("PageNum");
    var target =GetElementById("Target");
    var iff =GetElementById("IFF");
    var searchPage =GetElementById("SearchPageName");
    var searchPageName = ""
    if(searchPage!=null)
        searchPageName = searchPage.value;
    if(pageNum != null)
        pageNum.value = "1";

    //Action
    if(action != null)
        action.value = "Back";
    if(iff != null)
        iff.value = "";
                
    if(Form != null)
    {
        target.value = searchPageName;
        CleanAction();
        Form.submit();
    }
}
/***************************************************************************************/
/***************************************** TT *****************************************/
/*++++++++++++ Lists ++++++++++*/
function DeepLink(linkID)
{
    var Form = GetElementById('frmIBEMainForm');
    if(Form != null)
    {
        Form.action = "?lid=" + linkID;
        Form.submit();
    }
}
function ShowWait()
{
    var WaitDiv = GetElementById('divWaitLayer');
    var frmWait = GetElementById('WaitFrame');
    var WaitLayer = GetElementById('divWait');

    if(WaitLayer != null)
    {
        WaitLayer.style.visibility = "hidden";
        frmWait.src = "includes/Wait.aspx?HTML=" + WaitLayer.innerHTML + "&css=" + StyleSheet.href;
        WaitDiv.style.width = WaitWidth;
        WaitDiv.style.height = WaitHeight;
        WaitDiv.style.left = WaitLeft;
        WaitDiv.style.top = WaitTop;
        WaitDiv.left = WaitLeft;
        WaitDiv.top = WaitTop;
        frmWait.style.width = WaitWidth;
        frmWait.style.height = WaitHeight;
        WaitDiv.style.position="absolute";
        WaitDiv.style.display="";
        WaitDiv.style.visibility = "visible";
    }
}
function ShowFlights(code, targetPage)
{
    var action = GetElementById("Action");
    var lstAirports = GetElementById("DestinationAirport");
    if(lstAirports == null)
        return false;

    //Target Page
    var target = GetElementById("Target");
    if((target != null) && (targetPage != null))
        target.value = targetPage;
    //Action
    if(action != null)
        action.value = "ShowFlights";
    //Destination Airport
    for(i=0; i < lstAirports.options.length; i++)
    {
        if(lstAirports.options[i].value == code)
        {
            lstAirports.selectedIndex = i;
            break;
        }
    }
    if(CheckForm())
        GetElementById('frmIBEMainForm').submit();
}
function CheckForm()
{
    var action = GetElementById("Action");
        
    CleanAction();
    
    var destAirport = GetElementById("DestinationAirport");
    if(destAirport != null)
    {
        if(destAirport.value.replace(/ /g, '').length == 0)
        {
            //Action
            if(action != null)
                action.value = "Refresh";
        }
    }
    if(window.CustomFunctions!=undefined)
        CustomFunctions();
    return IsValidDate(GetElementById("FromDate").value, GetElementById("ToDate").value);
}

function DisableControls()
{
    var cont = GetElementById("");
    if(cont != null)
        cont.Disabled = true;
}
function UpdateAirports()
{
    //Airports is an array of: {<airport_id>:<airport_name>, ...}
    var departure = GetElementById("Departure");
    
    if(!departure)
        return false;
    
    var opt = departure.options;
    opt.length = 0;
    opt[0] = new Option("Any","");
    
    //Airport Groups {'member1,member2,...:Group name', ...}
    if(AirportGroups != null)
    {
        for(x = 0; x < AirportGroups.length; x++)
            opt[opt.length]=new Option(AirportGroups[x].split(":")[1],AirportGroups[x].split(":")[0].replace(/,/g,"-"));
    }
    
    for(i=0;i<Airports.length;i++)
    {
        opt[opt.length]=new Option(Airports[i].split(":")[1],Airports[i].split(":")[0]);
        if(Airports[i].split(":")[0] == DefaultAirport)
            opt[opt.length - 1].selected = "selected";
    }
}
function UpdateDestAirports()
{
    var destAirport = GetElementById("DestinationAirport");
    if(destAirport == null)
        return;
    if((destAirport.style.display=="none")||(destAirport.options == undefined))
        return;
        
    var opt = destAirport.options;
    opt.length = 0;
    opt[0] = new Option("---Please select ---","");
    count = 1;
    for(i=0;i<DestinationAirports.length;i++)
    {
        dest=DestinationAirports[i].split(":");
        opt[count++]=new Option(dest[0],"");
        airports = dest[1].split(';');
       for(a=0;a<airports.length;a++)
        {
            opt[count++]=new Option("   " + airports[a].split('|')[0],airports[a].split('|')[1]);
        }
    }
}
function UpdateGroups() {
    //IncludeGroups 
    UpdateAirports();
    UpdateDestAirports()
    UpdateAllResorts();

    var noOfIncludedGroups = 0;
    if (IncludeGroups.length > 0) {
        noOfIncludedGroups = IncludeGroups.split(',').length; 
    }
    
    if(UpdateList)
    {
        //GroupList is an array of: {<group_id>:<group_name>, ...}
        var group = GetElementById("Group");
        
        if(!group)
            return false;
        if(group.options == undefined)
        {
            alert("Destination dropdown list is missing.\nThis field is mangatory, please add it to the page.");
            return false;
        }
       
        var opt = group.options;
        opt.length = 0;
        if (GroupsList.length > 1) {
            found = 0;
            if (noOfIncludedGroups != 1 || noOfIncludedGroups ==0) { // If include group is available and only one group in the list do not add the Any option to the list
                opt[0] = new Option("Any", "");
                found = 1;
            }
        }
        else
            found = 0;
        for(i=0;i<GroupsList.length;i++)
        {
            sr = GroupsList[i].split(":");
            if (noOfIncludedGroups <= 0) { // if include list is not available include all 23/04/2010
                if (ExcludedGroups.indexOf("'" + sr[0] + "'") == -1) {
                    if (found >= opt.length)
                        opt[found++] = new Option(sr[1], sr[0]);
                    else {
                        opt[found].text = sr[1];
                        opt[found++].value = sr[0];
                    }
                    if (GroupsList.length == 1)
                        opt[found - 1].selected = "selected";
                }
            }
            else { // if Include list is available then include this in the list
                if (IncludeGroups.indexOf( sr[0] ) >= 0) {
                    if (found >= opt.length)
                        opt[found++] = new Option(sr[1], sr[0]);
                    else {
                        opt[found].text = sr[1];
                        opt[found++].value = sr[0];
                    }
                    if (GroupsList.length == 1)
                        opt[found - 1].selected = "selected";
                }
            }
        }
        while(opt.length > found)
            opt[opt.length-1]=null;
    }
}
function UpdateAllResorts()
{
    // All Resorts
    var lstResort = GetElementById("Resort");
    if(lstResort!=null)
    {
        if((lstResort.style.display=="none") || (lstResort.options == undefined))
            return false;
        opt = lstResort.options;
        opt.length = 0;
        opt[0] = new Option("Any","");

        for(i=0;i<AllResortsList.length;i++)
        {
            opt[i+1]=new Option(AllResortsList[i].split(":")[1],AllResortsList[i].split(":")[0]);
        }
    }
}
function UpdateRegion()
{
    var region = GetElementById("Region");
    var resort = GetElementById("Resort");

    AllResortsChanged = true;
    if((!region) || (!resort))
        return false;
    if((resort.value!=null) && (resort.value.split(';').length!=2))
        return false;
    regionId = resort.value.split(';')[0];
    UpdateList = false;
    for(i = 0; i < region.options.length; i++)
    {
        if(region[i].value == regionId)
        {
            region.selectedIndex = i;
            break;
        }
    }
    UpdateGroup();
    AllResortsChanged = false;
}
function UpdateCountry()
{
    //GroupList is an array of: {<group_id>:<group_name>, ...}
    var country = GetElementById("Country");
    
    if(!country)
        return false;
    if((country.style.display=="none") || (country.options == undefined))
        return false;
    
    var opt = country.options;
    opt.length = 0;
    found = 0;
    for(i=0;i<CID.length;i++)
    {
        sr=CID[i].split(":");
        if(found>=opt.length)
            opt[found++]=new Option(sr[1],sr[0]);
        else 
        {
            opt[found].text=sr[1];
            opt[found++].value=sr[0];
        }
    }
    while(opt.length > found)
        opt[opt.length-1]=null;
}

function UpdateResorts()
{
    //ResortsList is an array of: {<region_id>:<resort_name>, ...}
    var filterBy = GetElementById("FilterBy");
    
    if(!filterBy)
        return false;
     if((filterBy.style.display=="none") || (filterBy.options == undefined))
        return false;
   
    SendForm = false;
    
    var opt = filterBy.options;
    opt.length = 0;
    opt[0] = new Option("--- All resorts ---","");

    for(i=0;i<ResortsList.length;i++)
    {
        resortName=ResortsList[i].split(":")[1];
        opt[i+1]=new Option(resortName,resortName);
    }
    SendForm = true;
}

function UpdateRegions()
{
    //RegionsList is an array of integers: {<group_id>:<region_id>:<region_name>, ...}
    var group = GetElementById("Group");
    var region = GetElementById("Region");
    var resort = GetElementById("Resort");

    if((!region) || (!group))
        return false;
    if(region.options == undefined)
    {
        alert("Regions dropdown list is missing.\nThis field is mangatory, please add it to the page.");
        return false;
    }
    
    var ResortsSelectedValue=null;
    if((resort!=null)&&(resort.selectedIndex>0))
        ResortsSelectedValue = resort[resort.selectedIndex].value;
    if(resort && !AllResortsChanged)
        resort.selectedIndex = 0;
    
    opt = region.options;
    var SelectedValue = null;
    if(RegionsList.length>1)
    {
        if(region.selectedIndex>0)
            SelectedValue = opt[region.selectedIndex].value;
        opt.length = 0;
        opt[0] = new Option("Any","");
        found=1;
    }
    else
        found=0;

    if (group != null && group.selectedIndex > -1)
        group_id = group.options[group.selectedIndex].value;
    else  
       group_id = FindFilterGroupId(SelectedValue);

        for(i=0;i<RegionsList.length;i++)
        {
            sr=RegionsList[i].split(":");
            if (group_id=="" || sr[0] == group_id)
            {
                if(found>=opt.length)
                    opt[found++]=new Option(sr[2],sr[1]);
                else 
                {
                    opt[found].text=sr[2];
                    opt[found++].value=sr[1];
                }
                if((RegionsList.length==1)||((SelectedValue!=null)&&(SelectedValue.toString()==opt[found-1].value.toString())))
                    opt[found-1].selected="selected";
            }
        }

    if((opt.length==2)&&(opt[0].text=="Any"))
        region.remove(0);
    if(opt.length==1)
        opt[0].selected="selected";
    else if(region.style.visibility=="hidden")
    {
        if(opt[0].text=="Any")
            opt[0].selected="selected";
        else
        {for(i=0;i<opt.length;i++){opt[i].selected="";}}
    }
    if(resort!=null)
    {
        // Resorts
        var optResorts = resort.options;
        var foundResorts=0;
        if(AllResortsList.length>1)
        {
            optResorts.length = 0;
            optResorts[0] = new Option("Any","");
            foundResorts=1;
        }

        if((region.options[region.selectedIndex].text=="Any")&&(region.options.length>1))
        {
            for(r=0;r<region.options.length;r++)
            {
                if(region.options[r].value!="")
                {
                    for(i=0;i<AllResortsList.length;i++)
                    {
                        var srResorts=AllResortsList[i].split(":");
                        if(srResorts[0].split(";")[0] == region.options[r].value)
                        {
                            if(foundResorts>=optResorts.length)
                                optResorts[foundResorts++]=new Option(srResorts[1],srResorts[0]);
                            else 
                            {
                                optResorts[foundResorts].text=srResorts[1];
                                optResorts[foundResorts++].value=srResorts[0];
                            }
                        }
                    }
                }
                if((optResorts.length>0)&&((AllResortsList.length==1)||((ResortsSelectedValue!=null)&&(ResortsSelectedValue.toString()==optResorts[foundResorts-1].value.toString()))))
                    optResorts[foundResorts-1].selected="selected";
            }
        }
        else if((region.options.length>0)||(region.options[region.selectedIndex].text!="Any"))
        {
            for(i=0;i<AllResortsList.length;i++)
            {
                var srResorts=AllResortsList[i].split(":");
                if(srResorts[0].split(";")[0] == region.options[region.selectedIndex].value)
                {
                    if(foundResorts>=optResorts.length)
                        optResorts[foundResorts++]=new Option(srResorts[1],srResorts[0]);
                    else 
                    {
                        optResorts[foundResorts].text=srResorts[1];
                        optResorts[foundResorts++].value=srResorts[0];
                    }
                }
                if((optResorts.length>0)&&((AllResortsList.length==1)||((ResortsSelectedValue!=null)&&(ResortsSelectedValue.toString()==optResorts[foundResorts-1].value.toString()))))
                    optResorts[foundResorts-1].selected="selected";
            }
        }
        else
        {
            for(i=0;i<AllResortsList.length;i++)
            {
                var srResorts=AllResortsList[i].split(":");
                if(foundResorts>=optResorts.length)
                    optResorts[foundResorts++]=new Option(srResorts[1],srResorts[0]);
                else 
                {
                    optResorts[foundResorts].text=srResorts[1];
                    optResorts[foundResorts++].value=srResorts[0];
                }
                if((optResorts.length>0)&&((AllResortsList.length==1)||((ResortsSelectedValue!=null)&&(ResortsSelectedValue.toString()==optResorts[foundResorts-1].value.toString()))))
                    optResorts[foundResorts-1].selected="selected";
            }
        }
        if((optResorts.length==2)&&(optResorts[0].text=="Any"))
            resort.remove(0);
        if(optResorts.length==1)
            optResorts[0].selected="selected";
        if(ResortsSelectedValue!=null)
        {
            for(i=0;i<optResorts.length;i++)
            {
                if(ResortsSelectedValue.toString()==optResorts[i].value.toString())
                {
                    optResorts[i].selected="selected";
                    break;
                }
            }
        }
    }
   }
   function FindFilterGroupId(selectedRegionId) {
   	var group = GetElementById("Group");
   	if (selectedRegionId != null && selectedRegionId != "") {
   		for (i = 0; i < RegionsList.length; i++) {
   			sr = RegionsList[i].split(":");
   			if (sr[1] == selectedRegionId)
   				return sr[0];
   		}
   	} else if (group.value != "" && group.value != "Any") {
   	    return group.value;
   	   }
   	   return "";
   }

function UpdateGroup()
{
    var group = GetElementById("Group");
    var region = GetElementById("Region");
    var resort = GetElementById("Resort");
   
    if((!region) || (!group))
        return false;
    
    if(resort && !AllResortsChanged)
        resort.selectedIndex = 0;
    
    groupId = GetGroup(region.value);
    UpdateList = false;
    for(i = 0; i < group.options.length; i++)
    {
        if(group[i].value == groupId)
        {
            group.selectedIndex = i;
            break;
        }
    }
    UpdateList = true;
}

function UpdateOperators()
{
    //OperatorsList is an array of: {<opp_id>:<opp_name>, ...}
    var operator = GetElementById("Operator");
    var officeID = GetElementById("OfficeID");

    var ExcludedOperatorsList=null;

    //Added to Read Excluded operator list from web.config 29/01/10
    // var KID = GetElementById("KID");
    //var operatorKey = KID.value + "_" + ProductType;
    //var v1 = ConfigurationManager.AppSettings["operatorKey"].ToString();
    if (ExcludedOperators != "")
        ExcludedOperatorsList = ExcludedOperators.split(",");

    if (ExcludedOperatorsList != null && ExcludedOperatorsList.length > 0) {
        for (k = 0; k < ExcludedOperatorsList.length; k++) {
            for (i = 0; i < OperatorsList.length; i++) {
                if (ExcludedOperatorsList[k] == OperatorsList[i].split(":")[0])
                    OperatorsList.splice(i, 1);
            }
        }
    }

    //Added to Read Excluded operator list from web.config
    
    
    if(!operator)
        return false;
    if((operator.style.display=="none") || (operator.options == undefined))
        return false;
    
    var opt = operator.options;
    opt.length = 0;
    var all = "";
    if(OperatorsList.length>0)
    {
        for(i=0;i<OperatorsList.length;i++)
        {
            if(i==0)
                all = OperatorsList[i].split(":")[0];
            else
                all += ";" + OperatorsList[i].split(":")[0];
        }
    }
    else
        all = "NA";
    //Commented to pass list of all operators for the site
    //If no operator is selected in order to support the functionality
    //of excluding specific operators
    //if ((officeID != null) && (officeID.value.length == 0))
     //   all = "";

       if((officeID!=null) && (officeID.value.length==0) && ExcludedOperatorsList==null)
          all = "";

    //Commented to pass list of all operators for the site
    opt[0] = new Option("Any",all);

    found = 1;
    for(i=0;i<OperatorsList.length;i++)
    {
        sr=OperatorsList[i].split(":");
        if(found>=opt.length)
            opt[found++]=new Option(sr[1],sr[0]);
        else 
        {
            opt[found].text=sr[1];
            opt[found++].value=sr[0];
        }
    }
    while(opt.length > found)
        opt[opt.length-1]=null;
}
/*+++++++++++++++++++++++++++++*/

function GetGroup(regionId)
{
    var groupId;
    
    for(x = 0; x < RegionsList.length; x++)
    {
        if(parseInt(RegionsList[x].split(':')[1], 10) == parseInt(regionId, 10))
        {
            groupId = RegionsList[x].split(':')[0];
            break;
        }
    }
    return groupId;
}
function FilterByResort()
{
    var Form = GetElementById('frmIBEMainForm');
    SkipField = GetElementById("FilterBy");
    CheckFields();
    var target =GetElementById("Target");
    var action =GetElementById("Action");
    var iff =GetElementById("IFF");
    if(action != null)
        action.value = "";
    if(iff != null)
        iff.value = "";
    CheckForm()
    if((Form != null) && SendForm)
        Form.submit();
}
function SetTravelType(type, postBack)
{
    var Form = GetElementById('frmIBEMainForm');
    var travelType =GetElementById("TravelType");
    travelType.value = type;
    if(postBack==true)
        Form.submit();
}
function Search(targetPage)
{
    var Form = GetElementById('frmIBEMainForm');
    var action =GetElementById("Action");
    if(action != null)
        action.value = "Search";
    var pageNum =GetElementById("PageNum");
    var more = GetElementById("RoomTypeMore"); 
    var duration = GetElementById("Duration");
    var durationDays = GetElementById("DurationDays");
    var BID = GetElementById("BookingID");
    var target = GetElementById("Target");
        if(BID != null)
            BID.value = "";
        if((target != null)&&(targetPage != null))
            target.value = targetPage;
    if((duration!=null)&&(duration.options!=null))
    {
        if(duration.options[duration.selectedIndex].value=="6")
        {
            if((durationDays.value.length==0) || isNaN(durationDays.value))
            {
                alert("Invalid duration days");
                durationDays.focus();
                durationDays.select();
                return false
            }
        }
    }
    var pagename = GetElementById("PageName").value;
    if(more != null)
    {
        if((more.checked) && (list != null))
        {
            if(list.selectedIndex == 0)
            {
                alert("Please select a room type!");
                list.focus();
                return false;
            }
        }
    }
    if(pageNum != null)
        pageNum.value = "1";
    return CheckForm();
}

function ShowHotels(groupId, regionId)
{
    SelectRegion(groupId, regionId, '');
}
function SelectRegion(groupId, regionId, dlc, targetPage)
{
    var Form = GetElementById('frmIBEMainForm');

    Form.reset();
    InitDates();
    CheckFields();
    UpdateDate();
    CheckDuration(GetElementById("Duration"));
    SetSearchPage();
    UpdateRegions();

    //Weather
    var action = GetElementById("Action");
    var Dlc = GetElementById("DLC");
    if(Dlc != null)
        Dlc.value = dlc;
    var Group = GetElementById("Group");
    var region = GetElementById("Region");
    //Target Page
    var target = GetElementById("Target");
    if((target != null) && (targetPage != null))
        target.value = targetPage;

    if(Form!=null)
    {
        //Action
        if(action != null)
            action.value = "";
        //Group
        var found = false;
        for(i=0; i < Group.options.length; i++)
        {
            if(Group.options[i].value == groupId)
            {
                found = true;
                Group.selectedIndex = i;
                break;
            }
        }
        if(!found)
        {
            for(x = 0; x < GroupsList.length; x++)
            {
                if(parseInt(GroupsList[x].split(':')[0], 10) == parseInt(groupId, 10))
                {
                    Group.options[i] = new Option(GroupsList[x].split(':')[1], groupId);
                    Group.options[i].selected = "selected";
                    break;
                }
            }
        }
        //Region
        found = false
        for(i=0; i < region.options.length; i++)
        {
            if(region.options[i].value.toString()==regionId.toString())
            {
                region.selectedIndex = i;
                break;
            }
        }
        if(!found)
        {
            for(x = 0; x < RegionsList.length; x++)
            {
                if(parseInt(RegionsList[x].split(':')[1], 10) == parseInt(regionId, 10))
                {
                    region.options[i] = new Option(RegionsList[x].split(':')[2], regionId);
                    region.options[i].selected = "selected";
                    break;
                }
            }
        }
	    if(CheckForm())
            Form.submit();
    }
}
function ResetHotelsList()
{
    var BookingId = GetElementById("BookingID");
    if(BookingId != null)
        BookingId.value = "";
    var Op = GetElementById("BookingOperator");
    if(Op != null)
        Op.value = "";
    var target = GetElementById("Target");
    if(target != null)
        target.value = "";
}
function Sort(by)
{
    if(by == null)
        return;
    if(by.length == 0)
        return;
        
    var Form = GetElementById('frmIBEMainForm');
    Form.reset();
    CheckFields();
    //Resetting values
    var bookingId =GetElementById("BookingID");
    if(bookingId != null)
        bookingId.value = "";
    var pageNum =GetElementById("PageNum");
    if(pageNum != null)
        pageNum.value = "1";
    var target = GetElementById("Target");
    if(target != null)
        target.value = "";

    var sorting =GetElementById("Sorting");
    if(sorting == null)
        return;
    else
        sorting.value = by;
    Form.submit();
}
function Book_accom( bookingid, operator)
{        
    var Form = GetElementById('frmIBEMainForm');
    var secure = GetElementById("SecureSite");
    var BookingId = GetElementById("BookingID");
    var Op = GetElementById("BookingOperator");
    
    if(Form!=null)
    {
        if ( BookingId != null )
            BookingId.value = bookingid;
        Op.value=operator;
        Booking = true;
        Form.action = secure.value.replace(/;/g, ':');
        Form.submit();
    }
}
function CleanAction()
{
    var Form = GetElementById('frmIBEMainForm');
    if(Form.action.indexOf("?") > -1)
        Form.action = Form.action.substring(0, Form.action.indexOf("?"));
}
function Check_avail(bookingid, operator, airport, selectedBoard)
{
    //ShowWait();
    var Form = GetElementById('frmIBEMainForm');
    var BookingId = GetElementById("BookingID");
    var Op = GetElementById("BookingOperator");
    var airportId = GetElementById("BookingAirport");
    var action = GetElementById("Action");
    var sBoard = GetElementById("SelectedBoard");
    
    if(Form!=null)
    {
        Form.reset();
        CheckFields();

        if(sBoard != null)
            sBoard.value = selectedBoard;
        BookingId.value = bookingid;
        Op.value=operator;
        airportId.value=airport;
        CleanAction();
        Form.submit();
    }
}
function Hotel(iff, targetPage)
{
    var Form = GetElementById('frmIBEMainForm');
    var action = GetElementById("Action");
    
    Form.reset();
    CheckFields();

    var pageNum =GetElementById("PageNum");
    if(pageNum != null)
        pageNum.value = "1";

    var IFFCode = GetElementById("IFF");
    
    if ( action != null )
       action.value = "ShowOffers";

    //Target Page
    var target = GetElementById("Target");
    if((target != null) && (targetPage != null))
        target.value = targetPage;
    if(Form!=null)
    {
        IFFCode.value = iff;
        CheckForm();
        Form.submit();
    }
}
function Info(countryid, IFF, AccomCode, start, operator, KAT, nav, date, rate)
{
    var KID = GetElementById("KID");
    var seasonStart = new Date(parseInt(GetElementById("FromDate").value.split('/')[2], 10), 4, 1, 0, 0, 0, 0);
    var seasonEnd = new Date(parseInt(GetElementById("FromDate").value.split('/')[2], 10), 9, 31, 0, 0, 0, 0);
    var season = "s";
    var stars = "";

   if(date.length > 0)
    {
        cDate = new Date(parseInt(date, 10) * 1000);
        if((cDate < seasonStart) || (cDate > seasonEnd))
           season = "w";
    }

    if(rate != null)
    {
        if(rate.length > 0)
            stars = "&sterne=" + rate;
    }
       
    var url = "http://cp.traveltainment.de/content_page/index.php3?KID=" + KID.value + "&IFF=" + IFF + 
              "&Laender_Ref_ID=" + countryid + "&START=" + start + "&Kenner_Nav=" + nav +
              "&startva=" + operator + "&VA=" + operator + 
              "&KAT=" + KAT + "&season=" + season + "&CRS_CODE=" + AccomCode + "&lang=en" + stars + "&RequestArt=";
    var win = window.open(url,"","scroll=no,toolbar=no,menu=no,width=610,height=600",true);
}
function APInfo(airport)
{
    var KID = GetElementById("KID");
        
    url = "http://cp.traveltainment.de/content_page/index.php3?AF=" + airport + "&START=6&lang=en&KID=" + KID.value;
    var win = window.open(url,"","scroll=no,toolbar=no,menu=no,width=610,height=600",true);
}
function PremInfo(countryid, IFF, AccomCode, start, operator, KAT, nav, date, rate)
{
    var KID = GetElementById("KID");
    var seasonStart = new Date(parseInt(GetElementById("FromDate").value.split('/')[2], 10), 4, 1, 0, 0, 0, 0);
    var seasonEnd = new Date(parseInt(GetElementById("FromDate").value.split('/')[2], 10), 9, 31, 0, 0, 0, 0);
    var season = "s";
    var stars = "";

   if(date.length > 0)
    {
        cDate = new Date(parseInt(date, 10) * 1000);
        if((cDate < seasonStart) || (cDate > seasonEnd))
           season = "w";
    }

    if(rate != null)
    {
        if(rate.length > 0)
            stars = "&sterne=" + rate;
    }
       
    var url = "http://cp.traveltainment.de/content_page_premium/index.php?KID=" + KID.value + "&IFF=" + IFF + 
              "&Laender_Ref_ID=" + countryid + "&START=" + start +  "&Kenner_Nav=" + nav +
              "&startva=" + operator +  "&VA=" + operator + 
              "&KAT=" + KAT + "&season=" + season + "&CRS_CODE=" + AccomCode + "&lang=en" + stars + "&RequestArt=";
    var win = window.open(url,"","scroll=no,toolbar=no,menu=no,width=770,height=650",true);
}
function PremAPInfo(airport)
{
    var KID = GetElementById("KID");
        
    url = "http://cp.traveltainment.de/content_page_premium/index.php?AF=" + airport + "&START=6&lang=en&KID=" + KID.value;
    var win = window.open(url,"","scroll=no,toolbar=no,menu=no,width=770,height=465",true);
}
/***************************************************************************************/
/***************************************** Date ****************************************/
    
// days in month
var days_in_month = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    
// return true if leap year
function isLeapYear(year) 
{
    if (Math.floor(year / 4) != (year / 4))
        return false;
    else
        return true;
}
    
// get the number of days in a given month
function getDaysInMonth(month, year) 
{
    var m = days_in_month[month - 1];
    if ((month == 2) && (isLeapYear(year)))
    {
        m++;
    }
    return m;
}

function InitDates()
{
    UpdateList = false;
    var DepMonth = GetElementById("DepMonth");
    var RetMonth = GetElementById("RetMonth");
    //if datesOffset is set that means that the cusomer uses different offset between 'from' and 'to' dates
    if(window.datesOffset!=null)
    {
        var fromDate = GetElementById("FromDate");
        var toDate = GetElementById("ToDate");
        var splited = fromDate.value.split('/');
        var from = Date.parse(splited[1]+'/'+splited[0]+'/'+splited[2]);
        var to = from + (1000*60*60*24*(datesOffset+1));
        var newToDate = new Date(to);
        toDate.value = newToDate.getDate()+'/'+(newToDate.getMonth()+1)+'/'+newToDate.getFullYear();
    }
    if(DepMonth != null) 
    {
       var today = new Date();
       
       //Departure
       DepMonth.style.visibility = "hidden";
       op = DepMonth.options;
       op.length = 0;
       y = today.getFullYear().toString().substring(2,4);
       yText = y;
       f = 0;
       for(i=0; i < 18; i++)
       {
            m = (today.getMonth() + i + 1) - f;
            if(m > 12)
            {
                m = m - 12;
                f += 12;
                y++;
            }
            if(y.toString().length == 1)
                yText = "0" + y;
            else
                yText = y;
                
            op[op.length] = new Option(months[m-1] + " " + yText, m);
            DepMonth.selextedIndex = 0;
       }
       DepMonth.style.visibility = "visible";
       UpdateList = true; 
    }
   if(RetMonth == null)
        return false;
        
   //Return
   op = RetMonth.options;
   op.length = 0; 
   for(i=DepMonth.selectedIndex; i < 18; i++)
   {
        op[op.length] = new Option(DepMonth.options[i].text, DepMonth.options[i].value);
        RetMonth.selectedIndex = 0;
   }
   FillDate(GetElementById("ToDate"), "RetDay", "RetMonth");
   CheckDays(0,0);
   UpdateList = true; 
}
function CheckDays(dep_day, ret_day)
{
    var DepDay = GetElementById("DepDay");
    var RetDay = GetElementById("RetDay");
    var DepMonth = GetElementById("DepMonth");
    var RetMonth = GetElementById("RetMonth");
   
    var fromDate = GetElementById("FromDate");
    var toDate = GetElementById("ToDate");
    if((fromDate == null) || (toDate == null) || (DepDay == null))
        return false;
   var today = new Date();
   var dep_date = new Date();
   m = parseInt(DepMonth.options[DepMonth.selectedIndex].value, 10);
   y = 2000 + parseInt(DepMonth.options[DepMonth.selectedIndex].text.split(' ')[1], 10);
   if(NewDate)
      m = parseInt(fromDate.value.split('/')[1], 10);

   //Departure
    op = DepDay.options;
   if(dep_day == 0)
    dep_day = fromDate.value.split('/')[0];
   
       days = getDaysInMonth(m, fromDate.value.split('/')[2]);
       d = today.getDate() + 1;
            
       if(d > days)
            d = days;
       if(dep_day > days)
            dep_day = days;

       dep_date.setFullYear(y, m - 1, d);
       if(dep_date.getTime() == today.getTime())
       {
            dep_date.setTime(dep_date.getTime() + (60 * 60 * 24 * 1000));
            if(dep_date.getMonth() != today.getMonth())
                fromDate.value = "01/" + (dep_date.getMonth() + 1) + "/" + dep_date.getFullYear();
            else
                fromDate.value = dep_date.getDate() + "/" + (dep_date.getMonth() + 1) + "/" + dep_date.getFullYear();
            FillDate(fromDate, "DepDay", "DepMonth");
            UpdateDate();
            return;
       }

       if((y > today.getFullYear()) || (dep_date.getMonth() != today.getMonth()))
        {    d = 1;     }
            
   if((m != LastDepMonth) || (LastDepStart != d))
   {
       LastDepMonth = m;
       LastDepStart = d;
       op.length = 0;
       for(i=d; i <= days; i++)
       {
            if(i < 10)
                op[op.length] = new Option("0" + i, i);
            else
                op[op.length] = new Option(i, i);
            if(i == parseInt(dep_day, 10))
                op[op.length - 1].selected = "selected";
       }
   }
   else
   {
       for(i=0; i < op.length; i++)
       {
            if(parseInt(op[i].value, 10) == parseInt(dep_day, 10))
            {
                op[i].selected = "selected";
                break;
            }
       }
   }

   if(RetDay == null)
        return false;
   if(RetDay.style.visibility=="hidden")
        return false;
   
   m = parseInt(RetMonth.options[RetMonth.selectedIndex].value, 10);
   y = 2000 + parseInt(RetMonth.options[RetMonth.selectedIndex].text.split(' ')[1], 10);
   if(NewDate)
      m = parseInt(toDate.value.split('/')[1], 10);
    
   //Return
   op = RetDay.options;
   if(ret_day == 0)
    ret_day = toDate.value.split('/')[0];
 
       var ret_date = new Date();
       days = getDaysInMonth(m, toDate.value.split('/')[2]);
    if(ret_day==0)
        d = today.getDate() + 1;
    else
        d = ret_day;
       
       if(d > days)
            d = days;
       if(ret_day > days)
            ret_day = days;

       ret_date.setFullYear(y, m - 1, d);
       
       if(ret_date.getTime() < dep_date.getTime())
       {
           m = parseInt(toDate.value.split('/')[1], 10);
           ret_date.setFullYear(y, m - 1, d);
       }

       if(ret_date.getTime() < dep_date.getTime())
            ret_date.setTime(dep_date.getTime());

       if((y > today.getFullYear()) || (ret_date.getMonth() != today.getMonth()))
        {    d = 1;     }

   if((m != LastRetMonth) || (LastRetStart != d))
   {
       LastRetMonth = m;
       LastRetStart = d;
       op.length = 0;
       for(i=d; i <= days; i++)
       {
            if(i < 10)
                op[op.length] = new Option("0" + i, i);
            else
                op[op.length] = new Option(i, i);
            if(parseInt(ret_day, 10) == parseInt(op[op.length - 1].value, 10))
                op[op.length - 1].selected = "selected";
       }
   }
   else
   {
       for(i=0; i < op.length; i++)
       {
            if(parseInt(op[i].value, 10) == parseInt(ret_day, 10))
            {
                op[i].selected = "selected";
                break;
            }
       }
   }
    fromDate.value = dep_day + "/" + fromDate.value.split('/')[1] + "/" + fromDate.value.split('/')[2];
    toDate.value = ret_day + "/" + toDate.value.split('/')[1] + "/" + toDate.value.split('/')[2];
}

function UpdateDate()
{
    if(!UpdateList)
        return;

    var DepDay = GetElementById("DepDay");
    var DepMonth = GetElementById("DepMonth");
    var RetDay = GetElementById("RetDay");
    var RetMonth = GetElementById("RetMonth");
    
    var fromDate = GetElementById("FromDate");
    var toDate = GetElementById("ToDate");
    
    if(fromDate != null)
    {    
        var dep_day = DepDay.value;
        var ret_day = 0;
        if(RetDay != null)
            ret_day = RetDay.value;
        var month = DepMonth.value;

        if(dep_day.length==1)
            dep_day = "0" + dep_day;
        
        if(month.length==1)
            month = "0" + month;

        y = DepMonth.options[DepMonth.selectedIndex].text.split(' ')[1];

        if(y.substring(0,1) == "0")
            y = y.substring(1,2);
           
        if(fromDate.value != dep_day + "/" + month + "/" + (parseInt(y, 10) + 2000))
        {
            fromDate.value = dep_day + "/" + month + "/" + (parseInt(y, 10) + 2000);
            var fromDate = new Date();
            fromDate.setFullYear((parseInt(y, 10) + 2000), parseInt(month, 10) - 1, dep_day);
            var tmpDate = new Date();
            tmpDate.setFullYear((parseInt(toDate.value.split('/')[2], 10)), parseInt(toDate.value.split('/')[1], 10) - 1, toDate.value.split('/')[0]);
            if(isNaN(tmpDate) || (tmpDate.getTime()<=fromDate.getTime()))
            {
                tmpDate.setFullYear((parseInt(y, 10) + 2000), parseInt(month, 10) - 1, dep_day);
                var offset = window.datesOffset!=null ? datesOffset : 30;
                tmpDate.setTime(tmpDate.getTime() + (60 * 60 * 24 * offset * 1000));
            }
            if((toDate.value!="Any") || ((GetElementById("RetDay")!=null) && (GetElementById("RetDay").style.visibility!="hidden")))
            {
                toDate.value =  tmpDate.getDate() + "/" + (tmpDate.getMonth() + 1) + "/" + tmpDate.getFullYear();
                ret_day = tmpDate.getDate();
                if(ret_day.length==1)
                    ret_day = "0" + ret_day;
                GetElementById("RetDay").value = ret_day;
                GetElementById("RetMonth").value = (tmpDate.getMonth() + 1);
            }
            if((RetDay != null) && (toDate.value.indexOf('/')>-1))
                FillDate(toDate, "RetDay", "RetMonth");
            UpdateDate();
            return;
        }
        if(ret_day.length>0)
            CheckDays(dep_day, ret_day);
    } 
    NewDate = false;

    if((RetDay != null) && (ret_day.length>0))
    {
        ret_day = RetDay.value;
        month = RetMonth.value;
        if(ret_day.length==1)
            ret_day = "0" + ret_day;
        if(month.length==1)
            month = "0" + month;
                
        y = RetMonth.options[RetMonth.selectedIndex].text.split(' ')[1];

        if(y.substring(0,1) == "0")
            y = y.substring(1,2);
    
        toDate.value = ret_day + "/" + month + "/" + (parseInt(y, 10) + 2000);
    }
}

function FillDate(obj, day, month)
{
    if(obj != null)
    {
        var Day = obj.value.split("/")[0];
        var Month = obj.value.split("/")[1];
        var Year = obj.value.split("/")[2];
        var objDay = GetElementById(day);
        var objMonth = GetElementById(month);

        if((objDay != null) && (objMonth != null))
        {
            for(i=0; i<objDay.options.length; i++)
            {
                if(parseInt(objDay.options[i].value, 10)==parseInt(Day, 10))
                {
                    objDay.options[i].selected = "selected";
                    break;
                }
            }       
            
            for(i=0; i<objMonth.options.length; i++)
            {
                if((parseInt(objMonth.options[i].value, 10)==parseInt(Month, 10)) && (parseInt(objMonth.options[i].text.split(' ')[1], 10)==(parseInt(Year, 10) - 2000)))
                {
                    objMonth.options[i].selected = "selected";
                    break;
                }
            }
            if(obj.id == "FromDate")
                CheckDays(obj.value.split('/')[0],GetElementById("ToDate").value.split('/')[0]);   
            else
                CheckDays(GetElementById("FromDate").value.split('/')[0],obj.value.split('/')[0]);       
        }
    }
}
function formatDate(date)
{
	year = date.getYear()
	if (year < 2000)
		year = 1900 + year;
	return date.getDate() + "/" + (date.getMonth() + 1) + "/" + year;
}

function getDateInt(inDate)
{
    var parts = inDate.split("/");
    var day;
    var month;
    var year;
    
    if(parts.length==3)
    {
        day = parts[0];
        month = parts[1] - 1;
        year = parts[2];
    }
    else if(parts.length==2)
    {
        day = parts[0];
        month = parts[1] - 1;
        year = (new Date()).getYear();
    }
	else
		return 0;
        
        if(year.length==2)
            year = parseInt("20" + parts[2], 10);
        
        if(year < 2000)
            year = 1900 + year;
            
        var tempDate = new Date(year, month, day);
        var retDate = new Date(2000,01,01);

		if (isNaN(tempDate.getTime()))
			return retDate.getTime();
		else
			return tempDate.getTime();
}
function IsValidDate(fromDate, toDate)
{
    var Flexi = GetElementById("FlexiDays");
    UpdateDate();
    var startDate =  new Date();
    startDate.setFullYear(fromDate.split('/')[2], fromDate.split('/')[1] - 1, fromDate.split('/')[0]);
    var endDate  =  new Date();
    endDate.setFullYear(toDate.split('/')[2], toDate.split('/')[1] - 1, toDate.split('/')[0]);

    curentDate = new Date();
    curentDate.setFullYear(curentDate.getFullYear(), curentDate.getMonth(), curentDate.getDate());
    if(startDate.getTime()<curentDate.getTime())
    {
        GetElementById("FromDate").value = (curentDate.getDate()+1) + "/" + (curentDate.getMonth()+1) + "/" + curentDate.getFullYear();
        UpdateDate();
    }
    else if(startDate.getTime()>=endDate.getTime())
    {
        if(Flexi != null)
        {
            if((Flexi.selectedIndex == 0) || (Flexi.selectedIndex==undefined))
            {
                alert("End date must be greater than start date!");
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            alert("End date must be greater than start date!");
            return false;
        }
    }
    else
        return true;
}
function CompareValue(source,target,type)
{
    var sourcedate =  getDateInt(source.value);
    var targetdate  =  getDateInt(target.value);

    d = new Date();
    if( sourcedate<d.getTime() ){source.value = formatDate(d);sourcedate =  getDateInt(source.value);};
    
    try
    {
        switch(type)
        {
            case "GreaterThan":
                if( sourcedate<targetdate ) 
                {
                    source.value=target.value;
                    d.setTime(sourcedate);
                    today = new Date();
                    d.setTime(d.getTime() - (1000*60*60*24*7*3));
                    
                    if(today.getTime() > d.getTime())
                        d.setTime(today.getTime());
                        
                    target.value = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
                };
                break;
            case "LessThan":
                if (sourcedate>targetdate) 
                {
                    source.value=target.value;
                    d.setTime(sourcedate);
                    d.setTime(d.getTime() + (1000*60*60*24*7*3));
                    target.value = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
                };
            break;
            case "CanNotBeLessThan":
                if( sourcedate>targetdate ) 
                {
                    target.value=source.value;
                    d.setTime(sourcedate);
                    d.setTime(d.getTime() + (1000*60*60*24*7*3));
                    target.value = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
                };
                break;
            default:
                // Do Nothing
        }		
    }catch(e){}

    FillDate(GetElementById("FromDate"), "DepDay", "DepMonth");
    FillDate(GetElementById("ToDate"), "RetDay", "RetMonth");
}

function SetNewDate(selDate)
{
    var toDate = GetElementById("ToDate");
    if(SelectedField == null)
        return false;
    
    NewDate = true;
    SelectedField.value = selDate;
    
    if(SelectedField.id == "FromDate")
    {
        FillDate(SelectedField, "DepDay", "DepMonth");
        if(toDate.value!="Any")
        {
            var tmpDate = new Date();
            var Day = selDate.split("/")[0];
            var Month = selDate.split("/")[1];
            var Year = selDate.split("/")[2];
            tmpDate.setFullYear(parseInt(Year, 10), parseInt(Month, 10) - 1, Day);
            var offset = window.datesOffset!=null ? datesOffset : 30;
            tmpDate.setTime(tmpDate.getTime() + (60 * 60 * 24 * offset * 1000));
            toDate.value =  tmpDate.getDate() + "/" + (tmpDate.getMonth() + 1) + "/" + tmpDate.getFullYear();
            if(GetElementById("RetDay") != null)
                FillDate(toDate, "RetDay", "RetMonth");
        }
    }
    else
        FillDate(SelectedField, "RetDay", "RetMonth");
    UpdateDate();
}
/***************************************************************************************/
/*************************************** General ***************************************/
function CheckFields()
{
    var hist = GetElementById("SearchHistory");
    var sHistory = "";

    if (!jsonServer)
        init();
        
    if(hist != null)
        sHistory = hist.value;
    
    if(sHistory.length > 0)
        PostedFields = sHistory.split('|');
        
    for(i=0; i < PostedFields.length; i++)
    {
        if(PostedFields[i].split(':').length > 1)
        {
            control = GetElementById(PostedFields[i].split(':')[0]);
            // Could be an array of fields
            if(control == null)
                control = GetElementById(PostedFields[i].split(':')[0] + "1");

            if((control!=SkipField)||(PostedFields[i].split(':')[0] == "Child"))
            {
                if((PostedFields[i].split(':')[1].indexOf(",") > -1) && (PostedFields[i].split(':')[0] != "Departure"))
                {
                    for (x=1; x <= PostedFields[i].split(':')[1].split(',').length; x++)
                    {
                        if(PostedFields[i].split(':')[0] == "Child")
                            control = GetElementById(PostedFields[i].split(':')[0] + x.toString());
                        else
                            control = GetElementById(PostedFields[i].split(':')[0]);
                        if(PostedFields[i].split(':')[1].split(',')[x - 1] != undefined)
                            UpdateControl(control, PostedFields[i].split(':')[1].split(',')[x - 1]);
                        //Debug
                        //alert(control.id + " -> " + PostedFields[i].split(':')[1] + " [" + (x-1) + "] = " + PostedFields[i].split(':')[1].split(',')[x - 1] + " = " + (PostedFields[i].split(':')[1].split(',')[x - 1]==undefined));
                    }
                }
                else
                    UpdateControl(control, PostedFields[i].split(':')[1]);
            }
            else
                SkipField=null;
        }
    }
    FillDate(GetElementById("FromDate"), "DepDay", "DepMonth");
    FillDate(GetElementById("ToDate"), "RetDay", "RetMonth");
    if((GetElementById('OffersHTML')!=null)&&(GetElementById('service')!=null)&&(GetElementById('service').innerHTML.indexOf("Total")>0))
        GetElementById('OffersHTML').value = jsonServer.GetOfferHTML(GetElementById('service').innerHTML.replace(/£/g, "&pound;"));
}
function CheckDuration(dur)
{
    var days = GetElementById("DurationDays");
    if((days != null)&&(days.type=="text"))
    {
        days.style.height = dur.style.height;
        days.style.margin = "0px";
        if(dur.value == "6" && dur.style.visibility != "hidden" && dur.style.display != "none")
        {
            dur.style.width = (parseInt(dur.style.width.replace("px", ""), 10) - 27) + "px";
            days.style.width = "20px";
            if(!IsIE())
                days.style.left = parseInt(dur.style.left.replace("px", ""),10)+parseInt(dur.style.width.replace("px", ""),10)+"px";
            days.style.visibility = "visible";
            days.style.position = "absolute";
            days.style.display = "inline";
        }
        else
        {
            if(days.style.width != "0px")
            {
                days.style.width = "0px";
                days.style.position = "absolute";
                days.style.display = "none";
                days.style.visibility = "hidden";
                dur.style.width = (parseInt(dur.style.width.replace("px", ""), 10) + 27) + "px";
            }
        }
    }
}
function UpdateControl(control, value)
{
    if((value.length > 0) && (control != null))
    {
        if((control.id == "RoomType") && (value!="More"))
        {
            if(GetElementById("RoomTypeMore") != null)
            {
                if(GetElementById("RoomTypeMore").checked)
                {
                    if(GetElementById("RoomTypeList") != null)
                        control = GetElementById("RoomTypeList"); 
                }
            }
        }

        if(control.options != null)
        {
            for(o=0; o < control.options.length; o++)
            {
                if(control.options[o].value.toString() == value.toString())
                {
                    control.options[o].selected = "selected";
                    break;
                }
            }
        }
        else
        {
            if((control.type == "checkbox") || (control.type == "radio"))
            {
                if((value != "on") && (value.length>0) && (GetElementById(control.id + value) != null))
                    control = GetElementById(control.id + value);
                        
                control.checked = "checked";
                if(value == "on")
                    control.value = "on";
            }
            else
                control.value = value;
        }
    }
}
function GetElementById(id)
{
    var element = null;
    
    if(!document.getElementById)
    {
      if(document.all)
        element = document.all[id];
      else if(document.layers)
        element = document[arguments[0]];
    }
    else
        element = document.getElementById(id);
    return element;
}
/***************************************************************************************/
