Registry = function() {};
Registry.prototype._hash = Array();
Registry.prototype.set = function(key, value) {
    if (this._hash[key] != undefined) return false;
    this._hash[key] = value;
}
Registry.prototype.get = function(key) {
    if (this._hash[key] != undefined) return this._hash[key];
    return null;
}
Registry.prototype.unset = function(key) {
    if (this._hash[key] != undefined) delete this._hash[key];
}
var registry = new Registry();

$(document).ready(function(){ 
    $(document).pngFix();
});

function changeCaptcha(captchaImg, module, entity) {
	var newCaptcha = base + 'utils/captcha/';
	if (module != undefined) newCaptcha += module+'/';
	if (entity != undefined) newCaptcha += entity+'/';
	newCaptcha += Math.random();
	$('#'+captchaImg).attr('src', newCaptcha);
}

function toggleElm(elm) { $(elm).css('display', ($(elm).css('display') == 'none' ? '' : 'none')); }
function animToggleElm(elm) { $(elm).slideToggle('slow'); }

function request(dataToSend, successHandler, failHandler, method) {
    //dataToSend.hash = makeHash(dataToSend);
    var _url = base;
    if (dataToSend.url != undefined) {
    	_url = dataToSend.url;
    	if (method == undefined || method == 'GET')
    		dataToSend = {};
    }
    
    $.ajax({
        type:(method != undefined) ? method : 'GET',
        url:_url,
        dataType:'json',
        data:dataToSend,
        //contentType:"application/x-www-form-urlencoded",
        //beforeSend:onBeforeSend(dataToSend),
        success:function(data) { successHandler(data); },
        error:failHandler
    });
}

function failure(message) {
	if (message != undefined && (typeof message == 'object')) message = "Произошла ошибка при получении ответа от сервера! Извините за неудобство!";
	var message = message == undefined ? "Произошла ошибка при получении ответа от сервера! Извините за неудобство!" : message;
	alert(message);
}

function initSimpleEditor() {
	tinyMCE.init({
		mode : "none",
		baseURL :  base + 'js/editor',
		theme : "advanced",
		plugins : "inlinepopups",
		
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,outdent,indent,hr,|,emotions,link,unlink,image",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		apply_source_formatting : true,
		relative_urls : false
	});
}

function linkEditor(textArea) { if (!tinyMCE.get(textArea)) tinyMCE.execCommand("mceAddControl", false, textArea); }
function unlinkEditor(textArea) { if (tinyMCE.get(textArea)) tinyMCE.execCommand('mceRemoveControl', false, textArea); }