/*---START: General - load different Divs---*/
function changeer(){
	if (document.orderform.hotelOnly.checked){
		
			jQuery("#hasflight").hide();
			jQuery("#WithFlight").val('0');
	
	}
	
	if (document.orderform.hotelFlight.checked){
		
			jQuery("#hasflight").show();
			jQuery("#WithFlight").val('1');
	
	}
}

	jQuery(document).ready(function(){
		
									
		jQuery("#DepartureAirport").val('');
		jQuery("#bookDiv").show();
		jQuery("#WithFlight").val('1');
		jQuery("#hasflight").show();		   
	});
/*---END: General - load different Divs---*/

/*---START: functions---*/
function DateAdd(objDate, strInterval, intIncrement)
    {
        if(typeof(objDate) == "string")
        {
            objDate = new Date(objDate);
 
            if (isNaN(objDate))
            {
                throw("DateAdd: Date is not a valid date");
            }
        }
        else if(typeof(objDate) != "object" || objDate.constructor.toString().indexOf("Date()") == -1)
        {
            throw("DateAdd: First parameter must be a date object");
        }
 
        if(
        strInterval != "M"
        && strInterval != "D"
        && strInterval != "Y"
        && strInterval != "h"
        && strInterval != "m"
        && strInterval != "uM"
        && strInterval != "uD"
        && strInterval != "uY"
        && strInterval != "uh"
        && strInterval != "um"
        && strInterval != "us"
        )
        {
            throw("DateAdd: Second parameter must be M, D, Y, h, m, uM, uD, uY, uh, um or us");
        }
 
        if(typeof(intIncrement) != "number")
        {
            throw("DateAdd: Third parameter must be a number");
        }
 
        switch(strInterval)
        {
            case "M":
            objDate.setMonth(parseInt(objDate.getMonth()) + parseInt(intIncrement));
            break;
 
            case "D":
            objDate.setDate(parseInt(objDate.getDate()) + parseInt(intIncrement));
            break;
 
            case "Y":
            objDate.setYear(parseInt(objDate.getYear()) + parseInt(intIncrement));
            break;
 
            case "h":
            objDate.setHours(parseInt(objDate.getHours()) + parseInt(intIncrement));
            break;
 
            case "m":
            objDate.setMinutes(parseInt(objDate.getMinutes()) + parseInt(intIncrement));
            break;
 
            case "s":
            objDate.setSeconds(parseInt(objDate.getSeconds()) + parseInt(intIncrement));
            break;
 
            case "uM":
            objDate.setUTCMonth(parseInt(objDate.getUTCMonth()) + parseInt(intIncrement));
            break;
 
            case "uD":
            objDate.setUTCDate(parseInt(objDate.getUTCDate()) + parseInt(intIncrement));
            break;
 
            case "uY":
            objDate.setUTCFullYear(parseInt(objDate.getUTCFullYear()) + parseInt(intIncrement));
            break;
 
            case "uh":
            objDate.setUTCHours(parseInt(objDate.getUTCHours()) + parseInt(intIncrement));
            break;
 
            case "um":
            objDate.setUTCMinutes(parseInt(objDate.getUTCMinutes()) + parseInt(intIncrement));
            break;
 
            case "us":
            objDate.setUTCSeconds(parseInt(objDate.getUTCSeconds()) + parseInt(intIncrement));
            break;
        }
        return objDate;
    }

function updateMinDate(){
	jQuery("#DateTo").datepicker('destroy');
	jQuery("#DateTo").val("");
	jQuery("#DateTo").datepicker({
		changeMonth: false,
		dateFormat: 'd-mm-yy',
		changeYear: false,
		minDate: DateAdd(jQuery("#DateFrom").datepicker('getDate'), "D", +1)
	});
}

function resetForm(id) {
	jQuery('#'+id).each(function(){
	        this.reset();
	});
}

jQuery(document).ready(function()
	{
		
	resetForm("myform");

	jQuery("#DateFrom").datepicker({
		changeMonth: false,
		dateFormat: 'dd-mm-yy',
		changeYear: false,
		minDate: +1,
		onSelect: updateMinDate
	});
	
	jQuery("#DateTo").datepicker({
		changeMonth: false,
		dateFormat: 'dd-mm-yy',
		changeYear: false,
		minDate: +2
	});

});

function dorooms(dropdown){
		var dd = document.getElementById(dropdown);
		var trooms = parseInt(dd.value);
		
		for (var r = 1; r <= 9; r++){
			var divroom = document.getElementById('room_' + r);
			divroom.style.display = 'none';

			
			if (r > trooms) {
				for (var a = 1; a <= 3; a++) {
					document.getElementById('Room' + r + 'ChildAge' + a).value = '-1';
				}
				
				document.getElementById('AdultsRoom' + r).value = '1';
				document.getElementById('ChildrenRoom' + r).value = '0';
				document.getElementById('room_' + r + '_children').style.display = 'none';
			}
		}
		
		for (var r = 1; r <= trooms; r++){
			var divroom = document.getElementById('room_' + r);
			//divroom.style.display = 'block';
			jQuery(divroom).fadeIn(r*300);
		}
	}

