function loginFocus(obj) {
    obj2 = eval("document.urlap." + obj);
    obj2.focus();
}

function checkAll(formName, inputName, allapot, sajat){
    _allapot = false;
    if(allapot == 1){
        _allapot = true;
    }
    if (sajat.checked == true){
        form = eval("document." + formName);
        for (var i = 0; i < form.length; i++) {
            if(form[i].name.indexOf(inputName) > -1) {
                form[i].checked=_allapot;
            }
        }
        sajat.checked=true;
    }
}

function fooldalPopup( url){
    myopen = window.open(url,'galeria','toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,top=10,left=10,width='+600+',height='+385+'');
    myopen.document.close();
    myopen.focus();
}

function ablakUrl( url, width, height){
    map = window.open(url,'galeria','toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,top=10,left=10,width='+width+',height='+height+'');
    map.focus();
}

function ablakUrlScroll( url, width, height, scroll){
    myopen = window.open(url,'galeria','toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no,top=10,left=10,width='+width+',height='+height+'');
    
    myopen.focus();
}

function debug(obj){
    var ablak = window.open("","","");
    Kijelzo = obj;
    for (i in Kijelzo) { 
        if ( ( i!="innerHTML" )&&( i!="outerHTML" ) ) { 
            ablak.document.writeln(i,":"); 
            eval( 'ablak.document.writeln( Kijelzo.' + i + ',"<br>");' ); 
        }
    }
    ablak.document.close();
}

function ablakNyito(name,kep){
    myopen = window.open('','','toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,width=600,height=500');
    myopen.document.write('<html><META CHARSET=iso-8859-2><head><title>'+name+'</title></head>');
    myopen.document.write('<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" OnClick=self.close()>');
    myopen.document.write('<CENTER><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=560 HEIGHT=440><TR VALIGN=MIDDLE ALIGN=CENTER><TD><IMG SRC='+kep+'>');
    myopen.document.write('</TD></TR></TABLE></BODY></HTML>');
    myopen.document.close();
}

function ablakNyito2(name,kep){
    myopen = window.open('','prosi','toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,width=400,height=514');
    myopen.document.write('<html><META CHARSET=iso-8859-2><head><title>'+name+'</title></head>');
    myopen.document.write('<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" OnClick=self.close()>');
    myopen.document.write('<CENTER><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=400 HEIGHT=514><TR VALIGN=MIDDLE ALIGN=CENTER><TD><IMG SRC='+kep+'>');
    myopen.document.write('</TD></TR></TABLE></BODY></HTML>');
    myopen.document.close();
}

function ablakUrl2( url, width, height){
    map = window.open(url,'galeria2','toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,top=10,left=10,width='+width+',height='+height+'');
    map.focus();
}

function ablakPrint( url){
    printAblak = window.open(url,'galeria','toolbar=no,scrollbars=yes,resizable=no,top=10,left=10,width=600,height=600');
    printAblak.focus();
}

function myConfirm(obj){
    if(confirm('Biztosan törli?')){
        obj.submit();
    }
}

function szuloUrl(url){
    window.parent.opener.location=url;
    top.close();
}

function imageChange (name, url){
    var myImage=eval("document."+name);
    myImage.src=url;
}

function printArticle() {
    if (window.print) {
        setTimeout('window.print();',200);
    } else if (agt.indexOf("mac") != -1) {
        alert("Nyomja meg a 'Cmd+p' gombokat a cikk nyomtatásához!");
    } else {
        alert("Nyomja meg a 'Ctrl+p' gombokat a cikk nyomtatásához!")
    }
}

function ekezetetAtkodol(kodolando, eredmeny){
	adat = kodolando;
	if(adat != null){
	    eredmeny.value = adat.replace(/ö/g, "o").replace(/ü/g, "u").replace(/ó/g, "o").replace(/õ/g, "o")
		    .replace(/ú/g, "u").replace(/é/g, "e").replace(/á/g, "a").replace(/û/g, "u").replace(/í/g, "i")
		    .replace(/Ö/g, "o").replace(/Ü/g, "u").replace(/Ó/g, "o").replace(/Õ/g, "o").replace(/Ú/g, "u")
		    .replace(/É/g, "e").replace(/Á/g, "a").replace(/Û/g, "u").replace(/Í/g, "i").replace(/ /g, "_")
		    .replace(/[^a-zA-Z0-9]/g, "_");
	    eredmeny.value = eredmeny.value.replace(/_+/g, "_");
	}
}
function divMegjelenites(id){
    document.getElementById(id).style.display="inline";
}
function divEltuntetes(id){
    document.getElementById(id).style.display="none";
} 

