function initTinyMce() {
    //alert('inittmce');
    $('textarea.tinymce').tinymce({
        script_url: '../Scripts/tiny_mce/tiny_mce.js',
        // General options
        mode: "textareas",
        theme: "advanced",
        plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,|,cleanup,help,code",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,fullscreen",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: false,
        convert_urls : false,

        content_css: "../Styles/mce.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url: "lists/template_list.js",
        external_link_list_url: "lists/link_list.js",
        external_image_list_url: "lists/image_list.js",
        media_external_list_url: "lists/media_list.js",
        width: '83%'
    });
}

function initMiniMce() {
    $('.mceMini').tinymce({
        script_url: '../Scripts/tiny_mce/tiny_mce.js',
        // General options
        mode: "textareas",
        theme: "advanced",
        plugins: "emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,|,help",
        theme_advanced_buttons2: "cut,copy,paste,undo,redo,|,forecolor,backcolor,visualaid,emotions,|,fullscreen",
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: false,

        content_css: "../Styles/mce.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url: "lists/template_list.js",
        external_link_list_url: "lists/link_list.js",
        external_image_list_url: "lists/image_list.js",
        media_external_list_url: "lists/media_list.js",
        convert_urls : false,

        width: '83%'
    });
}
Shadowbox.init({
    continuous: true,
    counterType: "skip",
    overlayOpacity: 0.8
});
$().ready(function() {
    initTinyMce();
    initMiniMce();
    tb_init('a.thickbox, area.thickbox, input.thickbox');
    imgLoader = new Image(); // preload thickbox image
    imgLoader.src = "../Images/loadingAnimation.gif";
});
(function ($) {
    $.fn.valign = function (container) {
        return this.each(function (i) {
            if (container === null) {
                container = 'div';
            }
            var paddingPx = 10; //change this value as you need (It is the extra height for the parent element)
            $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
            var el = $(this).children(container + ":first");
            var elh = $(el).height(); //new element height
            var ph = $(this).height(); //parent height
            if (elh > ph) { //if new element height is larger apply this to parent
                $(this).height(elh + paddingPx);
                ph = elh + paddingPx;
            }
            var nh = (ph - elh) / 2; //new margin to apply
            $(el).css('margin-top', nh);
        });
    };
})(jQuery);

function UpdateTextArea() {
    tinyMCE.triggerSave(false, true);
}

function resizeRows(containerId) {
    var maxHeight = 0;
    var elements = $(containerId);
    jQuery.each(elements, function () {
        //alert(typeof ($(this));
        var thisHeight = $(this).height();
        if (thisHeight > maxHeight) {
            maxHeight = thisHeight;
        }
    });
    elements.height(maxHeight);
}
function deselectRadioButtonPeers(current) {
    // uncheck any radio buttons with the same id as current
    // except for the digit characters, which are wildcarded
    regex = new RegExp(current.id.replace(/\d/g, "\\d"))
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && regex.test(elm.id) && elm != current) {
            elm.checked = false;
        }
    }
}
function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

