

var img;
var img_mo;
var img_cl;
img = new Array();
img_mo = new Array();
img_cl = new Array();



function setCookie(name, value, expire) {
  if (expire == '') {
    document.cookie = name + '=' + escape(value) + '; path=/';
  } else {
    var expires = new Date();
    expires.setTime(expires.getTime() + expire);

    document.cookie = name + '=' + escape(value) + ((expire == null) ? '' : ('; expires=' + expires.toGMTString())) + '; path=/';
  }
}


function getCookie(name) {
   var search = name + "=";
   var val = "";
   var offset,end;
   
   if(document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 

      if(offset != -1) { // if cookie exists 
         offset += search.length;

         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 

         // set index of end of cookie value
         if (end == -1) {
            end = document.cookie.length;
         }

         val = unescape(document.cookie.substring(offset, end));
      } 
   }

   return val;
}

function initMo(uniqueid, origImgSrc, overImgSrc, clickImgSrc) {
  if (origImgSrc != '') {
    img[uniqueid] = new Image();
    img[uniqueid].src = origImgSrc;
  }
  if (overImgSrc != '') {
    img_mo[uniqueid] = new Image();
    img_mo[uniqueid].src = overImgSrc;
  }
  if (clickImgSrc != '') {
    img_cl[uniqueid] = new Image();
    img_cl[uniqueid].src = clickImgSrc;
  }
}


function mov(uniqueid) {
  if (img_mo[uniqueid]) {
    document[uniqueid].src = img_mo[uniqueid].src;
  }
}


function mou(uniqueid) {
  if(img[uniqueid]) {
    document[uniqueid].src = img[uniqueid].src;
  }
}


function md(uniqueid) {
  if (img_cl[uniqueid]) {
    document[uniqueid].src = img_cl[uniqueid].src;
  }
}



