








function performPBFunction(key, topframe) {
  if(topframe==null) {
    topframe = top;
  }
  if(topframe==null) {
    topframe=window;
  }
  if(!pbappIsAnonymous) {
    switch(key) {
      case "ecc": {
        if(typeof(showModalDialog)=="undefined" || navigator.platform!="Win32") {
          return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xedit_xlogin/index.html?workflow=no&menuLang='+pbappMenuLanguageID,'PBEDIT',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        }
        else {
          return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xedit_xlogin/index.html?workflow=no&menuLang='+pbappMenuLanguageID,'PBEDIT',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes');
        }
        break;
      }
      case "ec2k": {
        var openEc2k = true;
        if(typeof(qeRunning)!="undefined" && qeRunning == true) {
          openEc2k = confirmEntityString("The page is currently in quickedit mode. It is recommended, to end the quick edit mode, before you start the Edit Center 2000. Do you really want to open the Edit Center 2000?");
        }
        if(openEc2k) {
          return pbappOWin(topframe,'../../menu/-1_xlogin_eactivex-edit_pframe/index.html?ID='+pbappMenuID+'&LANGUAGE-ID='+pbappMenuLanguageID,'PBWEBEDIT',795,575, false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        }
        break;
      }
      case "admincenter": {
        if(document.layers && navigator.appName=="Netscape" && navigator.appCodeName=="Mozilla") {
        	//open Admincenter with fixed size in Netscape 4
        	return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xadmin_xlogin/index.html','PBADMIN',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        }
        else {
        	//open Admincenter resizable in other browsers
        	return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xadmin_xlogin/index.html','PBADMIN',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes');
        }
        break;
      }
      case "pageattributes": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_ppage-attributes/index.html?resultID='+pbappMenuID+'&resultLangID='+pbappMenuLanguageID,'pageattributes',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no');
        break;
      }
      case "workflowcenter": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ewfc_pwfcenter/index.html','wfcenter',795,575,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }
      case "workflowadmin": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ewfc_padmin_yno/index.html','WFCenter',800,600,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }
      case "communityadmin": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ecmd_padministration-frameset/index.html','COMMUNITYADMIN',800,600,false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "templatecompiler": {
        return pbappOWin(topframe,'../../templateCompiler','TEMPLATECOMPILER'+((new Date()).getTime()),800,600,false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "layoutwizard": {
        if (typeof(openLayoutWizard)=='function') {
          return openLayoutWizard('../../');
        } 
        else { 
          return false; 
        }
        break;
      }
      case "ec2k-blank": {
        return pbappOWin(topframe,'../../menu/-1_xlogin_eactivex-edit_pframe/index.html?DISPLAYID='+pbappMenuID,'PBWEBEDIT',795,575, false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "webdav-browser": {
        return pbappOWin(topframe,'../../menu/-1_xlogin_eWEBDAV_yyes/index5.0.5.2.155.html?PBUSERLANGUAGE='+pbappUserLanguageID,'PBWEBDAV',795,575, false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes');
        break;
      }
      case "addsibling": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_eactivex-edit_pfutureVersionPreview_xlogin_yno/index.html?QEAUTOSTART=true&WFACTION=VIEWCURRENTVERSION&ID='+pbappMenuID+'&LANGUAGE='+pbappMenuLanguageID+'&REDIRECT=FALSE&QEMODE=addsibling', 'ADDPAGE', 795, 575, false, 'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "addchild": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_eactivex-edit_pfutureVersionPreview_xlogin_yno/index.html?QEAUTOSTART=true&WFACTION=VIEWCURRENTVERSION&ID='+pbappMenuID+'&LANGUAGE='+pbappMenuLanguageID+'&REDIRECT=FALSE&QEMODE=addchild', 'ADDPAGE', 795, 575, false, 'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "quickedit": {
        qeToggleQuickedit(pbappMenuID, pbappMenuLanguageID, null, pbappShowQEMetaDataAutomatic);
        return true;
        break;
      }
      case "statistics": {
        pbappOpenPBStatWindow();
        break;
      }
      case "portaladmin": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ecmd_pportletpooladmin/index.html?menuid='+pbappMenuID,'PortalAdministration',470,530,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }
      case "portletadmin": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ecmd_pportletimpexp_yno/index.html','PortletAdministration',800,600,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }

      case "personalprofile": {
        return pbappOWin(topframe,'../../menu/'+pbappMenuID+'_xlogin_ecmd_puserdata_yno/index.html','UserSettings',600,500,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }
      case "updateorders": {
        return pbappOWin(topframe,'../../cmd/updateorders/index.html','UpdateOrders',550,500,false,'toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no');
        break;
      }
      case "telephonebook": {
        return pbappOWin(topframe,'../../search/user-phone-frame/index.html','Phonebook',660,550,false,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes');
        break;
      }
      case "edit-msg.workflow":{
        return alertEntityString('This page is in a workflow and cannot be edited at this moment.');
        break;
      }
      case "edit-msg.checkout":{
        var msg = "This page has been locked by %username% since %date%."; 
        msg = msg.replace("%username%", pbappCoUserName);
				msg = msg.replace("%date%", pbappCoDate);
        return alertEntityString(msg);
        break;
      }
      case "ec2k-msg.wrongbrowser":{
        return alertEntityString('You need Microsoft Internet Explorer 5.5 or better as well as a win32 based operating system to start Edit Center 2000!');
        break;
      }
      case "logout":{
        topframe.location.href = '../../menu/'+pbappMenuID+'_ecmd_plogout_xlogout_yno/index.html?time='+(new Date()).getTime();
        break;
      }
      default : {
        if(key.indexOf("custom.")==0) {
          if(typeof(performCustomFunction)=="function") {
            performCustomFunction(key, topframe);
          }
        }
        return;
      }
    }
  }
  else {
    switch(key) {
      case "login":{
        topframe.location.href = '../../menu/'+pbappMenuID+'_xlogin_yno/index.html?time='+(new Date()).getTime();
        break;
      }
      case "defaultlogin":{
        topframe.location.href = '../../menu/'+pbappMenuID+'_xdefaultlogin_yno/index.html?time='+(new Date()).getTime();
        break;
      }
      case "safelogin":{
        topframe.location.href = '../../menu/'+pbappMenuID+'_xsafelogin_yno/index.html?time='+(new Date()).getTime();
        break;
      }
      default : {
        if(key.indexOf("custom.")==0) {
          if(typeof(performCustomFunction)=="function") {
            performCustomFunction(key, topframe);
          }
        }
        return;
      }
    
    }
  
  }
  
}


function pbappOpenPBStatWindow() {
  var statWindow = top.open('../../menu/-1_xlogin_ecmd_pstat-frame/index.html', 'pageObjects',     
                  'width=800,height=600,toolbar=no,directories=no,status=no, scrollbars=yes,menubar=no,resizable=yes');
  if (statWindow) {
    if (statWindow.opener == null)
      statWindow.opener = top;
    statWindow.opener.top.name = "PBMAINWINDOW";
    statWindow.focus();
  }
}

function pbappOWin(windowObj, url,title,sizeH,sizeV,bReturnValue,prop) {
  if(pbappIsModeOffline) {
    if(navigator.appVersion.indexOf("MSIE 3",0)>=0)return;
    return(true);
  }
  if(prop == null) {
    windowObj["winHandle"] = pbappOWinInner(windowObj, url,title,'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=yes,resizable=yes,width='+sizeH+',height='+sizeV);
  }
  else {
    windowObj["winHandle"] = pbappOWinInner(windowObj, url,title,prop+',width='+sizeH+',height='+sizeV);
  }
  if(navigator.appVersion.indexOf("MSIE 3",0)==-1) {
    id = windowObj.setTimeout('window["winHandle"].focus()',1000);
  }
  else {
    return;
  }
  return(bReturnValue);
}

function pbappOWinInner(windowObj, url, title, prop) {
  if(title == "PBEDIT") {
    if(windowObj.editcenter!=null) {
      if(windowObj.editcenter.closed) {
        windowObj.editcenter = windowObj.open(url,title,prop);
      }
      else {
        windowObj.editcenter.focus();
      }
    }
    else {
      windowObj.editcenter = windowObj.open(url,title,prop);
    }
    return windowObj.editcenter;
  }
  else if(title == "PBADMIN") {
    if(windowObj.admincenter!=null) {
      if(windowObj.admincenter.closed) {
        windowObj.admincenter = windowObj.open(url,title,prop);
      }
      else {
        windowObj.admincenter.focus();
      }
    }
    else {
      windowObj.admincenter = windowObj.open(url,title,prop);
    }
    return windowObj.admincenter;
  }
  else if(title == "PBWEBEDIT") {
    title = "PBWEBEDIT_" + document.location.hostname.replace(/./g, "_");
    if(windowObj[title]!=null) {
      if(windowObj[title].closed) {
        windowObj[title] = windowObj.open(url,title,prop);
      }
      else {
        windowObj[title].focus();
      }
    }
    else {
      windowObj[title] = windowObj.open(url,title,prop);
    }
    return windowObj[title];
  }
  else {
    var newWin;
    newWin = windowObj.open(url,title,prop);
    return newWin;
  }
}



function decodeNumericEntities(content) {
  var res = "";
  for(i=0; i<content.length; i++) {
    if(content.substring(i, i+1)=="&") {
      var value = getNumericEntityValue(content, i);
      if(value==null) {
        res += "&";
      }
      else {
				res = res + value.string;
				i+=value.entityLength+2;
		  }
    }
    else {
      res = res + content.substring(i, i+1);
    }
  }
  return res;
}

function getNumericEntityValue(string, position) {
  if(string.substring(position+1, position+2)!="#") {
    return null;
  }

  var string2 = string.substring(position+1);
  var posSemiColon = string2.indexOf(";");
  if(posSemiColon<0) {
    return null;
  }

  var sequence = string2.substring(1, posSemiColon);
  if(sequence.length==0) {
    return null;
  }

  var i;
  for(i=0; i<sequence.length; i++) {
    if(("0123456789").indexOf(sequence.substring(i, i+1)) < 0) {
      return null;
    }
  }

  var newObject = new Object;
  newObject.entityLength = sequence.length;
  newObject.string = String.fromCharCode(parseInt(sequence));

  return newObject;

}

function alertEntityString(string) {
  alert(decodeNumericEntities(string));
}

function confirmEntityString(string) {
  return confirm(decodeNumericEntities(string));
}


function unescapeUnicode(string) {
  var str = string;
  var reg = new RegExp("%u([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])", "");
  var i=0;
  var arr;
  while ((arr = reg.exec(str)) != null) {
    i++;
    if(i>100000) break;
    if(arr.index >= 0) {
      str = str.substring(0, arr.index) +
      fromHex(RegExp.$1) + str.substring(arr.index+6);
    }
    else break;
  }

  return str;
}

function escapeUnicode(string) {
  var str = string;
  var reg = new RegExp("([\u0080-\uffff])", "");
  var i=0;
  var arr;
  while ((arr = reg.exec(str)) != null) {
    i++;
    if(i>100000) break;
    if(arr.index >= 0) {
      str = str.substring(0, arr.index) +
      "%u" + getHex(RegExp.$1.charCodeAt(0), 4) + str.substring(arr.index+1);
    }
    else {
      break;
    }
  }

  return str;

}

function escapeUnicodeURL(string) {
  if(string==null) {
    return escape(null);
  }
  string = escapeUnicode(string);
  var result = escape(string);
  result = result.replace(/%u/g, "%25u");
  return result;
}

function fromHex(str) {
  return String.fromCharCode(eval("0x"+str));
}

function getHex(charCode, lenMin) {
  var result = charCode.toString(16);
  while(result.length<lenMin) {
    result = "0" + result;
  }
  return result;
}

