//setupElementsForPrototype();

/*Element.prototype.xxx = function() {
	alert("xxx");
}*/

function setupBlackBg() {
	setOpacity(document.getElementById("BlackBg"),80);
	setInterval(function(){alignBlackBg()},200);
}

function alignBlackBg() {
	//window.status=Math.random()*100;
	var _bg=document.getElementById("BlackBg");
	var _bgc=document.getElementById("BlackBgContent");
	var _bgClose=document.getElementById("BlackBgClose");
	var w=Math.round((getWindowWidth()-getElementWidth(_bgc))/2);
	w+=getPageLeft();
	var h=Math.round((getWindowHeight()-getElementHeight(_bgc))/2);
	h+=getPageTop();
	_bgClose.style.left=getPageLeft()+"px";
	_bgClose.style.top=getPageTop()+"px";
	_bgc.style.left=w+"px";
	_bgc.style.top=h+"px";
	//_bg.style.width=getPageWidth()+"px";
	_bg.style.left=getPageLeft()+"px";
	h=Math.max(getPageHeight(),getWindowHeight());
	_bg.style.height=h+"px";
	
	var m=document.getElementById("Message");
	m.style.left=Math.round((getWindowWidth()-m.offsetWidth)/2)+"px";
	m.style.top=getPageTop()+"px";
}

function closeBlackBg() {
	var _bg=document.getElementById("BlackBg");
	var _bgc=document.getElementById("BlackBgContent");
	var _bgClose=document.getElementById("BlackBgClose");
	_bg.style.display="none";
	_bgc.style.display="none";
	_bgClose.style.display="none";
	
	document.getElementsByTagName("body")[0].style.overflow="scroll";
}

function openBlackBg(txt) {
	var _bg=document.getElementById("BlackBg");
	var _bgc=document.getElementById("BlackBgContent");
	var _bgClose=document.getElementById("BlackBgClose");
	_bg.style.display="block";
	_bgc.innerHTML=txt;
	alignBlackBg();
	_bgc.style.display="block";
	_bgClose.style.display="block";
	
	comfortableAllForm();
	
	document.getElementsByTagName("body")[0].style.overflow="hidden";
}

function closeMessage() {
	var m=document.getElementById("Message");
	m.style.display="none";
}

function message(msg) {
	var m=document.getElementById("Message");
	m.innerHTML=msg;
	m.style.display="block";
	setOpacity(m,80);
	setTimeout(closeMessage,2000);

	alignBlackBg();
}

var userAjax;
var userAjax2;
var toolTip = null;

function setup() {
	//incl("../komondorstudio.com/scripts.js");
	//include("http://privatnet.hu/scripts.js");
	//alert(document.getElementsByTagName('head')[0].innerHTML);
	setupBlackBg();
	userAjax=new TAjax();
	userAjax2=new TAjax();
	toolTip = new TToolTip(null,null,null);
}

function user(op_in,post) {
	//switch (op_in) {
		//case 'login_form': case 'registrate_form': case 'logout':
			userAjax.onSend=function(){openBlackBg('<img src="images/loading.gif" alt="Betöltés" title="Betöltés"/>');};
			userAjax.onReady=function(t){openBlackBg(t);EvalResponse(t);};
			if ((typeof post).toLowerCase() == "object") {
				var a=post;
				a.op=op_in;
				userAjax.send("./user.php",{},a,true);
			} else userAjax.send("./user.php",{},{op:op_in},true);
		//break;
		//default: openBlackBg('NAA HELLO'); break;
	//}
}

function user2(op_in,post) {
	//switch (op_in) {
		//case 'login_form': case 'registrate_form': case 'logout':
			userAjax2.onSend=function(){message('<img src="images/loading.gif" alt="Betöltés" title="Betöltés"/>');};
			userAjax2.onReady=function(t){message(t);EvalResponse(t);};
			if ((typeof post).toLowerCase() == "object") {
				var a=post;
				a.op=op_in;
				userAjax2.send("./user.php",{},a,true);
			} else userAjax2.send("./user.php",{},{op:op_in},true);
		//break;
		//default: openBlackBg('NAA HELLO'); break;
	//}
}


