var regday = new RegExp("^[0-9]{1,2}$");
//var regphone = new RegExp("^[0-9\-\/]+$");http://secure.click4sky.com/cs/click4sky?next=1&AIRLINES=OK&pricerPreference=SCP&JOURNEY_TYPE=RT&DAY_0=0&MONTH_SEL_0=7%2F2008&DEP_0=PRG&from1Combo=PRG&ID_LOCATION=&DAY_1=17&MONTH_SEL_1=7%2F2008&ARR_0=&to1Combo=&ADTCOUNT=1&PRICER_PREF=SCP
//var regemail = new RegExp("^([+]?[_a-zA-Z0-9\-]+([.][_a-zA-Z0-9\-]+)*@([0-9a-zA-Z][0-9a-zA-Z\-]*[.])+[a-zA-Z]{2,4})$");

var booking = new Array();
booking[booking.length] = new Array("DAY_0", "test_day(value)", "Prosím, zadejte platné datum odletu!");
booking[booking.length] = new Array("MONTH_SEL_0", "value.length > 0", "Prosím, zadejte platné datum odletu!");
booking[booking.length] = new Array("DAY_1", "test_day(value)", "Prosím, zadejte platné datum návratu!");
//booking[booking.length] = new Array("DAY_1", "checkArrDate_new('booking','dayFromID','monthYearFromID')", "Prosím, zadejte platné datum návratu!");
booking[booking.length] = new Array("MONTH_SEL_1", "testDates('dayFromID','monthYearFromID','dayToID','monthYearToID')", "Datum návratu nemůže být později než Datum odletu!");
//TODO booking[booking.length] = new Array("arrMonth", "checkDates('booking')", "Datum návratu nemůže být později než Datum odletu!");
//booking[booking.length] = new Array("from1Combo", "checkFrom1Combo()", "Prosím, zadejte místo odletu!");
booking[booking.length] = new Array("from1", "value > ''", "Prosím, zadejte místo odletu!");
//booking[booking.length] = new Array("DEP_0", "value > ''", "Prosím, zadejte místo odletu!");
//booking[booking.length] = new Array("from1Combo", "value > ''", "Prosím, zadejte místo odletu!");
booking[booking.length] = new Array("to1", "value > ''", "Prosím, zadejte místo příletu!");
booking[booking.length] = new Array("INFCOUNT", "testCountPass()", "Počet dětí nemůže být větší než počet dospělých cestujících!");
booking[booking.length] = new Array("ID_LOCATION", "value != ''", "Vyplňte prosím Místo prodeje!");
booking[booking.length] = new Array("pref", "checkPreference(value)", "Preferenci ceny lze uplatnit pouze u zpáteční letenky!");

/****************************** FUNCTIONS ********************************/
function test_day(value){
    if (value > 0 && value < 32 && regday.test(value))
        return true;       
    return false; 
}
function checkBooking(formular){
     //document.getElementById('from1').value=document.getElementById('from1Combo').options[document.getElementById('from1Combo').selectedIndex].value; 
     //document.getElementById('to1').value=document.getElementById('to1Combo').options[document.getElementById('to1Combo').selectedIndex].value;
//     target="_blank"('from='+document.getElementById('from1').value);
//     alert('loc='+document.getElementById('saleLocation').value);     
     if(check_Form('booking')){
        saveForm(document.getElementById('from1').value, document.getElementById('to1').value, getSelectedData('passADT'));
        var show = jQ('#buttonSubmit');
        //runJqmodalIBS();
     }     
}

function runJqmodalIBS() {
    jQ('#c4s_ibs_loading').jqm({overlay: 100});
    jQ('div.flash_rolover').hide();
    hideSelectBoxes();
    jQ('#c4s_ibs_loading').jqmShow();
    window.setTimeout('hidejqm()', 3000);
    displaySelectBoxes();
    return true;
}

function hidejqm(){
    jQ('#c4s_ibs_loading').jqmHide();
    document.forms[jqmFormName].submit();
    return false;
}


function hideSelectBoxes() {
	jQ("select").hide();
}
function displaySelectBoxes() {
   jQ("select").show();
}

function testDates(dFrom,mFrom,dTo,mTo){
    var my_f = document.getElementById(mFrom).value.split("/");
    var m_from = my_f[0];
    var y_from = my_f[1];
    var d_from = document.getElementById(dFrom).value;
    var my_t = document.getElementById(mTo).value.split("/");
    var m_to = my_t[0];
    var y_to = my_t[1];
    var d_to = document.getElementById(dTo).value;
    
     var fromDateObj = new Date();
    fromDateObj.setFullYear(y_from);
    fromDateObj.setMonth(m_from-1);
    fromDateObj.setDate(d_from);
    fromDateObj.setHours(0);
    
     var toDateObj = new Date();
    toDateObj.setFullYear(y_to);
    toDateObj.setMonth(m_to-1);
    toDateObj.setDate(d_to);
    toDateObj.setHours(0);      
     var aktDateObj = new Date();
    aktDateObj.setHours(0);
            
    if(fromDateObj.getTime() <= toDateObj.getTime() && aktDateObj.getTime() <= fromDateObj.getTime()) return true;
    else return false;    
}
function testCountPass(){
    var adult = new Number(document.forms['booking'].ADTCOUNT.value);
    var infant = new Number(document.forms['booking'].INFCOUNT.value);
    if(infant > adult)
        return false;
    return true;
}
function checkPreference(prefValue) {
    var i;
    var obj = document.forms['booking'].journey;
    if (obj) {
        for (i=0;i<obj.length;i++) {
            if (obj[i].checked) {
                if ((obj[i].value != 'roundTrip' && obj[i].value != 'oneway') && (prefValue == 'SCP')) return false;
                i = obj.length;
            }
        }
    }
    return true;
}