Function.prototype.extend=function(s,o){var F=function(){};F.prototype=s.prototype;this.prototype=new F();if(o){for(var i in o)this.prototype[i]=o[i];}};
String.prototype.unescapeHTML=function(){var d=document.createElement('div');d.innerHTML=this;return d.innerHTML;};
if (typeof(("").trim)=="undefined"){String.prototype.trim = function(){return this.replace(/(^\s+)|(\s+$)/g, "");}};
Date.prototype.format = function(f){var r="",re=Date.replaceChars;for(var i=0;i<f.length;i++){var cc=f.charAt(i);if(i-1>=0&&f.charAt(i-1)=="\\"){r+=cc;} else if(re[cc]){r+=re[cc].call(this);} else if(cc != "\\"){r+=cc;}}return r;};
Date.replaceChars = {
  shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  
  // Day
  d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
  D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
  j: function() { return this.getDate(); },
  l: function() { return Date.replaceChars.longDays[this.getDay()]; },
  N: function() { return this.getDay() + 1; },
  S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
  w: function() { return this.getDay(); },
  z: function() { var d = new Date(this.getFullYear(),0,1); return Math.ceil((this - d) / 86400000); }, // Fixed now
  // Week
  W: function() { var d = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7); }, // Fixed now
  // Month
  F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
  m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
  M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
  n: function() { return this.getMonth() + 1; },
  t: function() { var d = new Date(); return new Date(d.getFullYear(), d.getMonth(), 0).getDate() }, // Fixed now, gets #days of date
  // Year
  L: function() { var year = this.getFullYear(); return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)); },       // Fixed now
  o: function() { var d  = new Date(this.valueOf());  d.setDate(d.getDate() - ((this.getDay() + 6) % 7) + 3); return d.getFullYear();}, //Fixed now
  Y: function() { return this.getFullYear(); },
  y: function() { return ('' + this.getFullYear()).substr(2); },
  // Time
  a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
  A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
  B: function() { return Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24); }, // Fixed now
  g: function() { return this.getHours() % 12 || 12; },
  G: function() { return this.getHours(); },
  h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
  H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
  i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
  s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
  u: function() { var m = this.getMilliseconds(); return (m < 10 ? '00' : (m < 100 ? '0' : '')) + m; },
  // Timezone
  e: function() { return "Not Yet Supported"; },
  I: function() { return "Not Yet Supported"; },
  O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
  P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':00'; }, // Fixed now
  T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;},
  Z: function() { return -this.getTimezoneOffset() * 60; },
  // Full Date/Time
  c: function() { return this.format("Y-m-d\\TH:i:sP"); }, // Fixed now
  r: function() { return this.toString(); },
  U: function() { return this.getTime() / 1000; }
};
/*******************************************************************************
 * refresh support this functionality is for checking that a page has
 * implemented a refreshyourself function if the jsp page registers via
 * "registerRefresh(true)" then it can call "doRefreshYourself()" which then
 * will invoke the refreshyourself function in the jsp page.
 */

var registerRefresh;
var postPageAction;

function registerRefresh(dosaferefresh) {

    registerRefresh = dosaferefresh;
}
function doRefreshYourself() {

    if(registerRefresh != null)
    {
        refreshyourself();
    }

}

function windowOpenerRefresh()
{
    window.opener.doRefreshYourself();
}


/*
 * ********************************************************************* *
 * Common functions
 */


      function getObj(name)
      {
         if (document.getElementById)
         {
            this.obj = document.getElementById(name);
            if ( this.obj != null) {
               this.style = document.getElementById(name).style;
            }
         }
         else if (document.all)
         {
            this.obj = document.all[name];
            this.style = document.all[name].style;
         }
         else if (document.layers)
         {
               this.obj = document.layers[name];
               this.style = document.layers[name];
         }
         else {
            this.obj = null;
            this.style = null;
         }
      }
