﻿function fnc_BookNow(){
    if (typeof(Page_ClientValidate)   ==   'function'){  
        if(Page_ClientValidate('BookNow')){
            var airFrom,airTo;
            airFrom = document.getElementById(GlobalBookNowAirportFromID).value;
            airTo = document.getElementById(GlobalBookNowAirportToID).value;
            if (airFrom.indexOf('--') > -1) airFrom = airFrom.split('-')[2];
            if (airTo.indexOf('--') > -1) airTo = airTo.split('-')[2];
            document.forms['BookNowForm']._originSelected.value = 'Airport.' + airFrom; //.split('-')[2];        
            document.forms['BookNowForm']._destinationSelected.value = 'Airport.' + airTo; //.split('-')[2];        
            document.forms['BookNowForm']._origin.value = 'Airport.' + airFrom; //.split('-')[2];        
            document.forms['BookNowForm']._destination.value = 'Airport.' + airTo; //.split('-')[2];        
            var dd = document.getElementById(hidDepDateClientID).value;
            document.getElementById('_depdateisodate').value = dd.split('-')[2] + '-' + dd.split('-')[1] + '-' + dd.split('-')[0];       

            if (document.getElementById(rdTravelTypeClientID + '_1').checked){
                var rd = document.getElementById(hidRetDateClientID).value; 
                document.getElementById('_retdateisodate').value = rd.split('-')[2] + '-' + rd.split('-')[1] + '-' + rd.split('-')[0];        
            }
            else
                document.getElementById('_retdateisodate').value = '';
            document.forms['BookNowForm']._classType.value = document.getElementById(ddlClassClientID).value;
            document.forms['BookNowForm']._children.value = document.getElementById(ddlChildren12NumClientID).value;
            document.forms['BookNowForm']._childUnder6.value = document.getElementById(ddlChildren5NumClientID).value;
            document.forms['BookNowForm']._adults.value = document.getElementById(ddlAdultsNumClientID).value;
            document.forms['BookNowForm']._infants.value = document.getElementById(ddlInfantsNumClientID).value;
            document.forms['BookNowForm'].submit();
        }
        else{
        }
    }  
}
function HideReturnDateBookNow(){
    //document.getElementById('BookNow').blur();
    //alert(document.getElementById('BookNow').offsetLeft);
    var rdT = document.getElementById(rdTravelTypeClientID)
    var radios = document.getElementsByTagName('INPUT')
    for (i=0;i<radios.length;i++){
        if (radios[i].type == 'radio' && radios[i].id.indexOf(rdT.id)>-1){
            if (radios[i].value == 1 && radios[i].checked)
                document.getElementById(ReturnDateDIVClientID).style.visibility='hidden';
            else if (radios[i].value == 2 && radios[i].checked)
                document.getElementById(ReturnDateDIVClientID).style.visibility='visible';
        }
    }
}

function CheckArrivalDateBookNow(sender, args)
{
    if (document.getElementById(ReturnDateDIVClientID).style.visibility=='hidden')
        args.IsValid = true;
    else{
        /*
        var arrDate = new Date(args.Value.split('-')[0],args.Value.split('-')[1] - 1,args.Value.split('-')[2]);
        var arrO = document.getElementById(dpDateDepartureClientID).value;
        var depDate = new Date(arrO.split('-')[0],arrO.split('-')[1] - 1,arrO.split('-')[2]);
        */
        var dep = document.getElementById(hidDepDateClientID).value;
        var ret = document.getElementById(hidRetDateClientID).value;

        var depDate = new Date(dep.split('-')[2],dep.split('-')[1] - 1,dep.split('-')[0],0,0,0);
        var retDate = new Date(ret.split('-')[2],ret.split('-')[1] - 1,ret.split('-')[0],0,0,0);     
        
        if (retDate>=depDate)
            args.IsValid = true;
        else
            args.IsValid = false;
    }
}
  
function CheckArrivalDateRequiredBookNow(sender, args){
    
    if (args.Value.length == 0 && document.getElementById(ReturnDateDIVClientID).style.visibility=='visible')
        args.IsValid = false;
    else
        args.IsValid = true;
}


//FLASH MAP FUNCTIONS
function ge(e){
	return(document.getElementById(e));
}