function checkForEnter(e,t,f) {
	//if ((typeof window.event).toLowerCase()!="undefined") e=event;
	e=e||event;
	//return !(window.event && window.event.keyCode == 13);
	//if (e && e.which == 13)
	var c=e.which||e.keyCode;
	if (c==13) {
		//alert(typeof f);
		if (f) f.apply(t,[]);
		return false;
	}
}

function checkForKey(e,t,k,f) {
	e=e||event;
	var c=e.which||e.keyCode;
	if (c==k) {
		f.apply(t,[]);
		return false;
	}
}

function comfortableForm(form) {
	var c=form.firstChild;
	var b=true;
	var a=new Array();
	if (c) while (b) {
		if (c.nodeType==1) {
			if (c.nodeName.toLowerCase()=="input") if ((c.type.toLowerCase()=="text")||(c.type.toLowerCase()=="password")) {
				a.push(c);
			}
		}
		if (c==form.lastChild) b=false; else c=c.nextSibling;
	}
	for (var i=0;i<a.length;i++) {
		a[i].onkeypress=function(e) {
			e=e||window.event;
			var c=e.which||e.keyCode;
			if (c==13) {
				//alert("enter");
				var e=getNextFormElement(this,this.form);
				if (e) e.focus(); else this.form.onsubmit();
				return false;
			}
		}
	}
	if (a[0]) a[0].focus();
}

function comfortableAllForm() {
	var f=document.getElementsByTagName("form");
	for (i=0;i<f.length;i++) comfortableForm(f[i]);
	//alert(f.length);
}

function getNextFormElement(e,form) {
//return e.getNextElementEx("input",null);
//return e.getNextElementEx("input",["type","type"],["text","password"]);
	var c=e;
	while (c!=form.lastChild) {
		c=c.nextSibling;
		if (c.nodeType==1) {
			if (c.nodeName.toLowerCase()=="input") if ((c.type.toLowerCase()=="text")||(c.type.toLowerCase()=="password")) {
				return c;
			}
		}
	}
	return false;
}

/*Element.prototype.getNextElementEx = function(nodeNames, attributes, attributesValues) {
	//if (!nodeNames) return false;

	var t_n = (nodeNames)?((typeof nodeNames).toLowerCase()):(false);
	var t_a = (attributes)?((typeof attributes).toLowerCase()):(false);
	var t_v = (attributesValues)?((typeof attributesValues).toLowerCase()):(false);

	if (t_n) if (!(t_n in {"object":1,"array":1,"string":1})) return false;
	if (t_a) if (!(t_a in {"object":1,"array":1,"string":1})) return false;
	if (t_v) if (!(t_v in {"object":1,"array":1,"string":1})) return false;

	var c=this;
	var form=c.parentNode;
	var b=false;
	while (c!=form.lastChild) {
		c=c.nextSibling;
		if (c.nodeType==1) {
			if (attributes) {
				b=false;
				var attr="";
				for (var i=0;i<attributes.length;i++) {
					attr=attributes[i];
					if (eval("c."+attr)) if (eval("c."+attr).toLowerCase()==attributesValues[i]) {
						//alert(eval("c."+attr));
						b=true;
						break;
					}
				}
			} else b=true;
			if (t_n=="string") if ((c.nodeName.toLowerCase()==nodeNames)&&(b)) return c;
				//else if ((c.nodeName.toLowerCase() in nodeNames)&&(b)) return c;
		}
	}
	return false;
}*/

/*HTMLElement.prototype.rejt = function() {  
    this.style.display = "none";  
}*/

