<!-- AJAX and other stuff! -->

var urlDest;      // Global var holding destination of output for a call.
var Timer;        // Global var holding timeout to next request.
var TimerFade;    // Global var holding timeout to next fadein request.
var xEnd;         // x pos to end fade at.
var yEnd;         // y pos to end fade at.
var wEnd;         // Width to end fade at.
var hEnd;         // Height to end fade at.

/******************************************************************/
/*** Format a number with leading zeroes.                       ***/
/******************************************************************/
function leadZero(Number, Width)
{
   var Val = Number;
   var Lng = Val.toString().length;
   var Rem = Width - Lng;

   for (var i = 1; i <= Rem; i++)
   {
      Val = "0" + Val;
   }
   return Val;
}

<!-- This function sets an object's opacity -->
function setOpacity(obj, opacity) {

// IE/Win
   obj.style.filter = "alpha(opacity:"+opacity+")";

// Safari<1.2, Konqueror
   obj.style.KHTMLOpacity = opacity/100;

// Older Mozilla and Firefox
   obj.style.MozOpacity = opacity/100;

// Safari 1.2, newer Firefox and Mozilla, CSS3
   obj.style.opacity = opacity/100;
}

<!-- This function fades in objects -->
function fadein(objId, opacity)
{
   if (document.getElementById)
   {
      obj = document.getElementById(objId);
      if (opacity <= 100) 
      {
         setOpacity(obj, opacity);
         obj.style.top = (parseInt(yEnd) * opacity /100);
         obj.style.left = (parseInt(xEnd) * opacity /100);
         opacity += 5;
         TimerFade = window.setTimeout("fadein('"+objId+"',"+opacity+")", 5);
      }
   }
}

<!-- This function hides a DIV window -->
function hideDIV(divname)
{
   id = document.getElementById(divname);
   id.style.visibility = 'hidden';
   id.innerHTML = "";

}

<!-- This function shows a DIV window -->
function showDIV(divname)
{
   id = document.getElementById(divname);
   id.style.visibility = 'visible';

}

<!-- This function handles + signs in a URL -->
function escapeplus(instr)
{
   regexpobj = /\+/g;
   newstr = instr.replace(regexpobj, "%2B");
   return newstr;
}

<!-- This function handles rereading of certain page contents based on a time interval! -->
function reread(interval,url,type,parms)
{
   clearTimeout(Timer);  // Clear any pending requests!
   if (typeof parms == "undefined")
   {
      parms = '';
   }
   callUrl = "showPage('"+url+"','"+type+"'";
   if (parms != "")
   {
      callUrl = callUrl+",'"+parms+"'"; 
   }
   callUrl = callUrl+")"; 
   Timer = setTimeout(callUrl,interval*1000);
}

<!-- This function handles response from server! -->
function response(responseText)
{
   if (responseText.substr(0,6) == '<DEST>') // Handle alternate contents for a destination.
   {
      x = responseText.indexOf(':');
      ac = responseText.substr(6,x-6);
      i = responseText.indexOf('</DEST>');
      l = i - x;
      altCont = responseText.substr(x+1,l);
      responseText = responseText.substr(i+7,responseText.length-6); // Remove alternate contents from response text.
      var c = document.getElementById(ac);
      c.innerHTML = altCont; // Place alternate contents.
   }
   funcName = '';
   if (responseText.substr(0,6) == '<CALL>') // Handle call to function.
   {
      i = responseText.indexOf('</CALL>');
      l = i - 6;
      funcName = responseText.substr(6,l);
      responseText = responseText.substr(i+7,responseText.length-6); // Remove function name from response text.
   }

   var p = document.getElementById('progress');
   p.style.visibility = 'hidden';
   if (urlDest == "")
   {
      urlDest = 'content'; // If no destination, set a default.
   }
   if (responseText != "") // Only output response if not empty.
   {
      var c = document.getElementById(urlDest);
      c.innerHTML = responseText;
   }

   if (funcName != '') // If function should be called, do it now.
   {
      f = eval(funcName); // Typically used to activate javascript code to act on new contents in page...
   }
}

<!-- This function sets up an HTTP request and sends it to the server! -->
function xmlhttpPost(strURL,qstr,respFunc) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
//    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
//    self.xmlHttpReq.setRequestHeader('Content-Type', 'text/xml');
//    self.xmlHttpReq.setRequestHeader('Accept-Charset', 'iso-8859-1, utf-8');
//    self.xmlHttpReq.setRequestHeader('Accept-Language', 'da');

    var someFunc = eval(respFunc);
    self.xmlHttpReq.onreadystatechange = function() {
       if (self.xmlHttpReq.readyState == 4) {
           someFunc(self.xmlHttpReq.responseText);
       }
    }
    var p = document.getElementById('progress');
    p.style.visibility = 'visible';
    self.xmlHttpReq.send(qstr);
}

