/***mert az IE nem ismeri ezt a függvényt*************************************/
if(!Array.indexOf)
{
    Array.prototype.indexOf = function(obj)
    {
        for(var i=0; i<this.length; i++)
        {
            if(this[i]==obj)
            {
                return i;
            }
        }
        return -1;
    }
}
/******************************************************************************/	
 
function $(id) 
{
	return document.getElementById(id);
}


function initheight()
{
  if (document.body && typeof(document.body.offsetHeight) == 'number')
  {
    var height = document.body.clientHeight;
  }
  else if (typeof(window.innerHeight) == 'number')
  {
    var height = window.innerHeight;
  }
  else
  {
    var height = 600;
  }
  return height;
}

function setheight()
{
  var max    = initheight();
  
  $("bodydiv").style.height = max-280;
  //alert (max);
}



function bodySize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return (myWidth - 95);
}

function pagerank_pos()
{
  document.getElementById("pagerank").style.left = bodySize();
}

function loader()
{
  document.getElementById("loaddiv").style.visibility=false?'visible':'hidden';
}

function betolt(url,id,k,sender)
{
 document.getElementById(id).innerHTML = '<img src="../_pictures/webdesign/loader.gif">';
 var XMLHttpRequestObject = false;
 if (window.XMLHttpRequest) {
	XMLHttpRequestObject = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
 }
 if(XMLHttpRequestObject) {
	var obj = document.getElementById(id);
	XMLHttpRequestObject.open("GET", url, true);
	XMLHttpRequestObject.onreadystatechange = function() {
	   if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
		  obj.innerHTML = XMLHttpRequestObject.responseText;
		  switch(k)
		  {
        case 'keptallozo' : {betolt('../_admin/_media/dir_list.php?dir=../images&sender='+sender,'media_dir','',sender);break;}
      }

	   }
	}
	XMLHttpRequestObject.send(null);
 }
}	



function index_search(name,str)
{
  var index;
  var myselect=document.getElementById(name);
  for (var i=0; i<myselect.options.length; i++)
  { 
    var op=myselect.options[i].value;
    if (op.indexOf(str)>-1){index=i;break;}
  }
  return index;
}
function kivalaszt(id,i)
{
  document.getElementById(id).options[i].selected=true;
} 
/***********ajax post**********************************************************/

function asc(str) {
	return str.charCodeAt(0);
}
   
function termek_save(azo)
{
  new Ajax.Request ( '../_admin/modositas.php' , {method: "post", parameters:
  {
    azo             : azo,
    cikkszam        : betu_csere( $("_cikkszam").value ),
    image           : ektelenit($("_image").value ),
    megnevezes      : betu_csere( $("_megnevezes").value ),
    gyarto          : betu_csere( $("_gyarto").value ),
    szarmazasi_hely : betu_csere( $("_szarmazasi_hely").value ),
    ar              : betu_csere( $("_ar").value ),
    fixar           : $('_fixar').options[$('_fixar').selectedIndex].value,
    akcios          : $('_akcios').options[$('_akcios').selectedIndex].value,
    ajanlo          : $('_ajanlo').options[$('_ajanlo').selectedIndex].value,
    leiras          : betu_csere( $("_leiras").value )
  },onComplete: function(transport) { if (200 == transport.status) {
    $('termek_modositas').update(transport.responseText).setStyle({ background: '#ffffff' }); }}});
  setTimeout("ujratolt("+azo+")",2000);
}



function uj_termek_save()
{
  new Ajax.Request ( '../_admin/uj_termek.php' , {method: "post", parameters:
  {
    cikkszam        : betu_csere( $("uj_cikkszam").value ),
    image           : ektelenit($("uj_image").value ),
    megnevezes      : betu_csere( $("uj_megnevezes").value ),
    gyarto          : betu_csere( $("uj_gyarto").value ),
    szarmazasi_hely : betu_csere( $("uj_szarmazasi_hely").value ),
    ar              : betu_csere( $("uj_ar").value ),
    fixar           : $('uj_fixar').options[$('uj_fixar').selectedIndex].value,
    akcios          : $('uj_akcios').options[$('uj_akcios').selectedIndex].value,
    ajanlo          : $('uj_ajanlo').options[$('uj_ajanlo').selectedIndex].value,
    leiras          : betu_csere( $("uj_leiras").value )
  },onComplete: function(transport) { if (200 == transport.status) {
    $('termek_uj').update(transport.responseText).setStyle({ background: '#ffffff' }); }}});
  betolt('termek_list.php','termeklist');
  setTimeout("ujratolt2()",2000);
}

