function e(id){
  var element = document.getElementById(id);
  return element;
}

function eid(id){
  var element = document.getElementById(id);
  return element;
}

function v(id){
  var elementval = document.getElementById(id).value;
  return elementval;
}

function setHeights(){
//  var newHeight;
//  var mainDiv = document.getElementById('maindiv');
//  var contentDiv1 = document.getElementById('contentdiv1');
//  newHeight = contentDiv1.clientHeight + 50;
//  mainDiv.style.height = newHeight + 250;
//  contentDiv1.style.height = newHeight;
}

function iframeHeight(iframeid){
  var the_height=document.getElementById(iframeid).contentWindow.document.body.scrollHeight;
  if( the_height < 400 ){
    document.getElementById(iframeid).style.height=400;
  }else{
    document.getElementById(iframeid).style.height=the_height+50;
  }
}

//function sendUrl(url){
  // XMLHttpRequest object
//  if (window.XMLHttpRequest) {
//    req = new XMLHttpRequest();
//    req.open('GET', url, true);
//    req.send(null);

  // IE/Windows ActiveX version
//  } else if (window.ActiveXObject) {
//    req = new ActiveXObject('Microsoft.XMLHTTP');
//    if (req) {
//      req.open('GET', url, true);
//      req.send();
//    }
//  }
//}

function sendUrl(url) {
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    http_request.open('GET', url+(url.indexOf("?")>0 ? "&"+new Date().getTime() : "?"+new Date().getTime()), true);
    http_request.send(null);

}

function displaySwitch(id){
  if( document.getElementById(id).style.display=='block' ){
    document.getElementById(id).style.display='none'
  }else{
    document.getElementById(id).style.display='block'
  }
  setHeights();
}



function smiley(myField,myValue) {
  myField = e(myField);

  //IE support
  if (document.selection) {
    myField.focus();
		theSelection = document.selection.createRange();
		document.selection.createRange().text = ' ' + myValue + ' ' + theSelection.text;
    theSelection.moveStart('character',myValue.lenght + 2);
    theSelection.moveEnd('character',myValue.lenght + 2);

  //MOZILLA/NETSCAPE support
  } else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + ' ' + myValue + ' ' + myField.value.substring(myField.selectionStart, myField.selectionEnd) + myField.value.substring(endPos, myField.value.length);
    myField.selectionStart = endPos + myValue.length + 2;
    myField.selectionEnd = endPos + myValue.length + 2;
    myField.focus();

  } else {
    myField.value += ' ' + myValue + ' ';
  }

}


function insertAtCursor(myField, myValue1, myValue2) {
  myField = e(myField);

  //IE support
  if (document.selection) {
    myField.focus();
		theSelection = document.selection.createRange();
		document.selection.createRange().text = myValue1 + theSelection.text + myValue2;
    theSelection.moveStart('character',myValue1.lenght);
    theSelection.moveEnd('character',myValue1.lenght);

  //MOZILLA/NETSCAPE support
  } else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue1 + myField.value.substring(myField.selectionStart, myField.selectionEnd)
    + myValue2 +myField.value.substring(endPos, myField.value.length);
    myField.selectionStart = startPos + myValue1.length;
    myField.selectionEnd = startPos + myValue1.length;
    myField.focus();

  } else {
    myField.value += myValue1+myValue2;
  }

}

function inputboxLayoutFocus(field,new_class,default_textid){
  field.className = new_class;
  field.style.color = '#000000';
  if( field.value==e(default_textid).value ){
    field.value = '';
  }
}
function inputboxLayoutBlur(field,org_class,default_textid,def_color){
  field.className = org_class;
  if( field.value=='' ){
    field.value = e(default_textid).value;
    field.style.color = def_color;
  }
  if( field.value==e(default_textid).value ){
    field.style.color = def_color;
  }
}
function selectboxLayoutFocus(field,new_class){
  field.className = new_class;
  field.style.color = '#000000';
}
function selectboxLayoutBlur(field,org_class,def_color){
  field.className = org_class;
  if( field.value=='' ){
    field.style.color = def_color;
  }
}


// Menu
function switchMenu(id){
  if( document.getElementById(id).style.display=='block' ){
    document.getElementById(id).style.display='none'
  }else{
    document.getElementById(id).style.display='block'
  }
  setHeights();
}

// Images
function switchImage(image,titletext){
  document.getElementById('lightboxA').href='pictures/'+image;
  document.getElementById('lightboxA').name=titletext;
  document.getElementById('imageHolderMain').src='http://www.vijftigplusser.nl/makeimage.php?src='+escape('pictures/thumbs/'+image)+'&width=250&height=180';
  document.getElementById('imageHolderMain').title=titletext.replace(/NEWLINE/g,' ');
}

