﻿Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);

function onEndRequest(sender, args) {
    if (args.get_error() != undefined) {
        var msg = "An error occured on the server, administrators have been notified.";
        showErrorMessage("Error", msg);
        args.set_errorHandled(true);
    }
}
function showUploadError(sender, args) {
    sender.deleteFileInputAt($telerik.$(args.get_row()).index());

    //var notfication = getNotificationBadDocumentFormat();
    //notfication.show();
}
function filesUploaded(sender, args) {

    getRadAjaxManager().ajaxRequest('FilesUploaded');
   

}
function uploadFilesSelected(sender, args) {
    $telerik.$(".ruCancel").remove();


}
//-------------------CONTACT US----------------
function showMessageSentDialog() {
    var msg = "We have recieved your message and we will reply to your inquirey shortly.";
    showSuccessMessage("Email Sent", msg);
}

function showContactUs() {
    $('#dlgContactUs').parent().appendTo(jQuery('form:first'));
    $('#dlgContactUs').dialog('open');
}
//------------------------CHANGE PASSWORD-------------------------

function showChangePassword() {
    $('#dlgChangePassword').parent().appendTo(jQuery('form:first'));
    $('#dlgChangePassword').dialog('open');
}

function passwordChanged() {
    var html = "Your password has been changed successfully.";

    $('#dlgChangePassword').dialog("close", showSuccessMessage("Password Changed", html));
}

//-----------------------------------------------------------------

//--------------------------REGISTRATION REQUIRED------------------------------

function showRegistrationRequiredEmailLandlordWarning() {
    var msg = "Please register to be able to send an email to the landlord";
    showRegistrationRequired(msg);
}

function showRegistrationAddBookmarkWarning() {
    var msg = "Please register as a tentant to be able to add bookmarks.";
    showRegistrationRequired(msg);
}

function showAddListingWarning() {
    var msg = 'Please register as a landlord to add listings.';
    showRegistrationRequired(msg);
}

function showRegistrationRequired(msg) {
    var spn = $('#registrationRequiredMessage');
    spn.html(msg);
    $('#dlgRegistrationRequired').dialog('open');
}

//-----------------------------------------------------------------------------

function showSuccessMessage(title, msg) {
    var spn = $('#successMessage');
    $('#dlgSuccess').dialog("option", "title", title);
    spn.html(msg);
    $('#dlgSuccess').dialog('open');
}

function showErrorMessage(title, msg) {
    var spn = $('#errorMessage');
    $('#dlgError').dialog("option", "title", title);
    spn.html(msg);
    $('#dlgError').dialog('open');
}

$(function () {
    $('#tabsProvinces').tabs({ selected: 7, event: 'click' });


    $('#dlgSuccess').dialog({
        buttons: {
            'Close': function () {
                $(this).dialog("close");
            }
        },

        autoOpen: false,
        width: 480,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });


    $('#dlgError').dialog({
        buttons: {
            'Close': function () {
                $(this).dialog("close");
            }
        },

        autoOpen: false,
        width: 480,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });

    //REGISTRATION REQUIRED
    $('#dlgRegistrationRequired').dialog({
        buttons: {
            'Register': function () {
                window.location = "register.aspx";
            },
            'Close': function () {
                $(this).dialog("close");
            }
        },

        autoOpen: false,
        width: 480,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });

    ///---------------------

    $('#dlgChangePassword').dialog({
        buttons: {
            'Change Password': function () {
                changePassword();

            },
            'Close': function () {
                $(this).dialog("close");
            }
        },
        autoOpen: false,
        width: 430,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });
    $('#dlgContactUs').dialog({
        buttons: {
            'Contact Us': function () {
                submitContactUs();
            },
            'Close': function () {
                $(this).dialog("close");
            }
        },
        autoOpen: false,
        width: 430,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });
});

function logout() {
    getRadAjaxManager().ajaxRequest("logout");
}
function changePassword() {
    Page_ClientValidate("ChangePassword");
    if (Page_IsValid) {
        var ajax = getRadAjaxManager();

        ajax.ajaxRequest("ChangePassword");
    }

}
function submitContactUs() {
    Page_ClientValidate("ContactUs");
    if (Page_IsValid) {
        var ajax = getRadAjaxManager();

        ajax.ajaxRequest("ContactUs");
    }

}
