
function CheckAllLoginRequiredFields() {
    if ($('#txtLoginEmail').val() == "" || $('#txtLoginPassword').val() == "") {
        if ($('#txtLoginEmail').val() == "") { DoBorderColorRed("txtLoginEmail"); } else { ClearBorderColor("txtLoginEmail"); }
        if ($('#txtLoginPassword').val() == "") { DoBorderColorRed("txtLoginPassword"); } else { ClearBorderColor("txtLoginPassword"); }
        $('#LoginErrorMsg').html('Invalid email/password.');
        return false;
    } else {
        ClearBorderColor("txtLoginEmail");
        ClearBorderColor("txtLoginPassword");
        $('#LoginErrorMsg').html('');
        var emailAddress = $('#txtLoginEmail').val();
        if (ValidateEmail(emailAddress)) {
            $('#LoginErrorMsg').html('');
            var objFrm = document.getElementById("frmLogin");
            if(objFrm) {
                objFrm.action = 'https://' + window.location.host + '/booknow.aspx';
                $('#hdLoginEmail').val($('#txtLoginEmail').val());
                $('#hdLoginPassword').val($('#txtLoginPassword').val());
                objFrm.submit();
            }
        } else {
            $('#LoginErrorMsg').html('Please provide valid email address.');
            DoBorderColorRed("txtLoginEmail");     
            return false;
        }
    }
    return false;
}

function CheckForgotPwdEmail() {
    if ($('#txtForgotEmail').val() == "") {
        DoBorderColorRed("txtForgotEmail");
        $('#ForgotPwdErrorMsg').html('Invalid email address.');
        return false;
    } else {
        $('#ForgotPwdErrorMsg').html('');
        var emailAddress = $('#txtForgotEmail').val();
        if (ValidateEmail(emailAddress)) {
            $('#ForgotPwdErrorMsg').html('');
            ClearBorderColor("txtForgotEmail");
            CallForgotPassword(emailAddress);
        } else {
            $('#ForgotPwdErrorMsg').html('Invalid email address.');
            DoBorderColorRed("txtForgotEmail");
            return false;
        }
    }
}

function CheckAllStayTouchRequiredFields() {
    if ($('#txtStayFirstName').val() == "" || $('#txtStayEmail').val() == "" || $('#txtStayLastName').val() == "") {
        if (jQuery.trim($('#txtStayFirstName').val()) == "") { DoBorderColorRed("txtStayFirstName"); } else { ClearBorderColor("txtStayFirstName"); }
        if ($('#txtStayEmail').val() == "") { DoBorderColorRed("txtStayEmail"); } else { if (ValidateEmail($('#txtStayEmail').val())) { ClearBorderColor("txtStayEmail"); } }
        if (jQuery.trim($('#txtStayLastName').val()) == "") { DoBorderColorRed("txtStayLastName"); } else { ClearBorderColor("txtStayLastName"); }
//        if (jQuery.trim($('#txtStayZipcode').val()) == "") { DoBorderColorRed("txtStayZipcode"); } else { ClearBorderColor("txtStayZipcode"); }
        $('#STErrorMsg').html('Please provide all required information.');
        return false;
    } else {
        $('#STErrorMsg').html('');
        var emailAddress = $('#txtStayEmail').val();
        if (ValidateEmail(emailAddress)) {
            $('#STErrorMsg').html('');
            ClearBorderColor("txtStayFirstName");
            ClearBorderColor("txtStayEmail");
            ClearBorderColor("txtStayLastName");
//            ClearBorderColor("txtStayZipcode");
            SubmitStayInTouch();
            //CallSaveStayTouchInformation($('#txtStayFirstName').val(), $('#txtStayEmail').val(), $('#txtStayLastName').val(), $('#txtStayZipcode').val())
        } else {
        $('#STErrorMsg').html('Please provide valid email address.');
            DoBorderColorRed("txtStayEmail");
            return false;
        }
    }
}

function SubmitStayInTouch() {
    var objFrm = document.getElementById("frmNewsletter");
    if (!objFrm) return;
    objFrm.action = 'https://' + window.location.host + '/newslettersignup.aspx';
    var interests = "";
    $("#Interests :checked").each(function() {
        interests = interests + $(this).val() + ",";
    });

    if (interests.length > 0) {
        interests = interests.substring(0, interests.length - 1);
    }
    $('#hdStayFirstName').val($('#txtStayFirstName').val());
    $('#hdStayEmail').val($('#txtStayEmail').val());
    $('#hdStayLastName').val($('#txtStayLastName').val());
    $('#hdStayZipcode').val($('#txtStayZipcode').val());
    $('#hdTitle').val($('#cmbTitle').val());
    $('#hdMonth').val($('#cmbMonth').val());
    $('#hdYear').val($('#cmbYear').val());
    $('#hdInterests').val(interests);
    $('#returnURL').val($("input[cID='hdReturnURL']").val());
    objFrm.submit();
}

