function validateHtml(html)
{
  var html2 = "";
  if (html != null && html != "") {
    for (var i=0;i<html.length;i++) {
      switch (html.charAt(i)) {  
      case '\u20AC':
        html2 += '&euro;';
          break;
        default:
          html2 += html.charAt(i);
          break;
      }
    }
  }
  return html2;
}

/** Controleer of een String null of '' is
 * @param vCheck de te controleren String
 * @return true als de te controleren String leeg is; false als dat niet zo is
 */
function isEmpty(vCheck) {
  return (vCheck == null || vCheck == '');
}

/** Vervang een bepaalde String door een andere
 * @param vOrg orignele String
 * @param vSearch de te vervangen String
 * @param vReplace de String waardoor de vSearch vervangen wordt
 * @return nieuwe String
 */
function replaceAll(vOrg, vSearch, vReplace) {
/*
alert('VOOR\n'+
      'ORG: '+vOrg+'\n'+
      'SEARCH: '+vSearch+'\n'+
      'REPLACE: '+vReplace+'\n'+
      'INDEX: '+vOrg.indexOf(vSearch));
*/
  if (!isEmpty(vOrg) && !isEmpty(vSearch) && vReplace != null) {
    while (vOrg.indexOf(vSearch) > -1) {
      vOrg = vOrg.replace(vSearch, vReplace);
    }
  }
//alert('vOrg NA: '+vOrg);
  return vOrg;
}

/** Als er een relatieve link ingevoerd wordt in de editor wordt deze automatisch 
 *  vervangen door IE door een absolute url, wat we niet willen
 *  Deze moeten weer vervangen worden door relatieve paden.
 * @param html String
 * @return html waarvan de absolute paden vervangen zijn door relatieve
 */
/*
function replaceAbsoluteUrls(html) {
  if (!isEmpty(html)) {
  var vDocLoc = document.location.toString();
  var iDir   = new Number(-1);
  var vLoc   = '';
/*  
    var vHttp = (vDocLoc.indexOf('http://') > -1);
  if (vHttp) {
    vDocLoc = vDocLoc.substring(7);
  }
    var arDocLoc = vDocLoc.split("/");
    for (i=arDocLoc.length;i>0;i--) {
    var vUrl = '';
      for (j=0;j<i;j++) {
      if (vHttp && j==0) {
        vUrl+='http://';
        }
        if (arDocLoc[j].indexOf('.jsp') == -1) {
          vUrl+=arDocLoc[j]+'/';
        }
      }
    html = replaceAll(html, vUrl, "");
  }
*/  
/*
  html = replaceAll(html, vDocLoc, "");
  
    iLoc = new Number(vDocLoc.indexOf("admincmsmanager.jsp"));
  if (iLoc > -1) {
      vLoc = vDocLoc.substring(0, iLoc);
    if (!isEmpty(vLoc)) {
        html = replaceAll(html, vLoc, "");
    }
  }  
    iLoc = new Number(vDocLoc.indexOf(dynamicUrl));
    if (iLoc > -1) {
      vLoc = vDocLoc.substring(0,(iLoc+dynamicUrl.length));
      if (!isEmpty(vLoc)) {
        html = replaceAll(html, vLoc, "../");
      }
    }
  }
  return html;
}
*/
/**
 * Vervang de absolute URL door een relatief path...
 */
function replaceAbsoluteUrls(html) {
  if (!isEmpty(html)) {
  var vDocLoc = document.location.toString();

  // De URL die we terugkrijgen zal een paginanaam bevatten. Deze halen we er al vast vanaf.
  vDocLoc = vDocLoc.substring(0,vDocLoc.lastIndexOf('/'));
  // Verang eerst even deze URL + een '/' door '' zodat een link of een plaatje in de huidige 
  // directory (*live* is dat <SITE>/cms/) ook goed opgeslagen kan gaan worden
  html    = replaceAll(html, vDocLoc+'/', '');

  // Deze locatie gaan we opdelen in verschillende URL die we uit de locatie kunnen halen
  // Bijv. http://localhost:8080/test/1/2/3/
  // wordt een Array met: 
  // [0] http://localhost:8080/test/1/2/3/
  // [1] http://localhost:8080/test/1/2/
  // [2] http://localhost:8080/test/1/
  // [3] http://localhost:8080/test/
  // [4] http://localhost:8080/
  var vDocLocs = getLocs(vDocLoc);
  var vAntChk = vDocLocs.length;
  // Het totale aantal locaties minus 1 is het aantal .. die we moeten toevoegen vooraan
  // de nieuwe URL
  var vAntDir = vAntChk-1;

  for (vCurChk=0;vCurChk<vAntChk;vCurChk++) {
    // Vervang de huidige locatie door het aantal directories
    html = replaceAll(html, vDocLocs[vCurChk], getPoints4Dir(vAntDir));
    vAntDir--;
  }
  }
  return html;
}

/**
 * Geeft het aantal mogelijke locaties terug, die gemaakt kunnen worden 
 * met de meegegeven locatie
 */  