<!-- Show a page in the BODY area. -->
function showPage(name,type,parms,dest)
{
   clearTimeout(Timer);  // Clear any pending requests!
   if (typeof parms == "undefined")
   {
      parms = '';
   }
   if (typeof dest == "undefined")
   {
      dest = '';
   }
   urlDest = dest; // Store in global var.

// If type=='URL' use name as full url in stead of building it!
/***
   if (type == 'url')
   {
      url = name + '?_type=' + type + parms;
   }
   else
   {
***/
      url = 'kode/getpage.php?_page=' + name + '&_type=' + type + parms;
/***
   }
***/
   xmlhttpPost(url,'','response');
}

<!-- Response function regarding exitWindow -->
function exitWindowResp(rstr)
{
}

<!-- This function replaces the window.onclose event -->
function exitWindow()
{
   /* Only react to close events when mouse is outside work area of window */
   /* Means pressing [X] or reload... */
   if ((window.event.clientY < 0) || (window.event.clientX < 0))
   {
      var url = 'kode/getpage.php?_page=logoff&_type=php';
      xmlhttpPost(url,'','exitWindowResp');
   }
}

<!-- Print page. -->
function printPage()
{
   i = document.getElementById('doc');
   if (i == null)
   {
      d = new Date();
      day = d.getDate();
      year = d.getFullYear();
      mnth = d.getMonth() + 1;
      c = document.getElementById('content');
      h = c.innerHTML;
      w = window.open('');
      w.document.focus();
      w.document.writeln('<div style="position: absolute; left: 200; top; 1">Source: www.blconsulting.dk - all rights reserved! Date: '+year+'.'+mnth+'.'+day+'</div>' + h);
      w.document.close();
      w.print();
   }
   else
   {
      i.focus();
      i.click();
      i.print();
   }
}

<!-- Login. -->
function login()
{
   id = document.getElementById('loginform');
   parms = '&brugerid=' + escape(id.brugerid.value) + '&kodeord=' + escape(id.kodeord.value);
   parms = escapeplus(parms);
   showPage('login','php',parms);
}

<!-- Search page. -->
function search()
{
   id = document.getElementById('searchform');
   parms = '&sfor=' + escape(id.sfor.value);
   parms = escapeplus(parms);
   showPage('search','php',parms);
}

<!-- Send chat message. -->
function sendChat()
{
   id = document.getElementById('chatform');
   parms = '&sendto=' + escape(id.sendto.value) + '&msg=' + escape(id.msg.value) + '&refreshrate=' + escape(id.refreshrate.value);
   parms = escapeplus(parms);
   showPage('chat','php',parms);
}

<!-- Store user settings. -->
function storeSettings()
{
   id = document.getElementById('setform');
   if (id.beep[0].checked)
   {
      beepradiobutton = 'Y';
   }
   else
   {
      beepradiobutton = 'N';
   }
   if (id.device[0].checked)
   {
      deviceradiobutton = '';
   }
   else
   {
      deviceradiobutton = 'MOB';
   }
   parms = '&userid=' + escape(id.userid.value) + '&pwd=' + escape(id.pwd.value) + '&refreshrate=' + escape(id.refreshrate.value) +
           '&navn=' + escape(id.navn.value) + '&email=' + escape(id.email.value) + '&mobil=' + escape(id.mobil.value) +
           '&beep=' + escape(beepradiobutton) + '&sound=' + escape(id.sound.value) + '&fgcolor=' + escape(id.fgcolor.value) +
           '&unreadcolor=' + escape(id.unreadcolor.value) + '&mode=' + escape(id.mode.value) +
           '&mailpwd=' + escape(id.mailpwd.value) + '&mailsrv=' + escape(id.mailsrv.value) + 
           '&device=' + escape(deviceradiobutton);
   parms = escapeplus(parms);
   showPage('settings','php',parms);
}

<!-- Check/uncheck e-mails. -->
function Check(chk, chkall, antal)
{
   id = document.getElementById('mailform');
   aFieldName = 'id.'+chkall;
   idchkall   = eval(aFieldName);
   aFieldName = 'id.'+chk;
   idchk      = eval(aFieldName);
   aFieldName = 'id.'+antal;
   idant      = eval(aFieldName);
   if (idchkall.checked==true)
   {
      if (idant.value == 1)
      {
         idchk.checked = true ;
      }
      else
      {
         for (i = 0; i < idant.value; i++)
            idchk[i].checked = true ;
      }
   }
   else
   {
      if (idant.value == 1)
      {
         idchk.checked = false ;
      }
      else
      {
         for (i = 0; i < idant.value; i++)
            idchk[i].checked = false ;
      }
   }
}

