// JScript source code
function EmptyField (OldClassName) {
document.getElementById(OldClassName).className = 'Red' + document.getElementById(OldClassName).className;
}
function ValidateForm() {
 // Declare all the var`s
     var First_NameErr;
     var Surrname_NameErr;
     var FirstNameCheck = document.contact_form.First_Name.value;
     var SurrnameCheck = document.contact_form.Surrname_Name.value;
     var EmailErr;
     var CelPhoneErr;
     var FormCheck = 1;
     var ErrMainMsg;
     var InputErrMsgDisplay;
     nameRegExp = /^[a-zà-úA-Z]+$/;
  
 // Get the ID`s from the form
     InputErrMsgDisplay = document.getElementById('InputErrMsg');
     First_NameErr = document.getElementById('First_Name');
     Surrname_NameErr = document.getElementById('Surrname_Name');
     EmailErr = document.getElementById('Email');
     CelPhoneErr = document.getElementById('Cel_Phone');
     ErrMainMsg = document.getElementById('Cel_Phone');
          
     // Validate First name
     if (nameRegExp.test(FirstNameCheck) != true) {
         First_NameErr.className = 'InputBoxErr';
         FormCheck = 0;
     }
     else First_NameErr.className = 'InputBox';
     
     // Validate Surrname
     if (nameRegExp.test(SurrnameCheck) != true) {
         Surrname_NameErr.className = 'InputBoxErr';
         FormCheck = 0;
     }
     else Surrname_NameErr.className = 'InputBox';

     // Validate Email Check 
     if ((document.contact_form.Email.value.length == 0)||(!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(EmailErr.value))){
         EmailErr.className = 'InputBoxErr';
         FormCheck = 0;
     }
     else EmailErr.className = 'InputBox';
     // Validate Cel Phone Check 
     if (!/^\+?\d+(-\d+)*$/.test(document.contact_form.Cel_Phone.value)) {
         CelPhoneErr.className = 'InputBoxErr';
         FormCheck = 0;
     }
     else CelPhoneErr.className = 'InputBox';
     // Check Country 
     if (document.contact_form.Country.value == 0) {
         $("#CountryErrMsg").css("display", "block");
         $(".required").css("color", "red");
         FormCheck = 0;
     }
     else $("#CountryErrMsg").css("display", "none");
     // Check for FormCheck Value and print the Main Error messege to the screen
     if (FormCheck != 1) InputErrMsgDisplay.style.display = "block";
     else {
         $("#ContactUsSendBtn").attr("onclick", "");
         InputErrMsgDisplay.style.display = "none";
         document.contact_form.submit();
     }
  }

// Check Availability Form check
function ValidateFields() {
    // Get the date
    var checktheDate = new Date();
    var checkYear = checktheDate.getFullYear();
    var checkMonth = checktheDate.getMonth() + 1;
    var checkDay = checktheDate.getDate();
    var theDate;
    var booltryAgain = true;
    //Check the value of date
    theDate = document.ResDetails.AnotherDate.value;
    splitDate = theDate.split('/');   
    if (checkYear <= splitDate[2]) {
            if (checkYear < splitDate[2]);
            else
                if (checkYear = splitDate[2])
                    if (checkMonth <= splitDate[0]) 
                    {
                        if (checkMonth == splitDate[0])
                       {
                           if (checkDay < splitDate[1]);
                           else {
                                    alert('Please select a new date.');
                                    booltryAgain = false;
                                 }
                                   
                        }
                     }
                     else {
                         alert('Please select a new date.');
                         booltryAgain = false;
                     }                             
        }
        else {
            alert('Please select a new date.');
            booltryAgain = false;
        }
        if (booltryAgain) {
        // Declare varaibels
            var nightsNum;
            var roomsNum;
            var adultsNum;
            var kidsNum;
            // Get the value of the varaibels
            nightsNum = document.getElementById('Nights').value;
            roomsNum = document.getElementById('Rooms').value;
            adultsNum = document.getElementById('Adults').value;
            kidsNum = document.getElementById('Kids').value;
            // send the varaibels to the form
            //setTimeout(timeDelay);
            //submitBookingForm();
            window.open("booking.aspx?nightsNum=" + nightsNum + "&roomsNum="+roomsNum+"&adultsNum="+adultsNum+"&kidsNum="+kidsNum+"&year="+splitDate[2]+"&month="+splitDate[0]+"&day="+splitDate[1]);
        }

    }

    function Login() {
        //  if ($("#Username").val == "sex") alert("sex");
        //alert(document.Login.Username.value);
        if ($("#Username").val() == "metropole" && $("#Password").val() == "37663766!!") {
            $("#LoginErrMsg").hide();
            tb_remove();
            $.post("Handlers/CreateCookie.ashx", {},
              function(data) {
                  window.location = 'Rooms.aspx';
              });
        }
        else $("#LoginErrMsg").show();
    }