function getLocs(vLoc) {
  var vArray          = new Array();
  var vIndex          = 0;
  var vIndexLastSlash = 0;
  if (vLoc.indexOf('http://') == 0) {
    vIndexLastSlash = 7;
  }
  // Eerst voegen we de hele locatie toe
  vArray[vIndex] = vLoc;
  vIndex++;
  // Nu gaan we verder met de vervolglocatie(s)    
  while (vLoc.lastIndexOf('/') > vIndexLastSlash) {
    vLoc = vLoc.substring(0,vLoc.lastIndexOf('/'));    
    vArray[vIndex] = vLoc;
    vIndex++;
  }    
  return vArray;
}
/**
 * Deze functie geeft afhankelijk van vDir een aantal '..' terug
 */
function getPoints4Dir(vDirs) {
  var vReturn = '';
  while (vDirs > 0) {
    if (vReturn != '') vReturn += '/';
    vReturn += '..';
    vDirs--;
  }
  return vReturn;
}

function setSelected(vNameSelectBox, vSelect) {
  if (vNameSelectBox) {
    var aantalOptions = vNameSelectBox.length;
    for (var tel=0;tel<aantalOptions;tel++) {
      if (vNameSelectBox.options[tel].value==vSelect) {
//        vNameSelectBox.selectedIndex=tel;
        vNameSelectBox.options[tel].selected=true;
      }
    }
  } else {
  }
}

function selectAll(c,s) {    
  if (c.checked) {
	c.checked = true;
    s.disabled = true;
  } else {
	c.checked = false;
    s.disabled = false;
  }
  sortSelect(c,s);
}

function sortSelect(c,s)  {  
  var temp_opts = new Array();
  var temp = new Object();
  for(var i=0; i<s.options.length; i++)  {
    temp_opts[i] = s.options[i];
  }
  for(var x=0; x<temp_opts.length-1; x++)  {
    for(var y=(x+1); y<temp_opts.length; y++)  {
      if(temp_opts[x].text > temp_opts[y].text)  {
        temp = temp_opts[x].text;
        temp_opts[x].text = temp_opts[y].text;
        temp_opts[y].text = temp;
        temp = temp_opts[x].value;
        temp_opts[x].value = temp_opts[y].value;
        temp_opts[y].value = temp;
      }
    }
  }
  for(var i=0; i<s.options.length; i++)  {
    s.options[i].value = temp_opts[i].value;
    s.options[i].text = temp_opts[i].text;    
    s.options[i].selected = c.checked;
  }            
}
/**
 * Als er op de meegegeven checkcheck-checkbox geclicked wordt
 * en deze moet CHECKED worden dan zal de meegegeven checkbox(es)
 * ook geCHECKED worden
 */
function checkAll(checkcheck, checkbox) {
  if (checkcheck && checkbox) {
    if (checkbox.length) {
      for (i=0;i<checkbox.length;i++) {
        if (!checkbox[i].disabled) {
          checkbox[i].checked=checkcheck.checked;
        }
      }
    } else {
      checkbox.checked=checkcheck.checked;
    }
  } else {
  }
}

function checkMaxlength(vFrmElm, iMaxlength) {
  vVal = vFrmElm.value;
  if (vVal.length > (iMaxlength-1)) {
    setMaxlength(vFrmElm, iMaxlength);
  }
}

function setMaxlength(vFrmElm, iMaxlength) {
  vVal = vFrmElm.value;
  if (vVal.length > iMaxlength) {
    vFrmElm.value = vVal.substring(0, (iMaxlength));
  }
}

function setFocus(vFrmElm) {
  if (vFrmElm) {
    vFrmElm.focus();
  }
}

function fireCommand(command,commandId) {
    document.forms[0].fldCommand.value=command;
    document.forms[0].fldCommandId.value=commandId;
    document.forms[0].submit();
}

/**
 * Onderstaande is nodig om selectboxen aanklikbaar te maken
 */
var arrOldValues;

function SelectAllList(CONTROL){
for(var i = 0;i < CONTROL.length;i++){
CONTROL.options[i].selected = true;
}
}

function DeselectAllList(CONTROL){
for(var i = 0;i < CONTROL.length;i++){
CONTROL.options[i].selected = false;
}
}


function FillListValues(CONTROL)
{
	var arrNewValues;
	var intNewPos;
	var strTemp = GetSelectValues(CONTROL);
	arrNewValues = strTemp.split(",");
	
	for(var i=0;i<arrNewValues.length-1;i++)
	{
		if(arrNewValues[i]==1)
		{
			intNewPos = i;
		}
	}
	
	if(arrNewValues[0] == 1)
	{
		DeselectAllList(CONTROL);
		return;
	}
	
	for(var i=0;i<arrOldValues.length-1;i++)
	{
		if(arrOldValues[i]==1 && i != intNewPos)
		{
			CONTROL.options[i].selected= true;
		}
		else if(arrOldValues[i]==0 && i != intNewPos)
		{
			CONTROL.options[i].selected= false;
		}

		if(arrOldValues[intNewPos]== 1)
		{
			CONTROL.options[intNewPos].selected = false;
		}
		else
		{	
			CONTROL.options[intNewPos].selected = true;
		}
	}
}


function GetSelectValues(CONTROL)
{
	var strTemp = "";
	for(var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
		{
			strTemp += "1,";
		}
		else
		{
			strTemp += "0,";
		}
	}
	return strTemp;
}

function GetCurrentListValues(CONTROL)
{
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",")
}

function Redirect(url)
{
    window.location = url;
}