// Copyright 2000, 2001 by EDS (Electronic Data Systems) - All Rights Reserved
// Programming by Fred Keultjes

function jumpToPage(theBox)
{
  var index;
  var URL;

  index = theBox.selectedIndex;
  URL = theBox.options[index].value; 

  if (URL.indexOf(".",2) != -1
  || (URL.substring(0,1) == '#' && URL.length>1)
  || URL.substring(0,1) == '/')
  {
     theBox.selectedIndex = 0;
     try
     {
       var aElem = document.createElement("A");
       var aAnchor = document.getElementsByTagName("BODY")[0];
       aAnchor.appendChild(aElem);
       aElem.href = URL;
       aElem.click();
     }
     catch(ex)
     {
       document.location.href = URL; 
     }
  }
  else
  { 
     theBox.selectedIndex = 0;
  }
}

function HtmlEncode(s)
{
  var result = s;
  var i,c;

  for( i=0; i<result.length; i++ )
  {
    c = result.charAt(i);
    switch( c )
    {
    case '<':
      result = result.substring(0,i) + '&lt;' + result.substring(i+1,result.length);
      i += 3;
      break;
		case '>':
      result = result.substring(0,i) + '&gt;' + result.substring(i+1,result.length);
      i += 3;
      break;
		case '&':
      result = result.substring(0,i) + '&amp;' + result.substring(i+1,result.length);
      i += 4;
      break;
		case '"':
      result = result.substring(0,i) + '&quot;' + result.substring(i+1,result.length);
      i += 5;
      break;
		default:
      if( c.charCodeAt(0) > 0x0A0 )
      {
        var temp = '&#' + c.charCodeAt(0) + ';';

        result = result.substring(0,i) + temp + result.substring(i+1,result.length);
        i += temp.length-1;
      }
    }
  }
  return result;
}




/* utility function to change some statement to the onload sequence */

var gChainPrev = new Array();
var gChainFunc = new Array();

function chainToOnLoad( expression )
{
    var idx = gChainPrev.length;
    gChainPrev.length = idx + 1;
    gChainFunc.length = idx + 1;
    var f = window.onload ? window.onload :  new Function;
    gChainPrev[idx] = f;
    gChainFunc[idx] = expression;
    window.onload = new Function("eval(gChainFunc[" + idx + "]); var f = gChainPrev[" + idx + "];f();");
}

/* common initializing code */

function commonjs_onload()
{
  var forms = document.getElementsByTagName("FORM");
  if( forms.length>0 )
  {
    var i;

    for( i=0; i<forms.length; i++ )
    {
      var cur = forms[i];
      var attrAction = cur.action;
      if( attrAction!=null && typeof(attrAction)=="string" &&
         (attrAction.indexOf("/nlapps/diversen/mail.asp") >= 0
          || attrAction.indexOf("documents_ud.asp") >= 0
          || attrAction.indexOf("pollresult_u.asp") >= 0
          || attrAction.indexOf("apply_p.asp") >= 0) )
      {
        var result = null;
        try
        {
          // MSIE does not allow input elements to set its name attribute
          result = document.createElement("<INPUT type=\"hidden\" name=\"_form_spmchk\" value=\"\"/>");
        }
        catch(ex)
        {
        }
        if( result==null )
        {
          result = document.createElement("INPUT");
          result.name = "_form_spmchk";
          result.type = "hidden";
        }
        result.value = "spmchk";
        cur.appendChild(result);

        result = null;
        try
        {
          // MSIE does not allow input elements to set its name attribute
          result = document.createElement("<INPUT type=\"text\" name=\"_form_spmchc\" value=\"\"/>");
        }
        catch(ex)
        {
        }
        if( result==null )
        {
          result = document.createElement("INPUT");
          result.name = "_form_spmchc";
          result.type = "text";
        }
        result.className = "hide";
        cur.appendChild(result);
      }
    }
  }
  
}

chainToOnLoad("commonjs_onload()");

function ReloadScript(id)
{
 var oldurl = document.getElementById(id).src;
 var pos = oldurl.indexOf("&dummy=");
 var newurl = oldurl.substring(0,pos>=0 ? pos : oldurl.length) + "&dummy=" + escape(new Date().toString());
 document.getElementById(id).src = newurl;
}