<!-- Delete marked e-mails. -->
function deleteMails()
{
   rc = confirm('Du er ved at slette alle markerede mails! \n\n Vil du fortsætte?'); 
   if (!rc)
   {
      return false;
   }
   id = document.getElementById('mailform');
   antspam = id.antalspam.value;
   antnorm = id.antalnorm.value;
   id._mode.value = 'DELETE';
   parms = '&_mode=' + id._mode.value + '&antalspam=' + antspam + '&antalnorm=' + antnorm;
   for (x=0; x < antnorm; x++)
   {
      aFieldName = 'id.cbn';
      chkbox = eval(aFieldName);
      aFieldName = 'id.cbnorm'+leadZero(x,5);
      aField = eval(aFieldName);
      chkboxval = aField.value;
      if (antnorm == 1)
      {
         if (chkbox.checked)
         {
            checkMark = chkboxval;
         }
         else
         {
            checkMark = '0';
         }
      }
      else
      {
         if (chkbox[x].checked)
         {
            checkMark = chkboxval;
         }
         else
         {
            checkMark = '0';
         }
      }
      parms = parms + '&cbn' + leadZero(x,5) + '=' + checkMark;
   }
   for (x=0; x < antspam; x++)
   {
      aFieldName = 'id.cbs';
      chkbox = eval(aFieldName);
      aFieldName = 'id.cbspam'+leadZero(x,5);
      aField = eval(aFieldName);
      chkboxval = aField.value;
      if (antspam == 1)
      {
         if (chkbox.checked)
         {
            checkMark = chkboxval;
         }
         else
         {
            checkMark = '0';
         }
      }
      else
      {
         if (chkbox[x].checked)
         {
            checkMark = chkboxval;
         }
         else
         {
            checkMark = '0';
         }
      }
      parms = parms + '&cbs' + leadZero(x,5) + '=' + checkMark;
   }
   parms = escapeplus(parms);
   showPage('showpop','php',parms);
}

<!-- List e-mails. -->
function listMails()
{
   parms = '';
   showPage('showpop','php',parms);
}

<!-- Page forward e-mails. -->
function forwardMails()
{
   id = document.getElementById('mailform');
   offset = id.pageoffset.value;
   parms = '&pageoffset=' + offset + '&mode=FORWARD';
   showPage('showpop','php',parms);
}

<!-- Page backward e-mails. -->
function backwardMails()
{
   id = document.getElementById('mailform');
   offset = id.pageoffset.value;
   parms = '&pageoffset=' + offset + '&mode=BACKWARD';
   showPage('showpop','php',parms);
}

<!-- Show e-mail. -->
function showMail(cbname, msgnr)
{
   id = document.getElementById('mylayerdiv');
   id.style.visibility = 'visible';
   parms = '&msgnr='+msgnr;
   dest  = 'mylayerdiv';
   showPage('showpopcont','php',parms,dest);
}

<!-- Previous year in calendar. -->
function prevYearCal(yr)
{
   parms = '&mode=PREVYEAR&year='+yr;
   showPage('cal','php',parms);
}

<!-- Next year in calendar. -->
function nextYearCal(yr)
{
   parms = '&mode=NEXTYEAR&year='+yr;
   showPage('cal','php',parms);
}

<!-- Previous month in calendar. -->
function prevMonthCal(yr, mn)
{
   parms = '&mode=PREVMONTH&year='+yr+'&month='+mn;
   showPage('calmnd','php',parms);
}

<!-- Next month in calendar. -->
function nextMonthCal(yr, mn)
{
   parms = '&mode=NEXTMONTH&year='+yr+'&month='+mn;
   showPage('calmnd','php',parms);
}

<!-- Previous day in calendar. -->
function prevDayCal(yr, mn, dy)
{
   parms = '&mode=PREVDAY&year='+yr+'&month='+mn+'&day='+dy;
   showPage('calday','php',parms);
}

<!-- Next day in calendar. -->
function nextDayCal(yr, mn, dy)
{
   parms = '&mode=NEXTDAY&year='+yr+'&month='+mn+'&day='+dy;
   showPage('calday','php',parms);
}

<!-- Show year in calendar. -->
function yearCal(yr)
{
   parms = '&mode=YEAR&year='+yr;
   showPage('cal','php',parms);
}

<!-- Show month in calendar. -->
function monthCal(yr,mn)
{
   parms = '&mode=MONTH&year='+yr+'&month='+mn;
   showPage('calmnd','php',parms);
}