function setDropdownValue(whichDropDown, whichValue){
	var drd = whichDropDown == 'FROM' ? ge(GlobalBookNowAirportFromID) : ge(GlobalBookNowAirportToID);
    
    if (document.all && drd.options.length == 1){
        var opt = drd.contentHTML;
        opt = opt.split('-</OPTION>')[1].split('</SELECT>')[0].split('<OPTION value=');
        for (i=0;i<opt.length;i++){
            if (opt[i].indexOf('>') > -1){
                var name = opt[i].split('>')[1].split('<')[0];

                opt[i] = opt[i].split('>')[0];
                var code = opt[i].split('--')[1];
                var id =  opt[i].split('--')[0];
                
                if (whichValue == id){
                    while(drd.options.length>0){drd.options[0].removeNode(true);}
                    var elOptNew = document.createElement('option');
                    elOptNew.text = name.replace('&nbsp;',' ');
                    elOptNew.value = code;
                    drd.add(elOptNew); 
                    
                }
            }
        }
        
    }
    else{
        drd.value = whichValue;
        //DD Values contain Code too. So search
        for (i=0;i<drd.options.length;i++){
            if(drd.options[i].value.indexOf(whichValue + '--') == 0){
                drd.value = drd.options[i].value;
                break;
            }
        }	
    }
    
    if (whichDropDown == 'FROM'){
        if (document.all){
            eval(ge(GlobalBookNowAirportFromID).getAttribute('onchange').toString().replace('function anonymous() {','').replace('}','').replace('ValidatorOnChange(event);',''));
        }
        else{
            eval(ge(GlobalBookNowAirportFromID).getAttribute('onchange').replace('function anonymous(){','').replace('javascript:','').replace('}',''))
        }
    }
}


function getMapData(which) {
    switch (which) {
        case 'points':
            return (litPoints);
            break;
        case 'locations':
            return (litLocations);
            break;
        case 'names':
            return (litNames);
            break;
        case 'A3Relations':
            return (litA3Relations);
            break;
        case 'CSRelations':
            return (litCSRelations);
            break;
        case 'Temperature':
            return (litTemperature);
            break;
        default:
            break;
    }
}

//CALENDAR VISIBILITY FUNCTIONS
function HideDIV(d){
    document.getElementById(d).style.visibility = 'hidden';
}
function ShowDIV(d){
    document.getElementById(d).style.visibility = 'visible';
}
function HideAllCalendars(e){
    try{
        var src = '';
        if (document.all)
            src = window.event.srcElement;
        else
            src = e.target;
        
        //ON CLICK ON A DATE, MAKE CURSOR A WAITCURSOR, SO AS THE USER KNOWS THAT SOMETHING IS GOING ON
        if (
               (src.tagName == 'IMG' && (src.src.indexOf('CalPrevious.gif')>-1 || src.src.indexOf('CalNext.gif')>-1 ))
               ||
               (src.tagName == 'A' && src.parentNode && src.parentNode.parentNode && src.parentNode.parentNode.parentNode && src.parentNode.parentNode.parentNode.parentNode && src.parentNode.parentNode.parentNode.parentNode.getAttribute("ID").indexOf('Cal')>-1)
            ){
            document.body.style.cursor = 'wait';
            src.style.cursor = 'wait';
        }
        //HIDES ALL CALENDAR DIVS
        if (src && src.tagName!='IMG' && src.tagName!='A' && depCalDIVClientID && retCalDIVClientID)
        {
            document.getElementById(depCalDIVClientID).style.display='none';
            document.getElementById(retCalDIVClientID).style.display='none';
            ShowDIV(ddlClassClientID);
            ShowDIV(ddlAdultsNumClientID);
            ShowDIV(ddlChildren12NumClientID);
            ShowDIV(ddlChildren5NumClientID);
            ShowDIV(ddlInfantsNumClientID);
        }
        if (src && src.tagName!='IMG' && src.tagName!='A' && FLdepCalDIVClientID && FLretCalDIVClientID)
        {
            document.getElementById(FLdepCalDIVClientID).style.display='none';
            document.getElementById(FLretCalDIVClientID).style.display='none';
        }
        
    }
    catch(e){}
}
function HandleCalVisibility(WhichDiv){
    /*HIDE THE OTHER*/
    if (WhichDiv == depCalDIVClientID)
        document.getElementById(retCalDIVClientID).style.display = 'none'
    else
        document.getElementById(depCalDIVClientID).style.display = 'none'
    /*SHOW THE ONE*/
    if (document.getElementById(WhichDiv).style.display == 'none'){
        document.getElementById(WhichDiv).style.display = '';
        HideDIV(ddlClassClientID);
        HideDIV(ddlAdultsNumClientID);
        HideDIV(ddlChildren12NumClientID);
        HideDIV(ddlChildren5NumClientID);
        HideDIV(ddlInfantsNumClientID);
    }
    else{
        document.getElementById(WhichDiv).style.display = 'none';
        ShowDIV(ddlClassClientID);
        ShowDIV(ddlAdultsNumClientID);
        ShowDIV(ddlChildren12NumClientID);
        ShowDIV(ddlChildren5NumClientID);
        ShowDIV(ddlInfantsNumClientID);
    }
}