   // Functions used by WebtopONE portal pages (and some CMS pages)
   var WinHandle = new Array();
   var iframe2cnt = 0;

   function doCatalogWin()
   {
      var x = 30
      var y = 30
      var width = 950
      var height = 600

      if (screen.width <= 950) {
         x = 5; y = 5; width = 750; height = 450;
      }
      WinHandle["CatalogWin"] = window.open("catalog.aspx", "Catalog","width=" + width + ",height=" + height +
           ",left=" + x + ",top="+ y + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes")
      if (WinHandle['CatalogWin'] != null) {
         window.setTimeout("try{WinHandle['CatalogWin'].focus()} catch(e){}", 500);
      }
   }
   

   function doOpenWinWT1(url, name, width, height)  {
      var topleft = 'left=' + Math.round((screen.width-width)/2) + ',top=' + Math.round((screen.height-height)/2);
      WinHandle[name] = window.open(url, name, 'width=' + width + ',' + 'height=' + height + ',' + topleft +
                             ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no')
      if (WinHandle[name] != null) {
         window.setTimeout("try{WinHandle[name].focus()} catch(e){}", 500);
      }
   }

   function doRenameWin(navtab) {
      doOpenWinWT1("pagerename.aspx?nwt=" + escape(navtab), "Rename", 400, 185)
   }

   function doMovePgWin(navtab) {
      doOpenWinWT1("pagemove.aspx?nwt=" + escape(navtab), "Move", 400, 185)
   }

   function doUserWin(url)
   {
      doOpenWinWT1(url, "wt1uwin", 700, 400)
   }

   function pageSelect(txtboxId, pgid, type) {
      var url
      if (type != 'fnc')
         url = "sitepgselect.aspx?txtBoxId=" + txtboxId
      else
         url = "sitepgselect.aspx?fnc=" + txtboxId
      var pgwindow = window.open(url, "PageSelect",
        "toolbar=0, location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=300,height=450,top=50,left=50")
      pgwindow.focus()
   }

   var fprewin = false //?!
   function doPreviewWin(id) {
      fprewin = true
      WinHandle['PreviewWin']=window.open("previewcomp.aspx?nocmds=1&autoclose=1&acf=fprewin&id=" + id, "Example",
                "width=380,height=400,left=" + (screen.width - 400) + ",top=20," +
                 "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes")
      window.setTimeout("if (WinHandle['PreviewWin'].focus()) WinHandle['PreviewWin'].focus()", 500);
   }

   function WTCheckErrorMsg() {
      try { 
      if (document.getElementById('WTErrorMessage').value) {
         var errmsgfield = document.getElementById('WTErrorMessage')
         var msg = '' + errmsgfield.value
         if (msg.length > 1) {        
            alert(msg)
            document.getElementById('WTErrorMessage').Value = ''
         }
      }
      } catch(e) {}
   }

   function wtescape(s) {
      s = s.replace(/\+/, '%2b');  
      s = s.replace(/\=/, '%3d');  
      s = s.replace(/\?/, '%3f');  
      return s.replace(/\&/, '%26');
   }

   // -----------------------------------------------------------------
   // wt.asp - popupmenu support
   // -----------------------------------------------------------------
   function doEditComp(id) {
      if (eval('if (window.editComp' + id + ') true; else false;'))
         eval('editComp' + id + '()')
      else
         location.replace('setprop.aspx?id=' + id)
   }



   // -----------------------------------------------------------------
   // Default body onload and onload/unload registration service
   // -----------------------------------------------------------------
   function stdBodyOnload() {
      wttick();
      execOnLoadFunctions();
   }

   var onloadfncs = new Array()
   var onunloadfncs = new Array()

   function regOnLoadFnc(f) {
      onloadfncs[onloadfncs.length] = f;
   }

   function regOnUnloadFnc(f) {
      onunloadfncs[onunloadfncs.length] = f;
   }

   function execOnLoadFunctions() {
      var i;
      for (i = 0; i < onloadfncs.length; i++)
         onloadfncs[i]();
   }

   function execOnUnloadFunctions() {
      var i;
      for (i = 0; i < onunloadfncs.length; i++)
         onunloadfncs[i]();
   }

   function wttick() {
      wtResizeIframes();
      window.setTimeout("wttick();", 500);
   }



   // -----------------------------------------------------------------
   // Resize IFrame support
   // -----------------------------------------------------------------
   function resizeIFrame(sIfrmID, maxheight)
   {
      try {
      var oBody  = eval(sIfrmID + '.document.body;')
      var oFrame = document.getElementById(sIfrmID);

      var height = oBody.scrollHeight +
                      (oBody.offsetHeight - oBody.clientHeight);
      if (arguments.length == 1 || height < maxheight)
                oFrame.style.height = height;
      }

      //An error is raised if the IFrame domain != its container's domain
      catch(e)
      {
        // P.T. : Just do nothing: window.status =   'Error: ' + e.number + '; ' + e.description;
      }
   }
   
   function resizeIFrame2(frameId){
      // Crossbrowser
      try{
         var frame = document.getElementById(frameId);
         var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
         var objToResize = (frame.style) ? frame.style : frame;
         objToResize.height = innerDoc.body.scrollHeight + 10;
      }
      catch(err){
         // window.status = err.message;
      }
   }


   function wtResizeIframes()
   {
      // Resize all IFrames with an ID starting with "auto_" IE only
      var i, o
      try {
      iframe2cnt++;
      if (document.all) {
         o = document.all.tags("IFRAME")
         for (i = 0; i < o.length; i++) {
            if (o(i).id.substr(0, 5) == "auto_") {
               resizeIFrame(o(i).id);
            }
         }
      }
      } catch(e) {}
   }


   // -----------------------------------------------------------------
   // Client-site return helper
   // -----------------------------------------------------------------
   function wtReturn(defaultret, noclose)
   {
      try {
      if (window.opener && ('' + noclose != 'noclose')) window.close();
      var i;
      var returl;
      if (defaultret) 
         returl = defaultret;
      else
         returl = "wt.aspx";
      
      var s = window.location.href;
      if (s.lastIndexOf('#') == s.length - 1) s = s.substr(0, s.length - 1)
      if (s.indexOf('?') > 0) {
         var p  =  s.split('?')[0]
         var qs =  s.split('?')[1]
         var A = qs.split('&')
         for (i = 0; i < A.length; i++) {
            s2 = A[i]
            parm = s2.split('=')[0]
            if (parm == 'returl') {
               returl = unescape(s2.split('=')[1])
            }
         }
      }
      // returl not found
      // alert(returl)
      window.location = returl;
      } catch(e){window.location = "wt.aspx";}
   }


   // -----------------------------------------------------------------
   // Refresh component content support
   // -----------------------------------------------------------------
   function refreshComponentBase(id, sParm, fIdParm)
   {
      var sUrl
      var s = window.location.href
      if (!document.all) {
         // _NOT_ IE: Reload entire window with proper parms
         var p, qs, A, qs2, parm, s2
         if (s.lastIndexOf('#') == s.length - 1) s = s.substr(0, s.length - 1)
         if (s.indexOf('?') < 0) {
            p = s
            qs2 = ''
         }
         else {
            var p  =  s.split('?')[0]
            var qs =  s.split('?')[1]
            qs2 = ''
            A = qs.split('&')
            for (i = 0; i < A.length; i++) {
               s2 = A[i]
               parm = s2.split('=')[0]
               if (parm != 'type' && parm != 'parm' + id && parm != 'id')
                  qs2 = qs2 + s2 + '&'
            }
         }

         if (!fIdParm)
            sUrl = p + '?' + qs2 + 'id=' + id + '&parm=' + sParm
         else
            sUrl = p + '?' + qs2 + 'id=' + id + '&parm' + id + '=' + sParm
         window.location = sUrl;
      }
      else {

         // Explorer: use DHTML to reload component
         var divElement = document.getElementById('wt3div' + id)
         if (!divElement) return

         var myBasePath = '' + window.location;
         myBasePath = myBasePath.substr(0, myBasePath.lastIndexOf('/') + 1)
         
         // Create XML document
         var ArrDomNames = ["Msxml2.DOMDocument.3.0", "Microsoft.XmlDom"];
         var XMLObj = null;
         for (var i = 0; i < ArrDomNames.length && XMLObj == null; i++)
         {
            try {
               XMLObj = new ActiveXObject(ArrDomNames[i]);
               // alert(ArrDomNames[i]);
            }
            catch(e){}
         }
         XMLObj.async = false;
                   
         if (!fIdParm) {
            //alert(myBasePath + 'showcomp.aspx?type=xml&id=' + id + '&parm=' + sParm);
            XMLObj.load(myBasePath + 'showcomp.aspx?type=xml&id=' + id + '&parm=' + sParm);
         } else {
            //alert(myBasePath +       'showcomp.aspx?type=xml&id=' + id + '&parm' + id + '=' + sParm + '&info=' + sInfo);
            XMLObj.load(myBasePath + 'showcomp.aspx?type=xml&id=' + id + '&parm' + id + '=' + sParm);
         }
         if (XMLObj.parseError.errorCode != 0) {
            ; // do nothing - alert("Error: " + XMLObj.parseError.reason);
         }
         else {
            divElement.innerHTML = XMLObj.selectSingleNode("//Content").text
            try {eval('afterRefresh' + id + '()')} catch(e){}
         }
      }
   }

   // 5 slightly different refreshComponent versions
   function refreshComponent(id) {
      refreshComponentBase(id, '', false)
   }

   function refreshComponent2(id, sParm) {
      if (document.all) {
         var divElement = document.getElementById('wt3div' + id)
         if (!divElement) return;
         divElement.innerHTML = '...'
      }
      refreshComponentBase(id, sParm, false)
   }

   function refreshComponent3(id, sParm) {
      if (document.all) {
         var divElement = document.getElementById('wt3div' + id)
         if (!divElement) return
         divElement.innerHTML = '...'
      }
      window.setTimeout('refreshComponentBase(' + id + ', "' + sParm + '", true)', 50)
   }

   function refreshComponent4(id, sParm) { // Legacy
      refreshComponentBase(id, sParm, true)
   }

   function refreshComponent5(id, sParm) {
      if (document.all) {
         var divElement = document.getElementById('wt3div' + id)
         if (!divElement) return;
         divElement.innerHTML = '...'
      }
      refreshComponentBase(id, sParm, true)
   }


   // -----------------------------------------------------------------
   // Save Component-Property
   // -----------------------------------------------------------------
   function SaveProp(nID, sPropName, sVal)
   {
      if (!document.all) { alert("Explorer 5 or later required!") ;return;}
      var xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
      xmlDoc.async = false;
      xmlDoc.loadXML('<wtpropnode>' +
                     ' <id>' + nID + '</id>' +
                     ' <propname>' + sPropName + '</propname>' +
                     ' <value>x</value>' +
                     '</wtpropnode>');

      var node = xmlDoc.selectSingleNode("//value")
      node.text = '' + sVal;

      var url = 'wtsaveprop.aspx'
      var objXMLReq = new ActiveXObject( "Microsoft.XMLHTTP" );

      objXMLReq.open( "POST", url, false );

      // Debug:alert("SEND:" + xmlDoc.xml)
      objXMLReq.send( xmlDoc.xml );

      if (objXMLReq.status != 200) {
         // Problems ..
         alert(objXMLReq.responseText);
      }
   }


   // -----------------------------------------------------------------
   // Hide component
   // -----------------------------------------------------------------
   function hideComponent(id, fHide)
   {
      var sDisp = 'none';
      if (!fHide) sDisp = 'block';
      var o = document.getElementById('wt1div' + id);
      if (o) {
         o.style.display = sDisp;
      } else {
         o = document.getElementById('wt2div' + id);
         if (o) o.style.display = sDisp;
      }
   }

   //-----------------------------------------------------------------
   // WebTop COOKIE support
   //-----------------------------------------------------------------

   function wtSetCookie(sName, value, minsToExpire, path, domain, secure) {
      var expires = false
      var now = new Date()

      if (minsToExpire) {
         expires = true
         // Fix date
         var base = new Date(0)
         var skew = base.getTime()
         if (skew > 0)
            now.setTime(date.getTime() - skew)
         now.setTime(now.getTime() + minsToExpire * 60 * 1000)
      }
      var curCookie = sName + "=" + escape(value) +
          ((expires) ? "; expires=" + now.toGMTString() : "") +
           ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
             ((secure) ? "; secure" : "")
      document.cookie = curCookie
   }

   function wtGetCookie(sName) {
      var prefix = sName + "="
      var nStart = document.cookie.indexOf(prefix)
      if (nStart == -1)
         return null
      var nStop = document.cookie.indexOf(";", nStart +
         prefix.length)
      if (nStop == -1)
         nStop = document.cookie.length
      return unescape(document.cookie.substring(nStart +
                       prefix.length, nStop))
   }