function showWindow(uniqueid,id,qs,width,height) {
  var windowObj;
  windowObj = eval('top.Info' + uniqueid);

  if (windowObj !=null && (windowObj + "" != "undefined") && !windowObj.closed) {
    windowObj.focus();
  } else {
    windowObj = null;
    windowObj = top.open('/kpn/show/id=' + id + qs,'Info'+uniqueid,'toolbar=no,width=' + width + ',height=' + height + ',directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
    top.name = 'wm';

    if (windowObj != null) {
      windowObj.focus();
    }     
  }
  reload = false;
  return windowObj;
}

function newSession() {
  if (getCookie('session') == 'set') {
    return false;
  } else {
    setCookie('session', 'set', '');
    if (getCookie('session') == 'set') {
      return true;
    } else {
      return false;
    }
  }
}



function showURL(url, windowname, width, height) {
  var w;
  w = top.open(url, windowname, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=' + height + ',width=' + width);
  if(w==null) {
    return null;
  }
  w.opener = window;
  return w;
}


function showKpnInfo(title, info) {
  showKpnInfo(title, info, 184, 190);
}

function showKpnInfo(title, info, width, height) {
  if (!(typeof kpnInfoWin == 'undefined')) {
    kpnInfoWin.close();
  }

  if (typeof(width) == 'undefined') {
    width = 184;
  }

  if (typeof(height) == 'undefined') {
    height = 190;
  }

  leftPosition = (screen.width) ? (screen.width - width) / 2 : 0;
  topPosition = (screen.height) ? (screen.height - height) / 2 : 0;

  if (info.length > 220) {
    allowScroll = 1;
  } else {
    allowScroll = 0;
  }

  kpnInfoWin = window.open ('', 'kpnInfoWin', 'height=' + height + ',width=' + width + ',top=' + topPosition + ',left=' + leftPosition + ',scrollbars=' + allowScroll + ',resizable=1');

  kpnInfoWin.document.write('<html>');
  kpnInfoWin.document.write('  <head>');
  kpnInfoWin.document.write('    <title>');
  kpnInfoWin.document.write(unescape(title));
  kpnInfoWin.document.write('    </title>');
  kpnInfoWin.document.write('    <link rel="stylesheet" href="/static/stylesheet.css" type="text/css" />');
  kpnInfoWin.document.write('  </head>');
  kpnInfoWin.document.write('  <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#ffffff">');
  kpnInfoWin.document.write('    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
  kpnInfoWin.document.write('      <tr>');
  kpnInfoWin.document.write('        <td colspan="3"><img src="/e.gif" width="1" height="14" border="" alt="" /></td>');
  kpnInfoWin.document.write('      </tr>');
  kpnInfoWin.document.write('      <tr>');
  kpnInfoWin.document.write('        <td width="14" height="154"><img src="/e.gif" width="14" height="1" border="0" alt="" /></td>');
  kpnInfoWin.document.write('        <td height="154" style="border-left: 1px solid #C0C0C0; border-bottom:1px solid #C0C0C0; padding-left: 6px; padding-bottom: 6px;" align="left" valign="top">');
  kpnInfoWin.document.write('          <span class="g">');
  kpnInfoWin.document.write(unescape(title));
  kpnInfoWin.document.write('          </span>');
  kpnInfoWin.document.write('<br/><br/>');
  kpnInfoWin.document.write('          <span class="c">');
  kpnInfoWin.document.write(unescape(info));
  kpnInfoWin.document.write('          </span>');
  kpnInfoWin.document.write('          <td width="14" height="154"><img src="/e.gif" width="14" height="1" border="0" alt="" /></td>');
  kpnInfoWin.document.write('      </tr>');
  kpnInfoWin.document.write('      <tr>');
  kpnInfoWin.document.write('        <td colspan="3"><img src="/e.gif" width="1" height="14" border="0" alt="" /></td>');
  kpnInfoWin.document.write('      </tr>');
  kpnInfoWin.document.write('    </table>');
  kpnInfoWin.document.write('  </body>');
  kpnInfoWin.document.write('</html>');
  kpnInfoWin.document.close();
  kpnInfoWin.focus();
}

function showKpnInfoURL(title, url, width, height) {
  if (!(typeof kpnInfoWin == 'undefined')) {
    kpnInfoWin.close();
  }

  if (typeof(width) == 'undefined') {
    width = 184;
  }

  if (typeof(height) == 'undefined') {
    height = 190;
  }

  leftPosition = (screen.width) ? (screen.width - width) / 2 : 0;
  topPosition = (screen.height) ? (screen.height - height) / 2 : 0;

  kpnInfoWin = window.open (url, 'kpnInfoWin', 'height=' + height + ',width=' + width + ',top=' + topPosition + ',left=' + leftPosition + ',scrollbars=1,resizable=1');
  kpnInfoWin.focus();
}


/* StijnW 2006-08-30 KPN-970 [6845] popup maken */
var temphref = '';
var loggingRequestComplete = true;

/**
 *  This function can be used to invoke request logging on links. It works by
 *  setting the src attribute of the img element with id [identifier] to
 *  the specified [url]. The browser will fetch the image, which causes a
 *  request that will be logged. Before changing the src, this method attaches
 *  an onload listener to the img, to determine if / when the request has finished.
 *  When the request has finished this function will load the url in [ahref] using
 *  document.location, or, when returnControl is true, it will allow the native
 *  event handler to run (which, in the case of a link, will 'click' the link)
 *
 *  @param identifier   [String] The id of the image element
 *  @param url          [String] The url to fetch for logging
 *  @param ahref        [String] The destination of the link
 *  @param returnControl  [bool] Should control be returned to the native event
 *                               handler? Default = false
 *  @param returnTimeoutMs [int] The timeout, in milliseconds, before control is
 *                               returned even when the request has not completed
 *                               yet. Default = 2000
 *
 *  Modified on 2006-08-30 by StijnW
 *  KPN-970 [6845] popup maken
 *  Added two parameters that allow the caller to signal that this function
 *  should return control to the native event handler.
 */

var ahrefs = new Array();
var delay = 3000;

function setLoggingRequest(identifier, url, ahref, returnControl, returnTimeoutMs)
{
  if (ahref.indexOf('/ordermanager') > -1) {
    showHideElementDelay('pleasewait', 'show', delay);
    var found = false;
  for (var i = 0; i < ahrefs.length; i++) {
    ahrefs_i = ahrefs[i];
    if (ahrefs_i == ahref) {
          alert("Wacht a.u.b. tot het systeem klaar is met het verwerken van uw aanvraag");
      found = true;
      return false;
    }
  }
  if (!found) {
    ahrefs.push(ahref);
  }
  }

  temphref = ahref;
  var obj = document.getElementById(identifier);
  var seturl;

  if (returnControl == null)
    returnControl = false;

  if ((returnTimeoutMs == null) || (returnTimeoutMs <= 0))
    returnTimeoutMs = 2000;

  if (obj != null && url != '')
  {
    if (returnControl)
    {
      loggingRequestComplete = false;
      obj.onload = checkLoggingRequestFinishedReturnControl;
    }
    else
      obj.onload = checkLoggingRequestFinished;

    seturl = url.replace('/kpn/redir', '/kpn/empty/');
    seturl = seturl.replace('/kpn/restricted/redir', '/kpn/empty/');
    seturl = seturl + '&time=' + (new Date()).getTime();

    obj.src=seturl;

    if (returnControl)
    {
      var start = new Date().getTime();
      var now = new Date();
      while ((! loggingRequestComplete) && (now.getTime() < start + returnTimeoutMs))
      {
        // wait for logging request to complete
        now = new Date();
      }

      return true; // return control to native handler, will get location inside href attribute
    }

  }

  return true;
}

/**
 *  Changes document.location to the new location when img is loaded.
 *
 *  Attched to onload handler of img element by setLoggingRequest to determine if the
 *  logging request has finished. When it's finished, navigates to the new location using
 *  document.location.
 */
function checkLoggingRequestFinished() {
  document.location = temphref;
}

/**
 *  Signals that logging request has completed.
 *
 *  Attached to onload handler of img element by setLoggingRequest to determine if
 *  logging request has finished. This method does not change the location but just sets a
 *  flag to signal to setLoggingRequest that the request is complete.
 */
function checkLoggingRequestFinishedReturnControl() {
  loggingRequestComplete = true;
}
/* StijnW 2006-08-30 KPN-970 [6845] popup maken */


function showHetNetInfo(title, info) {
  showHetNetInfo(title, info, 184, 190);
}

function showHetNetInfo(title, info, width, height) {
  if (!(typeof hetNetInfoWin == 'undefined')) {
    hetNetInfoWin.close();
  }

  if (typeof(width) == 'undefined') {
    width = 184;
  }

  if (typeof(height) == 'undefined') {
    height = 190;
  }

  leftPosition = (screen.width) ? (screen.width - width) / 2 : 0;
  topPosition = (screen.height) ? (screen.height - height) / 2 : 0;

  if (info.length > 220) {
    allowScroll = 1;
  } else {
    allowScroll = 0;
  }

  hetNetInfoWin = window.open ('', 'hetNetInfoWin', 'height=' + height + ',width=' + width + ',top=' + topPosition + ',left=' + leftPosition + ',scrollbars=' + allowScroll + ',resizable=1');

  hetNetInfoWin.document.write('<html>');
  hetNetInfoWin.document.write('  <head>');
  hetNetInfoWin.document.write('    <title>');
  hetNetInfoWin.document.write(unescape(title));
  hetNetInfoWin.document.write('    </title>');
  hetNetInfoWin.document.write('    <link rel="stylesheet" href="/kpn/static/stylesheet.css" type="text/css" />');
  hetNetInfoWin.document.write('  </head>');
  hetNetInfoWin.document.write('  <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#ffffff">');
  hetNetInfoWin.document.write('    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
  hetNetInfoWin.document.write('      <tr>');
  hetNetInfoWin.document.write('        <td colspan="3"><img src="/kpn/e.gif" width="1" height="14" border="" alt="" /></td>');
  hetNetInfoWin.document.write('      </tr>');
  hetNetInfoWin.document.write('      <tr>');
  hetNetInfoWin.document.write('        <td width="14" height="154"><img src="/kpn/e.gif" width="14" height="1" border="0" alt="" /></td>');
  hetNetInfoWin.document.write('        <td height="154" style="border-left: 1px solid #C0C0C0; border-bottom:1px solid #C0C0C0; padding-left: 6px; padding-bottom: 6px;" align="left" valign="top">');
  hetNetInfoWin.document.write('          <span style="font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #000066; text-decoration: none;">');
  hetNetInfoWin.document.write(unescape(title));
  hetNetInfoWin.document.write('          </span>');
  hetNetInfoWin.document.write('<br/><br/>');
  hetNetInfoWin.document.write('          <span class="c">');
  hetNetInfoWin.document.write(unescape(info));
  hetNetInfoWin.document.write('          </span>');
  hetNetInfoWin.document.write('          <td width="14" height="154"><img src="/kpn/e.gif" width="14" height="1" border="0" alt="" /></td>');
  hetNetInfoWin.document.write('      </tr>');
  hetNetInfoWin.document.write('      <tr>');
  hetNetInfoWin.document.write('        <td colspan="3"><img src="/kpn/e.gif" width="1" height="14" border="0" alt="" /></td>');
  hetNetInfoWin.document.write('      </tr>');
  hetNetInfoWin.document.write('    </table>');
  hetNetInfoWin.document.write('  </body>');
  hetNetInfoWin.document.write('</html>');
  hetNetInfoWin.document.close();
  hetNetInfoWin.focus();
}

/* patrickh, KPN-770: Because of a patch for IE6, direct interaction with activeX controls that are loaded by EMBED, APPLET of OBJECT tags is blocked.
   This function must be used as a workaround.
 */
function documentWrite(text) {
  document.write(text);
}

/*
** Ordermanager functions
*/

var moverTop = null;
var moverLeft = null;
var ie4=document.all;

function showHideElementDelay(elementId, action, delay) {
  setTimeout('showHideElement(\'' + elementId + '\',\'' +  action + '\')',delay);
}

function showHideElement(elementId, action) {
  var obj = document.getElementById(elementId);

  if (obj) {
    if (action=='hide') {
      obj.style.display = 'none';
    } else {
      if (action=='show') {
        obj.style.display = 'block';

        var userAgent = navigator.userAgent;
        if(userAgent.indexOf('MSIE') != -1) {
          aname = elementId+'_tbl';
        } else {
          aname = elementId+'_a';
        }

        if (document.getElementById(aname)) {
          document.getElementById(aname).focus();
        }
      }
    }
  }
}

function ietest() {
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function floater(elementId) {
  floatobj = document.getElementById(elementId);
  // 158 is half the width of the element.
  if (ie4 && !window.opera) {
    moverLeft = "floatobj.style.pixelLeft = ietest().scrollLeft+"+((ietest().clientWidth/2) - 158 - 20) + ";";
    moverTop = "floatobj.style.pixelTop = ietest().scrollTop+" + ((ietest().clientHeight/2) - 75) + ";";
  } else {
    if (window.opera){
      moverLeft = "floatobj.style.left = " + (window.pageXOffset+(window.innerWidth/2) - 158) + ";";
      moverTop = "floatobj.style.top = " + (window.pageYOffset+(window.innerHeight/2) - 75) + ";";
    } else {
      moverLeft = "floatobj.style.left = " + (window.pageXOffset-80) + ";";
      moverTop = "floatobj.style.top = " + (window.pageYOffset+(window.innerHeight/2) - 75) + ";";
    }
  }

  eval(moverTop);
  eval(moverLeft);
  setTimeout("floater('pleasewait')", 30);
  return false;
}


function getUserInfo(__varname){
   var __userinfocookie= getCookie('userinfo');
   var __pairs='';

   if( !__varname && __varname == ''){return '';}

   if (__userinfocookie && __userinfocookie != '' && __userinfocookie.indexOf
('#')!=-1){
     __pairs = __userinfocookie.split('#');
     for(i=0 ; i<__pairs.length;i++){
       if(__pairs[i] != '' && __pairs[i].indexOf('=')!=-1){
         var __parts=__pairs[i].split('=');
         if(__parts[0]==__varname){return __parts[1];}
       }
     }
   }
   return '';
}
