//***********************************************************************************************************************************/
//
//	TinyRemoteCallCall v1.0
//
//	Author: Lukas Musalek
//	  Date: January 19, 2009
//
//  Description: TinyRemoteCallCall is a Class to call a remote php script and display result
//
// 
//
//***********************************************************************************************************************************/



/* ************************************
 *
 *  Description: Array - remote objects holder 
 *
 * ************************************ */
var remoteObject = new Array();

var remoteTextLoading = "";
var remoteTextClose = "";
var remoteTextMinimalize = "";
var remoteTextMaximalize = "";

// use in html code !!!!
setGlobalremoteParameters("Vyřizuje se Váš požadavek","Zavřít","Minimalizovat","Maximalizovat");
// end

/* ************************************
 *
 *  Description: simulate object creation and display
 *
 *  see function (constructor) TinyRemoteCall
 *
 * ************************************ */
function newRemCall(id, script, classname, constructParams, method, methodParams, formId) {
  if (remoteObject) {
    remoteObject[id] = new TinyRemoteCall(id, script, classname, constructParams, method, methodParams, formId);
    remoteObject[id].sendRequest();
  }
  return false;
}

/* ************************************
 * 
 *  Description: set global parameters
 *
 * ************************************ */
function setGlobalremoteParameters(remoteTextLoadingPom,remoteTextClosePom,remoteTextMinimalizePom,remoteTextMaximalizePom) {
  remoteTextLoading = remoteTextLoadingPom;
  remoteTextClose = remoteTextClosePom;
  remoteTextMinimalize = remoteTextMinimalizePom;
  remoteTextMaximalize = remoteTextMaximalizePom;
}

/* ************************************
 *
 * Description: Constructor
 *   
 * Params: id - [string] - set id of new remote object
 *         nazev - [string] - text to fill in remote bar header
 *         php - [string] - name of php script to call first
 *         width - [integer] - remote windows width
 *         height - [integer] - remote window height. 
 *         action - [string] - to define action in php script
 *         params - [string] - url params posted to php script (name=test&telefon=758965858....) 
 *         disableBackground - [boolean 1/0] - if 1, multiple remotes are allowed, if 0, only one remote is allowed
 *         
 * ************************************ */  
function TinyRemoteCall(id, script, classname, constructParams, method, methodParams, formId) {
  this._disableBackground = 0;
  this._id = id;
  this._formId = formId;
  this._nazev = "";
  this._php = "ajax";
  this._width = 350;
  this._height = 200;
  this._left = 0;
  this._top = 0;
  this._script = "<paramscript>"+script+"</paramscript>";
  this._classname = "<paramclassname>"+classname+"</paramclassname>";
  if (this.isArray(constructParams)) {
    this._constructParams = "<paramconstructparams>";
    for (var i in constructParams) {
      if (this.isNumeric(i)) {
        this._constructParams += "<param"+i+">"+constructParams[i]+"</param"+i+">";
      } else {
        this._constructParams += "<"+i+">"+constructParams[i]+"</"+i+">";
      }
    }
    this._constructParams += "</paramconstructparams>";
  }
  else {
    this._constructParams = "<paramconstructparams>"+constructParams+"</paramconstructparams>";
  }

  this._method = "<parammethod>"+method+"</parammethod>";
  if (this.isArray(methodParams)) {
    this._methodParams = "<parammethodparams>";
    for (var i in methodParams) {
      if (this.isNumeric(i)) {
        this._methodParams += "<param"+i+">"+methodParams[i]+"</param"+i+">";
      } else {
        this._methodParams += "<"+i+">"+methodParams[i]+"</"+i+">";
      }
    }
    this._methodParams += "</parammethodparams>";
  }
  else {
    this._methodParams = "<parammethodparams>"+methodParams+"</parammethodparams>";
  }
  
  this.doc = document;
  this._isGenerated = 0;
  this._isLoading = 0;
  this._isClosing = 0;
  this._firstLoad = 0;
  this._activeTab = 0;
  this._icon = "";
  this._formData = "";
  
  // default values
  this._def_width = this._width;
  this._def_height = this._height;
  this._def_left = 0;
  this._def_top = 0;
  this._def_outer_border = 1;
  this._def_inner_border = 5;
  this._def_but_height = 26;
  this._def_resizebox_height = 10;
  this._setButtons = 0;
  this._setResize = 0;
  this._def_tab_height = 23;
  this._setTabs = 0;
  this._def_nazev = "";
  this._def_timeout = 1000;
  this._def_loading_message = remoteTextLoading;
  this._def_close_message = remoteTextClose;
  this._def_icon = "./img/icon_info.jpg";
  this._icon = this._def_icon;
  this._debug_mode = 0;
  
  /*@cc_on
		/*@if (@_jscript)
			this.ie = (document.all && !window.opera) ? true : false;
		/*@else @*/
			this.ie = false;
		/*@end
	@*/
	this.ie7 = (this.ie && window.XMLHttpRequest);	
	//if (!this.ie) document.captureEvents(Event.MOUSEMOVE);
}

