<!--

var diff_all = 0;
var firstWeekDay=0;
var lastWeekDay=0;
var nextYear  = 0;


function isValidDate(dateStr) {
    // Date validation function courtesty of
    // Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

    // Checks for the following valid date formats:
    // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        alert(dateStr + " Date is not in a valid format.")
        return false;
    }
    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) { // check month range
        //alert("Mesiac musí mať hodnotu 1 až 12.");
        return false;
    }
    if (day < 1 || day > 31) {
        //alert("Deň musí mať hodnotu  1 až 31.");
        return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        //alert("Mesiac "+month+" nemá 31 - dní !")
        return false;
    }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) {
            //alert("Február " + year + " nemá " + day + " dní!");
            return false;
        }
    }
    return true;
}

function isValidTime(timeStr) {
    // Time validation function courtesty of
    // Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

    // Checks if time is in HH:MM:SS AM/PM format.
    // The seconds and AM/PM are optional.

    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

    var matchArray = timeStr.match(timePat);
    if (matchArray == null) {
        alert("Time is not in a valid format.");
        return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second=="") {
        second = null;
    }
    if (ampm=="") {
        ampm = null
    }

    if (hour < 0  || hour > 23) {
        alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
        return false;
    }
    if (hour <= 12 && ampm == null) {
        if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
            alert("You must specify AM or PM.");
            return false;
        }
    }
    if  (hour > 12 && ampm != null) {
        alert("You can't specify AM or PM for military time.");
        return false;
    }
    if (minute < 0 || minute > 59) {
        alert ("Minute must be between 0 and 59.");
        return false;
    }
    if (second != null && (second < 0 || second > 59)) {
        alert ("Second must be between 0 and 59.");
        return false;
    }
    return true;
}

function dateDiff(dateFirst,dateLast,timeFrom,timeTo) {
	
	
    date1 = new Date();
    date2 = new Date();
    diff  = new Date();

	
	

    if (isValidDate(dateFirst) && isValidTime(timeFrom)) { // Validates first date
        date1temp = new Date(dateFirst + " " +timeFrom);
        date1.setTime(date1temp.getTime());
    }
    else return false; // otherwise exits

    if (isValidDate(dateLast) && isValidTime(timeTo)) { // Validates second date
        date2temp = new Date(dateLast + " " + timeTo);
        date2.setTime(date2temp.getTime());
    }
    else return false; // otherwise exits

    // sets difference date to difference of first date and second date

    diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

    timediff = diff.getTime();

    weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
    timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

    days = Math.floor(timediff / (1000 * 60 * 60 * 24));
    timediff -= days * (1000 * 60 * 60 * 24);

    hours = Math.floor(timediff / (1000 * 60 * 60));
    timediff -= hours * (1000 * 60 * 60);

    mins = Math.floor(timediff / (1000 * 60));
    timediff -= mins * (1000 * 60);

    secs = Math.floor(timediff / 1000);
    timediff -= secs * 1000;

	
    var hourFrom = timeFrom.substr(0,2);
    var hourTo = timeTo.substr(0,2);
    var hourFromNum = eval(hourFrom);
    var hourToNum = eval(hourTo);
    var diff_hours = hourToNum - hourFromNum;
    //document.getElementById('townFreeTownTo').value= diff_hours;
    if(diff_hours >= 0 && diff_hours < 2 ){
        days = days -1;
    }
    diff_all = 0;

    diff_all = (weeks*7) + (days+1);
    if(nextYear==1){
        diff_all = 365- diff_all ;
    }
    //alert(diff_all);
    firstWeekDay = date1.getDay();
    lastWeekDay = date2.getDay();
	
//document.getElementById('townFreeTownTo').value= firstWeekDay;
	
	
}

function changeToNumberWithZero(num){
    /*return num;*/
    if(num.length==2){
        return num;
    }else{
        return '0'+num;
    }
}


function _doDateDiff(id){
    // format date mm/dd/yyyy
	 
    var __dateFromDay = changeToNumberWithZero(document.getElementById("calDayFrom"+id).value);
    var __dateFromMonth = (document.getElementById("calMonthFrom"+id).value);

   // alert("debug"+__dateFromMonth);

    var date1 = __dateFromMonth.split("-");
    __dateFromMonth  = changeToNumberWithZero(date1[0]);
    var __dateFromYear  = date1[1];

	 	
    var __dateToDay = changeToNumberWithZero(document.getElementById("calDayTo"+id).value);
    var __dateToMonth = (document.getElementById("calMonthTo"+id).value);


    var date2 = __dateToMonth.split("-");
 
    __dateToMonth  = changeToNumberWithZero(date2[0]);
    var  __dateToYear  = date2[1];

  /*  var _aktualYear = 2009;

    if(__dateToMonth<__dateFromMonth){
        _aktualYear = _aktualYear + 1;
        nextYear = 1;
    }*/
	 
    if(document.getElementById("calTimeFrom"+id)!= null ){
        var _timeFrom = document.getElementById("calTimeFrom"+id).value;
        var _timeTo = document.getElementById("calTimeTo"+id).value;
    }else{
        var _timeFrom = "10:00:00 AM";
        var _timeTo = "08:00:00 AM";
    }
	
	 
	 
    var d_from = __dateFromMonth + '/'+__dateFromDay +'/' + __dateFromYear;
    var d_to = __dateToMonth + '/'+__dateToDay +'/' + __dateToYear;
	 
	
    if( __dateFromDay>__dateToDay && (__dateFromMonth==__dateToMonth)){
        //alert("Nesprávny interval ");
        document.getElementById('cenaEur'+id).innerHTML="0";
        document.getElementById('cenaSk'+id).innerHTML="0";
        document.getElementById('price_all_'+id).value= val;
    }else{
		
        dateDiff(d_from,d_to,_timeFrom,_timeTo);
			
        if(diff_all>0){
            val =  makeCurrentFromInterval(diff_all,id);
            //alert(diff);
            if(document.getElementById('doplnky_price')!= null ){
                resetDoplnky();
            }

            val1 =(val*30.126)*100;
            val11 = Math.round(eval(val1))/100;
            document.getElementById('cenaEur'+id).innerHTML= val;
            document.getElementById('cenaSk'+id).innerHTML=val11;
            document.getElementById('price_all_'+id).value= val;
            document.getElementById('count_day'+id).value= diff_all;
        }
		
		
    }
	
}


