function loadFlash(mnu, ling){
    var page = '';
    if (mnu == 'admin') {
        page = '../flash/banner.swf';
    }
    else {
        page = 'flash/banner.swf';
    }
    
    $('#header').flash({
        swf: page,
        height: 375,
        width: 900,
        flashvars: {
            mnu: mnu,
            ling: ling
        },
        params: {
            wmode: 'transparent'
        }
    });
}

function pullDest(what, from){
    $.ajax({
        type: 'GET',
        url: 'scripts/getquotes.php',
        data: 'action=pullDest&from=' + from,
        success: function(responseText){
            var destArray = new Array();
            destArray = responseText.split("\n");
            $('#to').html('');
            for (var i = 0; i < destArray.length - 1; i++) {
                var strArray = new Array();
                var _class = '';
                strArray = destArray[i].split('=>');
                if (strArray[2] == 1) {
                    _class = 'class="itemBold"';
                }
                $('#to').append('<option value="' + strArray[0] + '" ' + _class + '>' + strArray[1] + '</option>');
            }
            updateQuote();
            $('#sbBottom').html('');
        }
    });
    
}

function getQuote(){
    var from = $('#from').val();
    var to = $('#to').val();
    var pax = $('#pax').val();
    var ret = $('#ret:checked').val();
    ;
    $.ajax({
        type: 'GET',
        url: 'scripts/getquotes.php',
        data: 'action=getQuote&from=' + from + '&to=' + to + '&pax=' + pax + '&ret=' + ret,
        success: function(responseText){
            $('#sbBottom').html(responseText);
        }
        
    });
}

function clearBot(){
    $('#sbBottom').html('');
}

function gotoOrder(){
    document.frmSBox.submit();
}


function updateQuote(){
    var from = $('#from').val();
    var to = $('#to').val();
    var pax = parseInt($('#ad').val()) + parseInt($('#ch').val());
    var form = $('#hidForm').val();
    $('#pax').val(pax);
    var ret = $('#ret:checked').val();
    var retStr = (ret == 'on') ? ' and return' : '';
    var quote = new Array();
    $.ajax({
        type: 'GET',
        url: 'scripts/getquotes.php',
        data: 'action=updateQuote&from=' + from + '&to=' + to + '&pax=' + pax + '&ret=' + ret,
        success: function(responseText){
            if (form == 'order') {
                quote = responseText.split(",");
                if (quote[1] != '') {
                    $('#quote').html('<span id="res_price"></span>' +
                    '<span id="res_way"></span><br/>' +
                    '<span id="res_pax"></span>');
                    $('#res_way').html($('#from :selected').text() + ' to ' + $('#to :selected').text() + retStr);
                    $('#res_pax').html('Price per ' + quote[1] + ' to ' + quote[2] + ' Passengers');
                    $('#res_price').html(quote[0] + ' &euro;');
                }
                else {
                    $('#quote').html('Transfer from ' + $('#from :selected').text() + ' to ' + $('#to :selected').text() + ' for ' + pax + ' passengers is not available, please <a href="contacts.php">contact us</a> for this transfer.');
                }
            }
        }
    });
    checkAirport(from);
    
}


function checkAirport(from){
    $.ajax({
        type: 'GET',
        url: 'scripts/getquotes.php',
        data: 'action=checkAirport&from=' + from,
        success: function(responseText){
            $('#airport').val(responseText);
        }
    });
}














function validate(what, str, div){
    var action = 'element';
    var str2;
    if (what == 'EmailConf') {
        str2 = document.frmBook.Email.value;
    }
    if (what == 'Flight' || what == 'DepAirport' || what == 'TimeArrival') {
        if (document.frmBook.hidAirport.value == 0) {
            return;
        }
    }
    str = encodeURIComponent(str);
    var url = "scripts/validation.php"
    url = url + "?what=" + what + "&str=" + str + "&str2=" + str2 + "&action=" + action;
    xmlHttpOpen(url, div);
}



function checkChildren(){
    var child = document.frmBook.inputChildren.value;
    var childAges = document.frmBook.ChildrenAges.value;
    var divObj = document.all ? document.all['chkAges'] : document.getElementById ? document.getElementById('chkAges') : "";
    if (child > 0) {
        validate(document.frmBook.ChildrenAges.id, childAges, 'chkAges');
    }
    else {
        divObj.innerHTML = '';
    }
}



function retAirport(value){
    if (value == 1) {
        document.frmBook.hidAirport.value = 1;
    }
    else {
        document.frmBook.hidAirport.value = 0;
    }
    var divArray = new Array('chkFlight', 'chkDepAirport', 'chkTimeArrival');
    var inputArray = new Array(document.frmBook.Flight.value, document.frmBook.DepAirport.value, document.frmBook.TimeArrival.value);
    for (i = 0; i < divArray.length; i++) {
        var divObj = document.all ? document.all[divArray[i]] : document.getElementById ? document.getElementById(divArray[i]) : "";
        if (value == 1) {
            if (inputArray[i] == '') {
                divObj.innerHTML = '<img src="images/img_checkRed.png" alt="error" width="16" height="16" />';
            }
            else {
                if (divArray[i] == 'chkTimeArrival') {
                    validate('TimeArrival', document.frmBook.TimeArrival.value, 'chkTimeArrival');
                }
                else {
                    divObj.innerHTML = '<img src="images/img_checkGreen.png" alt="error" width="16" height="16" />';
                }
            }
        }
        
        else {
            divObj.innerHTML = '';
        }
    }
    
}


