//***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 honlap="www.nagykoros.hu";
///////////////////////////////

//********
var pop_div_tohide =new Array;
//********

////////////////////////////////////////////////////////////////////////
//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";
    }
}

//****** link image ****
function imgover(imgname)
{
    var img_on = new Image;
    img_on.src  = "img/on.gif";
    imgname.src = img_on.src ;
}
function imgout(imgname)
{
    var img_off = new Image;
    img_off.src  = "img/off.gif";
    imgname.src = img_off.src ;
}

//****** vissza image ****
function backover(id)
{
    var vissza_on = new Image;
    vissza_on.src = "img/vissza2.gif";
    id.src = vissza_on.src;
}

function backout(id)
{
    var vissza_off = new Image;
    vissza_off.src = "img/vissza.gif";
    id.src = vissza_off.src;
}

//*** kezelői ablak********
function a()
{
    window.open('adm','mywin'+wszam);
}

/////////////////////////////////////////////////////////////////////
//***** 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);
}
*/

////////////////////////////
var sw=window.screen.width;
var sh=window.screen.height;
///////////////////////////





////////////////////////////////////////////////////////////////////

//*****PopUpWin*****
// Fontos: A TARGET MEGHATÁRZHATÓ !
 function PopUpWin(URL,NAME,w,h,sb)
 {
 sb=sb ? sb : 0;
 var MX, MY;
 
 if(opera)
 {
 if(sw<=w){sw=w;}
 if(sh<=h){sh=h;}
 }  
 
 MX = (sw) ? (sw-w)/2 : 0;
 MY = (sh) ? (sh-h)/2 : 0;
 settings ='height='+h+',width='+w+',top='+MY+',screenY='+MY+',left='+MX+',screenX='+MX+',scrollbars='+sb+',resizable'
 var win = window.open(URL,NAME,settings)
 win.focus();
}

//***NewWin*********************
//mb=1 ->menubar=yes
function NewWin(url,w,h,mb,a)
{
    if(!mb){mb=1}
    if(!a){a=0}

    if(opera)
    {
        if(sw<=w){sw=w;}
        if(sh<=h){sh=h;}
    }
 
    var MX = (sw) ? (sw-w)/2 : 0;
    var MY = (sh) ? (sh-h)/2 : 0;




    if(a==1)
    {
        if(confirm('Ön most elhagyja a ' + honlap + ' honlapot,\n és megnyitja a ' + url + ' oldalt!'))
        {


            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();
        }
    }
    else
    {
        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();
    }
}//end func


var innerWidth_=640;
var innerHeight_ =480;

addLoadEvent(function(){
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        innerWidth_ = window.innerWidth;        
        innerHeight_ = window.innerHeight;
   }
   else
   {
        if( document.body && typeof( document.body.clientHeight ) == 'number' )
        {        
            innerWidth_=document.body.clientWidth;
            innerHeight_=document.body.clientHeight;
        }
        else if(document.documentElement && typeof( document.documentElement.clientHeight ) == 'number' )
        {
            innerWidth_=document.documentElement.clientWidth; 
            innerHeight_=document.documentElement.clientHeight;
        }
   }
}
)


//***Új ABLAK MENÜVEL *********************
//mb=1 ->menubar=yes
function ujablak(url,w,h,confrm,cim)
{

    var MX = innerWidth_ ? ((innerWidth_-w)/2<=0) ? 0 : (sw-w)/2  : 0;
    var MY = innerHeight_ ? ((innerHeight_-h)/2<=0) ? 0 : ((innerHeight_-h)/2) : 0;
    
    var p="height="+h+",width="+w+",left="+MX+",top="+MY+",screenX="+MX+",screenY="+MY+",toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes";

    if(confrm && cim)
    {
        if(confirm('Ön most elhagyja a ' + honlap + ' honlapot és\náttér a(z) ' + cim + ' honlapjára\n('+ url + ')'))
        {
            var SW = window.open(url,"ujablak_"+wszam,p);
            if(window.focus)
            {
                SW.focus();
            };
        }
    }
    else if(confrm && !cim)
    {
        if(confirm('Ön most elhagyja a ' + honlap + ' honlapot és\náttér a ' + url + ' honlapra'))
        {
            var SW = window.open(url,"ujablak_"+wszam,p);
            if(window.focus)
            {
                SW.focus();
            };
        }
    }
    else
    {
        var SW = window.open(url,"ujablak_"+wszam,p);
        if(window.focus)
        {
            SW.focus();
        }
    }
}//end func