function makeCurrentFromInterval(_days,id){
		
    if(document.getElementById('isWeek')!= null ){
        document.getElementById('isWeek').value = 'false';
    }else{
        document.getElementById('isWeek'+id).value = 'false';
    }
	
    if(_days<7){
        if(_days==2){
            if( firstWeekDay == 5){
                var s = document.getElementById('price5_'+id).value;
                if(document.getElementById('isWeek')!= null ){
                    document.getElementById('isWeek').value = 'true';
                }else{
                    document.getElementById('isWeek'+id).value = 'true';
                }
                //return eval(_days*s);
                //alert(s);
                return eval(s);
            }
        }else{
            var s = document.getElementById('price1_'+id).value;
            return eval(_days*s);
        }
        var s = document.getElementById('price1_'+id).value;
        return eval(_days*s);
    }
    if(_days<13 && _days > 6 ){
        var s = document.getElementById('price2_'+id).value;
        return eval(_days*s);
    }

    if(_days<28 && _days > 13){
        var s = document.getElementById('price3_'+id).value;
        return eval(_days*s);
    }

    if(_days >= 28){
        var s = document.getElementById('price4_'+id).value;
        return eval(_days*s);
    }
		
	
}


function resetDoplnky(){
    document.getElementById('doplnky_price').value = 0;
    CheckAll(document.frmMain);

	
}

function CheckAll(fmobj) {
    for (var i=0;i<fmobj.elements.length;i++) {
        var e = fmobj.elements[i];
        if ( e.type=='checkbox' ) {
            e.checked = false;
        }
    }
}



function doplnkyCount(idDopnky,id){
	
    var valCheckbox = eval(document.getElementById(idDopnky).value);
    var  valPriceAll = eval(document.getElementById('price_all_'+id).value);
    var  valPriceAllDoplnky = eval(document.getElementById('doplnky_price').value);
    var  valCountDay = eval(document.getElementById('count_day'+id).value);
	
    if(!valPriceAllDoplnky){
        valPriceAllDoplnky = 0;
    }
	
	
    if(document.getElementById(idDopnky).checked){
        valPriceAllDoplnky = valPriceAllDoplnky + valCheckbox;
        valPriceAll = valPriceAll + (valPriceAllDoplnky*valCountDay);
		
    }else{
        valPriceAllDoplnky = valPriceAllDoplnky - valCheckbox;
        valPriceAll = valPriceAll - (valPriceAllDoplnky*valCountDay);
		
    }
	
    //alert(valCheckbox);
	
	
    document.getElementById('doplnky_price').value = valPriceAllDoplnky ;
    //valPriceAll = valPriceAll + valPriceAllDoplnky;
	
	
    val1 =((valPriceAll*30.126)*100);
    val11 = (Math.round(eval(val1))/100);
	
    document.getElementById('cenaEur'+id).innerHTML= valPriceAll;
    document.getElementById('cenaSk'+id).innerHTML=val11;


}

function roundNumber(num, dec) {
    var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
    return result;
}


function checkRezBox2Form(){
	
    var status1 = 0;
    var status2 = 0;
	
    if(document.getElementById('FromTownReturn').value == '-'){
        if(document.getElementById('townFreeTownFrom').value == 'Iné miesto'){
            alert('Nezadali ste miesto prevzatia !');
            status1 = 0;
            if(document.getElementById('townFreeTownFrom').value  == ''){
                alert('Nezadali ste miesto prevzatia !');
                status1 = 0;
            }
        }else{
            status1 = 1;
        }
    }else{
        status1 = 1;
    }
	
		
    if(document.getElementById('FromToReturn').value == '-'){
        if(document.getElementById('townFreeTownTo').value == 'Iné miesto'){
            alert('Nezadali ste miesto návratu !');
            status2 = 0;
            if(document.getElementById('townFreeTownTo').value  == ''){
                alert('Nezadali ste miesto návratu !');
                status2 = 0;
            }
        }else{
            status2 = 1;
        }
		
    }else{
        status2 = 1;
    }
	
    if(status1 == 1 && status2 == 1 ){
        document.frmMain.submit();
    }
	
}



//-->

