//***browsers
var isDOM=document.getElementById ? true : false;
var isOpera=/opera|OPERA|Opera/.test(navigator.userAgent.toLowerCase());
var isIE=(document.all && !isOpera) ? true : false;
var ieVers=parseFloat(navigator.appVersion.split("MSIE")[1]);

//*** névtelen új ablak nevéhez:
var wnow = new Date(); 
var wszam = wnow.getTime();

function getSiteUrl()
{
    var prot='';
    var sUrl='';
    var pat='';

    if(window.location.protocol)
    {
        prot=window.location.protocol+'//';
    }

    if(!/(127\.0\.0\.1)|localhost/i.test(window.location.hostname))
    {
        sUrl=prot + window.location.hostname;
    }
    else
    {
        pat=window.location.pathname.split('/');
        pat='/'+pat[1];
        sUrl=prot + window.location.hostname+pat;
    }
    return sUrl.replace(/\/$/g,'');
}
///////////////////////////////
var honlap=getSiteUrl();
//alert(honlap);
///////////////////////////////

function toRoot(){
	var x='0',path='';
    if(!/(127\.0\.0\.1)|localhost/i.test(document.location.hostname))
    {
        var x=2;
    }
    else
    {
        var x=3;
    }
	for( var i=0; i<document.location.pathname.split('/').length-x; i+=1)
	{
		path+='../';
	}
	return path;
}

//alert('Path: '+toRoot());


//********
var pop_div_tohide =[];
//********

////////////////////////////
var sw=window.screen.width;
var sh=window.screen.height;
///////////////////////////

//***********
function NewWin(url,w,h,mb,leavethis)
{
    //mb=1 ->menubar=yes
    leavethis=!leavethis ? 0 : leavethis;
    if(leavethis)
    {
        //alert('Ön most elhagyja a "' + honlap + '" honlapot,\n és megnyitja a\n"'+url+'" oldalt!');
        
        if(!confirm('Ön most elhagyja a "' + honlap + '" honlapot,\n és megnyitja a\n"'+url+'" oldalt!')){return};
        
    }

    mb=!mb ? 1 : mb;
    
    var MX, MY;
    if(isOpera)
    {
        if(sw<=w){sw=w;}
        if(sh<=h){sh=h;}
    }   
    MX = (sw) ? (sw-w)/2 : 0;
    MY = (sh) ? (sh-h)/2 : 0;
    var SW = window.open(url,"NewWin"+wszam,"height="+h+",width="+w+",left="+MX+",top="+MY+",screenX="+MX+",screenY="+MY+",menubar="+mb+",resizable=1,scrollbars=1");
    SW.focus();
}


//***********
function PopUpWin(url,wname,w,h,mb,leavethis)
{
    //mb=1 ->menubar=yes
    leavethis=!leavethis ? 0 : leavethis;
    if(leavethis)
    {
        alert('Ön most elhagyja a ' + honlap + ' honlapot!');
    }
    mb=!mb ? 1 : mb;
    var MX = (sw) ? (sw-w)/2 : 0;
    var MY = (sh) ? (sh-h)/2 : 0;
    var SW = window.open(url,wname,"height="+h+",width="+w+",left="+MX+",top="+MY+",screenX="+MX+",screenY="+MY+",menubar="+mb+",resizable=1,scrollbars=1");
    SW.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, warning) {
    if (field.value.length > maxlimit)
    {
        field.value = field.value.substring(0, maxlimit);
    }
    else
    {
        countfield.value = maxlimit - field.value.length;
    }

    if(warning && field.value.length === maxlimit)
    {
        alert('Nincs több karakterhely!');
    }
}

//*****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, o;
        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++)
        {
            o=field.form.elements[i]
            {
                if(o.type=="hidden" || o.disabled==true || o.style.display=="none" || o.style.visibility=="hidden")
                {
                    continue;
                }
                else
                {
                    o.focus();
                    return false;
                }
            }
        }
    } 
    else
    {
        validity=true;
    }
return  validity;
}     

//************
function addLoadEvent(myfunc)
{
    if(window.addEventListener)
    {
        window.addEventListener('load', myfunc, false);
    }
    else if(window.attachEvent)
    {
        window.attachEvent('onload', myfunc);
    }
}