// Form submitter on enter
function submitenter(myfield,e){
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if( keycode == 13 ){
    myfield.form.submit();
    return false;
  }else
    return true;
}

// Form validator
function Validator(frmname){
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname){
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
//------ begin form_submit_handler -----
function form_submit_handler() {
  for(var itr=0;itr < this.elements.length;itr++) {
    var inp = this.elements[itr];
    if (inp.type && inp.type.toLowerCase()=='radio')
      inp = this.elements[inp.name];

    if(inp.validationset &&
      !inp.validationset.validate())
        return false;
  }
  if(this.addnlvalidation) {
    str =" var ret = "+this.addnlvalidation+"()";
    eval(str);
    if(!ret) return ret;
  }
  return true;
}
//------ end form_submit_handler ------
function add_validation(itemname,descriptor,errstr){
  if(!this.formobj){
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}

	if(!itemobj.validationset)	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
//---------- begin function vdesc_validate--------
function vdesc_validate() {
  if(!V2validateData(this.desc,this.itemobj,this.error)) {
    if (this.itemobj.focus) this.itemobj.focus();
    return false;
  }
  return true;
}
//----------end function vdesc_validate----------
function ValidationSet(inputitem){
  this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error){
  this.vSet[this.vSet.length]=
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate(){
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
//---------------------------------EMail Check ------------------------------------
/*  checks the validity of an email address entered
*   returns true or false
*
*/
function validateEmailv2(email){
// a very simple email validation checking.
// you can add more complex email checking if it helps
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null)
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

/* function V2validateData
*  Checks each field in a form

*/
function V2validateData(strValidateStr,objValue,strError){
    var epos = strValidateStr.search("=");
    var  command  = "";
    var  cmdvalue = "";
    if(epos >= 0)
    {
     command  = strValidateStr.substring(0,epos);
     cmdvalue = strValidateStr.substr(epos+1);
    }
    else
    {
     command = strValidateStr;
    }

    switch(command)
    {
        case "req":
        case "required":
         {
           if(eval(objValue.value.length) == 0)
           {
              if(!strError || strError.length ==0)
              {
                strError = objValue.name + " : Verplicht veld";
              }//if
              alert(strError);
              return false;
           }//if
           break;
         }//case required

//------------begin akkoord -----------
	case "akkoord":
		{
			if (!objValue.checked)
				{
					if(!strError || strError.length ==0)
					{
					strError = objValue.name + " : ";
					}
					alert(strError);
					return false;
					}
					break;
		}
//-------------einde akkoord -----------

//------------begin radio required -----------

 case "radioreq":
   for (var radioN=0; radioN<objValue.length; radioN++)
    if (objValue[radioN].checked) return true;
  alert(strError);
   return false;

//------------end radio required ------------
        case "maxlength":
        case "maxlen":
          {
             if(eval(objValue.value.length) >  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
                 strError = objValue.name + " : "+cmdvalue+" karakters maximaal ";
               }//if
               alert(strError + "\n[Lengte is nu = " + objValue.value.length + " ]");
               return false;
             }//if
             break;
          }//case maxlen
        case "minlength":
        case "minlen":
           {
             if(eval(objValue.value.length) <  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
                 strError = objValue.name + " : " + cmdvalue + " karakters maximaal  ";
               }//if
               alert(strError + "\n[Lengte is nu = " + objValue.value.length + " ]");
               return false;
             }//if
             break;
            }//case minlen
        case "alnum":
        case "alphanumeric":
           {
              var charpos = objValue.value.search("[^A-Za-z0-9]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
               if(!strError || strError.length ==0)
                {
                  strError = objValue.name+": Alleen alfanumerieke karakters toegestaan ";
                }//if
                alert(strError);
                return false;
              }//if
              break;
           }//case alphanumeric
        case "num":
        case "numeric":
           {
              var charpos = objValue.value.search("[^0-9]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                if(!strError || strError.length ==0)
                {
                  strError = objValue.name+": Alleen cijfers toegestaan ";
                }//if
                alert(strError);
                return false;
              }//if
              break;
           }//numeric
        case "num_tel":
        case "numeric_tel":
           {
              var charpos = objValue.value.search("[^0-9\-]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                if(!strError || strError.length ==0)
                {
                  strError = objValue.name+": Geen correct telefoonnummer";
                }//if
                alert(strError);
                return false;
              }//if
              break;
           }//numeric_tel
        case "alphabetic":
        case "alpha":
           {
              var charpos = objValue.value.search("[^A-Za-z]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
                  strError = objValue.name+": Alleen alfabetische karakters toegestaan ";
                }//if
                alert(strError);
                return false;
              }//if
              break;
           }//alpha
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
                  strError = objValue.name+": Toegestane karakters zijn A-Z,a-z,0-9,- en _";
                }//if
                alert(strError);
                return false;
              }//if
			break;
			}
        case "email":
          {
               if(!validateEmailv2(objValue.value))
               {
                 if(!strError || strError.length ==0)
                 {
                    strError = objValue.name+": Geef een geldig emailadres op ";
                 }//if
                 alert(strError);
                 return false;
               }//if
           break;
          }//case email
        case "lt":
        case "lessthan":
         {
            if(isNaN(objValue.value))
            {
              alert(objValue.name+": zou een nummer moeten zijn ");
              return false;
            }//if
            if(eval(objValue.value) >=  eval(cmdvalue))

            {
              if(!strError || strError.length ==0)
              {
                strError = objValue.name + " : waarde zou minder moeten zijn dan "+ cmdvalue;
              }//if
              alert(strError);
              return false;
             }//if
            break;
         }//case lessthan
        case "gt":
        case "greaterthan":
         {
            if(isNaN(objValue.value))
            {
              alert(objValue.name+": Moet een nummer zijn ");
              return false;
            }//if
             if(eval(objValue.value) <  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
                 strError = objValue.name + " : Waarde moet groter zijn dan €"+ cmdvalue;
               }//if
               alert(strError);
               return false;
             }//if
            break;
         }//case greaterthan
        case "regexp":
         {
            if(!objValue.value.match(cmdvalue))
            {
              if(!strError || strError.length ==0)
              {
                strError = objValue.name+": Foutieve karakters ingevoerd ";
              }//if
              alert(strError);
              return false;
            }//if
           break;
         }//case regexp
        case "dontselect":
         {
            if(objValue.selectedIndex == null)
            {
              alert("BUG: dontselect command for non-select Item");
              return false;
            }
            if(objValue.selectedIndex == eval(cmdvalue))
            {
             if(!strError || strError.length ==0)
              {
              strError = objValue.name+": Selecteer uw keuze.";
              }//if
              alert(strError);
              return false;
             }
             break;
         }//case dontselect
    }//switch
    return true;
}


