//***browsers
var ns4=document.layers;
var ns6=window.navigator.userAgent.toLowerCase().match(/gecko/);
var opera=window.navigator.userAgent.toLowerCase().indexOf('opera') != -1;
var ie4=(document.all && !opera);

//*** névtelen új ablak nevéhez:
var wnow = new Date(); 
var wszam = wnow.getTime();

//********
var pop_div_tohide =new Array;


//****** link image ****
var img_on  = "img/on.gif";
var img_off = "img/off.gif";

function imgover(imgname) {
img_on = new Image;
img_on = "img/on.gif";
imgname.src = img_on;
}
function imgout(imgname) {
img_off = new Image;
img_off = "img/off.gif";
imgname.src = img_off;
}

//*** kezelői ablak********
function a()
{
	window.open('adm','mywin'+wszam);
}

////////////////////////////////////////////////////////////////////////
//Elemek elrejtése IE alatt, ha a menü ráhajlik:
//az elrejtendő elem ID-je: pl. <select name="test1" id="test1">
//az elrejtendő elemek tömbje: pl. <body onload="ie_menu_tohide =['test1', 'test2'];">
var ie_menu_tohide=new Array();
//////////////////////////////////////////////////////////////////////////

//************
function almenu_mutat(s)
{
	if(ie4)
	{
		document.all[s].style.visibility="visible";
		if(ie_menu_tohide.length>0)
		{
			for (i=0;i<ie_menu_tohide.length;i++)
			{
				if(document.all[ie_menu_tohide[i]])
				{
				   document.all[ie_menu_tohide[i]].style.visibility="hidden";
				}
			}
		}
	}
	else
	{
		document.getElementById(s).style.visibility = "visible";
	}
}

//************
function almenu_rejt(s)
{
	if(ie4)
	{
		document.all[s].style.visibility="hidden";
		if(ie_menu_tohide.length>0)
		{
			for (i=0;i<ie_menu_tohide.length;i++)
			{
				if(document.all[ie_menu_tohide[i]])
				{
				   document.all[ie_menu_tohide[i]].style.visibility="visible";
				}
			}
		}
	}
	else
	{
		document.getElementById(s).style.visibility = "hidden";
	}
}


/////////////////////////////////////////////////////////////////////
//***** hasznos képernyő méret
var sw,sh;

if( (opera||ns4) && (typeof( window.innerWidth ) == 'number'))
{
	if(opener)
	{
		sw = window.opener.innerWidth;
		sh = window.opener.innerHeight;
		//alert('Nem IE opener ' +sw+' * '+sh);
	}
    		
	else if(window.parent)
	{
		sw = window.parent.innerWidth;
		sh = window.parent.innerHeight;
		//alert('Nem IE window.parent ' +sw+' * '+sh);
	}

	else
	{
		sw = window.innerWidth;
		sh = window.innerHeight;
		//alert('Nem IE ' +sw+' * '+sh);
	}
}
else
{
	sw=window.screen.width;
	sh=window.screen.height;
	//alert('IE ' +sw+' * '+sh);
}

////////////////////////////////////////////////////////////////////

//*****Resize opera és ns4 *****
function reload_opera_ns4(init,sw,sh)
{
	if (init==true)
	{
		if (opera||ns4)
		{
    			//document.pgW=parent.innerWidth;
    			document.pgW=sw;
    			
    			//document.pgH=parent.innerHeight;
    			document.pgH=sh;
    			    			
    			onresize=reload_opera_ns4;
    		}
	}
	else if (sw!=document.pgW || sh!=document.pgH)
	{
		location.reload()
	}
}//end func reload_opera_ns4

reload_opera_ns4(true,sw,sh);

////////////////////////////////////////////////////////////////////

var leavethis_msg="Ön most elhagyja a www.cegled.hu honlapot!";

//***NewWin*********************
//mb=1 ->menubar=yes
function NewWin(url,w,h,mb,leavethis)
{
	mb=!mb ? 1 : mb;
 	if(opera)
 	{
 		sw=sw<=w ? w : sw;
 		sh=sh<=h ? h : sh;
 	}	
 	var MX = sw ? (sw-w)/2 : 0;
 	var MY = sh ? (sh-h)/2 : 0;
	var settings ="height="+h+",width="+w+",left="+MX+",top="+MY+",screenX="+MX+",screenY="+MY+",menubar="+mb+",resizable=1,scrollbars=1";
	if(leavethis)
	{
		alert(leavethis_msg);
	}
	var win = window.open(url,"NewWin"+wszam,settings);
	win.focus();
}