/* ************************************
 *
 *  Description: return x position of element
 *
 *  Params: obj - [object]
 *   
 * ************************************ */
TinyRemoteCall.prototype.findPosX = function(obj) {	
  var curleft = 0;
  if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}
  
/* ************************************
 *
 *  Description: return y position of element
 *
 *  Params: obj - [object]
 *   
 * ************************************ */
TinyRemoteCall.prototype.findPosY = function(obj) {
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

/* ************************************
 *
 *  Description: return true if object is generated
 *
 * ************************************ */
TinyRemoteCall.prototype.isGenerated = function() {
  return this._isGenerated;
}

/* ************************************
 *
 *  Description: return true if input is a number
 *
 * ************************************ */
TinyRemoteCall.prototype.isNumeric = function(input) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < input.length && IsNumber == true; i++) 
      { 
      Char = input.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

/* ************************************
 *
 *  Description: return true if input is an array
 *
 * ************************************ */
TinyRemoteCall.prototype.isArray = function(obj) {
   if (obj.constructor.toString().indexOf("{")==-1 && obj.constructor.toString().indexOf("Array")==-1)
      return false;
   else
      return true;
}


/* ************************************
 *
 *  Description: return z-index of a window
 *
 * ************************************ */
TinyRemoteCall.prototype.getZindex = function() {
  return this._zIndex;
}

/* ************************************
 *
 *  Description: set z-index of a window
 *
 * ************************************ */
TinyRemoteCall.prototype.setZindex = function(zIndex) {
  this._zIndex = zIndex;
}

/* ************************************
 *
 *  Description: create XMLHttp request
 *
 * ************************************ */
TinyRemoteCall.prototype.createXmlHttpRequestObject = function() {
  var xmlHttp;
  // pro vsechny prohlizece krome IE6 a starsich
  try {
    xmlHttp = new XMLHttpRequest();
  }
  // IE6 a starsi
  catch(e) {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
      try { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // vraci objekt nebo zobrazi chybu
  if (!xmlHttp) {
    alert("Error creating the XMLHttpRequest object.");
  }
  else { 
    return xmlHttp;
  }
}

/* ************************************
 *
 *  Description: set element position to the center of the visible page area
 *
 * ************************************ */
TinyRemoteCall.prototype.Centruj = function(id) {
  if (id) this._id = id;
  if (document.getElementById(this._id)) {
    el = document.getElementById(this._id);
    el.style.top = ((document.documentElement.clientHeight)/2)-(el.offsetHeight/2)+document.documentElement.scrollTop+"px";
    el.style.left = ((document.documentElement.clientWidth)/2)-(el.offsetWidth/2)+document.documentElement.scrollLeft+"px";
  }
}

/* ************************************
 *
 *  Description: generate remote windows objects
 *
 * ************************************ */
TinyRemoteCall.prototype.generateWindow = function() {
  var objBody = this.doc.getElementsByTagName("body").item(0);
  
  if (this._disableBackground==0) {
  var objOverlay = this.doc.createElement("div");
		objOverlay.setAttribute('id','lbOverlay'+this._id);
		objOverlay.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_prekryti_obrazovky');
		if ((this.ie && !this.ie7) || (this.ie7 && this.doc.compatMode == 'BackCompat')) {
			objOverlay.style.position = 'absolute';
		}
		objOverlay.style.display = 'none';
		objBody.appendChild(objOverlay);
	}	
  var objIs_popup1 = this.doc.createElement("div");
		objIs_popup1.setAttribute('id',this._id);
		objIs_popup1.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_hlavni');
		//objIs_popup1.setAttribute('onmousedown','popupObject[\''+this._id+'\'].focuspopup();');
		objIs_popup1.style.display = 'none';
		objIs_popup1.innerHTML = '<div class="popup_window_vnejsi_ram" id="ramecek_'+this._id+'"></div>';
		objBody.appendChild(objIs_popup1);
		
  var objRamecek = document.getElementById('ramecek_'+this._id);
  
  var objLista = this.doc.createElement("div");
    objLista.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_lista_active');
    objLista.setAttribute('id','is_popup1_lista'+this._id);
    objLista.innerHTML = '<a class="popup_window_zavrit" onclick="remoteObject[\''+this._id+'\'].hidePopup();return false;" title="'+this._def_close_message+'"></a>';
		objRamecek.appendChild(objLista); 
  var objNazev = this.doc.createElement("div");
    objNazev.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_nazev');
    objNazev.setAttribute('id','is_popup1_nazev'+this._id);
		objLista.appendChild(objNazev); 
		
	var objBox = this.doc.createElement("div");
    objBox.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_ram');
    objBox.setAttribute('id','is_popup1_content_box'+this._id);
    objRamecek.appendChild(objBox);	

  var objForm = this.doc.createElement("form");
    objForm.setAttribute('id','is_popup1_form'+this._id);
    objBox.appendChild(objForm); 	

  var objTabs = this.doc.createElement("div");
    objTabs.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_tabs');
    objTabs.setAttribute('id','is_popup1_tabs'+this._id);
		objForm.appendChild(objTabs); 
    	
  var objContent = this.doc.createElement("div");
    objContent.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_obsah2');
    objContent.setAttribute('id','is_popup1_content'+this._id);
		objForm.appendChild(objContent); 
	var objButtons = this.doc.createElement("div");
    objButtons.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_tlacitka');
    objButtons.setAttribute('id','is_popup1_buttons'+this._id);
		objBox.appendChild(objButtons); 
		
  var objResizebox = this.doc.createElement("div");
    objResizebox.setAttribute((this.ie ? 'className' : 'class'), 'popup_window_resizebox');
    objResizebox.setAttribute('id','is_popup1_resizebox'+this._id);
    objResizebox.innerHTML = '<div class="popup_window_resize" id="is_popup1_resize'+this._id+'"></div>';
		objRamecek.appendChild(objResizebox);  
     	

   this._isGenerated = 1;  
}

/* ************************************
 *
 *  Description: send request to server
 *
 * ************************************ */
TinyRemoteCall.prototype.sendRequest = function(script, classname, constructParams, method, methodParams) {
  if (this._isLoading!=1) {
    this._isLoading = 1;

    if (script) this._script = "<paramscript>"+script+"</paramscript>";
    if (classname) this._classname = "<paramclassname>"+classname+"</paramclassname>";
    if (constructParams) this._constructParams = "<paramconstructparams>"+constructParams+"</paramconstructparams>";
    if (method) this._method = "<parammethod>"+method+"</parammethod>";
    if (methodParams) this._methodParams = "<parammethodparams>"+methodParams+"</parammethodparams>";
    
    this.getForm();
    
    this._new_param = "params=<body><remote_id>"+this._id+"</remote_id>"+this._script+this._classname+this._constructParams+this._method+this._methodParams+this._formData+"</body>";
    if (this._debug_mode==1) {
      alert('PARAMS TO SEND: '+this._new_param);
    }  
    var http = this.createXmlHttpRequestObject();
    var id = this._id;
    
    http.open("POST", this._php+".php", true);
    http.onreadystatechange=function() {
      if(http.readyState == 4) {
        if (http.status == 200) {
          if (http.responseText) {
            remoteObject[id].decodeRequest(http);
          }  
        }
      }
    }
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    http.send(this._new_param);
  }  
}

/* ************************************
 *
 *  Description: get form data
 *
 * ************************************ */
TinyRemoteCall.prototype.getForm = function() {
  this._formData = "<formdata>";
  if (document.getElementById(this._formId)) {
    var objForm = document.getElementById(this._formId);
    var formData = objForm.elements;
    var newParam = Array();
    var poc = 0;
    
    if (formData.length>0) {
      
      for (var i=0; i < formData.length; i++) {
        if (formData[i].type == "checkbox") {
          if (formData[i].checked==1) {
            this._formData += "<"+formData[i].name+">1</"+formData[i].name+">";
          }  
        }else 
        if (formData[i].type == "radio") {
          if (formData[i].checked==1) {
            this._formData += "<"+formData[i].name+">"+formData[i].value+"</"+formData[i].name+">";
          }  
        }else 
        if (formData[i].tagName == "SELECT") {
          this._formData += "<"+formData[i].name+">"+formData[i].value+"</"+formData[i].name+">";
        }else 
        if (formData[i].tagName == "TEXTAREA") {
          this._formData += "<"+formData[i].name+"><![CDATA["+formData[i].value+"]]></"+formData[i].name+">";
        } else {
          this._formData += "<"+formData[i].name+"><![CDATA["+formData[i].value+"]]></"+formData[i].name+">";
        }
        poc++;
      }
    }
  }
  this._formData += "</formdata>";
}

/* ************************************
 *
 *  Description: hide select
 *
 * ************************************ */
TinyRemoteCall.prototype.hideSelects = function() {
  if (this.ie && !this.ie7) {
    //alert('id '+this._id);
   var selects = this.doc.getElementsByTagName("SELECT");
    if (selects.length>0) {
      for (var i = 0; i < selects.length; i++) {
        selects[i].style.visibility = "hidden";
        //alert('hide '+i);
      }
    }
    var objForm = document.getElementById('is_remote1_form'+this._id);
    if (objForm) {
      var formData = objForm.elements;
      if (formData.length>0) {
        for (var i=0; i < formData.length; i++) {
          if (formData[i].tagName == "SELECT") {
            formData[i].style.visibility = "";
            //alert('show '+i);
          }
        }
      } 
    } 
  }  
}

/* ************************************
 *
 *  Description: hide select
 *
 * ************************************ */
TinyRemoteCall.prototype.showSelects = function() {
  if (this.ie && !this.ie7) {
    var selects = this.doc.getElementsByTagName("SELECT");
    if (selects.length>0) {
      for (var i = 0; i < selects.length; i++) {
        selects[i].style.visibility = "";
      }
    } 
  }   
}


/* ************************************
 *
 *  Description: decode XML result from server
 *  
 *  Params: http - [XMLHttpRequest]  
 *
 * ************************************ */
TinyRemoteCall.prototype.decodeRequest = function(http) {
  if (this._debug_mode==1) {
    alert('RETURNED XML: '+http.responseText);
  } 
  if (this._isLoading==1) {
    this._isLoading = 0;
    //alert(http.responseText);
    var objparamsBOX = http.responseXML.getElementsByTagName('objparams')[0];
    var status = objparamsBOX.getElementsByTagName('status')[0].firstChild.nodeValue;
    
    if (objparamsBOX.getElementsByTagName('popupwidth')[0])
    this._width = objparamsBOX.getElementsByTagName('popupwidth')[0].firstChild.nodeValue;
    if (objparamsBOX.getElementsByTagName('popupheight')[0])
    this._height = objparamsBOX.getElementsByTagName('popupheight')[0].firstChild.nodeValue;
    if (objparamsBOX.getElementsByTagName('popupname')[0])
    this._nazev = objparamsBOX.getElementsByTagName('popupname')[0].firstChild.nodeValue;
    else this._nazev = this._def_nazev; 
    if (objparamsBOX.getElementsByTagName('resizable')[0]) this._setResize = 1;
    else this._setResize = 0;
    if (objparamsBOX.getElementsByTagName('popupicon')[0])
    this._icon = objparamsBOX.getElementsByTagName('popupicon')[0].firstChild.nodeValue;
    else this._icon = this._def_icon;
    
    var contentsBOX = http.responseXML.getElementsByTagName('contents')[0];
    if (contentsBOX) var content = contentsBOX.getElementsByTagName('content');
    
      

    if (status=='finished') {
      var otherContentsBOX = http.responseXML.getElementsByTagName('othercontents');
      if (otherContentsBOX) {
        var otherContents = otherContentsBOX[0].getElementsByTagName('othercontent');
        for (var i = 0; i < otherContents.length; i++) {
          var elementid = otherContents[i].getElementsByTagName('elementid')[0].firstChild.nodeValue;
          var newhtml = otherContents[i].getElementsByTagName('newhtml')[0].firstChild.nodeValue;
          var el = document.getElementById(elementid);
          el.innerHTML = newhtml;
        }
      }
    }
    else {
      this.generateWindow();
      if (document.getElementById(this._id)) {
        if (this._disableBackground==0) {
          var lbOverlay = document.getElementById('lbOverlay'+this._id);
          lbOverlay.style.display = 'block';
          var pageSize = this.getPageSizeWithScroll();
          lbOverlay.style.height = pageSize[1];
        }  
        popup = document.getElementById(this._id);
        if (popup!='block') {
          document.getElementById('is_popup1_nazev'+this._id).innerHTML = this._nazev;
          Drag.init(document.getElementById('is_popup1_lista'+this._id), document.getElementById(this._id));
        }
        this.setSize();
      }  
      var inpopup = document.getElementById('is_popup1_content'+this._id);
      var tabs = document.getElementById('is_popup1_tabs'+this._id);
      inpopup.innerHTML = content[0].getElementsByTagName('popuphtml')[0].firstChild.nodeValue;
  
    }
      

  
    if (status!='finished') {
      var buttons = document.getElementById('is_popup1_buttons'+this._id);
      buttons.innerHTML = "";
      var popupButtonsBOX = http.responseXML.getElementsByTagName('popupbuttons');
      if (popupButtonsBOX) {
        var popupButtons = popupButtonsBOX[0].getElementsByTagName('popupbutton');
        for (var i = 0; i < popupButtons.length; i++) {
          var name = popupButtons[i].getElementsByTagName('name')[0].firstChild.nodeValue;
          var className = popupButtons[i].getElementsByTagName('class')[0].firstChild.nodeValue;
          var onclickFuncBOX = popupButtons[i].getElementsByTagName('onclick')[0];
          if (onclickFuncBOX) {
            onclickFunc = onclickFuncBOX.firstChild.nodeValue
          } else onclickFunc = "";
          
          var newOnClick = "";
          var buttype = popupButtons[i].getElementsByTagName('buttype')[0];
          if (buttype) {
            if (buttype.firstChild.nodeValue == "send") {
              var newparamscript = null;
              var newparamclassname = null;
              var newparamconstructparams = null;
              var newparammethod = null;
              var newparammethodparams = null;
              
              var paramscript = popupButtons[i].getElementsByTagName('paramscript');
              if (paramscript[0].firstChild) {
                newparamscript = "'"+paramscript[0].firstChild.nodeValue+"'";
              }
              var paramclassname = popupButtons[i].getElementsByTagName('paramclassname');
              if (paramclassname[0].firstChild) {
                newparamclassname = "'"+paramclassname[0].firstChild.nodeValue+"'";
              }
              var paramconstructparams = popupButtons[i].getElementsByTagName('paramconstructparams');
              if (paramconstructparams[0].firstChild) {
                newparamconstructparams = "'"+paramconstructparams[0].firstChild.nodeValue+"'";
              }
              var parammethod = popupButtons[i].getElementsByTagName('parammethod');
              if (parammethod[0].firstChild) {
                newparammethod = "'"+parammethod[0].firstChild.nodeValue+"'";
              }
              var parammethodparams = popupButtons[i].getElementsByTagName('parammethodparams');
              if (parammethodparams[0].firstChild) {
                newparammethodparams = "'"+parammethodparams[0].firstChild.nodeValue+"'";
              }
              var newOnClick = "remoteObject['"+this._id+"'].sendRequest("+newparamscript+","+newparamclassname+","+newparamconstructparams+","+newparammethod+","+newparammethodparams+");";
            }
            if (buttype.firstChild.nodeValue == "close") {
              var newOnClick = "remoteObject['"+this._id+"'].hidePopup();";
            }
            
          }
          
          
          buttons.innerHTML += '<a href="" class="'+className+'" onclick="'+newOnClick+onclickFunc+';return false;">'+name+'</a>';
        }
        this._setButtons = 1;
      } else this._setButtons = 0; 
    
      this.setSize();
    } else {
    
      var otherContentsBOX = http.responseXML.getElementsByTagName('othercontents');
      if (otherContentsBOX) {
        var otherContents = otherContentsBOX[0].getElementsByTagName('othercontent');
        for (var i = 0; i < otherContents.length; i++) {
          var nid = otherContents[i].getElementsByTagName('elementid')[0].firstChild.nodeValue;
          var newHtml= otherContents[i].getElementsByTagName('newhtml')[0].firstChild.nodeValue;
          if (document.getElementById(nid)) {
            document.getElementById(nid).innerHTML = newHtml;
          }
        }
      }
      remoteObject[this._id].hidePopup();   
    }
    this._firstLoad = 1;
  }
  
}

/* ************************************
 *
 *  Description: set size and position of the remote window
 *  
 * ************************************ */
TinyRemoteCall.prototype.setSize = function() {
  if (this._icon!="") var pomIcon = '<img src="'+this._icon+'" \/>';
  else var pomIcon = "";
  document.getElementById('is_popup1_nazev'+this._id).innerHTML = pomIcon+this._nazev;

  var popup = document.getElementById(this._id);
  var ramecek = document.getElementById('ramecek_'+this._id);
  var lista = document.getElementById('is_popup1_lista'+this._id);
  var box = document.getElementById('is_popup1_content_box'+this._id);
  var tabs = document.getElementById('is_popup1_tabs'+this._id);
  var content = document.getElementById('is_popup1_content'+this._id);
  var buttons = document.getElementById('is_popup1_buttons'+this._id);
  var resizebox = document.getElementById('is_popup1_resizebox'+this._id);
  
  
  if (popup.style.display=="block") var isVis = 1;
  else var isVis = 0;
  popup.style.display = "block";
  popup.style.width = this._width+'px';
  popup.style.height = this._height+'px';
  lista.style.width = (this._width-(2*this._def_outer_border))+"px";
  

  //ramecek
  ramecek.style.width = this._width- (2*this._def_outer_border)+"px";
  ramecek.style.height = this._height- (2*this._def_outer_border)+"px";
  ramecek.style.margin = this._def_outer_border+"px";
    
  

  if (this._setTabs==1) {
    this._tab_height = this._def_tab_height;
    this._top_border = 0;
    content.className = "popup_window_obsah";
    tabs.style.display = "block";
  } else {
    this._tab_height = 0;
    this._top_border = 1;
    content.className = "popup_window_obsah2";
    tabs.style.display = "none";
  }  
  
  if (this._setButtons==1) {
    this._but_height = this._def_but_height;
    buttons.style.display = "block";
  } else {
    this._but_height = 0;
    buttons.style.display = "none";
  }  
  
  if (this._setResize==1) {
    this._res_height = this._def_resizebox_height;
    this._bottom_border = 0;
    resizebox.style.display = "block";
    
  } else {
    this._res_height = 0;
    this._bottom_border = this._def_inner_border;
    resizebox.style.display = "none";
  }  
  
  // box
  box.style.height = this._height - (2*this._def_outer_border) - this._def_inner_border - this._bottom_border - this._res_height - lista.offsetHeight+"px";
  box.style.width = lista.offsetWidth - (2*this._def_inner_border) + "px";
  box.style.margin =  this._def_inner_border + "px";
  box.style.marginBottom = this._bottom_border + "px";
  
  //content
  content.style.height = this._height - (2*this._def_outer_border) - this._def_inner_border - this._bottom_border - 2 + this._top_border - lista.offsetHeight - this._but_height - this._tab_height - this._res_height +"px";
  content.style.width = this._width - (2*this._def_outer_border) - (2*this._def_inner_border) - 2 + "px";
  
  

  tabs.style.height = this._tab_height+"px";
  tabs.style.width = this._width - (2*this._def_outer_border) - (2*this._def_inner_border) + "px";
  
  buttons.style.height = this._but_height+"px";
  buttons.style.width = this._width - (2*this._def_outer_border) - (2*this._def_inner_border) + "px";
  
  resizebox.style.height = this._res_height+"px";
  resizebox.style.width = this._width - (2*this._def_outer_border) + "px";

  if (isVis==1 && this._firstLoad==1 && this._left>0 && this._top>0) {
    popup.style.top = this._top + 'px';
    popup.style.left = this._left + 'px';
  } else this.Centruj(this._id); 

  this._left = popup.offsetLeft;
  this._top = popup.offsetTop;
}

/* ************************************
 *
 *  Description: hide remote window
 *  
 * ************************************ */
TinyRemoteCall.prototype.hidePopup = function() {
  var objBody = document.getElementsByTagName("body").item(0);	
  if (document.getElementById(this._id)) {
    popup = document.getElementById(this._id);
    popup.style.display = 'none';
    if (document.getElementById('lbOverlay'+this._id)) {
      document.getElementById('lbOverlay'+this._id).style.display = 'none';
    	if (document.getElementById('lbOverlay'+this._id)) {
    		objBody.removeChild(document.getElementById('lbOverlay'+this._id));
    	}
    } 
    objBody.removeChild(document.getElementById(this._id));
    this._isGenerated="0";
    delete remoteObject[this._id];
  } 
}


/* ************************************
 *
 *  Description: get page size
 *
 * ************************************ */
TinyRemoteCall.prototype.getPageSizeWithScroll = function() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

/* ************************************
 *
 *  Description: encode string
 *
 * ************************************ */
TinyRemoteCall.prototype.urlencode = function( str ) {
                                    
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

/* ************************************
 *
 *  Description: decode string
 *
 * ************************************ */
TinyRemoteCall.prototype.urldecode = function( str ) {
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
}




