﻿
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 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: "",
        forced_root_block: ''



    });


}
function toggleEditor(id) {
    if (tinyMCE.get(id))
        tinyMCE.execCommand('mceRemoveControl', false, id);
}

function StartSimpleTinyMceWithTextAreas(textboxid) {

    tinyMCE.init({
        mode: "textareas",
        theme: "simple"
    });

}
function StartSimpleTinyMce(textboxid) {

    tinyMCE.init({
        mode: "exact",
        elements: textboxid,
        theme: "simple"



    });

}




function BringCities(province, city) {
    $.getJSON(
        'GetTowns.ajax',
        { provinceID: province.val() },
        function(data) { city.loadSelect(data); });
}
function BringCitiesAsSelected(province, city, school, cityID,schoolID) {

  
    if(province.val()==0)
    return;
    $.getJSON(
        'GetTowns.ajax',
        { provinceID: province.val() },
        function(data) { 
                city.loadSelect(data); 
                    if(cityID>0)
                    {
                   
                      city.children("option[value='"+cityID+"']").attr('selected', 'selected'); 
                      BringSchoolsAsSelected(city,school,schoolID);
                      
                    
                         
                    }
                });
}

function BringSchoolsAsSelected(city, school,schoolID) {
    $.getJSON(
        'GetSchools.ajax',
        { townID: city.val(), Status: 1 },
        function(data) { 
        school.loadSelect(data);
        school.children("option[value='"+schoolID+"']").attr('selected', 'selected'); });
}

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('"','\\"');
//}



function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}

$(document).ready(function () {
    //Examples of how to assign the ColorBox event to elements
    if ($("a.contenteditor").colorbox != undefined && $("a.contenteditor").colorbox!=null)
            $("a.contenteditor").colorbox({width:"1024px",height:"768px"});

});