function getRandomNum(lbound, ubound) {
    return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getPassword(length) {
    var rc = "";
    if (length > 0)
        for (var idx = 0; idx < length; ++idx) {
            charSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            rc = rc +charSet.charAt(getRandomNum(0, charSet.length));
        }
    return rc;
}

function kikapcsol(){
    for( i=0; i<tombi.length; i++){
        hideDiv(tombi[i]);
    }
}

function bekapcsol( divid ){
    for( i=0; i<tombi.length; i++){
        hideDiv(tombi[i]);
    }
    showDiv(divid);
}
function showDivAction( divid ){
    for( i=0; i<tombi.length; i++){
      hideDiv(tombi[i]);
//      document.getElementById(tombi[i]+'Link').className = '';
    }
    document.getElementById(divid+'Link').className = 'selected';
    showDiv(divid);

}
function showDiv(divid) {
    if (document.layers) document.layers[divid].visibility="show";
    else document.getElementById(divid).style.display="inline";
}
function hideDiv(divid) {
    if (document.layers) document.layers[divid].visibility="hide";
    else document.getElementById(divid).style.display="none";
}

var bediv = new Object();
function bekidiv(divid){
  if( bediv[divid] == "1" ){
    document.getElementById(divid).style.display="none";
    bediv[divid] = "0";
  } else {
    document.getElementById(divid).style.display="inline";
    bediv[divid] = "1";
  }
}


function ajaxValidate(component, inputName) {
  new Ajax.Request('/ajax.php?ajax=' + component + '&inputName=' + inputName + '&' + inputName + '=' + document.getElementById(inputName).value, {
      asynchronous:true, method: 'get', onSuccess: 
        function(transport) {
          var json = transport.responseText.evalJSON();
          if(json.error){
            hibasMezoJelolo(inputName);
            hibasMezoSzovegBeiras(component + '_errorInput_' + inputName, eval("json.errors." + inputName));
          } else {
            hibaTorles(component, inputName);
          }
        } });
  return false;
}


function hibasMezoJelolo(mezonev){
    elemek = document.getElementsByName(mezonev);
    elem = elemek[mezonev];
    if(elemek.length == 0){
        elem = document.getElementById(mezonev);
    }
    elem.onfocus = mezoSzinVisszaallit;
    if( null != elem.style ){
        elem.style.backgroundColor = '#FF9300';
    }
}

function mezoSzinVisszaallit(){
    if( null != elem.style ){
        this.style.color = '#000000';
        if(elem.id == "body"){
          this.style.backgroundColor = '#EFEFEF';
        } else {
          this.style.backgroundColor = '#FFFFFF';
        }
    }
}

function hibaTorles(component, mezonev){
  document.getElementById(mezonev).style.color = '#000000';
  document.getElementById(mezonev).style.backgroundColor = '#FFFFFF';
  document.getElementById(component + "_errorInput_" + mezonev).innerHTML = "";
}

function hibasMezoSzovegBeiras(mezonev, szoveg){
  if(document.getElementById(mezonev) + "" != "null"){
    document.getElementById(mezonev).innerHTML = szoveg;
  }
}


function send_form(ajaxUrl, form) {
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:Form.serialize(form), method: 'post', onSuccess: formResponse});
  Form.reset(form);
  return false;
}

function send_form_message(ajaxUrl, form) {
  document.getElementById('messageLoad').style.display='inline';
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:Form.serialize(form), method: 'post', onSuccess: formResponseMessage});
  return false;
}

function getResponse(oReq) {
  var re = new RegExp("^[^\\\|]*\\\|[^\\\|]*\\\|[^\\\|]*\\\|$", "g");
  var m = re.exec(oReq.responseText);
  if (m == null) {
    document.getElementById(ajaxId).innerHTML = oReq.responseText;
    alert("#" + responseText);
  } else {
    alert(responseText);
  }
}
function formResponse(transport) {
  var json = transport.responseText.evalJSON();
  if(json.error){
    for(i = 0; i < json.errorArray.length; i++){
      inputName = json.errorArray[i];
      hibasMezoJelolo(inputName);
      hibasMezoSzovegBeiras(json.component + '_errorInput_' + inputName, eval("json.errors." + inputName));
    }
  } else {
    // nincs hiba, johet a masik div
    document.getElementById(json.divId).innerHTML = json.divContent;
  }
}
function formResponseMessage(transport) {
  var json = transport.responseText.evalJSON();
  document.getElementById('messageLoad').style.display='none';
  if(json.error){
    for(i = 0; i < json.errorArray.length; i++){
      inputName = json.errorArray[i];
      setErrorInput(json.component + "_" + inputName);
    }
  } else {
    // nincs hiba, johet a masik div
    document.getElementById(json.divId).innerHTML = json.divContent;
  }
}