/*var TToolTip = Class({
	construct: function () {
		this.arguments = arguments;
		this.tips=this.arguments[0];
		this.t_id = 0;
		this.i_id = 0;
		this.opacity = 100;
		this.maxOpacity = 80;
		this.timeoutTime = 700;
		this.visible = false;
		this.h = document.createElement("DIV");
		setOpacity(this.h,this.maxOpacity);
		this.h.innerHTML="";
		this.h.style.position="absolute";
		this.h.style.display="none";
		this.h.style.width="auto";
		this.h.style.height="auto";
		this.h.style.padding="5px";
		this.h.style.color="black";
		this.h.style.backgroundColor="#ffff99";
		this.h.style.border="1px solid black";
		document.getElementsByTagName("BODY")[0].appendChild(this.h);
	},
	Show: function (obj_in, tip_in) {
		if (!tip_in||!obj_in) return false;
		if (this.t_id!=0) clearInterval(this.t_id);
		var tip=(this.tips&&this.tips[tip_in])?this.tips[tip_in]:tip_in;
		this.h.innerHTML=tip;
		this.h.style.left=(getElementLeft(obj_in)+getElementWidth(obj_in))+"px";
		//this.h.style.top=(getElementHeight(obj_in)+getElementTop(obj_in))+"px";
		this.h.style.top=getElementTop(obj_in)+"px";
		this.h.style.display="inline-block";
		this.opacity=this.maxOpacity;
		setOpacity(this.h,this.opacity);
		this.visible=true;
	},
	Hide: function () {
		this.HideFade();
	},
	_Hide: function () {
		this.h.style.display="none";
		this.visible=false;
		clearTimeout(this.t_id);
		this.t_id=0;
		clearInterval(this.i_id);
		this.i_id=0;
	},
	HideTimeout: function () {
		if (this.t_id!=0) clearInterval(this.t_id);
		var _t=this;
		this.t_id = setTimeout(function(){_t._Hide();},this.timeoutTime);
	},
	HideFade: function () {
		//if (this.t_id!=0) clearInterval(this.t_id);
		if (this.i_id!=0) return false;
		var _t=this;
		this.i_id = setInterval(function(){
			_t.opacity-=15;
			_t.opacity=(_t.opacity<=0?0:_t.opacity);
			_t.opacity=(_t.opacity>=_t.maxOpacity?_t.maxOpacity:_t.opacity);
			setOpacity(_t.h,_t.opacity);
			if (_t.opacity<=0) {
				_t.opacity=0;
				_t._Hide();
			}
		},40);
		//this.t_id = setTimeout(function(){_t._Hide();},this.timeoutTime);
	}
});*/

function deletePic(id_in) {
	if (confirm("Biztosan törli a képet?")) user2("gallery_delete",{id:id_in});
}
function editPic(id_in) {
	user("gallery_edit",{id:id_in});
}

function opt(id_in,gallery) {
//var s = '<img alt="Törlés" title="Törlés" style="cursor:pointer" src="./images/icons/delete.png" onclick="toolTip.Hide();deletePic('+id_in+')"/><img alt="Szerkesztés" title="Szerkesztés" style="cursor:pointer" src="./images/icons/edit.png" onclick="toolTip.Hide();editPic('+id_in+')"/><br/><input type="checkbox" class="checkbox" onclick="var a=(this.checked?\'1\':\'0\');user2(\'gallery_picture\',{id:\''+id_in+'\',value:a})"'+(gallery?' checked="yes"':'')+'/><span>galériában</span>';
var s = '<img alt="Törlés" title="Törlés" style="cursor:pointer" src="./images/icons/delete.png" onclick="toolTip.Hide();deletePic('+id_in+')"/><input type="checkbox" class="checkbox" onclick="var a=(this.checked?\'1\':\'0\');user2(\'gallery_picture\',{id:\''+id_in+'\',value:a})"'+(gallery?' checked="yes"':'')+'/><span>galériában</span>';
return s;//"Fejlesztés alatt...";
}

//á
