// start of DHTML library from DHTMLCentral.com

/****************************************************************************
DHTML library from DHTMLCentral.com
*   Copyright (C) 2001 Thomas Brattli 2001
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli 2001
***************************************************************************/
//Browsercheck (needed) ***************
function lib_bwcheck(){
  this.ver=navigator.appVersion;
  this.agent=navigator.userAgent;
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1;
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(!this.dom && !this.opera5 && document.all)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6;
  this.mac=this.agent.indexOf("Mac")>-1;
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(!this.dom && document.layers)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
  return this;
}
var bw;
bw=new lib_bwcheck(); //Browsercheck object

//Debug function ******************
function lib_message(txt) {
  alert(txt);
  return false;
}

//Object referencing  ********************
function getObjByID(obj,doc) {
  if(!bw.bw) return lib_message('Old browser');
  //nest=(!nest) ? "":'document.'+nest+'.'
  var nest="";
  if(!doc) { doc = document; }
//  alert(doc.getElementById(obj));
  this.evnt=bw.dom? doc.getElementById(obj):
    bw.ie4?doc.all[obj]:bw.ns4?eval(nest+"doc.layers." +obj):0;
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')'
    +'\nIf your using Netscape please check the nesting of your tags!');
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;
  this.ref=bw.dom||bw.ie4?doc:this.css.document;
  //this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  //this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  //this.w=this.evnt.offsetWidth||this.css.clip.width||
  //  this.ref.width||this.css.pixelWidth||0;
  //this.h=this.evnt.offsetHeight||this.css.clip.height||
  //  this.ref.height||this.css.pixelHeight||0;
  //this.c=0; //Clip values
  //if((bw.dom || bw.ie4) && this.css.clip) {
  //this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1);
  //this.c=this.c.split(' ');
 //for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  //}
  //this.ct=this.css.clip.top||this.c[0]||0;
  //this.cr=this.css.clip.right||this.c[1]||this.w||0;
  //this.cb=this.css.clip.bottom||this.c[2]||this.h||0;
  //this.cl=this.css.clip.left||this.c[3]||0;
  //this.obj = obj + "Object"; eval("var " + this.obj + "; this.obj + "=this");
  return this;
}

/*function getObjByName(obj,doc) {
  if(!bw.bw) return lib_message('Old browser');
  var nest="";
  if(!doc) { doc = document; }
  this.evnt=bw.dom?(doc.getElementsByName(obj)?doc.getElementsByName(obj)[0]:0):
    bw.ie4?doc.all[obj]:bw.ns4?eval(nest+"doc.layers." +obj):0;
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')'
    +'\nIf your using Netscape please check the nesting of your tags!');
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;
  this.ref=bw.dom||bw.ie4?doc:this.css.document;
  //this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  //this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  //this.w=this.evnt.offsetWidth||this.css.clip.width||
  //  this.ref.width||this.css.pixelWidth||0;
  //this.h=this.evnt.offsetHeight||this.css.clip.height||
  //  this.ref.height||this.css.pixelHeight||0;
  //this.c=0; //Clip values
  //if((bw.dom || bw.ie4) && this.css.clip) {
  //this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1);
  //this.c=this.c.split(' ');
  //for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  //}
  //this.ct=this.css.clip.top||this.c[0]||0;
  //this.cr=this.css.clip.right||this.c[1]||this.w||0;
  //this.cb=this.css.clip.bottom||this.c[2]||this.h||0;
  //this.cl=this.css.clip.left||this.c[3]||0;
  //this.obj = obj + "Object"; eval("var " + this.obj + "; this.obj + "=this");
  return this;
}
*/
// end of DHTML library from DHTMLCentral.com


  function getFrameByName(framename) {
    var phrame = "top";
    var x;
    var y = new Array();
    y[0] = 0;
    var level = 0;
    var found;

    if (framename == "") { return self; }

    function parsetree()
    {
      var i;
      for (i=y[level];i<x.length;i++)
      {
      //document.write('<LI>The frame named ' + x.frames[i].name + ' (containing ' + x.frames[i].document.title + ')');
        if (x.frames[i].name == framename) found = x.frames[i];

        if (x.frames[i].length > 0)
        {
          phrame = phrame + '.frames[' + i + ']';
          y[level] = i + 1;
          //document.write(', which contains<UL>');
          level++;
          y[level] = 0;
          return;
        }
      }
      phrame = phrame.substring(0,phrame.lastIndexOf('.'));
      //document.write('</UL>');
      if (level == 0) phrame == "";
      level--;
    }

    if (phrame == framename) {
      found = eval(phrame);
    } else {
      found = false;
    }

    while (phrame != "" && !found)
    {
      x = eval(phrame);
      parsetree();
    }
    //alert(found.name);
    return found;
  };

  function getIDRef(id, Frame) {
    if (Frame == "") { Frame = "top"; }
    var doc = getFrameByName(Frame).document;
    if ( doc ) {
      return getObjByID(id, doc)
    }
    return false;
  }