function ValidateEmail(emailAddress) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    if (emailPattern.test(emailAddress)) {
        return true;
    } else {
        return false;
    }
}



function CallLogin(emailAddress, password) {
    /*$("input[CID='btnLoginClientID']").attr('disabled', true);
    ShowElement('loginAnimationDiv');
    jAjax('/reservations/ReservationService.asmx/VerifyLogin',
       '{"EmailAddress":"' + emailAddress + '","Password":"' + password + '"}',
        function(obj) {
            if (obj.d == null) return;

            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1], function(data) {
                $('#LoginErrorMsg').html(data); 
                HideElement('loginAnimationDiv');
                $("input[CID='btnLoginClientID']").attr('disabled', false);
            }, 
            null, function(data) { window.location.href = data; }, null).SuccessAction();
        }, null, false);

        
    return false;*/
}

function GiftCard_CheckBalance() {
    var giftCardNumber = $("input[CID='giftcardNumber']");
    giftCardNumber.val(giftCardNumber.val().replace(/ /g,''));
    jAjax('/reservations/ReservationService.asmx/GiftCard_CheckBalance',
       '{"CardNumber":"' + giftCardNumber.val() + '"}',
        function(obj) {
            if (obj.d == null) return;
            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1], function(data) {
                $('#messageLabel').html(data); HideMainAnimation();
            }, 
            function(data) {
                $('#messageLabel').html(data); HideMainAnimation();}, null, null).SuccessAction();
        }, null, true);
        
    return false;
}

function CallForgotPassword(emailAddress) {

    jAjaxReservationService('ForgotPassword',
       '{"EmailAddress":"' + emailAddress + '"}',
        function(obj) {
            if (obj.d == null) return;

            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1],
                function(data) {
                    $('#ForgotPwdErrorMsg').html(data);
                    //$('#ForgotPwdErrorMsg').html('Your password has been emailed. Please check your email.');
                    //if (jQuery.trim(data) == "Couldn't find the username or the password doesn't match") { $('#ForgotPwdErrorMsg').html('<br />Invalid email address') }
                    //else { $('#ForgotPwdErrorMsg').html(data); };
                },
                function(data) {
                    //$('#ForgotPwdErrorMsg').html(data);
                    $('#ForgotPwdErrorMsg').html('Your password has been emailed. Please check your email.');
                },
                null, null).SuccessAction();
        }, null, false);
    return false;
}

function CallSaveStayTouchInformation(firstName, emailAddress, lastName, zipCode) {

    var interests = "";
    $("#Interests :checked").each(function() {
        interests = interests + $(this).val() + ",";
    });

    if (interests.length > 0) {
        interests = interests.substring(0, interests.length - 1);
    }

    jAjaxReservationService('SaveStayTouchInformation',
       '{"Title":"' + $('#cmbTitle').val() + '","FirstName":"' + firstName + '","LastName":"' + lastName + '","EmailAddress":"' + emailAddress + '","ZipCode":"' + zipCode + '","TravelMonth":"' + $('#cmbMonth').val() + '","TravelYear":"' + $('#cmbYear').val() + '","Interests":"' + interests + '"}',
        function(obj) {
            if (obj.d == null) return;

            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1], function(data) { $('#STErrorMsg').html(data); },
            function(data) { $('#STErrorMsg').html(data); },
                null, null).SuccessAction();
        }, null, false);
    return false;
}

function CallSignUP() {

    jAjax('/reservations/ReservationService.asmx/SignUP','{}',       
        function(obj) {
            if (obj.d == null) return;

            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1], function(data) {
                $('#LoginErrorMsg').html(data);
            },
            null, function(data) { window.location.href = data; }, null).SuccessAction();
        }, null, true);

    return false;
}

function DoBorderColorRed(id) {
    document.getElementById(id).style.borderColor = "red";
}

function ClearBorderColor(id) {
    document.getElementById(id).style.borderColor = "";
}

function CallLogout() {

    jAjaxReservationService('Logout',
       '{}',
        function(obj) {
            if (obj.d == null) return;

            var arr = obj.d.split('~');
            if (arr.length < 2) return;

            var obj = new SuccessHandler(arr[0], arr[1], null, null,
                function(data) { window.location.href = data; }, null).SuccessAction();
        }, null, false);
    return false;
}
    
function CheckLoginStatus(){    
    var loginStatus;
    loginStatus=ReadCookieContents('IsUserLoggedIn');
    var firstName;
    firstName =ReadCookieContents('CustomerFirstName');

    if (loginStatus==1)
    {            
        document.getElementById('welcomemessage').innerHTML="Hi " + firstName;      
    }
}
function ShowStayInTouchMessage() {
    HideMainAnimation();
    $("#newsletterSuccessDialog").dialog({ modal: true, width: 400 });
    $("#newsletterSuccessDialog").dialog('open');
}
function HideStayInTouchMessage() {
    $("#newsletterSuccessDialog").dialog('close');
    return false;
}