(function($){

//{name:'x',value:123} => {x:123}
$.extend(Array.prototype,{
	pairsToObject: function() {
		var ret={};
		$.each(this, function(i,value){
			ret[value.name]=value.value;
		});
		return ret;
	}
});
//Trim
String.prototype.trim=function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//striptags
String.prototype.striptags=function(allowed) {
	allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
//        commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
        commentsAndPhpTagsAndScript = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>|<(?:script)[\s\S]*>.*<[\s\S]*\/(?:script)[\s\S]*>/gi;
    return this.replace(commentsAndPhpTagsAndScript, '').replace(tags, function ($0, $1) {
        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
    });
}
//cut string to length
String.prototype.cutstr=function(length, cutchr, postfix) {
	var cutchrpos,ret;
	if(length == undefined) length = 80;
	if(cutchr == undefined) cutchr = ' ';
	if(postfix == undefined) postfix = '&hellip;';
	if(this.length<length) {
		ret = this;
	} else {
		cutchrpos = this.substr(0, length).lastIndexOf(cutchr);
		if(cutchrpos == -1) ret = this.substr(0, length)+postfix;
		else ret = this.substr(0, cutchrpos)+postfix;
	}
	return ret.toString();
}
//encode emoticons
String.prototype.emoticon=function() {
	return this.toString();
}
//htmlspec
String.prototype.htmlspecialchars = function() {
	return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#039;').replace(/"/g, '&quot;');
}
//normalize
String.prototype.normalize = function() {
	ret = '';
	test = this.split('');
	s = 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ';
	r = 'ouooueauiOUOOUEAUI'.split('');
	for(i=0; i<test.length; i++) {
		ret+= test[i].replace(s[s.indexOf(test[i])], r[s.indexOf(test[i])]);
	}
	return this.replace(test.join(''), ret);
}


//realDimension
$.fn.realDimension=function(method,args){
	args=args || [];
	if($(this).is(':hidden')){
		var measureElement=$(this).clone().css({'position':'absolute','left':-10000}).appendTo($('body')).show();
		var ret=measureElement[method].apply(measureElement,args);
		measureElement.remove();
		return ret;
	}
	return $(this)[method].apply($(this),args);
}

/*
 * AjaxLoader
 */
window.ajaxLoader={}
window.ajaxLoader.extend=$.extend;
var aL=window.ajaxLoader;
window.ajaxLoader.extend({
	slotsLoaders: {},
	addSlotLoader: function(slotselector) {
//		return;
		if(typeof(aL.slotsLoaders[slotselector])=='undefined')
		{
			var slot=$(slotselector);
			if(slot.get().length){
				var slotloader=$("<div class='ajax-loader-slot'></div>")
					.appendTo($("body"))
					.css({
						height: slot.outerHeight(),
						width: slot.outerWidth(),
						top:  slot.offset().top,
						left:  slot.offset().left
					});
				slot.css({opacity:'0.2'});

				aL.slotsLoaders[slotselector]=slotloader;
			}
		}
	},
	removeSlotLoader: function(slot) {
//		return;
		if(aL.slotsLoaders[slot]) {
			aL.slotsLoaders[slot].remove();
			$(slot).css({opacity:'1'});
			delete(aL.slotsLoaders[slot]);
		}
	},
	removeSlotLoaders: function(){
//		return;
		$.each(aL.slotLoaders,function(i,slot){
			aL.removeSlotLoader(slot);
		});
	}
});
//kill sb
$.fn.sb=function(){
	return;
}

/**
 * régió
 */
$.fn.mRegionSelect=function(options)
{
	$(this).each(
		function(elementIndex)
		{
			if(!$(this).attr('data-region-added'))new $mRegionSelect(elementIndex,this,options);
		}
	);
}

//konstruktor
$.mRegionSelect=function(elementIndex,element,options)
{
	this.elementIndex=elementIndex;
	this.element=element;

	var dataoptions={};
	if($(this.element).attr('data-regiondata'))	{
		dataoptions=$.parseJSON($(this.element).attr('data-regiondata'));
		$(this.element).attr('data-region-added',1)
	}

	this.options={};
	$.extend(
		this.options,
		$mRegionSelect.defaultOptions,
		options,
		dataoptions
	);
	this.loadTimer=null;
	this.loading();
	this.bindEvents();
	this.changeRegion(this.options.initRegionID);
}

//shortcutok
$mRegionSelect=$.mRegionSelect;
$mRegionSelect.fn=$mRegionSelect.prototype={};
$mRegionSelect.fn.extend = $mRegionSelect.extend = $.extend;

//statikus v�ltoz�k, f�ggv�nyek:
$mRegionSelect.extend(
{
	defaultOptions: {
		version: 'v1',
		ajaxURL: '/getregion.php?isajax=1',

		initRegionID: 1,
		onChange: function(){}
	},

	//Itt adhat�ak meg a konstansok
	constants: {

	}
	//statikus fgvk
});

//Instance f�ggv�nyei
$mRegionSelect.fn.extend({
	loading: function(regionID) {
		if(typeof(regionID)=='undefined') regionID=this.options.initRegionID;
		$(this.element).html("<option value='"+regionID+"'>letöltés...</option>");
	},
	bindEvents: function() {
		var This=this;
		$(this.element).bind(
			'change',
			function() {
				if(This.loadTimer){
					clearTimeout(This.loadTimer);
				}
				This.loading(this.value);
				This.options.onChange(this);
				This.changeRegion($(this).val());
			}
		);
	},
	changeRegion: function(regionID)
	{
		var This=this;
		$(This.element).attr('disabled',true);
		var versionUrl;
		if(This.options.version=='v1'||This.options.version=='v2')
		{
			versionUrl=This.options.ajaxURL+"?act="+This.options.version+'&regionid='+regionID;
		}
		else if(This.options.version=='inst')
		{
			versionUrl="/institute.php?act=getinstitute&id="+regionID;
		}
		$.ajax(
			{
				type: 'GET',
				url: versionUrl,
				dataType: "html",
				success:function(req)
				{
					$(This.element).html(req);
					$(This.element).attr('disabled',false);
				}
			}
		);
	}
});




})(jQuery)


function AjaxLoadingGif() {
	var secNum=0;
	var count=0;
	var activeNumList=new String();
	var loadindDivId=new String("ajaxloadergif");

	this.newAjaxRequest=function(){
        return 1;
	}

	this.doneAjaxRequest=function(sn){}

	this.requestIsLive=function(sn){}

	this.addLoadingGif=function(){}

	this.removeLoadingGif=function(){};
	this.getString=function(sn){return '';};
	this.getCount=function(){return 1;};
}
window.ALG=new AjaxLoadingGif();

window.VideoStat=function(videoid){
	this.videoid=videoid;
	var This=this;
	This.played=false;
	this.play=function(){
		if(!This.played){
			jQuery.ajax('/videoview.php?nooutput=1&isajax=1&videoid='+This.videoid);
			This.played=true;
		}
	}
};