/*
 * *********************************************************************** *
 * FRAME AND DOCUMENT RELATED
 */

        /* function for loading personal pages */

        function loadPersonal( actions, treehead, topaction ){
            parent.location.href = document.location.protocol + '//' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead;
        }

        function loadPersonalSecure( actions, treehead, topaction ){
          openw( 'https://' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead );
        }

        function quick_loadPersonal( actions, treehead, topaction ){
          document.location.href = document.location.protocol + '//' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead;
        }

        function quick_loadPersonalSecure( actions, treehead, topaction ){
          document.location.href = 'https://' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead;
        }

        function pda_loadPersonal( actions, treehead, topaction ){
          document.location.href = document.location.protocol + '//' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead;
        }

        function pda_loadPersonalSecure( actions, treehead, topaction ){
          document.location.href = 'https://' + document.location.hostname + '/corevvsadm/servlet/CoreFMArealUserServlet?action='+ actions +'&selectedTreeHead='+ treehead;
        }

   /*
	 * * refreshToolbar(action) * refresh the toolbar * * action: string: href
	 * to frame source
	 */
      function refreshToolbar(action)
                {
                  if( parent.navigation != null )
                    parent.navigation.location.href='CoreFMArealUserServlet?action=' + action + '&date='+getCurrentTime();
      }


   /*
	 * * loadActionInFrame(action,frame,waittext) * puts at action in the fram
	 * specified * * action: string: href to frame source * frame: string: frame
	 * name
	 */
      function loadActionIntoFrame(action,frame,waittext)
      {
         waitString = 'parent.'+ frame +'.document.write(\"<body bgcolor=\'#ffffff\'><br><br><font face=\'arial,helvetica\' size=4><center>' + waittext + '</center>\")';
         eval( waitString);
         actionString='CoreFMArealUserServlet?action=' + action + '&date='+getCurrentTime();
         eval('parent.'+ frame +'.location.href=actionString');
      }


   /*
	 * * loadHelpActionInFrame(action,waittext) * puts at action in the fram
	 * specified * * action: string: href to frame source * frame: string: frame
	 * name
	 */
      function loadHelpActionIntoFrame(action,frame,waittext)
      {
      	var framePath = '';
      	if ( parent.autohelp) {
      		framePath = 'parent.autohelp';
      	}
      	if ( framePath != '') {
	         waitString = framePath + '.document.write(\"<body bgcolor=\'#ffffff\'><br><br><font face=\'arial,helvetica\' size=4><center>' + waittext + '</center>\")';
	         eval( waitString);
	         actionString='CoreFMArealUserServlet?action=' + action + '&date='+getCurrentTime();
	         eval( framePath + '.location.href=actionString');
	    }
      }


   /*
	 * * loadActionInFrameFromSubframe(action,frame) * puts at action in the
	 * fram specified * * action: string: href to frame source * frame: string:
	 * frame name
	 */
      function loadActionIntoFrameFromSubFrame(action,frame)
      {
         actionString='CoreFMArealUserServlet?action=' + action + '&date='+getCurrentTime();
         eval('parent.parent.'+ frame +'.location.href=actionString');
      }
      
   /*
    * loadActionInFrame(action,frame,waittext) puts at action in the frame specified
    * 
    * @action: string: href to frame source
    * @frame: string: frame name
    */
   function loadAction(action,waittext) {
      
      waitString = "<body bgcolor=\"#ffffff\"><br/><br/><font face=\"arial,helvetica\" size=\"4\"><center>" + waittext + "</center></font>";
      var body = document.getElementsByTagName("body")[0];
      body.setAttribute("bgcolor", "#ffffff");
      body.innerHTML = waitString;
      actionString = "CoreFMArealUserServlet?action=" + action + "&date=" + getCurrentTime();
      document.location.href = actionString; 
   }
   
   function blockBody(waittext) {
      $("<div style=\"z-index:1000;position:fixed;top:0px;left:0px;width:100%;height:100%;background:#ffffff;\"><br/><br/><font face=\"arial,helvetica\" size=\"4\"><center>" + waittext + "</center></font></div>").appendTo("body");
   }
   
   /*
	 * * nextPage(href) * * action: string: href to document source
	 */
      function nextPage(action)
      {
            document.location.href=action;

      }



   /*
	 * * historyBackOne() * goes back one
	 */
      function historyBackOne()
      {
         window.history.go(-1);
      }


   /*
	 * * Set window on top *
	 */
      function FocusMe()
      {
         setTimeout("self.focus()",250);
      }



   /*
	 * * ScreenWidth * maybe not in use // HUSK
	 */
      ScreenWidth=screen.availWidth;
      ScreenHeight=screen.availHeight;

/*
 * * /FRAME AND DOCUMENT RELATED END
 * ***********************************************************************
 */