/*  function getNameRef(name, Frame) {
    if (! Frame) { Frame = self.name; }
    var doc = getFrameByName(Frame).document;
    if ( doc ) {
      return getObjByName(name, doc)
    }
    return false;
  }
*/

/* loginform eljárások */
  function loginform_doChallengeResponse(challenge) {
	var str = "";
	str = encodeURIComponent(document.login.username.value) + ":" + MD5(document.login.password.value) + ":" + challenge;
    document.login.password.value = "";
    document.logintrue.username.value = document.login.username.value;
    document.logintrue.response.value = MD5(str);
    submitform('logintrue');
    return false;
  };

  function loginform_setFocus() {
    // A felhasználónévre vagy a jelszóra teszi a fókuszt
    if (document.login.username.value == "") {
      document.login.username.focus();
    } else {
      document.login.password.focus();
    }
  };

  function click_login_emlekezteto() {
    submitform('form_login_emlekezteto');
  };


  function winopen(url, name, options, ret) {
    var w=window.open(url, name, options);
    if (ret) { return w; } else return null;
  };

  function submitform(formname) {
    document.forms[formname].submit();
    //eval("document."+formname+".submit();");
    //return false;
  };
  
  function reloadframe(framename) {
    var f;
    f = getFrameByName(framename);
    if (f) {
      f.location.href = f.location.href;
    } else {
      //alert("reloadframe: A " + framename + " nevű frame nem található.");
    }
  };

  function setlocation(framename, href) {
    var f;
    f = getFrameByName(framename);
    if (f) {
      f.location.href = href;
    } else {
      //alert("setlocation: A [" + framename + "] nevű frame nem található.");
    }
  };

  function afterlogin() {
    reloadframe('frame_menu');
    reloadframe('frame_kosar');
    reloadframe('frame_res');
  };

  function afterlogout() {
    reloadframe('frame_menu');
    reloadframe('frame_kosar');
    reloadframe('frame_res');
  };

function toggle_display(framename, element_id, display) {
    var f;
    f = getFrameByName(framename);
    if (f) {
      var e;
      e = f.document.getElementById(element_id);
      if (e) {
        if (e.style.display == display) {
          e.style.display = "none";
        } else {
          e.style.display = display;
        }
      } else {
        //alert("toggle_display: A [" + element_id + "] element id nem található.");
      };
    } else {
      //alert("toggle_display: A [" + framename + "] nevű frame nem található.");
    }
  };

