/*var Loader = {
		_cmds		: 'www,wap,ajax,login',
		_url		: '',
		_session 	: '',
		_subKey		: '',
		_lang		: 0,
		_di			: '',
	setUrl	: function (geturl,params){
		if (!geturl) var geturl='/b/';
		if (!params) var params='ajax';
		this._url = geturl+'?'+params; 
	},
	subKey	: function (subkey){
		this._subKey = subkey; 
	},
	lang	: function (language){
		if((language<1)||(language>200)||!language) var language=2;
		this._lang = language; 
	},
	init	: function (){
		var allVars = this._getUrlVars();
		if (allVars['di']) this._di	= allVars['di'];
		if (allVars['sk']) this._subKey= allVars['sk'];
		if (allVars['ln']) this._lang	= allVars['ln'];
		this.setUrl();
		this._cmds = this._cmds.split(',');
	},
	loads	: function(){
		var url = this._url+'&sk='+this._subKey+'&ln='+this._lang;
		$.ajax({
			type:	'POST',
			url:	url,
			cache:	false,
			global:	false,
			success: function(data){
				var content = datas.split("\n");
				$.each(content, function(index, tmp) {
					var tmps = tmp.split('|||');
					eval('$('+tmps[0]+').'+tmps[1]+'('+tmps[2]+')');
				});
			},
			error:	function(xhr,err,e){ 
				alert( "Bad request or server overloaded." ); 
				return false;
			}
		});
	},
	_getUrlVars	: function (){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('='); 
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
}

var Loader = {
		_cmds		: 'www,wap,ajax,login',
		_url		: '',
		_session 	: '',
		_subKey		: '',
		_lang		: 0,
		_di			: '',
	setUrl	: function (geturl,params){
		if (!geturl) var geturl='/b/';
		if (!params) var params='ajax';
		this._url = geturl+'?'+params; 
	},
	subKey	: function (subkey){
		this._subKey = subkey; 
	},
	lang	: function (language){
		if((language<1)||(language>200)||!language) var language=2;
		this._lang = language; 
	},
	init	: function (){
		var allVars = this._getUrlVars();
		if (allVars['di']) this._di	= allVars['di'];
		if (allVars['sk']) this._subKey= allVars['sk'];
		if (allVars['ln']) this._lang	= allVars['ln'];
		this.setUrl();
		this._cmds = this._cmds.split(',');
	},
	postt		: function(){
		var url = this._url+'&sk='+this._subKey+'&ln='+this._lang;
		$.ajax({
			type:	'POST',
			url:	url,
			data:	{neshto:'takowa'},
			cache:	false,
			global:	false,
			success: function (data) {
	           return data;
	        },
			error:	function(xhr,err,e){ 
				alert( "Bad request or server overloaded." ); 
				return false;
			}
			statusCode: {
				404: function() {
			    	alert('Page not found');
			    }
			}
		}).responseText;
	},
	_getUrlVars	: function (){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('='); 
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
};*/

