// JavaScript Document
function addEvent(obj, evType, fn, useCapture) {	if (obj.addEventListener) {	obj.addEventListener(evType,fn,useCapture);		return true;	} else if(obj.attachEvent){		return obj.attachEvent("on"+evType,fn);	} else {		return false;	}}
function getElementsByClass(searchClass,node,tag) {	var classElements = new Array();	if (node == null) node = document;	if (tag == null) tag = '*';	var elems = node.getElementsByTagName(tag);	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");	var i = 0;	for (var j = 0; j < elems.length; j++) {		if ( pattern.test(elems[j].className) ) {			classElements[i++] = elems[j];		}	}	return classElements;}
function getFirstElementByClass(searchClass,node,tag) {	if (node == null) node = document;	if (tag == null) tag = '*';	var elems = getElementsByClass(searchClass,node,tag);	if (elems.length > 0) return elems[0];	return null;}
function hiddenAllSelect() {var s = document.getElementsByTagName('select');for (i=0; i<s.length; i++) {		s[i].style.visibility = 'hidden';	}}
function visibleAllSelect() {var s = document.getElementsByTagName('select');for (i=0; i<s.length; i++) {		s[i].style.visibility = 'visible';	}}
function createXMLHttpRequest() {	var types = ['Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0',  'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];	for (i in types) { 		try {			return new ActiveXObject(types[i]);		} catch(e) {}	}	try { 	return new XMLHttpRequest();	} catch(e) { }	return false;}

function popupInit() {	var links = getElementsByClass("popup",null,"a");	for(var i = 0; i < links.length; i++) { links[i].onclick = function() { popit(this.href,this.title,location.href,location.search);	return false;		}}}
addEvent(window, 'load', popupInit );
function popit(url,stitle,slocation,req){var spost='link='+slocation;if(req!='')spost=spost+req;AJAXrequest(url,popupLayer,stitle,'post',spost);}

function popupLayer(req,xtitle) {	if (req.readyState == 4) {if (req.status == 200) {popup(req.responseText,xtitle,540,460);  }	}}
function AJAXrequest(url, myfunction,xtitle, method, post) {	var req = createXMLHttpRequest();	if (method == null) method = 'post';	if (post == null) post = '';	url += (( url.indexOf('?') != -1 )?"&":"?")+('ajax=1');	req.open(method, url, true);	req.setRequestHeader('Ajax', 'true');	if (method == 'post') {		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-2');	}	req.onreadystatechange = function() {		myfunction(req,xtitle);	};req.send(post);}


function loadToLayer(req,sLayer) {if (req.readyState == 4) {if (req.status == 200) {;sLayer.innerHTML =req.responseText;	  }	else {sLayer.innerHTML ='hiba az oldal betöltésekor';}	}}
function AJAXload(url, myfunction,Layer, method, post) {var req = createXMLHttpRequest(); if (method == null) method = 'post';	if (post == null) post = '';	url += (( url.indexOf('?') != -1 )?"&":"?")+('ajax=1'); 	req.open(method, url, true);	req.setRequestHeader('Ajax', 'true');	if (method == 'post') {		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	}	req.onreadystatechange = function() {		myfunction(req,Layer);	};req.send(post);}
function popupClose() {	;if(is_ie){visibleAllSelect();var xLAYER =document.getElementById('Xlayer')}else var xLAYER =document.body;document.onkeydown=null;if ( document.getElementById('popupLayer') ) {xLAYER.removeChild( document.getElementById('popupLayer') );	}	if ( document.getElementById('popupAlpha') ) {		xLAYER.removeChild( document.getElementById('popupAlpha') );return false;	}	//return false;
}

function getRegio(regio){
var dvregio=document.getElementById('DVregio');
AJAXload('./include/stat/loadregio.php?regio='+regio.value,loadToLayer,dvregio,'post','');
}

function popupwindowLayer(req,xtitle,ww,wh) {	if (req.readyState == 4) {if (req.status == 200) {popup(req.responseText,xtitle,ww,wh);	  }	}}
function popwindow(url,post,title,ww,wh){var req = createXMLHttpRequest();	url += (( url.indexOf('?') != -1 )?"&":"?")+('ajax=1'); 	req.open('post', url, true);	req.setRequestHeader('Ajax', 'true');	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	req.onreadystatechange = function() {		popupwindowLayer(req,title,ww,wh);	};req.send(post);}

function popLinkInit() {	var links = getElementsByClass("popLink",null,"a");	for(var i = 0; i < links.length; i++) { links[i].onclick = function() { popwindow('./include/stat/loadPage.php?link='+this.href,'',this.title,500,320);	return false;		}}}
addEvent(window, 'load', popLinkInit );

function popalert(alerttext){popup(alerttext+"<hr><br><div onClick='popupClose();' class='popsubmit'> OK</div>","Rendszerüzenet",380,170);document.onkeydown=popupClose;}
function popalertWindow(title,width,height,alerttext){popup(alerttext+"<br><hr><div onClick='popupClose();' class='popsubmit'> OK</div>",title,width,height);document.onkeydown=popupClose;}

function popup(xtext,xtitle,xwidth,xheight){
			if(xheight>=(screen.AvailHeight-200))xheight=screen.AvailHeight-200;
			if (is_ie) { hiddenAllSelect(); 
	     var xLAYER =document.getElementById('Xlayer');
	     } else var xLAYER =document.body;
			var oldDiv =document.getElementById('popupLayer');
			if(oldDiv){popupClose();};
			var xdiv = document.createElement("div");
			document.onkeydown=null;
			xdiv.className = "popupLayer";
			xdiv.setAttribute("id", "popupLayer");
			xdiv.style.width=xwidth+'px';
			xdiv.style.height=xheight+'px';
			xdiv.style.top= (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )+(xheight/2)+'px';

			xLAYER.appendChild(xdiv);

			var dtext = document.createElement("div");
			xdiv.appendChild(dtext);
			dtext.className = "popuptext";
			dtext.setAttribute("id", "popuptext");
			dtext.style.height=(xheight-20)+'px';
			dtext.style.width=(xwidth-30)+'px';
			dtext.innerHTML = xtext;
			var closeLink = document.createElement("div");
			xdiv.insertBefore(closeLink, xdiv.firstChild);
			closeLink.className = 'popupClose';
			closeLink.style.width=(xwidth-29)+'px';
			var h1 = document.createElement("h1");
			h1.appendChild( document.createTextNode(xtitle) )
			closeLink.appendChild( h1 );

			var closeLinkA = document.createElement("div");
			closeLink.appendChild(closeLinkA);
			closeLinkA.setAttribute("title", 'bezár');
			closeLinkA.appendChild( document.createTextNode("X") )
			closeLinkA.onclick = popupClose;

			var popupAlphaDiv = document.createElement("div");
			xLAYER.appendChild(popupAlphaDiv);
			popupAlphaDiv.className = "popupAlpha";
			popupAlphaDiv.setAttribute("id", "popupAlpha");
			popupAlphaDiv.style.height=document.body.clientHeight+'px';
			popupAlphaDiv.style.filter="alpha(opacity=65)";

			var inputs = dtext.getElementsByTagName('input');
			for(var i=0;i<inputs.length;i++) {
			if(inputs[i].type=='text'){inputs[i].focus(); inputs[i].select();break;}
			}
 
}