/*
  function toggle_display(framename, element_id, display) {

    var f;
    f = getFrameByName(framename);
    if (f) {
      var e;
      e = f.document.getElementById(element_id);
      if (e) {
        var win = winopen('blank.php',element_id,'outerWidth='+'1000'+',outerHeight='+'600'+',scrollbars=yes,resizable=yes,hotkeys=no,status=no',true);
        win.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
        win.document.write("<html lang=\"hu\">\n");
        win.document.write("<head>\n");
        win.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
        win.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/xdcr.css\">\n");
        win.document.write("<script type=\"text/javascript\" src=\"/script/global.js\"></script>\n");
        win.document.write("</head>\n");
        win.document.write("<body>\n");
        win.document.write(e.innerHTML);
        win.document.write("</body>\n");
        win.document.write("</html>\n");
        alert(e.innerHTML);
      } else {
        alert("toggle_display: A [" + element_id + "] element id nem található.");
      };
    } else {
      alert("toggle_display: A [" + framename + "] nevű frame nem található.");
    }
  };
*/
  function forcelogin() {
    var f = getFrameByName("frame_main");
    if (f) {
      var prev_location = f.location.href; // elmentjük a frame_main előző tartalmát
      document.forcelogin.prev_location.value = prev_location;
      submitform("forcelogin");
    } else {
      //alert("forcelogin: A [frame_main] nevű frame nem található.");
    }
  };


 function trim(str)
 {
   return str.replace(/^\s*|\s*$/g,"");
 }

 /*
  function getParameter(param) {
    var r = getIDRef(param, "");
    if (r && r.evnt) { return r.evnt.value; }
    return false;
  }

  function setParameter(param, val) {
    var r = getIDRef(param, "");
    if (r && r.evnt) { r.evnt.value = val; return true; }
    return false;
  }
*/

/*
function getParameter(param) {
    var r = getIDRef(param, "");
    if (r && r.evnt) { return r.evnt.name; }
    return false;
  }

  function setParameter(param, val) {
    var r = getIDRef(param, "");
    if (r && r.evnt) { r.evnt.name = val; return true; }
    return false;
  }

*/
/*
  function show(obj) {
    obj.css.visibility="visible";
  }
*/
  function toggle_visibility(id) {

    obj = document.getElementById(id);
    if (obj) {
      if (obj.style.display == "none" ||obj.style.display == "") {
        obj.style.display="block";
      } else {
        obj.style.display="none";
      }
    }
  }


/* szám formázó függvények */
  function Sign(y) {
    return (y > 0 ? "" : y < 0 ? "-" : " ");
  };

  function Prfx(Q, L, c) {
    var s = Q + "";
    if (c.length > 0) {
        while (s.length < L) {
            s = c + s;
        }
    }
    return s;
  };

  function StrU(X, M, N) {
    var T, S = new String(Math.round(X * Number("1e" + N)));
    if (/\D/.test(S)) {
        return "" + X;
    }
    var d = ",";
    var s = new String(Prfx(S, M + N, "0"));

    for (var i = T =(s.length - N); i > 3; i-=3) {
      d = " "+s.substring(i-3,i)+d;
    }
    d = s.substring(0,i) + d;
    //return substring(0, T = (length - N)) + substring(T);
    return d + s.substring(T);
  };

  function StrS(X, M, N) {
    return Sign(X) + StrU(Math.abs(X), M, N);
  };

//var DetailedItem;
var OriginalClassName;
//var DetailedOriginalClassName;

function item_select(object)
{
  if(object.className != "item_selected")
  {
    OriginalClassName = object.className;
    object.className = "item_selected";
  }
}

function item_unselect(object)
{
  if(object.className == "item_selected")
    object.className = OriginalClassName;
}


function stopevents(e)
{
  var event;
  if (!e) {
    event = window.event;
  } else {
    event = e;
  }
  event.cancelBubble = true;
  if (event.stopPropagation) event.stopPropagation();
  return true;
}


/*function SelectField(object) {
  this.select;
//IE support
  if (document.selection) {
    sel = document.selection.createRange();
    sel.moveStart(’character’, -this.length);
sel.select();
    sel.text = myValue;
  }
//MOZILLA/NETSCAPE support
  else {
    this.selectionStart = 0;
    this.selectionEnd = this.Value.length;
  }
}
*/

