﻿function SetFlexibilityEnabled() {
	alert(document.requestForm.flexibilityChosen.value)
	var flex = document.requestForm.flexibilityChosen.value;
	if (flex == 0) {
		document.requestForm.SelectFlexibility.disabled = 'false';
		document.requestForm.flexibilityComment.disabled = 'false';
	}
	else if (flex == 1) {
		document.requestForm.SelectFlexibility.disabled = 'true';
		document.requestForm.flexibilityComment.disabled = 'true';
	} 
}
		
function checkChoice(field) {  
    var n = field.length;
    if (document.getElementById("notPCO").checked){ 
        for (i=0; i<n; i++) 
            field[i].disabled = true;
        //$("submitRqst").attr("disabled", "false");
        document.getElementById("submitRqst").disabled = false;
        return;
    }
    else {
        b = false;
        for (i=0; i<n; i++){ 
            if (field[i].checked == true)
                b = true;
            field[i].disabled = false;
        }
        if (b == true) {
            //$("submitRqst").attr("disabled", "false"); 
            document.getElementById("submitRqst").disabled = false;
        }
        else {
            //$("submitRqst").attr("disabled", "true");
            document.getElementById("submitRqst").disabled = true;
        }  
    }  
}

function submitDetails(language){
    var oForm = document.getElementById("searchDetails");
    var selectedFasilities = getSelectedFacilities();
    var queryString = "";
    for(var i in selectedFasilities)
        if(i != (selectedFasilities.length - 1))
            queryString += selectedFasilities[i].id + ",";
        else 
            queryString += selectedFasilities[i].id; 
    $("#FacilityIdlist").val(queryString);
    if (language == 1033)
        $("#searchDetails").attr("action", "/composite-4268.chtm");
    else
        $("#searchDetails").attr("action", "/composite-4326.chtm");
    oForm.submit();
}

function buttonSubmitForm(value, language) {
    var oForm = document.getElementById("searchDetails");
    $("#requestChoice").val(value);
    if (language == 1033)
        $("#searchDetails").attr("action", "/composite-4078.chtm");
    else
        $("#searchDetails").attr("action", "/composite-4323.chtm");
    oForm.submit();
}
		
function setTimeOfChoise(){
	var d = new Date();
	var t = d.getDay() + '-' + d.getMonth() + '-' + d.getFullYear() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
	$("#TimeOfChoice").val(t.toString());
}

function SubmitRequest() {
    setTimeOfChoise();
    var oForm = document.requestForm;	
	var validForm = ValidateFields();
	if (validForm == true) {
	    saveMails();
	    saveFacilityList();
        if (language == 1033)
            $("#requestForm").attr("action", "/composite-4103.chtm");
        else
            $("#requestForm").attr("action", "/composite-4325.chtm");
        var requestType = $("#RequestType").val();
        if (requestType != "2") {
            setMyCookie("facility_name", "");
            delCookie("facility_name");
        }
        oForm.submit();
	}
}

function Submit_mfFacilitiesOrderForm(lcid) {
    setTimeOfChoise();
    var oForm = document.requestForm;	
	var validForm = ValidateFields();
	if (validForm == true) {
	    saveMails();
	    saveFacilityList();
	    switch(lcid)
	    {
	        case 1030:
	            $("#requestForm").attr("action", "/composite-4325.chtm");
	            break;
	        case 1033:
	            $("#requestForm").attr("action", "/composite-4103.chtm");
	            break;
	    }
        oForm.submit();
	}
}

function ValidateFields() {
	var oForm = document.requestForm;
	var errMsg = '';
	var startDate = new Date(oForm.SelectYearStart.value, oForm.SelectMonthStart.value-1, oForm.SelectDayStart.value, oForm.SelectTimeStart.value);
	var endDate = new Date(oForm.SelectYearEnd.value, oForm.SelectMonthEnd.value-1, oForm.SelectDayEnd.value, oForm.SelectTimeEnd.value);

	if (startDate >= endDate) { 
	    alert(gAlertMsg1);
	    return false;
	}
	
	if (oForm.LargestMeetingRoom.value == '') {
		errMsg = errMsg + gAlertMsg2;
		document.getElementById('LargestMeetingRoom').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('LargestMeetingRoom').style.backgroundColor = '#ffffff';
	}
	if (oForm.NumberMeetingRooms.value == '') {
		errMsg = errMsg + gAlertMsg3;
		document.getElementById('NumberMeetingRooms').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('NumberMeetingRooms').style.backgroundColor = '#ffffff';
	}
	if (oForm.NumberSingleRooms.value == '') {
		errMsg = errMsg + gAlertMsg4;
		document.getElementById('NumberSingleRooms').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('NumberSingleRooms').style.backgroundColor = '#ffffff';
	}
	if (oForm.NumberDoubleRooms.value == '') {
		errMsg = errMsg + gAlertMsg5;
		document.getElementById('NumberDoubleRooms').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('NumberDoubleRooms').style.backgroundColor = '#ffffff';
	}
	if (oForm.ContactName.value == '') {
		errMsg = errMsg + gAlertMsg6;
		document.getElementById('ContactName').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('ContactName').style.backgroundColor = '#ffffff';
	}
	if (oForm.ContactOrganisation.value == '') {
		errMsg = errMsg + gAlertMsg7;
		document.getElementById('ContactOrganisation').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('ContactOrganisation').style.backgroundColor = '#ffffff';
	}
	if (oForm.ContactEmail.value == '') {
		errMsg = errMsg + gAlertMsg8;
		document.getElementById('ContactEmail').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('ContactEmail').style.backgroundColor = '#ffffff';
	}
	if (oForm.ContactPhone.value == '') {
		errMsg = errMsg + gAlertMsg9;
		document.getElementById('ContactPhone').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('ContactPhone').style.backgroundColor = '#ffffff';
	}
	if (oForm.ContactCountryCode.value == '') {
		errMsg = errMsg + gAlertMsg10;
		document.getElementById('ContactCountryCode').style.backgroundColor = '#c38383';
	}
	else {
		document.getElementById('ContactCountryCode').style.backgroundColor = '#ffffff';
	}
	if (errMsg != '') {
	    alert(errMsg);
	    return false;
	}
	
	return true;
}

function submitSearchResults(language){
    var aForm = document.requestForm;
    setMyCookie("facility_name", "");
    delCookie("facility_name");
    if (language == 1033)
        aForm.action = '/composite-4103.htm';
    else
        aForm.action = '/composite-4325.htm';
    if (document.getElementById("notPCO").checked){
        $("#RequestType").val("3");
        aForm.submit();
    }
    else{
        /*var aStrValue = "";
        var aChosenPCOTitles = "";
        var aChosenPCOMails = "";
        $("input[@type='checkbox']").each(
            function(){ 
                if (this.checked){
                    aStrValue = this.value;
                    var aStrValues = aStrValue.split(";");
                    if (aStrValues[1] != "") 
                        aChosenPCOTitles += aStrValues[1] + ";";
                    if ((aStrValues[2] != "") && (aStrValues[2].search(/@/i) != -1))
                        aChosenPCOMails += aStrValues[2] + ";";
                }                
            }
        );
        if (aStrValue != ''){
            $("#ChosenPCOTitle").val(aChosenPCOTitles);
            $("#ChosenPCOMail").val(aChosenPCOMails);
            aForm.submit();
        }*/
        
        // the following must be deleted
        aForm.submit();
    }
}
        
        		