//***NewWinMax*********************
//mb=1 ->menubar=yes
function NewWinMax(url,mb)
{
var w, h, MX, MY;
if(ie4&&!opera)
{
    w=window.screen.availWidth; 
    h=window.screen.availHeight;
}
else if(opera)
{
    w=window.screen.width;
    h=window.screen.height;
}
else if(ns4)//ns4
{
    w=window.innerWidth;
    h=window.innerHeight;
}
else if(ns6)//gecko/mozilla
{
    w=window.screen.availWidth; 
    h=window.screen.availHeight;
}
else
{
    w=window.screen.width;
    h=window.screen.height;
}
settings ='height='+h+',width='+w+',top='+MY+',screenY='+MY+',left='+MX+',screenX='+MX+',scrollbars=1,resizable=1,menubar='+mb
var win = window.open(url,"NewWinMax"+wszam,settings)
win.focus();
}

//*****PUF*****
//Fotoknak
// Fontos: A TARGET MEGHATÁRZHATÓ !
function PUF(URL,NAME,w,h){
if(w<240){w=240}
var MX, MY;
 if(opera)
 {
 if(sw<=w){sw=w;}
 if(sh<=h){sh=h;}
 }  
 MX = (sw) ? (sw-w)/2 : 0;
 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){
document.location.href="mailto:"+c1+"@"+c2;
}

//***** 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])
            {
                //alert(name);
                if(type=="hidden" || disabled==true || style.display=="none" || style.visibility=="hidden" || type=='checkbox')             
                {
                    continue;
                }
                else
                {
                    focus();
                    return false;
                }
            }
        }
    } 
    else
    {
        validity=true;
    }
    return  validity;
}   

//************************
var el_px = "3px";
var vissza_px = "-3px";

function kepel(x)
{
if(ie4)
  {
    y=document.all[x].style;
  }
else
  {
    y=document.getElementById(x).style;
  }
y.left=el_px;
}
//*************************
function kepvissza(x)
{
if(ie4)
  {
    y=document.all[x].style;
  }
else
  {
    y=document.getElementById(x).style;
  }
//y.left=vissza_px;
y.left=0;
}






//***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)
{
 if(!ns4)
 {
   document.write('<div id="' + DIVID + '">xxx</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 addLoadEvent(myfunc)
{
    if(window.addEventListener)
    {
        window.addEventListener('load', myfunc, false);
    }
    else if(window.attachEvent)
    {
        window.attachEvent('onload', myfunc);
    }
}

//*****************
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;
    }
}

//**************************
 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;
 }
 
//////////////////////////////////////////////
/*
<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)
    {
        if(div)
        {
            xmlHttp.onreadystatechange=function()
                {
                if(xmlHttp.readyState==4)
                {
                        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);
                            break;
                        }
                }
                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.');
        //return false;
    }
}

//***********
function blink(id,c){
    var o=document.getElementById(id);
    o.style.visibility=(o.style.visibility=='visible') ? 'hidden' : 'visible';
    if(c)
    {
        o.style.color='#'+c;
    }
}

//***********
function newImgCode(root_dir,kep_kod_konyvtar,sessId,DIV)
{
    HRU(root_dir+'biztonsagi_kod/new_code.php',{'path_to_root':root_dir+'biztonsagi_kod','kep_kod_konyvtar':kep_kod_konyvtar,'sessId':sessId},'post',DIV);
}