//***NewWinMax*********************
//mb=1 ->menubar=yes
function NewWinMax(url,mb,leavethis)
{
	mb=!mb ? 1 : mb;
	var MX=0;
	var MY=0;
	var w=window.screen.width;
	var h=window.screen.height;
	var settings ='fullscreen=1,height='+h+',width='+w+',top='+MY+',screenY='+MY+',left='+MX+',screenX='+MX+',scrollbars=1,resizable=1,menubar='+mb	

	if(leavethis)
	{
		alert(leavethis_msg);
	}
 	
 	var win = window.open(url,"NewWinMax"+wszam,settings);
	win.focus();
}

//*****PopUpWin*****
//Fontos: A TARGET MEGHATÁRZHATÓ !
function PopUpWin(URL,NAME,w,h,sb,leavethis)
{
	sb=sb ? sb : 0;
	if(opera)
 	{
 		sw=sw<=w ? w : sw;
 		sh=sh<=h ? h : sh;
 	}
 	var MX = sw ? (sw-w)/2 : 0;
	var MY = sh ? (sh-h)/2 : 0;
 	var settings ='height='+h+',width='+w+',top='+MY+',screenY='+MY+',left='+MX+',screenX='+MX+',scrollbars='+sb+',resizable'
	if(leavethis)
	{
		alert(leavethis_msg);
	}
 	var win = window.open(URL,NAME,settings)
 	win.focus();
}

//*****PUF*****
//Fotóknak
// Fontos: A TARGET MEGHATÁRZHATÓ !
function PUF(URL,NAME,w,h)
{
	w=w<240 ? 240 : w;
 	if(opera)
 	{
 		sw=sw<=w ? w : sw;
 		sh=sh<=h ? h : sh;
 	}	
	var MX = (sw) ? (sw-w)/2 : 0;
 	var MY = (sh) ? (sh-h)/2 : 0;
	var prop = "";
	prop += "top="+MY+",";
	prop += "screenY="+MY+",";
	prop += "left="+MX+",";
	prop += "screenX="+MX+",";
	prop += "directories=no,";
	prop += "height="+h+",";
	prop += "location=no,";
	prop += "menubar=no,";
	prop += "resizable=no,";
	prop += "scrollbars=no,";
	prop += "status=no,";
	prop += "statusbar=no,";
	prop += "toolbar=no,";
	prop += "width="+w;
	var win = window.open(URL,NAME,prop)
	win.focus();
}

//***********
function elevel(c1,c2,s,b)
{
	if(!s && !b)
	{
		document.location.href="mailto:"+c1+"@"+c2;
	}
	else if(s && !b)
	{
		document.location.href="mailto:"+c1+"@"+c2+'?SUBJECT=' + escape(s);
	}
	else if(!s && b)
	{
		document.location.href="mailto:"+c1+"@"+c2+'?BODY=' + escape(b);
	}	
	else if(s && b)
	{
		document.location.href="mailto:"+c1+"@"+c2+'?SUBJECT=' + escape(s) + '&BODY=' + escape(b);
	}	
}

//***** textaera max charakter ******
function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0,maxlimit);
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
	}
}

//*****Enter tiltása********
function handleEnter (field, event)
{
	var validity=true;
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	{
		var i, j;
		for (j = 0; j < field.form.elements.length; j++)
		{
			if (field == field.form.elements[j])
			{
				break;
			}
		}	
		for (i = (j+1); i < field.form.elements.length; i++)
		{
			with(field.form.elements[i])
			{
				if(type=="hidden" || disabled==true || style.display=="none" || style.visibility=="hidden")
				{
					continue;
				}
				else
				{
					focus();
					return false;
				}
			}
		}
	} 
	else
	{
		validity=true;
	}
	return	validity;
} 

//**********
function ures(obj)
{
	var validity = true;
	var regex = /^\s*$/i;
	if(!regex.test(obj.value))
	{
		validity = false;
	}
	return validity;
}