///////////////////////////
var TOGGLEDIVS={
actDIV:"",

t: function(i,si,p_t)
{
	var dh,o,oldI="";

    o=jQuery("#hszovegDIV_"+i)[0];
    
    if(this.actDIV && this.actDIV!==i)
    {
        oldI=this.actDIV;
    }

    //rejtve volt:   
    if(jQuery("#bovdiv_"+i).css('display')==='none')
    {
        //régi azonnali rejtése
        if(oldI)
        {
           jQuery("#bovdiv_"+oldI).hide();
        }
        
        jQuery("#bovdiv_"+i).css('display','');
		this.actDIV=i;
   
        //üres volt:
        if(o.innerHTML==="")
        {
            jQuery.ajax({
                url: "akt/akt_ajax_hszoveg.php",
                type: "post",
                data: ({'i':i,'id':si, 'p_t':p_t}),
                dataType: "html",
                beforeSend: function()
                {
                    jQuery(o).html("<div align='center' style='padding:20px'><img src='img/ajax.gif' alt='Betölt' /><br />Betölt</div>");
                },
                success: function(data)
                {
					jQuery(o).html(data);
                    dh=o.offsetHeight;
                    
                    jQuery(o).height(0);
                    jQuery(o).animate({'height':dh},800,'easeOutQuart',function(){
						jQuery("#aktSorId_"+si).scrollintoview({  
						duration: 400,
						direction: "y",
						complete: function() {
								}
						});                   
                    });
                    slimboxForAjax();
                },
                error: function(XMLHttpRequest, textStatus, errorThrown)
                {
                    alert("XMLHttpRequest=" + XMLHttpRequest.responseText + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown);
                }
            });
        }
        
        //Korábban már be volt hívva a tartalom:
        else
        {
            dh=o.offsetHeight;
			jQuery(o).height(0);            
			jQuery(o).animate({'height':dh},800,'easeOutQuart',function(){
				jQuery("#aktSorId_"+si).scrollintoview({  
				duration: 400,
				direction: "y",
				complete: function() {
					}
				});		
			});            
        }
        
        //+- gomb csere és bővebben » elrejtése/mutatása
		if(oldI)
		{
			jQuery("#hrefIdG_"+oldI).removeClass('minus14g').addClass('plus14g');
            jQuery("#bovLink_"+oldI).show();
		}
		
        jQuery("#hrefIdG_"+i).removeClass('plus14g').addClass('minus14g');
        jQuery("#bovLink_"+i).hide();
        
    }
    
    //ELREJTÉS:
    else
    {
			dh=o.offsetHeight;
			selObjH=jQuery("#aktSorId_"+si).height();
			
			jQuery(o).animate({'height':0},1000,'easeOutQuart',function(){
				jQuery(o).height(dh);	
				jQuery("#bovdiv_"+i).css('display','none');
				if(jQuery(window).height()<selObjH)
				{
					if(!oldI)
					{
						jQuery("#aktSorId_"+si).scrollintoview({
						duration: 400,
						direction: "y",
						complete: function() {}
						});					
					}
				}
			});
			
        //+- gomb csere és bővebben » elrejtése/mutatása
		if(oldI)
		{
			jQuery("#hrefIdG_"+oldI).removeClass('minus14g').addClass('plus14g');
		}
        jQuery("#hrefIdG_"+i).removeClass('minus14g').addClass('plus14g');
        jQuery("#bovLink_"+i).show();
        
	}
}
};//end Class

///////////////////////////

//*****************
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 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;
 }
 
//////////////////////////////////////////////
// //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')">     
//
//header("Content-Type: text/html; charset=iso-8859-2");
//header("Cache-Control: no-cache, must-revalidate");
//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
//
//////////////////////////////////////////////

//********
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;
}

//To check if HRU ok
var HRU_READY="true";

//******
function HRU(file,req,reqTip,div)
{

    HRU_READY="false";

    reqTip=(reqTip && reqTip!="") ? reqTip.toUpperCase()  : "GET"; ;
    
    var xmlHttp;
    var mimetyp='text/html'; //'text/xml'
    xmlHttp = GetXmlHttpObject(mimetyp);
    
    if(xmlHttp!==null)
    {
        if(div)
        {
            xmlHttp.onreadystatechange=function()
                {
                if(xmlHttp.readyState==4)
                {
                        switch(xmlHttp.status)
                        {
                            case 200:
                                callback(xmlHttp.responseText,div);
                                window.HRU_READY="true";
                                break;
                            case 404:
                                callback("<span style='color:red'><b>Nem található a fájl!<br />File not found!</b><br />"+file+"</span>",div);
                                window.HRU_READY="true";
                                break;
                            default:
                                window.HRU_READY="true";
                        }
                }
                else if(xmlHttp.readyState==1)
                {
                    callback("<div align='center' style='padding:20px'><img src='img/ajax.gif' alt='Betöltés' /><br />Betöltés</div>",div);
                }
                }
            }
            
            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.');
    }
}