// Hints
var horizontal_offset="5px" //horizontal offset of hint box from anchor link
var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all
function getposOffset(what, offsettype){
  var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  var parentEl=what.offsetParent;
  while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}
function iecompattest(){
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function clearbrowseredge(obj, whichedge){
  var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
  if (whichedge=="rightedge"){
    var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
      edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
  }else{
    var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
      edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
  }
  return edgeoffset
}
function showhint(menucontents, obj, e, tipwidth){
  var IE = document.all?true:false
  // If NS -- that is, !IE -- then set up for mouse capture
  if (!IE) document.captureEvents(Event.MOUSEMOVE)
  // Temporary variables to hold mouse x-y pos.s
  var tempX = 0
  var tempY = 0
  // Main function to retrieve mouse x-y pos.s

  var tipwidth2 = tipwidth.replace('px','')

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}

  if ((ie||ns6) && document.getElementById("hintbox")){
    dropmenuobj=document.getElementById("hintbox")
    dropmenuobj.innerHTML="<div>"+menucontents+"</div>"
    dropmenuobj.style.left=dropmenuobj.style.top=-500
    if (tipwidth!=""){
      dropmenuobj.widthobj=dropmenuobj.style
      dropmenuobj.widthobj.width=tipwidth
    }
    dropmenuobj.x=getposOffset(obj, "left")
    dropmenuobj.y=getposOffset(obj, "top")
//    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
//    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
//    dropmenuobj.style.left=dropmenuobj.x+5
//    dropmenuobj.style.top=dropmenuobj.y+20
    dropmenuobj.style.left=tempX-tipwidth2
    dropmenuobj.style.top=tempY+20
    dropmenuobj.style.zIndex="1960"
    dropmenuobj.style.visibility="visible"
    obj.onmouseout=hidetip
  }
}
function hidetip(e){
  dropmenuobj.style.visibility="hidden"
  dropmenuobj.style.left="-500px"
}
function createhintbox(){
  var divblock=document.createElement("div")
  divblock.setAttribute("id", "hintbox")
  document.body.appendChild(divblock)
}
if (window.addEventListener)
  window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
  window.attachEvent("onload", createhintbox)
else if (document.getElementById)
  window.onload=createhintbox