function ajaxGetUrl(divId, url) {
  new Ajax.Updater(divId, url);
  return false;
}

function checkNewMessages(){
  // lekerdezi hogy van e uj uzenet

  new Ajax.Request(messagesAjaxUrl, {asynchronous:true, method: 'post', onSuccess: checkNewMessagesJson});

  setTimeout("checkNewMessages()", 30000); // 30 sec

  // /lekerdezi hogy van e uj uzenet
}

function checkNewMessagesJson(transport){
  var json = transport.responseText.evalJSON();
  if( json.have_new_message ){
    document.getElementById("youHaveNewMessage").style.display = 'inline';
  }
}

function getProfile(id){
  // lekerdezi a user egy profile adatait 

  profileAjaxUrl = profileAjaxUrl + '&id=' + id;
  new Ajax.Request(profileAjaxUrl, {asynchronous:true, method: 'post', onSuccess: getProfileJson});

}

function getProfileJson(transport){
  var json = transport.responseText.evalJSON();
  document.forms['user_profile'].name.value = json.profileArray[0]['name'];
  document.forms['user_profile'].postcode.value = json.profileArray[0]['postcode'];
  document.forms['user_profile'].city.value = json.profileArray[0]['city'];
  document.forms['user_profile'].street.value = json.profileArray[0]['street'];
  document.forms['user_profile'].street_number.value = json.profileArray[0]['street_number'];
  document.forms['user_profile'].door.value = json.profileArray[0]['door'];

  document.forms['user_profile'].trans_name.value = json.profileArray[0]['trans_name'];
  document.forms['user_profile'].trans_postcode.value = json.profileArray[0]['trans_postcode'];
  document.forms['user_profile'].trans_city.value = json.profileArray[0]['trans_city'];
  document.forms['user_profile'].trans_street.value = json.profileArray[0]['trans_street'];
  document.forms['user_profile'].trans_street_number.value = json.profileArray[0]['trans_street_number'];
  document.forms['user_profile'].trans_door.value = json.profileArray[0]['trans_door'];

  document.forms['user_profile'].telefon.value = json.profileArray[0]['telefon'];
  document.forms['user_profile'].tax_invoice.value = json.profileArray[0]['tax_invoice'];
  document.forms['user_profile'].profile_name.value = json.profileArray[0]['profile_name'];
  document.forms['user_profile'].user_profile_id.value = json.profileArray[0]['id'];
}

function autoHeight(obj){
  document.getElementById("body").style.height = (6+document.getElementById("body").scrollHeight)+"px"; 
}


function tooltipHideDiv( obj ) {
  obj.style.display = 'none';
}

function tooltipShowDiv(obj) {
  obj.style.display = 'block';
} 

function tooltipShow( objNeve ){
  obj=document.getElementById(objNeve);
  tooltipShowDiv(obj);
}

function tooltipHide( objNeve ){
  obj=document.getElementById(objNeve);
  tooltipHideDiv(obj);
}

function getPositionLeft(This){
  var el = This;
  var pL = 0;
  while(el){
    pL+=el.offsetLeft;
    el=el.offsetParent;
  }
  return pL;
}

function getPositionTop(This){
  var el = This;
  var pT = 0;
  while(el){
    pT+=el.offsetTop;
    el=el.offsetParent;
  }
  return pT;
}

function checkPaymentMode(transObj){
  trans = transObj.options[transObj.selectedIndex].value;
  url = "/ajax.php?action=userOrderPaymentMode&payment_mode=1&trans_type_id="+trans;
  new Ajax.Updater('payment_mode', url);
  return false;
}