//******************
function int_onkeyup(obj)
{
	var x=obj.value;
	var temp=x.replace(new RegExp(/\D/g), "");
	if(x!=temp)
	{
		alert("Érvénytelen karakter !\nEnnek a mezőnek az értéke csak egy pozitív EGÉSZ szám lehet.");
		obj.focus();
		obj.value=temp;
	}
}



//******óra********
function tS()
{
	var x=new Date();
	x.setTime(x.getTime());
	return x;
} 
function lZ(x)
{
	return (x>9)?x:'0'+x;
} 

var oT="lZ(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '";

function ora(l)
{
	var msg="";
	var oraObj;
	if(document.all){oraObj=document.all.oradiv;}
 	if(document.getElementById){oraObj=document.getElementById("oradiv");}
 	if((document.all||document.getElementById)&&oraObj)
	{
		switch(l)
		{
		case "m":
		  msg="Idő: <b>";
		  break    
		case "a":
		  msg="Time: <b>"
		  break
		case "d":
		  msg="Uhrzeit: <b>"
		  break		  
		case "f":
		  msg="Heure: <b>"
		  break		  
		case "i":
		  msg="Ora: <b>"
		  break		  
		  
		default:
		  msg="Idő: <b>";
		}
		oraObj.innerHTML=msg+eval(oT)+"</b>";
		setTimeout("ora('" + l + "')",1000);
	}
}



//******************
function mutat_rejt_div( melyik_div )
{
	var elem, vis;
	if( document.getElementById )
	{
		elem = document.getElementById(melyik_div);
	}
	else if( document.all )
	{
		elem = document.all[melyik_div];
	}
	else if( document.layers )
	{
		elem = document.layers[melyik_div];
	}
	
	vis = elem.style;
	
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	{
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0) ? 'block' : 'none';
	}
	else
	{
		vis.display = (vis.display==''||vis.display=='block') ? 'none' : 'block';
	}
}