var Loader = {
		_cmds		: 'www,wap,ajax,login,wait',
		_url		: '',
		_session 	: '',
		_subKey		: '',
		_lang		: 0,
		_di			: '',
	setUrl	: function (geturl,params){
		if (!geturl) var geturl='/';
		if (!params) var params='ajax';
		this._url = geturl+'?'+params; 
	},
	subKey	: function (subkey){
		if(subkey)this._subKey = subkey; 
	},
	lang	: function (language){
		if((language<1)||(language>200)||!language) var language=2;
		this._lang = language; 
	},
	init	: function (){
		var allVars = this._getUrlVars();
		if (allVars['di']) this._di	= allVars['di'];
		if (allVars['sk']) this._subKey= allVars['sk']; 
		if (allVars['ln']) this._lang	= allVars['ln'];
		this.setUrl();
		var nn = this._cmds;
		var stb = nn.split(',');
//		this._cmds = stb;
		var cookies = this._get_cookies_array();
		this._session = cookies['sid'];
	},
zarejdane	: function (cmd,datas,deb) {  
	if (!deb && (this._url == '')) this.setUrl();
	if (this._lang == 0) this.lang();
	
	if (deb != true){ 
		var url = this._url+'&di='+this._di+'&ln='+this._lang;
		
		if (this._subKey != ''){
		var url = url + '&sk='+this._subKey;
		}
		var dis = {nameD:cmd,mmore:datas,sk:this._subKey,di:this._di,ln:this._lang,sid:this._session};
	}else{
		var url = '/wait/?';
		if (this._subKey) var url = url + 'sk='+this._subKey;
		if(cmd==false) cmd='GetMoore';
		var dis = {nameD:cmd,sk:this._subKey,di:this._di,ln:this._lang,sid:this._session};
	}
	/*{nameD:cmd,mmore:datas,sk:this._subKey,di:this._di,ln:this._lang}*/
	$.ajax({
		type:	'POST',
		url:	url,
		data:	dis,
		cache:	false,
		global:	false,
		success:function (datas) {
				var content = datas.split("\n");
				$.each(content, function(index, tmp) {
					var tmps = tmp.split('|||');
					switch(tmps[0]){
					    case "51":
					    	$(tmps[1]+"[class="+tmps[2]+"]").html(
					    			
					    			"<div class=\"hintBlue\">" +
					    			"<div class=\"hintBlueTop\">" +
					    			"<div class=\"hintBlueMiddle\">" + 
					    			Base64.decode(tmps[3]) +
					    			"</div></div>"+
					    			"<div class=\"hintBlueBottom\">&nbsp;</div>" +
					    			"</div>") ;
                        break;
						case "6": //inner HTML - zamestwane
							$(tmps[1]+"[id="+tmps[2]+"]").html(Base64.decode(tmps[3])).show();
						break;
						case "16":
							$(tmps[1]+"[name="+tmps[2]+"]").html(Base64.decode(tmps[3])).show();
						break;
						case "26":
							$(tmps[1]+"[class="+tmps[2]+"]").html(Base64.decode(tmps[3])).show();
						break;
						case "36":
							$(tmps[1]+"[type="+tmps[2]+"]").html(Base64.decode(tmps[3])).show();
						break;
						case "7": //append
							$(tmps[1]+"[id="+tmps[2]+"]").append(Base64.decode(tmps[3])).show();
						break;
						case "17":
							$(tmps[1]+"[name="+tmps[2]+"]").append(Base64.decode(tmps[3])).show();
						break;
						case "27":
							$(tmps[1]+"[class="+tmps[2]+"]").append(Base64.decode(tmps[3])).show();
							$("div#loader").hide();
						break;
						case "37":
							$(tmps[1]+"[type="+tmps[2]+"]").append(Base64.decode(tmps[3])).show();
						break;
						case "8": //prepend
							$(tmps[1]+"[id="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "18":
							$(tmps[1]+"[name="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "28":
							$(tmps[1]+"[class="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "38":
							$(tmps[1]+"[type="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "151":
							$('#grayBG').show();
							$(tmps[1]+'#'+tmps[2]).html(Base64.decode(tmps[3]));
							$(tmps[1]+'#'+tmps[2]).css('display','block').css('visibility','visible');
							$(tmps[1]+'#'+tmps[2]).prepend('<div id="dixito"><img src="/pics/img/close_light.png" height=24 width=24 id="closeButt" /></div>');
						break;
						case "152":
							$(tmps[1]+"[name="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "153":
							this._add_popup(tmps[3]);
//							$(tmps[1]+"[class="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "154":
							$(tmps[1]+"[type="+tmps[2]+"]").prepend(Base64.decode(tmps[3])).show();
						break;
						case "9":
							$(tmps[1]+"[class="+tmps[2]+"]").hide();
						break;
						case "10":
							$(tmps[1]+"[class="+tmps[2]+"]").hide().html('');
						break;
						case "12":
                        	alert(Base64.decode(numbers[1]));
                        break;
						case "44":
                        	$.cookie(Base64.decode(tmps[1]),Base64.decode(tmps[2]),Base64.decode(tmps[3]));
                        break;
						case "45":
                        	document.location.href=Base64.decode(tmps[1]);
                        break;
						case "46":
                        	$.cookie(Base64.decode(tmps[1]),null);
                        	this._subKey=null;
                        break;
						case "47":
                        	this._subKey=Base64.decode(tmps[1]);
                        	this._session=Base64.decode(tmps[2]);
                        break;
					}
				});
			},
			error:	function(xhr,err,e){ 
				alert( "Bad request or server overloaded. "); 
				return false;
			}
		});
	},
	_getUrlVars	: function (){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('='); 
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	_get_cookies_array : function() {
		var cookies = { };
		if (document.cookie && document.cookie != '') {
			var split = document.cookie.split(';');
			for (var i = 0; i < split.length; i++) {
				var name_value = split[i].split("=");
				name_value[0] = name_value[0].replace(/^ /, '');
				cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
			}
		}
		return cookies;
	},
	_add_popup : function(data) {
		$('#grayBG').show();
		$('div#popup').html(Base64.decode(data));
		$('div#popup').css('display','block').css('visibility','visible');
//		$(name).add(data).show();
		return true;
	},
	_hide_popup : function() {
		$('#grayBG').hide();
		$('din#popup').hide();
		$('din#popup').html('');
		$('div#popup').css('display','none').css('visibility','hidden');
		return true;
	}
};

var Base64 = {
		// private property
		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

		// public method for encoding
		encode : function (input) {
		    var output = "";
		    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		    var i = 0;

		    input = Base64._utf8_encode(input);

		    while (i < input.length) {

		        chr1 = input.charCodeAt(i++);
		        chr2 = input.charCodeAt(i++);
		        chr3 = input.charCodeAt(i++);

		        enc1 = chr1 >> 2;
		        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		        enc4 = chr3 & 63;

		        if (isNaN(chr2)) {
		            enc3 = enc4 = 64;
		        } else if (isNaN(chr3)) {
		            enc4 = 64;
		        }

		        output = output +
		        this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
		        this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		    }

		    return output;
		},

		// public method for decoding
		decode : function (input) {
		    var output = "";
		    var chr1, chr2, chr3;
		    var enc1, enc2, enc3, enc4;
		    var i = 0;

		    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		    while (i < input.length) {

		        enc1 = this._keyStr.indexOf(input.charAt(i++));
		        enc2 = this._keyStr.indexOf(input.charAt(i++));
		        enc3 = this._keyStr.indexOf(input.charAt(i++));
		        enc4 = this._keyStr.indexOf(input.charAt(i++));

		        chr1 = (enc1 << 2) | (enc2 >> 4);
		        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		        chr3 = ((enc3 & 3) << 6) | enc4;

		        output = output + String.fromCharCode(chr1);

		        if (enc3 != 64) {
		            output = output + String.fromCharCode(chr2);
		        }
		        if (enc4 != 64) {
		            output = output + String.fromCharCode(chr3);
		        }

		    }

		    output = Base64._utf8_decode(output);

		    return output;

		},

		// private method for UTF-8 encoding
		_utf8_encode : function (atring) {
			if(atring == null) {
				return '';
			}
		    var string = atring.replace('/\r\n/g',"\n");
		    var utftext = "";

		    for (var n = 0; n < string.length; n++) {

		        var c = string.charCodeAt(n);

		        if (c < 128) {
		            utftext += String.fromCharCode(c);
		        }
		        else if((c > 127) && (c < 2048)) {
		            utftext += String.fromCharCode((c >> 6) | 192);
		            utftext += String.fromCharCode((c & 63) | 128);
		        }
		        else {
		            utftext += String.fromCharCode((c >> 12) | 224);
		            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
		            utftext += String.fromCharCode((c & 63) | 128);
		        }

		    }

		    return utftext;
		},

		// private method for UTF-8 decoding
		_utf8_decode : function (utftext) {
		    var string = "";
		    var i = 0;
		    var c = c1 = c2 = 0;

		    while ( i < utftext.length ) {

		        c = utftext.charCodeAt(i);

		        if (c < 128) {
		            string += String.fromCharCode(c);
		            i++;
		        }
		        else if((c > 191) && (c < 224)) {
		            c2 = utftext.charCodeAt(i+1);
		            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
		            i += 2;
		        }
		        else {
		            c2 = utftext.charCodeAt(i+1);
		            c3 = utftext.charCodeAt(i+2);
		            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
		            i += 3;
		        }

		    }

		    return string;
		}
	};



/*
var  TimerOn = {
	_counter	: 0,
	_counter_end: 0,
	_cnt		: 0,
	init		: function(alo){alert('edno');
		if(alo<1)return false;
		if(alo <= 10) this._counter_end = alo;
		if(alo >= 1000)  this._counter_end = parseInt(alo / 1000);
		setTimeout(function(){
			TimerOn.counter();
		},	1000);
	},
	counter		: function(){alert('JHGjghjgjGJgjhgjh');
		this._counter=this._counter + 1;
	},
	_printCount	: function(){
		this._cnt ++;
		$('div.counter_civik').html(this._cnt);
		$('div.counter_civik').show();
		return true;
	}
};

var Test = (function(){
	 function _class() {
		 var _self = this; // <== this is solution part one
		 this.func1 = function() {
			 setTimeout(this.func2, 100);
		 };
		 this.func2 = function() {
			 alert(_self.func3()); // <== this is solution part two
		 };
		 this.func3 = function() {
			 return 'hello world';
		 };
	 };
	 return _class;
})();*/ 