function setListElement(label, obj){
  id = obj.id;
  // kikapcs
  if(propertyArray[label][id] != undefined && propertyArray[label][id] != ""){
    propertyArray[label][id] = "";
    document.getElementById(id).style.backgroundColor = "#fafafa";
    document.getElementById(id).style.color = "#000000";
    document.getElementById(id+"Hidden").value = "";
  } else {
    str = "propertyList" + label;
    var re = new RegExp(str, 'g');
    idValue = id.replace(re, "");
    propertyArray[label][id] = idValue;
    document.getElementById(id).style.backgroundColor = "#54565b";
    document.getElementById(id).style.color = "#ffffff";
    document.getElementById(id+"Hidden").value = idValue;
  }
}
function resetAllListElement(label){
  for(i in propertyArray[label]){
    id = i;
    if(propertyArray[label][id] != undefined && document.getElementById(id) != "" && document.getElementById(id) != null){
      document.getElementById(id).style.backgroundColor = "#fafafa";
      document.getElementById(id).style.color = "#000000";
      document.getElementById(id+"Hidden").value = "";
    }
  }
  propertyArray[label] = new Array();
}
function setAllListElement(label){
  for(i in origPropertyArray[label]){
    id = i;
    if(origPropertyArray[label][id] != undefined && document.getElementById(id) != "" && document.getElementById(id) != null){
      str = "propertyList" + label;
      var re = new RegExp(str, 'g');
      idValue = id.replace(re, "");
      propertyArray[label][id] = idValue;
      document.getElementById(id).style.backgroundColor = "#54565b";
      document.getElementById(id).style.color = "#ffffff";
      document.getElementById(id+"Hidden").value = idValue;
    }
  }
}
function selectListElement(label, obj, type){
  id = obj.id;
  // be
  if(type == 1){
    document.getElementById(id).style.backgroundColor = "#e5e5e5";
    document.getElementById(id).style.color = "#000000";
  }
  // ki
  if(type == 0){
    if(propertyArray[label][id] != undefined && propertyArray[label][id] != ""){
      document.getElementById(id).style.backgroundColor = "#54565b";
      document.getElementById(id).style.color = "#ffffff";
    } else {
      document.getElementById(id).style.backgroundColor = "#fafafa";
      document.getElementById(id).style.color = "#000000";
    }
  }
}

function send_basket(pieceObj, productId, packageId, commentObj){
  piece = 1;
  if(pieceObj.value > 0 && pieceObj.value != ""){
    piece = pieceObj.value;
  }
  comment = "";

  if(commentObj != null){
    comment = commentObj.options[commentObj.selectedIndex].value;
  }

  if(comment == ""){
    setPosition('basketSizeEmpty');
    return false;
  }
  
  url = "/ajax.php?action=basketBox&_formId=basket/insert&productId="+productId+"&piece="+piece+"&comment="+comment;
  if (packageId != undefined){
    url = url+"&packageId="+packageId;
  }
  new Ajax.Updater('basketBox', url, {asynchronous:true, evalScripts: false, method: 'post', 
      onSuccess:function (res) {
        showBasketPut();
      }
    }
  );
  return false;
}


function send_basket_refresh(pieceObj, productId, packageId){
  piece = 1;
  if(pieceObj.value > 0 && pieceObj.value != ""){
    piece = pieceObj.value;
  }


  url = "/ajax.php?action=basketBox&_formId=basket/update&productId="+productId+"&piece="+piece;
  if (packageId != 0){
    url = url+"&packageId="+packageId;
  }
  if(document.getElementById('productOrderListLoad') != null){
    document.getElementById('productOrderListLoad').style.display='inline';
  }
  new Ajax.Updater('basketBox', url, {asynchronous:true, evalScripts: false, method: 'post', 
      onSuccess:function (res) {
        if(document.getElementById('productOrderListLoad') != null){
          document.getElementById('productOrderListLoad').style.display='none';
        }

        new Ajax.Updater('productOrder', "/ajax.php?action=productOrder");
      }
    }
  );
  return false;
}

function send_basket_delete_by_id(id){
  url = "/ajax.php?action=basketBox&action2=delete&id="+id;
  divId = 'basketBox';

  if(document.getElementById('productOrderListLoad') != null){
    document.getElementById('productOrderListLoad').style.display='inline';
  }
  new Ajax.Updater( divId, url, {asynchronous:true, evalScripts: false, method: 'post', 
      onSuccess:function (res) {
        if(document.getElementById('productOrderListLoad') != null){
          document.getElementById('productOrderListLoad').style.display='none';
        }

        new Ajax.Updater('productOrder', "/ajax.php?action=productOrder");
      }
    }
  );

  return false;
}