function doChildren(noofchildren, roomno)
	{
		var noc = parseInt(noofchildren);
		for (var x = 1; x <= 3; x++) {
			document.getElementById('Room' + roomno + 'ChildAge' + x).style.display = 'none';
			if (x > noofchildren)
			{
				document.getElementById('Room' + roomno + 'ChildAge' + x).value = '-1';
			}
		}
	

		
		document.getElementById('room_' + roomno + '_children').style.display = 'none';
		
		if (noc > 0) {
			
			document.getElementById('room_' + roomno + '_children').style.display = 'block';
			for (var x = 1; x <= noc; x++) {
				//document.getElementById('Room' + roomno + 'ChildAge' + x).style.display = 'inline';
				jQuery(document.getElementById('Room' + roomno + 'ChildAge' + x)).fadeIn();
			}
		}
	}

var fromDestination = false;

function checkHotelSearch(){
		if (fromDestination == false)
		{
			var hotelsearcherror = document.getElementById('hotelsearcherror');
			jQuery(hotelsearcherror).hide();

			var DepartureAirport = jQuery('#DepartureAirport').val();
			var Destination = jQuery('#Destination').val();
			var DateFrom = jQuery('#DateFrom').val();
			var DateTo = jQuery('#DateTo').val();
			var iswithflight = jQuery('#WithFlight').val();
			var founderror = false;
			myerror = "";
	
			if (iswithflight == '1'){
				if (DepartureAirport == '') {
					hotelsearcherror.innerHTML = 'Please select departure airport';
					jQuery(hotelsearcherror).slideDown();
					return false;
				}
			}
			
			var dateerror = false;
			if ((DateFrom == '') || (DateTo == '')){
				hotelsearcherror.innerHTML = 'Please select travelling dates';
				jQuery(hotelsearcherror).slideDown();
				return false;
			}				
	
			var childerrorfound = false;
			
			for (var r = 1; r <= 9; r++){	
				var children = parseInt(jQuery("#ChildrenRoom"+r).val());
				if (children > 0)
				{
					for (var c = 1; c <= children; c++){
						if (jQuery("#Room"+r+"ChildAge"+c).val() == "-1") {
							if (!childerrorfound) {
								childerrorfound = true;
								hotelsearcherror.innerHTML = 'Kindly provide the age of each child at the time of travel.';
								jQuery(hotelsearcherror).slideDown();
								return false;
							}
						}
					}
				}
			}
		} 
		else 
		{
			fromDestination = false;
			return false;
		}
		return true;
	}
	
/*---END: functions---*/

/*---START: Departure---*/
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Left(str, n){
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}

jQuery(document).ready(function(){
    jQuery("#filter").focus(function(){
        jQuery("#filter").select();
        jQuery(".innerdropbox").show();
    });
    
   jQuery(".filtered li").click(function(){
        jQuery("#filter").val(jQuery(this).html());
        code = Right(jQuery("#filter").val(),3);
        length1 = jQuery("#filter").val().length;
        pointer1 = length1 - 6;
        place = Left(jQuery("#filter").val(),pointer1);
        full = code + " - " + place;
        jQuery("#DepartureAirport").val(full.toUpperCase());
        jQuery(".innerdropbox").hide();
    });
    
    jQuery("#filter").keyup(function () {
        var filter = jQuery(this).val(), count = 0;
        jQuery(".filtered:first li").each(function () {
            if (jQuery(this).text().search(new RegExp(filter, "i")) < 0) {
                jQuery(this).addClass("hidden");
            } else {
                jQuery(this).removeClass("hidden");
                count++;
            }
            
        });
    if(count == 0){
        jQuery(".innerdropbox").hide();
    }else
    {
        jQuery(".innerdropbox").show();
    }
    jQuery("#filter-count").text(count);
    });
	
	
	
	
	
	
	jQuery("#filter2").focus(function(){
        jQuery("#filter2").select();
        jQuery(".innerdropbox2").show();
    });
    
   jQuery(".filtered2 li").click(function(){
        jQuery("#filter2").val(jQuery(this).html());
        jQuery("#Destination").val(jQuery("#filter2").val());
        jQuery(".innerdropbox2").hide();
    });
    
    jQuery("#filter2").keyup(function () {
        var filter = jQuery(this).val(), count = 0;
        jQuery(".filtered2:first li").each(function () {
            if (jQuery(this).text().search(new RegExp(filter, "i")) < 0) {
                jQuery(this).addClass("hidden");
            } else {
                jQuery(this).removeClass("hidden");
                count++;
            }
            
        });
    if(count == 0){
        jQuery(".innerdropbox2").hide();
    }else
    {
        jQuery(".innerdropbox2").show();
    }
    jQuery("#filter-count2").text(count);
    });
	
	
});
/*---END: Departure---*/