//functions for decrypting spam-protected email addresses
function navto_mailtodecrypt(s)
{
   location.href="mailto:" + navto_decrypt(s);
}
function write_decrypt(s)
{
   document.write(navto_decrypt(s));
}
//function for decrypting
function navto_decrypt(s)
{
	var i=0;
	var r="";
	
	for(i=0; i< s.length; i++)
	{
		var c=s.charCodeAt(i) - 1 - (i % 11);
		r += String.fromCharCode(c<32 ? 95+c : c);
	}
	return r;
}


function instrumentFormForMsgEncode(f)
{
   f.action_origbeforemsg = f.action;
   f.action = "javascript:submitMsgEncodedForm(document.getElementById(\"" + f.id + "\"))";
}

function MsgUrlEncode(v)
{
  var hexchars = "0123456789ABCDEF";
  var i;
  var result = "";

  for( i=0; i<v.length; i++ )
  {
     var c = v.charAt(i);
     if( (c>="0" && c<="9") || (c>="A" && c<="Z") || (c>="a" && c<="z") )
     {
       result += c;
     }
     else
     {
       var cCode = v.charCodeAt(i);
       if( cCode<256 )
       {
         result += "_" + hexchars.charAt((cCode >> 4) & 15) + hexchars.charAt(cCode & 15);
       }
       else
       {
         result += "_u" + hexchars.charAt((cCode >> 12) & 15) + hexchars.charAt((cCode >> 8) & 15) + hexchars.charAt((cCode >> 4) & 15) + hexchars.charAt(cCode & 15);
       }
     }
  }
  return result;
}

function submitMsgEncodedForm(f)
{
   var url = f.action_origbeforemsg;
   var elems = f.elements;
   var i;

   for( i=0; i<elems.length; i++ )
   {
      var curElem = elems.item(i);
      if( i==0 && url.indexOf("?")<0 )
         url += "?";
      else
         url += "&";

      url += MsgUrlEncode(curElem.name) + "=" + MsgUrlEncode(curElem.value);
   }

   document.location.href = url; 
}

function RssLoadingTimeout(feedNr)
{
   var msg0 = document.getElementById("rsfm0_" + feedNr);
   if( msg0 != null )
   {
      var msg1 = document.getElementById("rsfm1_" + feedNr);
      if( msg1 !=null )
      {
         msg0.style.display = "none";
         msg1.style.display = "block";
      }
   }
}


//-----------------------------------------------------------------
// expand/collapse the specified id and toggle the icons
//-----------------------------------------------------------------
function icprefs_hideshow(id, action, storesetting) {
  // set the display value
  var display = (action == "show") ? "block" : "none";

  // toggle the show/hide icons
  if (action == "show") { 
    document.getElementById(id).style.display = "block";
    document.getElementById("show_" + id + "_icon").style.display = "none";
    document.getElementById("hide_" + id + "_icon").style.display = "block";
  }
  else {
    document.getElementById(id).style.display = "none";
    document.getElementById("show_" + id + "_icon").style.display = "block";
    document.getElementById("hide_" + id + "_icon").style.display = "none";
  }

  // set cookie
  if( storesetting )
    set_icprefs(id, action);
}

function toggleapplet(id)
{
  var elIcon = document.getElementById(id + "_icon");
  var actionExpand = elIcon.innerHTML.indexOf("-")<0;
  
  document.getElementById(id).style.display = actionExpand ? "" : "none";
  elIcon.innerHTML = actionExpand? "-" : "+";

  set_icprefs(id, actionExpand ? "show" : "hide");
}

function set_icprefs(cookie, info)
{
    var URL = "/nlapps/diversen/storepref.asp?modejs=1&key=" + cookie + "&value=" + info + "&dummy=" + escape(new Date().toString());
    var scriptElem = document.createElement("SCRIPT");
    scriptElem.type = "text/javascript";
    scriptElem.src = URL;
    var aAnchor = document.getElementsByTagName("BODY")[0];
    aAnchor.appendChild(scriptElem);
}

