﻿/*Extending the functionality of Jquery to add validation*/


jQuery.fn.extend({
validate: function(fn) {
///<summary>Validate the element.</summary>
///<param name="fn" optional="true">The validation function.</param>
///<returns type="bool" />

// make sure the calling object exists
if (this[0] == undefined)
return true;

if (fn) {
return this.data("validate", fn);
} else {
fn = this.data("validate");
var ret = true;

// call the validate function if found
if (fn)
ret = fn();

return ret;
}
}
});

/**Tiny MCE Configuration***/
var __editorConfig = {
    mode: "textareas",
    theme: "advanced",
    plugins: "advhr,advimage,advlink,contextmenu,inlinepopups,media,paste,safari,spellchecker,xhtmlxtras",

    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "center",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing_use_cookie: false,
    theme_advanced_resize_horizontal: false,
    theme_advanced_resizing: true,
    theme_advanced_resizing_min_height: 200,

    convert_urls: false,

    gecko_spellcheck: true,
    dialog_type: "modal",

    paste_auto_cleanup_on_paste: true,
    paste_convert_headers_to_strong: true,
    paste_strip_class_attributes: "all"
};

/****Message Box******/
function DisplayMessage(display, input, css, text) {
    var message = $(input).parent().children("span.inputMessage");

    message.removeClass("inputInfo inputError");
    if (display) {
        if (css == "inputError") {
            message.data("error", text);
            $(input).attr("error", "true");
        }

        message.text(text);
        message.addClass(css);
    } else {
        if (css == "inputError") {
            message.removeData("error");
            $(input).removeAttr("error");
        }

        if (message.data("error") != undefined && message.data("error") != "") {
            message.text(message.data("error"));
            message.addClass("inputError");
        } else {
            message.text("");
        }
    
    }

}

function DisplayError(display, input, message) {
    DisplayMessage(display, input, "inputError", message);
}

function ShowMessage(input, message) {
    DisplayMessage(true, input, "inputInfo", message);
}

function HideMessage(input) {
    DisplayMessage(false, input, "inputInfo", "");
}