function AWF(url,param,sendType,div,func,funcParamArr)
{
	jQuery.ajax({
		url: url,
		type: sendType,
		data: (param),
		dataType: "html",
		beforeSend: function(x)
		{
			if( (typeof(div)=='string') && div!='')
			{
				jQuery("#"+div).html("<div align='center' style='padding:20px'><img src='img/ajax.gif' alt='Betölt' /><br />Betölt</div>");
			}
		},
		success: function(data)
		{

			if( (typeof(div)=='string') && div!='')
			{
				jQuery("#"+div).html(data);
			}
			if(typeof(func)=='function')
			{
				func(funcParamArr);
			}


/*

			if( (typeof(div)=='string') && div!='')
			{
				jQuery("#"+div).html(data).function(func,funcParamArr){
							if(typeof(func)==='function')
							{
								alert('hej');
								func(funcParamArr);
							}
				
				};
			}
*/








		},
		error: function(XMLHttpRequest, textStatus, errorThrown)
		{
			alert("XMLHttpRequest=" + XMLHttpRequest.responseText + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown);
		}
	});
}

//***********
function newImgCode(root_dir,kep_kod_konyvtar,sessId,DIV)
{
	AWF(root_dir+'biztonsagi_kod/new_code.php',{'path_to_root':root_dir+'biztonsagi_kod','kep_kod_konyvtar':kep_kod_konyvtar,'sessId':sessId},'post',DIV,'','');
}

//***********
function clearForm(oForm) {
    var elements = oForm.elements; 
    oForm.reset();
    for(i=0; i<elements.length; i++)
    {
        field_type = elements[i].type.toLowerCase();
        switch(field_type)
        {
            case "text": 
            case "password": 
            case "textarea":
            case "hidden":   
                elements[i].value = ""; 
                break;
        
            case "radio":
            case "checkbox":
                if (elements[i].checked)
                {
                    elements[i].checked = false; 
                }
                break;

            case "select-one":
            case "select-multi":
                elements[i].selectedIndex = -1;
                break;

            default: 
            break;
        }
    }
}

//*****************
function sc(u,p)
{
	AWF(u+'biztonsagi_kod/img.php',{'p':p,'u':u},'post','kepkod_div','','');
}

//**********
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;
    }
}

//*****************
function is_int(obj)
{
    var validity = true;
    var regex = /\D/g;
    if(!regex.test(obj.value))
    {
        validity = false;
    }
return validity;
}   

//**********
function opDiv(ID,state)
{
    var o;
    if(document.getElementById)
    {
        o=document.getElementById(ID);
    }
    else
    {
        return;
    }
    if(state=="on")
    {
        o.className='opdivon';
    }
    else if(state=="out")
    {
        o.className='opdiv';
    }
    else
    {
        return;
    }
}

//**********
function opImg(img,state)
{
    if(state=="on")
    {
			window.origBorderColor=jQuery(img).css('border-left-color');
			
			opImg_prevBorderColor=jQuery(img).css('border-left-color')
			
			if(opImg_prevBorderColor.substring(0,3)==="rgb")
			{
				window.opImg_prevBorderColor=rgb2hex(opImg_prevBorderColor);
			}
			else
			{
				window.opImg_prevBorderColor=opImg_prevBorderColor;
			}
		
			jQuery(img).css('opacity','1');
			jQuery(img).css('border-color','red');
			jQuery(img).animate(			
			{
				opacity:0.5
			},500,'easeOutQuad');
	}
    else if(state=="out")
    {
			jQuery(img).css('border-color',window.opImg_prevBorderColor);
			jQuery(img).animate(
			{
				opacity:1
			},500,'easeOutQuad');
    }
    else
    {
        return;
    }
}

//**********
function rgb2hex(rgb){
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); return "#" + ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) + ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) + ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
}




//**********
function fbs_click(u,t)
{
    t= strip_tags (t, "");
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}

//**********
function strip_tags (input, allowed)
{
    allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
    return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1)
    {
        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
    }
    );
}