function send_basket_delete(productId, packageId){
  url =
  "/ajax.php?action=basketBox&action2=delete&productId="+productId+"&packageId="+packageId;
  divId = 'basketBox';

  if(document.getElementById('productOrderListLoad') != null){
    document.getElementById('productOrderListLoad').style.display='inline';
  }
  new Ajax.Updater( divId, url, {asynchronous:true, evalScripts: false, method: 'post', 
      onSuccess:function (res) {
        if(document.getElementById('productOrderListLoad') != null){
          document.getElementById('productOrderListLoad').style.display='none';
        }

        new Ajax.Updater('productOrder', "/ajax.php?action=productOrder");
      }
    }
  );

  return false;
}

function checkTransData(transObj){
  trans = transObj.options[transObj.selectedIndex].value;

  if(trans == 2){
    hideDiv('trans');
    hideDiv('trans_check');
  } else {
    if( ! $('equals').checked) {
      showDiv('trans');
    }
    showDiv('trans_check');
  }
}

function clearTransAddress(){
  document.getElementById("trans_postcode").value = "";
  document.getElementById("trans_city").value = "";
  document.getElementById("trans_street").value = "";
  document.getElementById("trans_street_number").value = "";
  document.getElementById("trans_door").value = "";
}

function fillTransAddress(){
  if( $('equals').checked ) {
    document.getElementById("trans_postcode").value = document.getElementById("postcode").value;
    document.getElementById("trans_city").value = document.getElementById("city").value;
    document.getElementById("trans_street").value = document.getElementById("street").value;
    document.getElementById("trans_street_number").value = document.getElementById("street_number").value;
    document.getElementById("trans_door").value = document.getElementById("door").value;
  }
}

function getWindowSize () {
  w = window;
  var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
  var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
  return [width, height];
}

function getDelta (){
  var deltaX =  window.pageXOffset
    || document.documentElement.scrollLeft
    || document.body.scrollLeft
    || 0;
  var deltaY =  window.pageYOffset
    || document.documentElement.scrollTop
    || document.body.scrollTop
    || 0;
  return [deltaX, deltaY];
}

function setPosition (id){
  element = $(id);
  var dimW = 200;
  var dimH = 100;
  var winSize = getWindowSize();
  var winWidth = winSize[0];
  var winHeight = winSize[1];

  delta = getDelta();
  var offLeft = (delta[0] + Math.floor((winWidth-dimW)/2));
  var offTop = (delta[1] + Math.floor((winHeight-dimH)/2));

  element.style.top = ((offTop != null && offTop > 0) ? offTop : '0')+ 'px';
  element.style.left = ((offLeft != null && offLeft > 0) ? offLeft :'0') + 'px';
  element.style.display = "inline";
}

function showBasketPut(){
  setPosition('basketPut');
//  Event.observe(window, 'resize', setPosition('basketPut'), false);
//  Event.observe(window, 'scroll', setPosition('basketPut'), false);
  return false;
}

function hideBasketPut(){
//  Event.stopObserving(window, 'resize', function(evt) { hideBasketPut(); });
//  Event.stopObserving(window, 'scroll', function(evt) { hideBasketPut(); });
  $('basketPut').style.display = "none";
}

function sendFormNews(ajaxUrl, form) {
  document.getElementById('newsLoad').style.display='inline';
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:Form.serialize(form), method: 'post', onSuccess: sendFormResponseNews});
  return false;
}

function sendFormResponseNews(transport) {
  var json = transport.responseText.evalJSON();
  document.getElementById('newsLoad').style.display='none';

  if(json.error){
    for(i = 0; i < json.errorArray.length; i++){
      inputName = json.errorArray[i];
      setErrorInput(json.component + "_" + inputName);
      $(inputName).value = '';
    }
  } else {
    // ha nincs hiba vagyis sikerult, akkor frissitsuk a dobozt
    document.getElementById(json.divId).innerHTML = json.divContent;
  }
}

function search(obj){
  searchValue = obj.value;
  if(searchValue.length > 2){
    url = "/ajax.php?action=mainPageSearch&search_text="+searchValue;
    divId = 'search';

    document.getElementById(divId).style.display='inline';
    new Ajax.Updater( divId, url, {asynchronous:true, evalScripts: false, method: 'post', 
        onSuccess:function (res) {
        }
      }
    );

    return false;
  }
}



