﻿/// <reference path="/scripts/jquery-1.5.2.js" />
$(document).ready(function () {
    $('textarea.tinymce').tinymce({
        // Location of TinyMCE script
        script_url: '/scripts/tiny_mce/tiny_mce_gzip.ashx',

        // General options
        theme: "advanced",
        plugins: "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: "preview,code,fullscreen,|,bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,charmap,iespell,media",
        theme_advanced_buttons4: "styleprops,|,attribs,|,visualchars,nonbreaking,template,pagebreak",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",

        style_formats: [
                { title: 'Red text', inline: 'span', styles: { color: '#ff0000'} },
                { title: 'Red and Bold', inline: 'span', classes: 'redandbold' },
                { title: 'Example 2', inline: 'span', classes: 'example2' },
                { title: 'Table styles' },
                { title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
        ],

        // Example content CSS (should be your site CSS)
        content_css: "/Styles/Content.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"
    });
    
    var searchTimeout;

    $("#txtQuickSearch").keyup(function(){
        clearTimeout(searchTimeout);
        searchTimeout = setTimeout('Search()',250);    
    });

    $(".modal").hide();
    $(".modal").draggable({ handle: "h6" });
    $(".modal > h6").prepend("<span><a href=\"javascript:HideModal();\">X</a></span>");

    $(".accordion").accordion({ active: 0, autoHeight: false });


});

function ShowModal(id) {
    var mdl = $("#" + id);
    var w = parseInt(mdl.css("width"));
    mdl.css("margin-left", (0 - (w / 2)) + "px");
    $("#modalBg").show();
    mdl.show();

}
function HideModal(id) {
    if (id == undefined) {
        $("#modalBg").hide();
        $(".modal:visible").hide();
    }
    else {
        $("#"+id).hide();
    }
}

function ajaxFailed(xmlRequest) {
    alert(xmlRequest.status + ' \n\r ' +
        xmlRequest.statusText + '\n\r' +
        xmlRequest.responseText);
}
function Search(){
    var q = $("#txtQuickSearch").val();
    if(q == ""){
        $("#quickSearchPanel").hide();
        return;
    }
            
    $("#quickSearchResults").empty();

    $.ajax({
        type: "POST", url: "/search/default.aspx/QuickSearch",
        data: "{ q: '" + escape(q) + "' }",
        contentType: "application/json; charset=utf-8", dataType: "json",
        success: function (msg) {
            $("#quickSearchPanel").show();
            $("#quickSearchResults").html(msg.d);
        },
        error: ajaxFailed,
    });

}
