function ShowHotelAutocomplete(fld)
{
    var options = {
        script: baseurl + '/LocationSearchHotel.aspx?',
        varname: 'zk',
        json: true,
        shownoresults: false,
        minchars: 3,
        setWidth: true,
        minWidth: 250,
        maxWidth: 300,
        cache: false,
        callback: function (obj) {
            
            document.getElementById("RegionID").value = obj.id;

            switch (fld) {
                case 'fldvertrekplaatsheen2':

                    $j("#hotelaankomstdatum").focus();
                    break;

                default:
                    return false;
            }
        }
    };
    var json = new AutoComplete(fld, options);return true;
}


	function GetForm() {
	    // Workaround Browser Bugs

	    if (document.formfchotel) return document.formfchotel;
	    if (document.forms.formfchotel) return document.forms.formfchotel;
	    if (document.layers["body"].document.formfchotel) return document.layers["body"].document.formfchotel;
	    alert("Error in GetForm()");
	    return document.formfchotel;
	}
		
	function GetValue(field) {
	    //alert("GetValue("+field.type+" "+field.name+" "+field.value+")");
	    if (field.value) {
	        return field.value;
	    }else{ // Workaround Browser Bugs
	        switch (field.type) {
	            case "select-one":
	                return field.options[field.selectedIndex].value;
	            default: 
	                alert("Error in GetValue("+field.type+" "+field.name+")");
	                return "";
	        }
	    }
	}
	
	function SetValue(field, value) {
	    //alert("SetValue("+field.type+" "+field.name+","+value+")");
	    switch (field.type) {
	    case "select-one": // Workaround Browser Bugs
	        for (var i=0; i<field.options.length; i++){
	            if (field.options[i].value == value){
	                field.selectedIndex = i;
	                break;
	            }
	        }
	        break;
	    default:
	        field.value = value;
	    }
	}
	
	function feedFcZoeksnel(inDest){
		var f = GetForm();
		f.RegionID.value 	= inDest;
		return true;
	}
	
	function BXOnLoad() {    
	    SetWeekDayNames();
	    AutoPeriod();
	    status="Zoek en boek uw hotel online";
	}
	
	function SetDayNames(daySelect, monthSelect, datum) {
    	var month    = GetValue(monthSelect).substring(0,2);
    	var year     = GetValue(monthSelect).substring(3,7);
    	var day      = 1;
    	var monthDay = new Date(year, month-1, day, 0, 0, 0);
    	var oldMonth = monthDay.getMonth();
    	var names    = 'zondag,maandag,dinsdag,woensdag,donderdag,vrijdag,zaterdag'.split(',');
		if (datum == 1) {
			if ((GetForm().maandjaar1.selectedIndex + 1) == GetForm().maandjaar1.length) {
				var max_days_future = 5;
			} else {
				var max_days_future = 31;
			}
		} else {
			//if ((GetForm().maandjaar2.selectedIndex + 1) == GetForm().maandjaar2.length) {
			//	var max_days_future = 5;
			//} else {
			//	var max_days_future = 31;
			//}
		}
		
    		daySelect.length = max_days_future;
		for (day=1; day<=max_days_future; day++) {
			monthDay.setDate(day);
			if (oldMonth != monthDay.getMonth()) {
				// This month has less then 31 days 
				// because the next day is already in the next month
				daySelect.length = day-1;
				break;
			}
			daySelect.options[day-1].value = day;
			daySelect.options[day-1].text  = names[monthDay.getDay()]+" "+day;
		}
	}

	function SetWeekDayNames() {
		SetDayNames(GetForm().dag1, GetForm().maandjaar1, 1);
	}
	
	function AutoPeriod(){
		var f      = GetForm();
		var jaar   = GetValue(f.maandjaar1).substring(3,7);
		var maand  = GetValue(f.maandjaar1).substring(0,2);
		var dag    = f.dag1.selectedIndex+1;
		var feat    = f.Nights.selectedIndex+1;
		var datum1 = new Date(jaar, maand-1, dag, 0, 0, 0, 0);
		var datum2 = new Date(datum1.valueOf() + (feat*24*3600*1000)); //Add x days (in msec)
		var featjaar=datum2.getYear();
		if (featjaar < 1000) featjaar+=1900;
		var featdag=datum2.getDay();
		var featmaand=datum2.getMonth();
		var featdagm=datum2.getDate();
		var dayarray=new Array("Zondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag");
		var montharray=new Array("januari","februari","maart","april","mei","juni","juli","augustus","september","october","november","december");
		var leaveDate =  dayarray[featdag]+" "+featdagm+" "+montharray[featmaand]+" "+featjaar;
		
		var shwDate = document.getElementById("shwDate");
		shwDate.firstChild.nodeValue=leaveDate;
	}
	function mkDatum(formname) {
	    var errormsg_ht_inccheckoutdate = $j('#errormsg_ht_inccheckoutdate').val();
	    var errormsg_ht_arrivaldate = $j('#errormsg_ht_arrivaldate').val();
	    var errormsg_ht_inccheckindate = $j('#errormsg_ht_inccheckindate').val();
	    var errormsg_ht_location = $j('#errormsg_ht_location').val();

	    //var f = GetForm();
	    if (document.formfchotel) {
	        var f = document.formfchotel;
	    }
	    if (document.formfchotel_home) {
	        var f = document.formfchotel_home;
	    } 

		var blnValid = true;
		var strError = "";

		var arrdate1 = f.hotelaankomstdatum.value.split("/");
		var datum1 = new Date(Date.parse(arrdate1[2] + "/" + arrdate1[1] + "/" + arrdate1[0]));

		if (f.hotelvertrekdatum !== undefined) {
		    var arrdate2 = f.hotelvertrekdatum.value.split("/");
		    var datum2 = new Date(Date.parse(arrdate2[2] + "/" + arrdate2[1] + "/" + arrdate2[0]));

		    if (datum2.valueOf() < datum1.valueOf()) {
		        execAlert(360, 125, errormsg_ht_inccheckoutdate);
		        return false;
		    }
		}

		//blnValid *= f.ArrivalDate.value.length > 0;
		if(!blnValid) {

		    execAlert(360, 125, errormsg_ht_arrivaldate);
		    return false;
		}

		if (!changeDateMessage())
        {
            blnValid = 1;
            execAlert(360, 125, errormsg_ht_inccheckindate);
           return false;

        }
	    
        if(f.RegionID.value.length == 0)
		{
		    f.RegionID.value = f.location2.value;
		}

		blnValid *= f.RegionID.value.length > 0;
		
        if(!blnValid)
		{
		    execAlert(360, 125, errormsg_ht_location);
		    return false;
		}
		
		if(blnValid)
		{
		    var arrArrivalDate = f.ArrivalDate.value.split("/");
		    f.ArrivalDay.value = arrArrivalDate[0];
		    f.ArrivalMonthYear.value = arrArrivalDate[2] + arrArrivalDate[1];
		  
		f.submit();
		}
		
		/* Martijn:Uitgezet vanwege nieuwe calendar control
		var AM = f.maandjaar1.value.substr(0,2);
		var AY = f.maandjaar1.value.substr(3,4);
		
		f.ArrivalDay.value = f.dag1.value;
		f.ArrivalMonthYear.value = AY + AM;*/
	}
	
	function doShowRooms(){
		var Rooms = document.getElementById("Rooms");
		var showRoom2 = document.getElementById("showRoom2");
		if (Rooms.selectedIndex == 1){
		showRoom2.style.display = "block";

		} else {
		showRoom2.style.display = "none";
		}
		if (Rooms.selectedIndex == 0){
		showRoom2.style.display = "none";
		}
	}
	
	function doSelectChildren() {
		var Children = document.getElementById("Children");
		var Children2 = document.getElementById("Children2");
		var Child1Age = document.getElementById("Child1Age");
		var Child2Age = document.getElementById("Child2Age");
		var Child1Age2 = document.getElementById("Child1Age2");
		var Child2Age2 = document.getElementById("Child2Age2");
		var txtLeeftijd = document.getElementById("txtLeeftijd");
		//kamer 1 kind 1
		if (Children.selectedIndex == 1){
			Child1Age.style.visibility = "visible";
			txtLeeftijd.style.visibility = "visible";
		} else {
			Child1Age.style.visibility = "hidden";
		}
		txtLeeftijd.style.visibility = "visible";
		//kamer 1 kind 2
		if (Children.selectedIndex == 2){
			Child1Age.style.visibility = "visible";
			Child2Age.style.visibility = "visible";
		} else{
			Child2Age.style.visibility = "hidden";
		}
		//kamer 2 kind 1
		if (Children2.selectedIndex == 1){
			Child1Age2.style.visibility = "visible";
			txtLeeftijd.style.visibility = "visible";
		} else {
			Child1Age2.style.visibility = "hidden";
		}
		//kamer 2 kind 2
		if (Children2.selectedIndex == 2){
			Child1Age2.style.visibility = "visible";
			Child2Age2.style.visibility = "visible";
		} else{
			Child2Age2.style.visibility = "hidden";
		}
	}
	
	function RadioVal(rb_bestval){	
		document.formfchotel.RegionID.value = rb_bestval;
}

function checkSelectedItem(value) 
{
    if (value == "autocomplete") 
    {
        $j("#selectDestination").css("display", "none");
        $j("#inputDestination").css("display", "block");
        $j("#fldvertrekplaatsheen2").val("");
        $j("#fldvertrekplaatsheen2").focus();
    }
}	