/*
 * *********************************************************************** *
 * TIME RELATED
 */


   /*
	 * * getCurrentTime(){ * make a timestamp
	 */
      function getCurrentTime(){
         now=new Date();
         return now.getTime();
      }

   /*
	 * * now * maybe not in use // HUSK
	 */
      now=new Date();
      now=now.getTime();


/*
 * * /TIME RELATED END
 * ***********************************************************************
 */

function redirect(parameters) {
    document.location = '/corevvsadm/servlet/CoreFMArealUserServlet?' + parameters;
}
function redirectFullscreen( parameters )
{
    window.moveTo( 0, 0 );
    window.resizeTo( screen.availWidth, screen.availHeight );
    redirect(parameters);
}

function redirectType2( parameters )
{
    window.resizeTo( 420, 380);
    redirect(parameters);
}

function redirectType3( parameters )
{
    window.resizeTo( 680, 530);
    redirect(parameters);
}

function redirectType4( parameters )
{
    window.resizeTo( 660, 380);
    redirect(parameters);
}

function redirectType5( parameters )
{
    window.resizeTo( 560, 480);
    redirect(parameters);
}

/*
 * *********************************************************************** *
 * POPUP RELATED
 */



   /*
	 * * openwindow(action,width,height) * open a pop-up window * * action:
	 * string: href to window source * width : int : window width * height: int :
	 * window height
	 */
      function openwindow(action, width, height) {
         leftwin=(ScreenWidth-700)*.5;
         topwin=(ScreenHeight-500)*.5;
         q="CoreFMArealUserServlet?action=" + action +"&"+ window.top.getCurrentNodeFunctionName() +"=" + window.top.getCurrentNodeId() + "&date="+getCurrentTime()+"&entityId="+ window.top.getCurrentNodeId() +"&entityType="+ window.top.getCurrentNodeType() +"&id="+ window.top.getCurrentNodeId();
         project=window.open(q,'No_Name','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+leftwin+',top='+topwin);
         project.moveTo(leftwin,topwin);
         project.focus();
      }

      function openwindowfullscreen( action ) {
         leftwin=(ScreenWidth-700)*.5;
         topwin=(ScreenHeight-500)*.5;
         q="CoreFMArealUserServlet?action=" + action +"&"+ window.top.getCurrentNodeFunctionName() +"=" + window.top.getCurrentNodeId() + "&date="+getCurrentTime()+"&entityId="+ window.top.getCurrentNodeId() +"&entityType="+ window.top.getCurrentNodeType() +"&id="+ window.top.getCurrentNodeId();
         project=window.open(q,'No_Name','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+ScreenWidth+',height='+ScreenWidth+',left=0,top=0');
         project.moveTo(leftwin,topwin);
         project.focus();
      }
      
      function openwindowastab( action ) {
          leftwin=(ScreenWidth-700)*.5;
          topwin=(ScreenHeight-500)*.5;
          q="CoreFMArealUserServlet?action=" + action +"&"+ window.top.getCurrentNodeFunctionName() +"=" + window.top.getCurrentNodeId() + "&date="+getCurrentTime()+"&entityId="+ window.top.getCurrentNodeId() +"&entityType="+ window.top.getCurrentNodeType() +"&id="+ window.top.getCurrentNodeId();
          project=window.open(q,'No_Name');
          project.focus();
       }

      function openw(q){
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;

         if( screen.availWidth == 800 ){
            width = 775;
            height = 575;
         }
         else{
            width = 1000;
            height = 710;
         }

         q=q+"&dato="+this.getCurrentTime();
         leftwin=(ScreenWidth-width)*.5;
         topwin=((ScreenHeight-height)*.5) - 10;
         project=window.open(q,'Core_FM_Areal','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+leftwin+',top='+topwin);

         project.moveTo(leftwin,topwin);
         project.focus();
         return false;
      }

   /*
	 * * popupByAction(action,width,height) * common popup * * action: string:
	 * href to window source * width : int : window width * height: int : window
	 * height
	 */

      // warning doo NOT call POST popups with nexturl=waiturl or any taget =
		// windowname submit ...it has a timing problem setting the target witch
		// i cant solve
      // the postpage includes the waittext within so its not needed!


      function popupByAction(action,width,height)
      {
         popupByActionNew(action,width,height, 'popupByAction')
      }


      function popupByActionType1( action, name)
      {
         popupByActionNew(action, 420, 280, name)
      }
      function popupByNameType2(name)
      {
         popupByActionExtern( '', 420, 380, name);
      }

      function popupByActionType2( action, name)
      {
         popupByActionNew(action, 420, 380, name)
      }
      function popupByActionType2WithPost( action, name)
      {
         popupByActionNewWithPost(action, 420, 380, name)
      }

      function popupByActionType24( action, name)
      {
         popupByActionNew(action, 420, 530, name)
      }
      function popupByActionType3( action, name)
      {
         popupByActionNew(action, 680, 530, name)
      }
      function popupByActionType4( action, name)
      {
         popupByActionNew(action, 660, 380, name)
      }
      function popupByNameType4(name)
      {
         popupByActionExtern( '', 660, 380, name);
      }

      // new 4 now with POST
      function popupByActionType4WithPost( action, name)
      {
         popupByActionNewWithPost(action, 660, 380, name)
      }
      function popupByActionType5( action, name)
      {
         popupByActionNew(action, 560, 480, name)
      }
      function popupByActionType6( action, name)
      {
         popupByActionNew(action, 790, 530, name)
      }
      function popupByActionType7( action, name)
      {
         popupByActionNew(action, 420, 480, name)
      }
      function popupByActionType8( action, name)
      {
         popupByActionNew(action, 850, 530, name)
      }
      function popupByActionTypeP( action, name)
      {
         popupByActionNew(action, 600, 600, name)
      }
      function popupByActionTypeH( action, name)
      {
         popupByActionNew(action, 750, 580, name)
      }
      function popupByActionTypeHC( action, name)
      {
         popupByActionNewControlled(action, 750, 580, name, 0)
      }
      function popupByActionTypeBrava( action, name)
      {
         popupByActionNew(action, 810, 610, name)
      }
      function popupByActionTypeBIG( action, name)
      {
         popupByActionNew(action, 1000, 700, name)
      }

      function popupByActionSetupType2( action, name)
      {
         popupByActionSetupNew(action, 420, 380, name)
      }
      function popupByActionSetupType3( action, name)
      {
         popupByActionSetupNew(action, 680, 530, name)
      }
      function popupByActionSetupType4( action, name)
      {
         popupByActionSetupNew(action, 660, 380, name)
      }

      function popupByActionNew( action, width, height, name)
      {
	      popupByActionNewControlled( action, width, height, name, 1);
      }

      function popupByActionNewControlled( action, width, height, name, doPosition)
      {
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;
         leftwin = (ScreenWidth-width) * 0.5;
         topwin = (ScreenHeight-height) * 0.5;

         q = "CoreFMArealUserServlet?action=" + action + "&date=" + getCurrentTime();

         project = window.open(q, name, 'toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + width + ',height=' + height + ',left=' + leftwin + ',top=' + topwin);

		 if ( doPosition && doPosition == 1) {
	         project.moveTo(leftwin,topwin);
	         project.focus();
	     }
      }


      // warning doo NOT call this with nexturl=waiturl ...it has a timing
		// problem setting the target
      // the postpage includes the waittext within so its not needed!
      function popupByActionNewWithPost( action, width, height, name)
      {
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;
         leftwin = (ScreenWidth-width) * 0.5;
         topwin = (ScreenHeight-height) * 0.5;
         postPageAction = null;
         if(action && action != ''){
             postPageAction = action;
         }

         var tempPostPageAction = "CoreFMArealUserServlet?action=2400003&nexturl=postPage.jsp&date=" + getCurrentTime();

         project = window.open(tempPostPageAction, name, 'toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + width + ',height=' + height + ',left=' + leftwin + ',top=' + topwin);
         project.moveTo(leftwin,topwin);

         var counter = 150;
         // try 300 times and wait 100 millis = 30 sec max
         // its usually the first form that takes time,,,normally it takes
			// 100 millies max
         // but this depends of the speed of the client computer

         do{
             setTimeout("finalizePost()",200);
             counter -= 1;
         }while(!project.document.forms["postForm"] && counter > 0);

      }// end function


      // since its not possible to maintain variables (in scopes calling
		// settimeout) or return from a timeout ...we had to make this function
      // basically this gets called until the form is created or the caller
		// chooses to timeout
      function finalizePost()
      {
         var theForm;
         var action = postPageAction;
         theForm = project.document.forms["postForm"];


         if(!action || !theForm )
         {

         }else{

         if(theForm && action){

            var paramArray = new Array();
             paramArray = action.split('&');

            var doneAction = false;
            var idx = 0;

            while(idx < paramArray.length){

                var parameterName = '';
                var parameterValue= '';
                var currentParamStr = paramArray[idx];

                // since our action has no name prefix we handle this specially
                // we have to set the parameter to 'action'
                 if(!doneAction)
                {
                    parameterValue = currentParamStr;
                    parameterName = 'action';
                    // cut out actions
                    doneAction = true;
                }else{
                    var indexEquals = currentParamStr.indexOf('=');

                    parameterName = currentParamStr.substring(0,indexEquals);
                    parameterValue = currentParamStr.substring(indexEquals + 1,currentParamStr.length);
                }

                // advice some way of adding new hidden fields to the form
                if(parameterName != ''){
                    var input = project.document.createElement("input");
                    input.setAttribute("type", "hidden");
                    input.setAttribute("name", parameterName);
                    input.setAttribute("value", parameterValue);
                    theForm.appendChild(input);
                }
                idx += 1;
            }
             theForm.submit();
         }
         project.focus();
        }
      }


      function popupByActionSetupNew( action, width, height, name)
      {
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;
         leftwin = (ScreenWidth-width) * 0.5;
         topwin = (ScreenHeight-height) * 0.5;

         q = "CoreFMArealSetupServlet?action=" + action + "&date=" + getCurrentTime();
         project = window.open(q, name, 'toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + width + ',height=' + height + ',left=' + leftwin + ',top=' + topwin);
         project.moveTo(leftwin,topwin);
         project.focus();
      }


      function popupByActionFullScreenAndSetParentOpener( action,name)
      {
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;
         // leftwin = (ScreenWidth-width) * 0.5;
         // topwin = (ScreenHeight-height) * 0.5;
          leftwin=(ScreenWidth-700)*.5;
         topwin=(ScreenHeight-500)*.5;
         q = "CoreFMArealUserServlet?action=" + action + "&date=" + getCurrentTime();
         project = window.open(q, name, 'toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + ScreenWidth + ',height=' + ScreenHeight + ',left=' + leftwin + ',top=' + topwin);
         project.opener = window.opener;
         project.moveTo(leftwin,topwin);
         project.focus();
      }


      function popupByActionExternTypeH( action, name)
      {
         popupByActionExtern(action, 750, 580, name)
      }

      function popupByActionExtern( url, width, height, name)
      {
         ScreenWidth=screen.availWidth;
         ScreenHeight=screen.availHeight;
         leftwin = (ScreenWidth-width) * 0.5;
         topwin = (ScreenHeight-height) * 0.5;

         project = window.open(url, name, 'toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + width + ',height=' + height + ',left=' + leftwin + ',top=' + topwin);
         project.moveTo(leftwin,topwin);
         project.focus();
      }

      /**
       * resizePopupTypeX()
       */
      function resizePopupType1()
      {
         window.resizeTo(420, 280)
      }
      function resizePopupType2()
      {
         window.resizeTo(420, 380)
      }
      function resizePopupType3()
      {
         window.resizeTo(650, 530)
      }
      function resizePopupType4()
      {
         window.resizeTo(660, 380)
      }
      function resizePopupType5()
      {
         window.resizeTo(560, 480)
      }
      function resizePopupType6()
      {
         window.resizeTo(755, 530)
      }
      function resizePopupType7()
      {
         window.resizeTo(420, 480)
      }
      function resizePopupTypeP()
      {
         window.resizeTo(600, 600)
      }
      function resizePopupTypeBrava()
      {
         window.resizeTo(830, 610)
      }




   /*
	 * * closeWindow() * close the window
	 */
      function closeWindow()
      {
         window.close();
      }


   /*
	 * * closeWindowAfterSek(sek) * close the window * * sek: int: seconds to
	 * window closes
	 */
      function closeWindowAfterSek(sek)
      {
         setTimeout("closeWindow()",sek);
      }



   /*
	 * * closePopupWindow() * Close the popup window and call refreshyourself on
	 * the parent.
	 */
      function closePopupAndRefresh()
      {
         windowOpenerRefresh();
         window.close();
      }






   /*
	 * * windowOpenerReload() * deprecated. Use windowOpenerRefresh
	 */
      function windowOpenerReload()
      {
            window.opener.document.location.reload();
      }


   /*
	 * * windowOpenerLoadAction(actionstring) * * actionstring: string: the new
	 * href
	 */
      function windowOpenerLoadAction(actionstring)
      {
            window.opener.document.location.href="CoreFMArealUserServlet?action=" + actionstring + "&date=" + getCurrentTime();
      }



    /*
	 * * windowOpenerLoadAction(actionstring) * * actionstring: string: the new
	 * href
	 */


        function changeIcon(icon,iconId,fieldname)
        {
            window.opener.document.icon.src=icon;
            eval('window.opener.document.buildingElements_properties.' + fieldname + '.value=' + iconId);
        }

        function changeIcon(icon,iconId,formname, fieldname)
        {
            window.opener.document.icon.src=icon;
            eval('window.opener.document.' + formname + '.' + fieldname + '.value=' + iconId);
        }







/*
 * * /POPUP RELATED END
 * ***********************************************************************
 */


/*
 * *********************************************************************** *
 * FORM RELATED
 */


      /*
		 * Verifies the submit process has finished on the server before the
		 * user can push the button again
		 */
      var requestIsSubmitted = false;
      function doWaitUrl(actionStr, alertmsg ){
          if(!requestIsSubmitted){
          // alert('document.location.href=' + actionStr);
          requestIsSubmitted = true;
          document.location.href=actionStr;

        }
        else{
          alert( alertmsg );
        }
      }





      /*
		 * Verifies the submit process has finished on the server before the
		 * user can push the button again
		 */
      var requestSubmitted = false;
      function doForm(formname, alertmsg) {
        var returns = true;
          if(!requestSubmitted) {
              returns = document.forms[formname].submit();
           requestSubmitted = true;
        } else {
          alert( alertmsg );
        }
          return returns;
      }


      function doFormDefault()
      {
         // Default function for popups closing with
			// closeAndExecuteParentJs.jsp without a saferefresh
      }


   /*
	 * * submitForm(formname) * submit a form * * formname: string: the name of
	 * the form to be submited
	 */
      function submitForm(formname) {

          document.forms[formname].submit();
      }


   /*
	 * * visibility(obj,vis) * hide visibility * * obj: string: the object *
	 * vis: string: visibility - hidden or visible
	 * 
	 */

      function visibility(obj,vis)
      {
         var x = new getObj(obj);
            x.style.visibility='' + vis

      }


   /*
	 * * disableElement(formname,field) * disables if the element is enabled and
	 * visa versa * * formname: string: the form * field: string: fieldname
	 */
      function disable(formname,field)
      {
         str=eval('document.' + formname + '.' + field + '.disabled');
         if(str==false) {
            eval("document." + formname + "." + field + ".disabled=true");
         }
         else {
            eval("document." + formname + "." + field + ".disabled=false");
         }
      }





   /*
	 * * setCheckedValue(obj,value) * Set true or false on checkbox * * obj:
	 * string: the object * value: string: checkvalue - true or false *
	 */

      function setCheckedValue(formname,obj,value)
      {

         eval('document.' + obj + '.checked=true');
         // var x = new getObj(obj);
            // eval('x.checked=true')
            // !N?r der bliver lavet nyt, skal der kun kaldes med objektet!
      }


   /*
	 * * isInteger(objName) * Checks if a value is an integer or not * * value:
	 * string: the object *
	 */
    function isInteger(objName)
    {
        // only allow 0-9 be entered
        var checkOK = "0123456789";
        var checkStr = objName;
        var allValid = true;

        for (i = 0;  i < checkStr.value.length;  i++)
        {
            ch = checkStr.value.charAt(i);

            for (j = 0;  j < checkOK.length;  j++) if (ch == checkOK.charAt(j)) break;

            if (j == checkOK.length)
            {
                allValid = false;
                break;
            }

        }
        if (allValid)
        {
            return true;
        }
        else
        {
            return false;
        }
    }



    /*
	 * * Set the selected item in the objName SELECT control. * * *
	 */
    function setDropdownSelection( objName, value)
    {
        var selectbox1 = document.getElementById( objName);

        for ( var i = 0; i < selectbox1.length ; i++) {
            if ( selectbox1.options[i].value == value) {
                selectbox1.selectedIndex = i;
                break;
            }
        }
    }

    /*
	 * * Set the selected item in the objName RADIO GROUP control.
	 */
    function setRadioGroupSelection(formName, objName, value) {
        var radioGroup = document.forms[formName].elements[objName];
        if(radioGroup != undefined) {
            for(var i = 0; i < radioGroup.length; i++) {
                radioGroup[i].checked = false;
                if(radioGroup[i].value == value) {
                    radioGroup[i].checked = true;
                }
            }
        }
    }


/*
 * * /FORM RELATED END
 * ***********************************************************************
 */




/*
 * *********************************************************************** *
 * SELECT USER/COMPANY RELATED
 */

function selectResponsible(formName, fieldName, visibleFieldName, action, fieldType, childFieldName, visibleChildFieldName) {
      now = new Date().getTime();
      popupByActionType2(action + "&retformname="+ formName + "&retfieldname="+ fieldName + (fieldType?"&retfieldtype="+fieldType:"") + "&retvisiblefieldname="+ visibleFieldName + (childFieldName?"&retchildfieldname="+childFieldName:"") + (visibleChildFieldName?"&retvisiblechildfieldname="+visibleChildFieldName:"") + "&date"+now, "selectResponsible" + formName);
}

// Same as selectResponsible, except that it changes the current url instead of
// creating a popup.
function selectResponsibleSameWindow( formName, fieldName, visibleFieldName, action )
{
    now=new Date();
    now=now.getTime();

    action = action + "&retformname="+ formName + "&retfieldname="+ fieldName + "&retvisiblefieldname="+ visibleFieldName;
    var q = "CoreFMArealUserServlet?action=" + action + "&date=" + getCurrentTime();
    document.location.href = q;
}

// refreshAction must be escaped before calling the function
function selectResponsibleWideWithRefresh( formName, fieldName, visibleFieldName, action, refreshAction )
{
      now=new Date();
      now=now.getTime();

      popupByActionType2( action + "&retformname="+ formName + "&retfieldname="+ fieldName + "&retvisiblefieldname="+ visibleFieldName + "&date"+now+"&passon8=" + refreshAction, "selectResponsibleW" + formName);
// window.open("CoreFMArealUserServlet?action=" + action + "&retformname="+
// formName + "&retfieldname="+ fieldName + "&retvisiblefieldname="+
// visibleFieldName + "&date"+now+"&passon8=" + refreshAction, "title",
// "toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,width=600,height=500,left=200,top=200");
}


// refreshAction must be escaped before calling the function
function selectResponsibleWithRefresh( formName, fieldName, visibleFieldName, action, fieldType, refreshAction )
{
      now=new Date();
      now=now.getTime();

      popupByActionType2( action + "&retformname="+ formName + "&retfieldname="+ fieldName + "&retfieldtype="+ fieldType + "&retvisiblefieldname="+ visibleFieldName + "&date"+now+"&passon8=" + refreshAction, "selectResponsible" + formName);
// window.open("CoreFMArealUserServlet?action=" + action + "&retformname="+
// formName + "&retfieldname="+ fieldName + "&retfieldtype="+ fieldType +
// "&retvisiblefieldname="+ visibleFieldName + "&date"+now+"&passon8=" +
// refreshAction, "title",
// "toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,width=400,height=500,left=400,top=200");
}

function setParentFormField(formName, fieldName, visibleFieldName, childFieldName, visibleChildFieldName, data, visibleData, typeName, typeData) {

    var form = window.opener.document.forms[formName];
    var clear = false;    
    
    if(form.elements[fieldName]) {
        clear = form.elements[fieldName].value && (form.elements[fieldName].value != data);
        form.elements[fieldName].value = data;
    }
    
    if(form.elements[visibleFieldName]) form.elements[visibleFieldName].value = visibleData;
    
    if (clear && (form.elements[childFieldName] || form.elements[visibleChildFieldName])) {
        alert('Når du skifter leverandør på et produkt fjernes den tidligere leverandørs kontaktperson fra produktet!');
        if(form.elements[childFieldName]) form.elements[childFieldName].value = -1;
        if(form.elements[visibleChildFieldName]) form.elements[visibleChildFieldName].value = '';
    }
    
    if(typeName && form.elements[typeName]) form.elements[typeName].value = typeData;
}

function setParentFields(values) {
	
    for( var i = 0; i < values.length; i += 2 ) {
        var id = values[ i ];
        var val = values[ i+1 ];
        alert( 'setting ' + id + ' to ' + val );
        var elem = d.getElementById( id );
        if( elem )
        {
            alert( 'setting it' );
            elem.value = val;
        }
    }
}

/*
 * * /SELECT USER/COMPANY RELATED
 * ***********************************************************************
 */


/*
 * *********************************************************************** *
 */

   /*
	 * * speclocation(action, selectedTab) * * action: string: href to frame
	 * source
	 */
      function speclocation(action, selectedTab) {
         now=new Date();
         now=now.getTime();
         parent.spec.location.href="CoreFMArealUserServlet?action=" + action + "&selectedTab="+ selectedTab +"&date="+now;
      }
      function specsublocation(action, selectedSubTab) {
         now=new Date();
         now=now.getTime();
         parent.spec.location.href="CoreFMArealUserServlet?action=" + action + "&selectedSubTab="+ selectedSubTab +"&date="+now;
      }
/*
 * * ***********************************************************************
 */


/** ****************************************************************** */
/* Log History JS Functions */
/** ****************************************************************** */
    function anotherRowSelection(multiply){
        if( multiply != 1 ){
            document.theForm.firstRow.value = (multiply-1)*document.theForm.rows.value;
        }
        else{
            document.theForm.firstRow.value = 1;
        }
        document.theForm.submit();
    }



/** ****************************************************************** */


/** ****************************************************************** */
/*
 * Functions for creating an on load sequece. Call addToOnload( "stringto be
 * eval'ed" ) to append to the onload sequence Setting <window onload=... >
 * prevents this from working, as these scripts are called before this.
 */
/** ****************************************************************** */

function createSequence(first, last) {

    if(first == null) return last;
    if(last == null) return first;

    return function() {first();last();};
}

// helper function, that can be used when code sequenced uses this / event
// argument
// note that event is firefox only.
function createEventSequence( first, last )
{
    if( null == first ) return last;
    if( null == last ) return first;
    var f = function( )
    {
        return first.apply( this, arguments ) && last.apply( this, arguments );
    }
    return f;
}


function createEvalFromString( str )
{
    var f = function()
    {
        return eval( str );
    };
    return f;
}

function addToOnload( str )
{
    window.onload = createSequence( window.onload, createEvalFromString( str ) );
}

function addFunctionToOnload( f )
{
    window.onload = createSequence( window.onload, f );
}

/** ****************************************************************** */

function getPageNumberString()
{
    var xx = document.getElementById("test");
    var yy = xx.contentWindow.document.getElementById("tableViewPage");
    if( yy && yy.value )
    {
        return '&page=' + yy.value;
    }

    return '';
}

function map2str( map, pretty )
{
    var newline = pretty ? '\n' : '';
    var s = '';
    s += '{' + newline;
    for( var v in map )
    {
        s += v +':'+map[v]+','+newline;
    }
    s += '};'+newline;
    return s;
}


// takes only an event object (mozilla support)!
function CRcheck( e, submitFunc)
{
  if (e.keyCode == 13)
  {
      eval( submitFunc);
  }
}


/*
 * *********************************************************************** *
 * SELECT USER/COMPANY RELATED
 */

function generalHandleContextMenu( event)
{
    // Doesn't work
    event.returnvalue = false;
    event.cancelBubble = true;

    // Doesn't work
    window.event.returnvalue = false;
    window.event.cancelBubble = true;

    return false;
}


function generalHandleContextMouseDown( event, link)
{
    bV  = parseInt(navigator.appVersion)
    bNS = navigator.appName=="Netscape"
    bIE = navigator.appName=="Microsoft Internet Explorer"

     if ((bNS && e.which > 1) || bIE && event.button == 2){
        eval( link);
        event.returnValue = false;
        return false;
    }

    return true;
}

GPS = function(){};
GPS.prototype = {

    encode: function(d, m, s) {
        return Math.round((Math.abs(d) + ((m-0.) + ((s-0.) / 60)) / 60) * Math.pow(10, 6)) / Math.pow(10, 6) * (d < 0 ? -1 : 1);
    },

    decode: function (coordinate) {
        var deg = Math.abs(coordinate);
        var min = (deg - Math.floor(deg)) * 60.;
        var sec = (min - Math.floor(min)) * 60.;
        return [Math.floor(deg) * (coordinate < 0 ? -1 : 1), Math.floor(min), Math.floor(sec * Math.pow(10, 2)) / Math.pow(10, 2)];
    }

};