<!-- Show day in calendar. -->
function dayCal(yr,mn,dy)
{
   parms = '&mode=DAY&year='+yr+'&month='+mn+'&day='+dy;
   showPage('calday','php',parms);
}

<!-- Close edit appointment window and refresh underlaying window. -->
function closeApp()
{
   id = document.getElementById('app');
   comefrom = id.comefrom.value;
   fradato = id.perdate.value;
   yr = fradato.substr(0,4);
   mn = fradato.substr(5,2);
   dy = fradato.substr(8,2);
   if (comefrom == 'calday')
   {
      mode = 'DAY';
   }
   else
   {
      mode = 'MONTH';
   }
   parms = '&mode='+mode+'&year='+yr+'&month='+mn+'&day='+dy;
   hideDIV('mylayerdiv');
   showPage(comefrom,'php',parms);
}

<!-- New appointment in calendar. -->
function newApp(date,comefrom)
{
   id = document.getElementById('mylayerdiv');
   id.style.visibility = 'visible';
   dest  = 'mylayerdiv';
   parms = '&perdate='+date+'&date='+date+'&comefrom='+comefrom;
   showPage('calnewapp','php',parms,dest);
}

<!-- Edit appointment in calendar. -->
function editApp(eventid,comefrom,date)
{
   id = document.getElementById('mylayerdiv');
   id.style.visibility = 'visible';
   dest  = 'mylayerdiv';
   parms = '&perdate='+date+'&mode=EDIT&_id='+eventid+'&comefrom='+comefrom;
   showPage('calnewapp','php',parms,dest);
}

<!-- Delete appointment in calendar. -->
function delApp(eventid,comefrom,date)
{
   rc = confirm('Ok at slette aftale?');
   if (rc)
   {
      id = document.getElementById('mylayerdiv');
      id.style.visibility = 'visible';
      dest  = 'mylayerdiv';
      parms = '&perdate='+date+'&comefrom='+comefrom+'&mode=DELETE&_id='+eventid;
      showPage('calnewapp','php',parms,dest);
      return true;
   }
   else
   {
      return false;
   }
}

<!-- Store appointment in calendar. -->
function storeApp()
{
   id = document.getElementById('app');
   dest  = 'mylayerdiv';

   parms = '&mode=STORE'+
           '&perdate='+escape(id.perdate.value)+
           '&comefrom='+escape(id.comefrom.value)+
           '&_id='+escape(id._id.value)+
           '&fradato='+escape(id.fradato.value)+
           '&fratim='+escape(id.fratim.value)+
           '&framin='+escape(id.framin.value)+
           '&tildato='+escape(id.tildato.value)+
           '&tiltim='+escape(id.tiltim.value)+
           '&tilmin='+escape(id.tilmin.value)+
           '&id_eventtype='+escape(id.id_eventtype.value)+
           '&gentaghver='+escape(id.gentaghver.value)+
           '&gentagtil='+escape(id.gentagtil.value)+
           '&oversk='+escape(id.overskrift.value)+
           '&besk='+escape(id.beskrivelse.value)+
           '&mdato='+escape(id.markdato.value)+
           '&col='+escape(id.color.value)+
           '&bgcol='+escape(id.bgcolor.value)+
           '&url='+escape(id.url.value);
   showPage('calnewapp','php',parms,dest);
}

function togglesmileys()
{
   if (document.all.showsmiley.style.display == "inline")
   {
      document.all.showsmiley.style.display = "none";
   }
   else
   {
      document.all.showsmiley.style.display = "inline";
   }
}

<!-- Create new user group. -->
function newUserGroup()
{
   id = document.getElementById('newform');
   id.mode.value = 'STORE';
   parms = '&ugname=' + escape(id.ugname.value) + '&mode=' + escape(id.mode.value);
   parms = escapeplus(parms);
   showPage('usergroup','php',parms);
}

<!-- Alter user group. -->
function alterUserGroup()
{
   id = document.getElementById('setform');
   id.mode.value = 'ALTER';
   parms = '&id=' + escape(id.avail.value) + '&mode=' + escape(id.mode.value);
   parms = escapeplus(parms);
   showPage('usergroup','php',parms);
}

<!-- Delete user group. -->
function deleteUserGroup()
{
   id = document.getElementById('setform');
   rc = confirm('Ok at slette brugergruppe?');
   if (rc)
   {
      id.mode.value = 'DELETE';
      parms = '&id=' + escape(id.avail.value) + '&mode=' + escape(id.mode.value);
      parms = escapeplus(parms);
      showPage('usergroup','php',parms);
   }
   else
   {
      return false;
   }
}

<!-- New sound select in settings for chat room -->
function nyLyd()
{
   id2 = document.getElementById('sound2');
   id = document.getElementById('sound');
   id.value = id2.value;
}