//*********************
function mrd(f,p,m,d)
{
	var e, eid, v;
	if( document.getElementById )
	{
		e = document.getElementById(d);
		eid = document.getElementById(d+'_a');
	}
	else if( document.all )
	{
		e = document.all[d];
		eid = document.all[d+'_a'];
	}
	
	else if( document.layers )
	{
		e = document.layers[d];
		eid = document.layers[d+'_a'];
	}
	
	v = e.style;
	
	if(v.display=='' && e.offsetWidth!=undefined && e.offsetHeight!=undefined)
	{
		if(e.offsetWidth!=0 && e.offsetHeight!=0)
		{
			v.display ='block';
			HRU(f,p,m,d);
			eid.innerHTML='<b>Elrejtés &raquo;</b>';
	
		
		}
		else
		{
			v.display ='none';
			e.innerHTML='';
			eid.innerHTML='<b>Megtekintés &raquo;</b>';
		}
		
	}
	else
	{
		if(v.display=='' || v.display=='block')
		{
			v.display ='none'
			e.innerHTML='';
			eid.innerHTML='<b>Megtekintés &raquo;</b>';
		}
		else
		{
			v.display ='block';
			HRU(f,p,m,d);		
			eid.innerHTML='<b>Elrejtés &raquo;</b>';
		
		}
	}
}



 //**************************
 function GetXmlHttpObject(mimetyp)
 {
 	var xmlHttp=null;
 	try
 	{
 		xmlHttp=new XMLHttpRequest();
 		if (xmlHttp.overrideMimeType)
 		{
 			xmlHttp.overrideMimeType(mimetyp);
 		}
 	}
 	catch (e)
 	{
 		try
 		{
 			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 		}
 		catch (e)
 		{
 			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
 	}
 	return xmlHttp;
 }
 
//**************************
//pl. <a href="javascript:
//HRU('polgm_hiv/nyomtatvanyok/penzugyi/httprequest_minta.php',{'k':'1','l':'kettő','m':'Árvíztűrőtükörfúrógép'},'post','okm_div')">                   					
//**************************

function callback(serverData,div)
{       
	document.getElementById(div).innerHTML=serverData;
}

//******
function arrLenAss( a )
{
	var aL=0;
	for(var x in a)
	{
		if(x && a[x])
		 {
		 	aL++;
		 }
	}
	return aL;
}

//******
function HRU(file,req,reqTip,div)
{
	reqTip=(reqTip && reqTip!="") ? reqTip.toUpperCase()  : "GET"; ;
	
	var xmlHttp;
	var mimetyp='text/html'; //'text/xml'
  	xmlHttp = GetXmlHttpObject(mimetyp);
  	
  	if(xmlHttp!=null)
	{
  		xmlHttp.onreadystatechange=function()
      		{
  			switch(xmlHttp.readyState)
  			{
				case 0: //uninitialized
					callback("A lekérés folyamatban",div);
					break;
				case 1: //loading
					callback("<div align='center' style='padding:20px'><img src='img/ajax.gif' alt='Betöltés' /><br />Betöltés</div>",div);
					break;				
				case 2: //loaded
					callback("Betöltve",div);
					break;  			
				case 3: //interactive ????
					callback("A lekérés folyamatban",div);
					break;
				case 4: //complete
  			    		switch(xmlHttp.status)
			    		{
			     	 		case 200:
		        				callback(xmlHttp.responseText,div);
			        			break;
			      			case 404:
			        			callback("<span style='color:red'><b>Nem található a fájl!<br />File not found!</b></span>",div);
			        			//return false;
			       				break;
			      			default:
			        			//callback("HTTP Status:" + xmlHttp.status,div);
			        			break;
     					}					
					break;				
				default:
					callback("A lekérés folyamatban",div);
					break;
			}
      		}
      		
      		var post_req="";
		
		if(arrLenAss(req)>0)
		{
			for(var x in req)
			{
	  			if(reqTip=='POST')
  				{
  					post_req+= "&" + x + "=" + req[x];
  				}
  				else
  				{
  					post_req+= "&" + x + "=" + encodeURIComponent(req[x]);
  				}
			}
			post_req=post_req.replace(/&/,'');
		}
		
		if(reqTip=='POST')
		{
			xmlHttp.open(reqTip,file,true);
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2 ');
			if(post_req!="")
			{
				xmlHttp.send(post_req);
			}
			else
			{
				xmlHttp.send(null);
			}
		}
		else
		{
			if(post_req!="")
			{
				xmlHttp.open(reqTip,file+'?'+post_req,true);
			}
			else
			{
				xmlHttp.open(reqTip,file,true);
			}			
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2');			
			xmlHttp.send(null);
		}
  	}
  	else
  	{
  		alert('No AJAX-support!/nPlease use FireFox, Opera or Internet Explorer.');
  		//return false;
  	}
}


//***video********
function CreateControl_video(DIVID, CLASSID, OBJECTID, WIDTH, HEIGHT, FILENAME, AUTOSTART)
{
 if(!ns4)
 {
   document.write('<div id="' + DIVID + '">xxx</div>');
   
   
   if(ie4)
   {
	var obj= '<object classid="' + CLASSID + '" ';
	obj += 'id="' + OBJECTID + '" ';
	obj += 'width="' + WIDTH + '" ';
	obj += 'height="' + HEIGHT +'" >';
   }
   
   
   
   else
   {
	var obj= '<object ';
	obj += 'id="' + OBJECTID + '" ';
	obj += 'width="' + WIDTH + '" ';
	obj += 'height="' + HEIGHT +'" ';   
   	obj += 'type="application/x-mplayer2" >';  
   	obj += '<param name="pluginurl" value="http://www.microsoft.com/Windows/MediaPlayer/" />';
   }
	obj += '<param name="AnimationAtStart" value="0" />';
	obj += '<param name="AutoSize" value="0" />';
	obj += '<param name="autoStart" value="' + AUTOSTART + '" />';
	obj += '<param name="ClickToPlay" value="0" />';
	obj += '<param name="ControlType" value="1" />';
	obj += '<param name="DisplayMode" value="0" />';
	obj += '<param name="DisplaySize" value="4" />';
	obj += '<param name="EnableContextMenu" value="0" />';
	obj += '<param name="FileName" value="' + FILENAME + '" />';
	obj += '<param name="PlayCount" value="1" />';
	obj += '<param name="PreviewMode" value="0" />';
	obj += '<param name="SelectionEnd" value="-1" />';
	obj += '<param name="SelectionStart" value="-1" />';
	obj += '<param name="SendMouseClickEvents" value="1" />';
	obj += '<param name="ShowControls" value="1" />';
	obj += '<param name="ShowDisplay" value="0" />';
	obj += '<param name="ShowStatusBar" value="1" />';
	obj += '<param name="ShowTracker" value="1" />';
	obj += '<param name="TransparentAtStart" value="0" />';
	obj += '<param name="VideoBorderWidth" value="0" />';
	obj += '<param name="VideoBorderColor" value="0" />';
	obj += '<param name="VideoBorder3D" value="0" />';
	obj += '<param name="Volume" value="-500" />';
	obj += '<param name="WindowlessVideo" value="0" />';
	obj += '</object>';
	document.getElementById(DIVID).innerHTML=obj;
 }
}

//***flash********
function CreateControl_flash(DIVID, CLASSID, CODEBASE, OBJECTID, WIDTH, HEIGHT, MOVIE, LOOP, WMODE)
{

pop_div_tohide.push(DIVID);

 if(!ns4)
 {
   document.write('<div id="' + DIVID + '"></div>');
   if(ie4)
   {
	var obj= '<object classid="' + CLASSID + '" ';
	obj += 'codebase="' + CODEBASE + '" ';
	obj += 'id="' + OBJECTID + '" ';
	obj += 'width="' + WIDTH + '" ';
	obj += 'height="' + HEIGHT +'" >';
	
	obj += '<param name="movie" value="' + MOVIE + '" />';
	obj += '<param name="quality" value="high" />';
	obj += '<param name="loop" value="' + LOOP + '" />';
	obj += '<param name="wmode" value="' + WMODE + '" />';
	obj += '</object>';
   }
   else
   {
	var obj= '<object data="' + MOVIE + '" ';
	obj += 'id="' + OBJECTID + '" ';
	obj += 'width="' + WIDTH + '" ';
	obj += 'height="' + HEIGHT + '" ';
	obj += 'type="application/x-shockwave-flash" >';
	obj += '<param name="quality" value="high" />';
	obj += '<param name="loop" value="' + LOOP + '" />';
	obj += '<param name="wmode" value="' + WMODE + '" />';
	obj += '<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />';	
	obj += '</object>';
   }
   document.getElementById(DIVID).innerHTML=obj;
 }
}

//*****************
function toggleBottomElements(table, BottomElementsDiv)
{
	var tableTop=getY(document.getElementById(table));
	var tableHeight=document.getElementById(table).offsetHeight;
	var helyigeny=(tableHeight+tableTop);

	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' )//Non-IE
	{
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )//IE 6+ in 'standards compliant mode'
	{
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )//IE 4 compatible
	{
		myHeight = document.body.clientHeight;
	}

	if(helyigeny>myHeight)
	{
		document.getElementById(BottomElementsDiv).style.display='block';
	}
	else
	{
		document.getElementById(BottomElementsDiv).style.display='none';
	}
}//end func

//******
function getY(oElement)//get top position of an element...
{
	var iReturnValue = 0;
	while( oElement != null )
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

//*************************
function AJAX_updateMysql(file,req,reqTip)
{
	reqTip=(reqTip && reqTip!="") ? reqTip.toUpperCase()  : "GET"; ;
	
	var xmlHttp;
	var mimetyp='text/html'; //'text/xml'
  	xmlHttp = GetXmlHttpObject(mimetyp);
  	
  	if(xmlHttp!=null)
	{
      		var post_req="";
		
		if(arrLenAss(req)>0)
		{
			for(var x in req)
			{
	  			if(reqTip=='POST')
  				{
  					post_req+= "&" + x + "=" + req[x];
  				}
  				else
  				{
  					post_req+= "&" + x + "=" + encodeURIComponent(req[x]);
  				}
			}
			post_req=post_req.replace(/&/,'');
		}
		
		if(reqTip=='POST')
		{
			xmlHttp.open(reqTip,file,true);
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2 ');
			if(post_req!="")
			{
				xmlHttp.send(post_req);
			}
			else
			{
				xmlHttp.send(null);
			}
		}
		else
		{
			if(post_req!="")
			{
				xmlHttp.open(reqTip,file+'?'+post_req,true);
			}
			else
			{
				xmlHttp.open(reqTip,file,true);
			}			
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2');			
			xmlHttp.send(null);
		}
  	}
  	else
  	{
  		alert('No AJAX-support!/nPlease use FireFox, Opera or Internet Explorer.');
  		//return false;
  	}
}