function ScrollToElementById(id) {
  // kliens ablak magassága
  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;
  }
  //alert(myWidth + ' x ' + myHeight);

  // kliens ablak pozíciója
  var scrollX, scrollY;
  if (document.all)
  {
     if (!document.documentElement.scrollLeft)
        scrollX = document.body.scrollLeft;
     else
        scrollX = document.documentElement.scrollLeft;

     if (!document.documentElement.scrollTop)
        scrollY = document.body.scrollTop;
     else
        scrollY = document.documentElement.scrollTop;
  }
  else
  {
     scrollX = window.pageXOffset;
     scrollY = window.pageYOffset;
  }
  //alert(scrollX + ' x ' + scrollY);

  theElement = document.getElementById(id);

  var selectedPosX = 0;
  var selectedPosY = 0;
  if (theElement.offsetParent)
  {
    while (theElement.offsetParent)
    {
      selectedPosX += theElement.offsetLeft;
      selectedPosY += theElement.offsetTop;
      theElement = theElement.offsetParent;
    }
  }
  else if (theElement.y)
    selectedPosY += theElement.y;

  //alert(selectedPosX + ' x ' + selectedPosY);

  if (selectedPosY < (scrollY + 25)) {
    window.scrollTo(selectedPosX, selectedPosY - 50);
  } else if (selectedPosY > (scrollY + myHeight - 25)) {
    window.scrollTo(selectedPosX, selectedPosY - myHeight + 50);
  }

}

function RestoreFrames()
{
	if(parent.location.href == self.location.href)
	{
		if(window.location.href.indexOf("fsurl") < 0)
		{
			var target_page = '/fs_main.php?fsurl='+encodeURIComponent(self.location.href);
			if(window.location.replace)
				window.location.replace(target_page);
			else // causes problems with back button, but works
				window.location.href = target_page;
		}
	}
}

function ReloadFrameset() {
  var myurl = '/fs_main.php'
  var myparam = "";
  var f = getFrameByName("frame_main");
  if(f) {
    myparam = '?fsurl='+encodeURIComponent(f.location.href);
  }
  myurl = myurl + myparam;

  if(top.location.replace)
    top.location.replace(myurl);
  else
    top.location.href = myurl;
}

function openfull(myurl) {
  //settings = 'width='+screen.width+',height='+screen.height+',top=0,left=0,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  settings = 'fullscreen=1,scrollbars=yes';
  w1 = window.open(myurl, 'fw', settings);
  w1.focus();
}

function openw(myurl) {
  settings = 'width=640,height=480,top=0,left=0,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,scrollbars=no';
  //settings = 'fullscreen=1,scrollbars=yes';
  w1 = window.open(myurl, 'fw', settings);
  w1.focus();
}

function openwin(myurl, settings) {
  w1 = window.open(myurl, 'fw', ' ' + settings);
  w1.focus();
  return false;
}

function nemelerheto() {
var p=window.createPopup()
var pbody=p.document.body
pbody.style.backgroundColor="white"
pbody.style.border="solid green 1px"
pbody.innerHTML="A termékkel kapcsolatban kérem keresse munkatársainkat! <a href='elerhetoseg.php' target='_blank'>Elérhetőségeink</a>"
p.show(350,150,300,50,document.body)
}

function rpcCallMegerositessel(MyURL, Uzenet) {
  var separator = "";
  var valasz = "";
  if(Uzenet != '') {
    separator = ((MyURL.indexOf("?") > -1)?"&":"?");
    valasz = "yesno="+(confirm(Uzenet)?"true":"false");
  }
  callToServer(MyURL+separator+valasz, false);
}


function setTextareaMaxLength() {
	var textarea = document.getElementsByTagName('textarea');
	for(var i=0; i<textarea.length; i++) {
		if(textarea[i].getAttribute('maxlength')) {
			textarea[i].onkeyup = textarea[i].onchange = checkTextareaMaxLength;
			textarea[i].onkeyup();
		}
	}
}

function checkTextareaMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if(currentLength > maxLength) {
		this.value = this.value.substring(0, maxLength);
  }
}