function _delete(azo)
{
  new Ajax.Request ( '../_admin/delete.php' , {method: "post", parameters:
  {
    azo             : azo  
  },onComplete: function(transport) { if (200 == transport.status) {
    $('_delete').update(transport.responseText).setStyle({ background: '#ffffff' }); }}});
  setTimeout("betolt('../_admin/termek_list.php','termeklist')",500);   
}







function makePOSTRequest(url,id, parameters) 
{
  var http_request = false;
  if (window.XMLHttpRequest) {
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) {
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request.onreadystatechange = function(){
    if (http_request.readyState == 4) {
       if (http_request.status == 200) {
          result = http_request.responseText;
          document.getElementById(id).innerHTML = result;            
       } else {
          alert('There was a problem with the request.');
       }
    }      
  };
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}




function keptallozo_delete(element,sender)
{
  var poststr='';
  
  var input = document.getElementById(element).getElementsByTagName("input");
  
  for(var i = 0; i < input.length; i++)
  {
    if(input[i].checked==true)
    {
      poststr += "&image"+i+"=" + input[i].value; 
    }
  }
  var post=poststr.substr(1)+";"
  if(post.length > 1)
  {
    makePOSTRequest('../_admin/kep_delete.php', 'kep_delete', poststr);
    setTimeout("betolt('_media/dir_list.php?dir=../images&sender="+sender+"','media_dir','',"+sender+")",500);   
  }
  else
  {
    alert('Nincs kiválasztva semmi!');
  }
  
  
}


function ujratolt(azo)
{
  betolt('termek_list.php','termeklist');
  betolt('termekdata.php?azo='+azo,'termekdata');
}

function ujratolt2()
{
  $('termek_uj').innerHTML=''
  betolt('termek_list.php','termeklist');
}
/******************************************************************************/



function _scrollHeight()
{
  return document.body.scrollHeight;
}

function setOpacity(level,id) 
{
  $(id).style.opacity = level;
  $(id).style.MozOpacity = level;
  $(id).style.KhtmlOpacity = level;
  $(id).style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function createfolia()
{
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id', 'kepoverlayer');
  newdiv.style.width      = '100%';
  newdiv.style.height     = _scrollHeight()+"px";
  newdiv.style.position   = "absolute";
  newdiv.style.top        = "0px";
  newdiv.style.left       = "0px";
  newdiv.style.background = "#555555";
  newdiv.style.zIndex     = "1";
  newdiv.style.border     = "0px solid #000";
  newdiv.innerHTML        = "";
  document.body.appendChild(newdiv);
  setOpacity('0.5','kepoverlayer');
}

function createtallozo()
{
  
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id', 'keptallozo');
  newdiv.style.width      = '700px';
  newdiv.style.height     = (_scrollHeight()-100)+"px";
  newdiv.style.position   = "absolute";
  newdiv.style.top        = "50px";
  newdiv.style.left       = "50%"; 
  newdiv.style.marginLeft = "-350px";
  newdiv.style.background = "#ffffff";
  newdiv.style.zIndex     = "2";
  newdiv.style.border     = "0px solid #000";
  newdiv.style.overflow   = "auto";
  document.body.appendChild(newdiv);
}

function keptalloz(sender)
{
  createfolia();
  createtallozo();
  betolt('tallozo.php?sender='+sender,'keptallozo','keptallozo',sender);
}

function keptallozo_mini(k,sender)
{
  if(k=='n')
  {
    betolt('_media/dir_list.php?dir=../images&sender='+sender,'media_dir','',sender);
  }
  else
  {
    betolt('_media/dir_list_mini.php?dir=../images/&sender='+sender,'media_dir','',sender);
  }
}

function keptallozo_off()
{
  document.body.removeChild($('keptallozo'));
  document.body.removeChild($('kepoverlayer'));
}

function kepnev_beszur(kepnev,sender)
{
  $(sender).value=kepnev;
  keptallozo_off();
}








function showKeyCode()
{
  var character = document.characterCode.character.value.substring(0,1);
  var code = document.characterCode.character.value.charCodeAt(0);
  var msg = "ASCII = "+code+"";
  alert(msg);
}







//  nyomásszabályzó szelep
function betu_csere(szo)
{   
  
  //g => mindet cserelje
  //i => ne legyen key szenzitív

  
  szo = szo.replace(/é/g,'&eacute;');
  szo = szo.replace(/á/g,'&aacute;');
  szo = szo.replace(/ö/g,'&ouml;');
  szo = szo.replace(/õ/g,'&#337;');
  szo = szo.replace(/ó/g,'&oacute;');
  szo = szo.replace(/ü/g,'&uuml;');
  szo = szo.replace(/û/g,'&#369;');
  szo = szo.replace(/ú/g,'&uacute;');
  szo = szo.replace(/í/g,'&iacute;');
  szo = szo.replace(/É/g,'&Eacute;');
  szo = szo.replace(/Á/g,'&Aacute;');
  szo = szo.replace(/Ö/g,'&Ouml;');
  szo = szo.replace(/Õ/g,'&#336;');
  szo = szo.replace(/Ó/g,'&Oacute;');
  szo = szo.replace(/Ü/g,'&Uuml;');
  szo = szo.replace(/Û/g,'&#368;');
  szo = szo.replace(/Ú/g,'&Uacute;');
  szo = szo.replace(/Í/g,'&Iacute;');  
  
  

  
  
  return szo;
}



function ektelenit(str)
{
   return strtr(str,"ÁÉÚÕÛÓÜÖÍáéúõûóüöí ",  
                     "AEUOUOUOIaeuououoi_");
}




function strtr (str, from, to) 
{
    // Translates characters in str using given translation tables  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/strtr    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +      input by: uestla
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Alan C
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // +      input by: Taras Bogach
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: jpfle
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // -   depends on: krsort    // -   depends on: ini_set
    // *     example 1: $trans = {'hello' : 'hi', 'hi' : 'hello'};
    // *     example 1: strtr('hi all, I said hello', $trans)
    // *     returns 1: 'hello all, I said hi'
    // *     example 2: strtr('äaabaaccasdeöoo', 'äaö','aao');    // *     returns 2: 'aaabaaccasdeooo'
    // *     example 3: strtr('ääääääää', 'ä', 'a');
    // *     returns 3: 'aaaaaaaa'
    // *     example 4: strtr('http', 'pthxyz','xyzpth');
    // *     returns 4: 'zyyx'    // *     example 5: strtr('zyyx', 'pthxyz','xyzpth');
    // *     returns 5: 'http'
    // *     example 6: strtr('aa', {'a':1,'aa':2});
    // *     returns 6: '2'
    var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0, tmpStrictForIn = false, fromTypeStr = '', toTypeStr = '', istr = '';    var tmpFrom = [];
    var tmpTo = [];
    var ret = '';
    var match = false;
     // Received replace_pairs?
    // Convert to normal from->to chars
    if (typeof from === 'object') {
        tmpStrictForIn = this.ini_set('phpjs.strictForIn', false); // Not thread-safe; temporarily set to true
        from = this.krsort(from);        this.ini_set('phpjs.strictForIn', tmpStrictForIn);
 
        for (fr in from) {
            if (from.hasOwnProperty(fr)) {
                tmpFrom.push(fr);                tmpTo.push(from[fr]);
            }
        }
 
        from = tmpFrom;        to = tmpTo;
    }
    
    // Walk through subject and replace chars when needed
    lenStr  = str.length;    lenFrom = from.length;
    fromTypeStr = typeof from === 'string';
    toTypeStr = typeof to === 'string';
 
    for (i = 0; i < lenStr; i++) {        match = false;
        if (fromTypeStr) {
            istr = str.charAt(i);
            for (j = 0; j < lenFrom; j++) {
                if (istr == from.charAt(j)) {                    match = true;
                    break;
                }
            }
        }        else {
            for (j = 0; j < lenFrom; j++) {
                if (str.substr(i, from[j].length) == from[j]) {
                    match = true;
                    // Fast forward                    i = (i + from[j].length)-1;
                    break;
                }
            }
        }        if (match) {
            ret += toTypeStr ? to.charAt(j) : to[j];
        } else {
            ret += str.charAt(i);
        }    }
 
    return ret;
}






























