﻿
var flashplayererror = "<p style='padding:10px;'>You need latest flash palayer and a browser with javascript.<br /><a href='http://www.adobe.com/go/getflash/' target='_blank'>Click here to download latest version of flash player </a>  </p>";

(function($) {
    $.fn.emptySelect = function() {
        return this.each(function() {
            if (this.tagName == 'SELECT') this.options.length = 0;
        });
    }

    $.fn.loadSelect = function(optionsDataArray) {
        return this.emptySelect().each(function() {
            if (this.tagName == 'SELECT') {
                var selectElement = this;
                $.each(optionsDataArray, function(index, optionData) {
                    var option = new Option(optionData.Caption,
                            optionData.Value);

                    if ($.browser.msie) {
                        selectElement.add(option);
                    }
                    else {
                        selectElement.add(option, null);
                    }
                });
            }
        });
    }
})(jQuery);


function ResourceObject() {
    this.ResourceKey = "";
};

var resourceObject = null;

function ShowPopup(resourceKey) {
    resourceObject = new ResourceObject();

    $('#basicModalContent').modal();

    FillResourceValue(resourceKey, $("#_DropDownList_Language").val());


    $('#TinyMCETextBox').css("display", "inline");
    StartTinyMce("TinyMCETextBox");


    void (0);
}

function StartTinyMceWithoutCSS(textboxid) {

    tinyMCE.init({
        mode: "exact",
        elements: textboxid,
        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,CustomFileManager",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,CustomFileManager",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,
        forced_root_block: '',
        convert_urls: false



    });

}
function StartTinyMce(textboxid) {

    tinyMCE.init({
        mode: "exact",
        elements: textboxid,
        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,CustomFileManager",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,CustomFileManager",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,
        content_css: "/includes/css/editorcss.css",
        forced_root_block: ''



    });

}
function StartSimpleTinyMceWithTextAreas(textboxid) {

    tinyMCE.init({
        mode: "textareas",
        theme: "simple"
    });

}
function StartSimpleTinyMce(textboxid) {

    tinyMCE.init({
        mode: "exact",
        elements: textboxid,
        theme: "simple"



    });

}
$(document).ready(function() {

    $("#SaveResourceKey").click(function(e) {
        tinyMCE.activeEditor.save();

        $.post(
            "SaveResourceValue.ajax",
            { ResourceKey: resourceObject.ResourceKey, ResourceValue: $('#TinyMCETextBox').val(), CultureCode: $("#_DropDownList_Language").val(), Location: location.href },
             function(data) {


                 if (data.Value.Value != null) {
                     $('#TinyMCETextBox').val(data.Value.Value);

                     if (tinyMCE.activeEditor != null)
                         tinyMCE.activeEditor.load();

                     window.location.reload();

                 }
             }, "json");

    });


    $("#_DropDownList_Language").change(function() {
        FillResourceValue(resourceObject.ResourceKey, $(this).val());
    });

});



function FillResourceValue(resourceKey, cultureCode) {
    $.post(
                "GetResourceValue.ajax",
                { ResourceKey: resourceKey, CultureCode: cultureCode },
                 function(data) {

                     if (data.Key = "ReturnMessage") {
                         if (data.Value != null) {
                             $('#TinyMCETextBox').val(data.Value.Value);

                         }
                         else {
                             $('#TinyMCETextBox').val("");
                         }

                         resourceObject.ResourceKey = resourceKey;

                         if (tinyMCE.activeEditor != null)
                             tinyMCE.activeEditor.load();

                     }

                 }, "json");
}

function BringCities(province, city) {
    $.getJSON(
        'GetTowns.ajax',
        { provinceID: province.val() },
        function(data) { city.loadSelect(data); });
}

function BringSchools(city, school) {
    $.getJSON(
        'GetSchools.ajax',
        { townID: city.val(), Status: 1 },
        function(data) { school.loadSelect(data); });
}




function CharacterLimiter(item, max, remaningBox) {
    if (item.val().length > max)
        item.val(item.val().substr(0, max));

    remaningBox.html(max - item.val().length);
}

function LimitCharacter(obj, max, remaningBox) {
    obj.keydown(function() {

        CharacterLimiter($(this), max, remaningBox);

    });
    obj.keyup(function() {

        CharacterLimiter($(this), max, remaningBox);

    });

    obj.change(function() {

        CharacterLimiter($(this), max, remaningBox);
    });

    obj.mouseout(function() {

        CharacterLimiter($(this), max, remaningBox);
    });
}

var LoadingElement = null;

$(document).ready(function() {
    $(this).ajaxStart(function() {
        Loading("start");
    });

    $(this).ajaxStop(function() {
        Loading("stop");
    });

});

function Loading(status, display) {

    if (LoadingElement == null)
        return;
        
    if (status == "start") {
        LoadingElement.after("<div id='loadingDiv' style='font-size:16px;'><img id='loadingImg' src='/includes/images/ejut8v2y.gif' />&nbsp;&nbsp;&nbsp;Yükleniyor...</div>");
        LoadingElement.css("display", "none");
    } else {
    $("#loadingDiv").remove();

        if (display == "undefined" || display == null)
            LoadingElement.css("display", "block");
        else
            LoadingElement.css("display", display);
    }
}

//function EncodeJSOnString(text)
//{
//   return text.replace('\\','\\\\').replace('"','\\"');
//}