var formMutationStatus = false;
var checkFormMutationStatus = false;

function setFormMutationStatus(status) {
  formMutationStatus = status;
}

function setCheckFormMutationStatus(status) {
  checkFormMutationStatus = status;
}

function setElementValue(item, v){
        document.getElementById(item).value = v;
        if (document.getElementById(item).getAttribute("onchange")!=null)
          document.getElementById(item).onchange();
}

function onBeforeUnload() {
    if (checkFormMutationStatus && formMutationStatus) {
        window.event.returnValue = 'Uw gegevens zijn niet opgeslagen\nWeet u zeker dat u wilt afsluiten?';
    }
}

function openMaximizedWindow(windowname, moduleURL) {
      var newWindow = window.open( moduleURL
                                 , windowname
                                 , 'scrollBars=yes, width='+(screen.availWidth-50)+', height='+(screen.availHeight-240)+", menubar=yes, location=yes, titlebar=yes, toolbar=yes, directories=yes, dependent=no, resizable=yes"
                                 );
      newWindow.moveTo(10,10);
      newWindow.focus();
}

function openInformationWindow(windowname,  moduleURL, width, height) {
              if (width==null) width = screen.availWidth-100;
              if (height==null) height = screen.availHeight-100;
              var newWindow = window.open( moduleURL
                                         , windowname
                                         , "scrollBars=yes,resizable=yes, width="+width+", height="+height+", menubar=yes, location=no, titlebar=no, toolbar=no, directories=no, dependent=no"
                                         );
              newWindow.focus();
}

var des_id = Array();
function openLOV(myurl, lovidfield, w, h, searchValuesURL ) {
  des_id    = lovidfield;
  var newWindow;
  var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=yes,location=no,dependent=yes, directories=no,width='+w+',height='+h;

  //Add searchvalue to filter list in LOV page
  if (searchValuesURL!=null)
   myurl = myurl+searchValuesURL;
  newWindow = window.open(myurl, "lov_window", props);
  newWindow.focus();
}


function addToParentLOVitem( p1, aantalkolommen ) {
  for (i = 0; i < aantalkolommen ;i++) {
    if (document.getElementById(des_id[i]) != null) {
      document.getElementById(des_id[i]).value = p1[i];
    }
  }
}

function isMaxTextArea(field, maxlimit) {
  var item;

  if (typeof(field) == 'object')
    item = field;
  else
    item = document.getElementById(field);

  if (item.value.length > maxlimit)
    item.value = item.value.substring(0, maxlimit);
}

function showWaitStatus() {
    try{
        var img = document.getElementById("titleheaderimage");
        img.src = img.src.substring(0, img.src.lastIndexOf("/"))+"/btnWait.gif";
    }catch(err){}
}

function registerSubmitButton(val) {
    showWaitStatus();
    document.getElementById("submitaction").value = val;
}

function submitForm(e, action) {
    showWaitStatus();
    var charCode = (document.layers) ? e.which : e.keyCode;
    if (charCode == 13)
      document.forms[0].submit();
    return true;
}

function surfTo(cst_website) {
  if (cst_website != '') {
    if ( cst_website.indexOf("http://") == -1)
      openInformationWindow("cst_website", "http://"+cst_website);
    else
      openInformationWindow("cst_website", cst_website);
  }
}

function setFocusOnFirstElement(){
    var ndList = document.getElementsByTagName("input");
    if (ndList.length !=0 ){
       for (i=0; i<ndList.length; i++ ){
        if (ndList[i].type!="hidden" && !ndList[i].getAttribute("readonly")){
          document.getElementById(ndList[i].id).focus();
          break;
          }
       }
    }
}

function setFocus(itemname) {
    try {
        if (itemname==null||itemname==""){
          setFocusOnFirstElement();
        }
        else
          document.getElementById(itemname).focus();
    }
    catch (err) {
    }
}

function toggleTextArea(elementid, minRows, maxRows) {
     if (elementid.rows==minRows)
       elementid.rows=maxRows;
     else
       elementid.rows=minRows;
}

function toggleDiv(divnameParam, imagename, imagepath) {
        var divname = document.getElementById( divnameParam );
        if (divname.style.display == "") {
           divname.style.display = "none";
           if (imagename!=null)
             document.getElementById(imagename).src=imagepath+"btnPlus.gif";

        }
        else {
           divname.style.display = "";
           if (imagename!=null)
             document.getElementById(imagename).src=imagepath+"btnMin.gif";
        }
}
//LETOP: document.getElementsByName('naam') opgeven
function getRadioSelection( radiofield ) {
       slechtsEen = true;
       if (typeof(radiofield)!='object') return -1;
       var value = -1;
       for (var b = 0; b < radiofield.length; b++){
         slechtsEen = false;
         if (radiofield[b].checked) return radiofield[b].value;
       }
       if (slechtsEen && radiofield.checked)
         value = radiofield.value;

       return value;
}

