
      function findObj(theObj, theDoc)
      {
        var p, i, foundObj;
        
        if(!theDoc) theDoc = document;
        if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
        {
          theDoc = parent.frames[theObj.substring(p+1)].document;
          theObj = theObj.substring(0,p);
        }
        if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
        for (i=0; !foundObj && i < theDoc.forms.length; i++) 
          foundObj = theDoc.forms[i][theObj];
        for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
          foundObj = findObj(theObj,theDoc.layers[i].document);
        if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
        
        return foundObj;
      }

      function Pos(x,y)
      {
        this.x = x;
        this.y = y;

        this.move = function(x,y)
        {
          this.x += x;
          this.y += y;
        }
      }

      function Size(w,h)
      {
        this.w = w;
        this.h = h;
      }

      function Box(x,y,w,h)
      {
        this.__constructorPos = Pos;
        this.__constructorSize = Size;
        this.__constructorPos(x,y);
        this.__constructorSize(w,h);
      }

      var ap_bad = new Array("BODY","TABLE");
      ap_bad.contain = function(tag)
      {
        for(var i=0; i<this.length; i++)
          if(this[i]==tag)
            return true;
        return false;
      }
    
      function absolutePos(control,client)
      {
        var result;
        var parent;
        if(client==null || client)
        {
          result = new Box(0,0,control.offsetWidth,control.offsetHeight);
          parent = control;
        }
        else
        {
          result = new Box(control.offsetLeft,control.offsetTop,control.offsetWidth,control.offsetHeight);
          parent = control.offsetParent;
        }
        while(parent!=null)
        {
          result.move(parent.offsetLeft,parent.offsetTop);
          if(!ap_bad.contain(parent.tagName))
          {
            if(typeof(parent.clientLeft)!="undefined")
              result.move(parent.clientLeft,parent.clientTop);
          }
          parent = parent.offsetParent;
        }
        return result;
      }

      //*********************************************************

      // Tê funkcje dodamy do zbioru utils.js
      function repos(childName,parentName,left,top,right,bottom)
      {
        var parent = findObj(parentName);
        var child = findObj(childName);
        if(parent!=null && child!=null)
        {
          var parentPos = absolutePos(parent);
          var childPos = absolutePos(child);
          if(left!=null)
            child.style.left = parentPos.x+left;
          if(top!=null)
            child.style.top = parentPos.y+top;
          if(right!=null)
            child.style.left = parentPos.x+parentPos.w-childPos.w+right;
          if(bottom!=null)
            child.style.top = parentPos.y+parentPos.h-childPos.h+top;
        }
      }      
      
	function ReplaceImage(sImgName,sImgFile)
	{ 
	  document.images[sImgName].src = sImgFile; 
	}

	function checkTextLenght(text, long, msg) {
	    var maxlength = new Number(long); // Change number to your max length.

	    if (text.value.length > maxlength) {
	        text.value = text.value.substring(0, maxlength);
	        alert(msg);
	    }
	}