function setRadioSelection( radiofieldname, value_to_select ) {
       var radiofield=document.getElementsByName(radiofieldname);
       slechtsEen = true;
       if (typeof(radiofield)!='object') return;
       for (var b = 0; b < radiofield.length; b++){
         slechtsEen = false;
         if (radiofield[b].value==value_to_select) {
          radiofield[b].checked = true;
          return;
         }
       }
       if (slechtsEen && radiofield.value==value_to_select)
          radiofield.checked = true;
}

function getRadioSelectionIndex( radiofieldname ) {
       var radiofield=document.getElementsByName(radiofieldname);
       slechtsEen = true;
       if (typeof(radiofield)!='object') return -1;
       var value = -1;
       for (var b = 0; b < radiofield.length; b++){
         slechtsEen = false;
         if (radiofield[b].checked) return b;
       }
       if (slechtsEen && radiofield.checked)
         value = 0;

       return value;
}

  function insertOptionInList(olist, value, text){
    var optionlists = document.getElementsByName(olist); //is een combo
    for (i=0; i<optionlists.length; i++) {
      optionlist = optionlists[i] //is een combo
      if (optionlist.getAttribute("refcode")==refCode)
        optionlist.options[optionlist.options.length] = new Option(text,value);
    }
    refCodeControl.options[refCodeControl.options.length-1].selected=true;
 }

 function removeOptionFromList(olist, index) {
    var optionlists = document.getElementsByName(olist); //is een combo
    for (i=0; i<optionlists.length; i++) {
      optionlist = optionlists[i] //is een combo
      if (optionlist.getAttribute("refcode")==refCode) {
        optionlist.options[index] = null;
      }
    }
 }

 var refCodeControl = null;
 var refCode = ""
 function setRefCodeControl(control) {
  if (!control.options)
    control = control.previousSibling
  refCodeControl = control
  refCode = refCodeControl.getAttribute("refcode")
 }
 function getRefCodeControl() {
  return refCodeControl
 }


<!-- JS Library voor flatbuttons. Copyright (c) By Itris BV 2006 -->

 function flatBtnUpeffect(cur){
    cur.className='overbutton'
 }

 function flatBtnDowneffect(cur){
    cur.className='downbutton'
 }

 function flatBtnNormaleffect(cur){
    cur.className='normalbutton'
 }


	function adjustIFrameHeight (iframeWindow) {

		if (iframeWindow.document.height) {
		    var iframeElement = document.getElementById(iframeWindow.name)
		    iframeElement.style.height = iframeWindow.document.height+ 40 + 'px'

		} else if (document.all) {
		    var iframeElement = document.all[iframeWindow.name]

		    if (iframeWindow.document.compatMode &&
			    iframeWindow.document.compatMode != 'BackCompat') {
			    iframeElement.style.height = 
				    iframeWindow.document.documentElement.scrollHeight+ 40 + 'px'

			} else {
			    iframeElement.style.height = 
				    iframeWindow.document.body.scrollHeight+ 40 + 'px'
			}
		}
	}

	function adjustIFrameWidth (iframeWindow) {

		if (iframeWindow.document.height) {
		    var iframeElement = document.getElementById(iframeWindow.name)
			iframeElement.style.width = iframeWindow.document.width + 'px'

		} else if (document.all) {
		    var iframeElement = document.all[iframeWindow.name]

		    if (iframeWindow.document.compatMode &&
		    	iframeWindow.document.compatMode != 'BackCompat') {
				iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 'px'

			} else {
				iframeElement.style.width = frameWindow.document.body.scrollWidth + 'px'
			}
		}
	}


// Dit is een kopie vanuit ViewPage.js. Veel EditSchermen hebben ViewPage.js niet geinclude, maar roepen
// middels Select_From tag wel getKeyPress aan. Dit resulteert in een crash. Omdat de editpages wel over
// Validaties.js beschikken zal de crash voorkomen worden
function getKeyPress(e, action) {
    var charCode = (document.layers) ? e.which : e.keyCode;
    if (charCode == 13) {
      // Alleen search uitvoeren in viewpage. Er wordt vanuit gegaan, dat als searchElement bestaat of er
      // minstens 1 element "searchcriteria" bestaat dat niet hidden is, het een viewpage betreft.
      if (document.getElementById("searchElement") != null) {
        search(action);
      } else {
        var itemList = document.getElementsByName("searchcriteria");
        if (itemList != null) {
          for (i=0; i<itemList.length; i++ ){
            if (itemList[i].type!="hidden") {
              search(action);
              break;
            }
          }
        }
      }
    }
    return true;
}

function replaceImage(imgid, newimagename){
  var s = document.getElementById(imgid).src;
  var i = s.lastIndexOf("/");
  if (i!=-1)
    document.getElementById(imgid).src = s.substring(0, i+1)+newimagename;
}

/**
 * sets the selected option of the specified select control to the one having the specified text.
 */
function setSelectOption(select, text) {
    for (var i=0; i<select.options.length; i++)
        if (select.options[i].text == text) {
            select.options[i].selected = true
            return
        }
}



