/* Algemene browserbepalingsfuncties */
var ie4 = document.all&&navigator.userAgent.indexOf("Opera")==-1;
var ns6 = document.getElementById&&!document.all;
var ns4 = document.layers;
var opera = (navigator.userAgent.indexOf("Opera")>=0);
ns6 = (ns6||opera);

function getElem(id) {
	return ie4? eval('document.all.'+id) : ns6? document.getElementById(id) : ns4? eval('document.'+id) : "";
}

function setElemPosition(id, refEL) {
  var iLeft=0; var iTop=0; 
  
  var obj=refEL;
  while (obj.offsetParent!=null) {
    iLeft+=obj.offsetLeft; iTop+=obj.offsetTop;
    obj=obj.offsetParent;
  }
  
  var El = getElem(id); El.ts=(ie4||ns6)?El.style : El;
  if(El) {
    El.ts.top = iTop - 5;//(El.offsetHeight/2);
    El.ts.left = iLeft - 5;// (El.offsetWidth/2);// - getElem('menu').offsetWidth;
  }
}

/* Credits to: http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html */
function addEvent(obj, evType, fn)
{ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function ShowZoekDialog(sUrl) {
  var sProps = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,status=0,toolbar=0,scrollbars=1';
  sProps = 'height=' + 420 + ',width=' + 470 + 
  		   ',left=' + parseInt((screen.width - 470)/2) + 
		   ',top=' + parseInt((screen.height - 420)/2) + ',' + sProps;
  var w=window.open(sUrl+'?action=zoeken&dialog=1','SPECMS_zoek',sProps);
  w.focus();
  return w;
}
function ShowToolDialog(sUrl) {
  var sProps = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,status=1,toolbar=0,scrollbars=0';
  sProps = 'height=' + 450 + ',width=' + 450 + 
  		   ',left=' + parseInt((screen.width - 450)/2) + 
		   ',top=' + parseInt((screen.height - 450)/2) + ',' + sProps;
  var w=window.open(sUrl,'SPECMS_tool',sProps);
  w.focus();
  return w;

}
function ShowListenDialog(sType,sUID) {
  var sProps = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scrollbars=0';
  sProps = 'height=' + 105 + ',width=' + 435 + 
  		   ',left=' + parseInt((screen.width - 435)/2) + 
		   ',top=' + parseInt((screen.height - 105)/2) + ',' + sProps;
  var w=window.open('/cms2/dialog.asp?type='+sType+'&uid='+sUID,'SPECMS_listen',sProps);
  w.focus();
  return w;
}

function ShowWebCamDialog() {
  var sProps = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scrollbars=0';
  sProps = 'height=' + 440 + ',width=' + 460 + 
  		   ',left=' + parseInt((screen.width - 460)/2) + 
		   ',top=' + parseInt((screen.height - 440)/2) + ',' + sProps;
  var w=window.open('/cms2/dialog.asp?type=webcam','SPECMS_listen',sProps);
  w.focus();
  return w;
}
function ShowMusicPlugin(sUrl) {
  var sProps = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,status=0,toolbar=0,scrollbars=1';
  sProps = 'height=' + 350 + ',width=' + 510 + 
  		   ',left=' + parseInt((screen.width - 510)/2) + 
		   ',top=' + parseInt((screen.height - 350)/2) + ',' + sProps;
  var w=window.open(sUrl+'&dialog=1','SPECMS_plugin',sProps);
  w.focus();
  return w;
}

function getMail(sEmail)
{
  return sEmail.replace("[apestaart]", "@").replace(/\[p\]/g, ".");
}

function writeMail(sEmail)
{
  document.write("<a href=\"javascript:doMailto('"+sEmail+"');\">"+getMail(sEmail)+"</a>");
}

function doMailto(sEmail) {
   window.location = "mailto:" + getMail(sEmail);
}

function doeGA(action, id)
{
	document.frmGA.action.value = action;
	document.frmGA.id.value = id;
	document.frmGA.submit();
}

function ShowHelp(mzEvent,sID) {
	var helptext = getHelpText(sID);
	var html = '<table><thead><tr><td>'+helptext[0]+'</td><td width="7"><a href="javascript:HideHelp();">x</a></td></tr></thead>';
	html += '<tbody><td colspan="2">'+helptext[1]+'</td><tbody>';
	html += '</table>';
	
	var hlp=getElem('toolhelp');
	if(!hlp) {
		var newNode = document.createElement("div");
		newNode.setAttribute("id", 'toolhelp');
		newNode.setAttribute("style", "display: none;");
		document.body.appendChild(newNode);
				
		hlp=getElem('toolhelp');
	}
	if(hlp){
		hlp.innerHTML=html;
		hlp.ts=(ie4||ns6)?hlp.style : hlp;
		hlp.ts.display=(ie4||ns6)?"":"";
		setElemPosition('toolhelp',mzEvent.target ? mzEvent.target : event.srcElement);
	}
}
function HideHelp() {
	(ie4||ns6)?getElem('toolhelp').style.display="none" : getElem('toolhelp').display="none";
}

function storeCaret (el) { 
	if (el.createTextRange) el.caretPos = document.selection.createRange().duplicate(); 
}
function textCounter (el, maxlength) {
      if (el.value.length > maxlength) el.value = el.value.substring(0, maxlength);
}

function generiekEditForm(elForm, sType) {
	var sb=''; var sm=''; var sa='';
	var c=null; var s='';
	if (elForm.caretPos)
	{
		c = elForm.caretPos;
		s = c.text;
	}
	switch (sType) {
		case 'b': sb='<strong>';
				  sa='</strong>';
				  if(s=='') {
					var sInp = prompt("Welke tekst moet in de stijl vet gezet worden?","");
				    if (sInp!=null) {
				    	s=sb+sInp+sa;
					}				  	
				  } else {
				  	s=sb+s+sa;
				  } break;
		case 'i': sb='<em>';
				  sa='</em>';
				  if(s=='') {
					var sInp = prompt("Welke tekst moet in de stijl schuingedrukt gezet worden?","");
				    if (sInp!=null) {
				    	s=sb+sInp+sa;
					}				  	
				  } else {
				  	s=sb+s+sa;
				  } break;
		case 'l': sb='<a href="';
		          stg='" target="_new';
				  sm='">';
				  sa='</a>';
				  if(s=='') {
					var sLnk = prompt("Waar moet de link naar verwijzen (url of mailto:)?","http://");
				    if (sLnk!=null) {
					  if ((sLnk.indexOf('http://')==-1) && (sLnk.indexOf('mailto:')==-1)) sLnk='http://'+sLnk;
					  s=sb+sLnk;
	            	  var sInp = prompt("Geef een omschijving van de pagina of de naam in het geval van een emailadres:","");
				      if (sInp!=null) {
						  if (sLnk.indexOf('mailto:')==-1) s=s+stg;
					      s=s+sm+sInp;
					  } else {
						  s=s+sm;
					  }
					  s=s+sa;
					}
				  } else {
				  	if((String(s).indexOf('www.')>-1) || (String(s).indexOf('http://')>-1)) {
					  	if ((s.indexOf('http://')==-1) && (s.indexOf('mailto:')==-1)) s='http://'+s;
						var o = s.replace('http://','').replace('www.','').substr(0, s.lastIndexOf('.')-1);
						s=sb+s+stg+sm+o+sa;
					} else {
						if (s.indexOf('@')==-1)
						{
							s=sb+sm+s+sa;
						}
						else
						{
							if (s.indexOf('mailto:')==-1)
							{
								s=sb+'mailto:'+s+sm+s+sa;
							}
							else
							{
							 	s=sb+s+sm+sa;
						 	}
						}
					}
				  } break;
		case 'o': sb='<ul><li>';
				  sm='</li>\n<li>';
				  sa='</li></ul>';
				  if(s=='') {
					do {
						var sInp = prompt("Welke tekst moet aan de lijst worden toegevoegd? (annuleren na laaste item)","");
					    if (sInp!=null) {
					    	s += (s=='')?(sb + sInp):(sm + sInp);
						} else {
							if(s!='') s += sa;
						}
					} while (sInp!=null);
				  } else {
				  	s=sb+s.replace(/(\n|\r)+/gi, sm)+sa;
				  } break;
		case 'k': sb='<h3>';
				  sa='</h3>';
				  if(s=='') {
					var sInp = prompt("Welke tekst moet in de stijl kop gezet worden?","");
				    if (sInp!=null) {
				    	s=sb+sInp+sa;
					}				  	
				  } else {
				  	s=sb+s+sa;
				  } break;
	}
	if(s!='') {
		if (c) {
			c.text = s;
		} else {
			elForm.value += s;
		}
	}
	elForm.focus();
	
}

function setTabPage(mzEvent, bShow)
{
	var ev = mzEvent ? mzEvent : (ie4||opera)? window.event : e;
	if (ev != null)
	{
		var el = (ie4||opera)? ev.srcElement : ev.originalTarget;
		pageDIV = getElem('tabpage_'+el.id.substr(4));
		if (bShow)
		{
			if (pageDIV!= null) pageDIV.className="tabpage_selected";
		}
		else
		{
			if (pageDIV!= null) pageDIV.className="tabpage";
		}
	}
}

function selectTabPage(mzEvent)
{
	var ev = mzEvent ? mzEvent : (ie4||opera)? window.event : e;
	if (ev != null)
	{
		var el = (ie4||opera)? ev.srcElement : ev.originalTarget;
		ul = el; li = el;
		while ((li!=null) && (li.tagName.toLowerCase()!="li")) li = li.parentNode;
		while ((ul!=null) && (ul.tagName.toLowerCase()!="ul")) ul = ul.parentNode;
		if ((li!=null) && (ul!=null))
		{
			var lis = ul.getElementsByTagName("li");
			for (var i=0; i<lis.length; i++)
			{
				if (lis[i].className == "selected")
				{
					lis[i].className = "";
					pageDIV = getElem('tabpage_'+lis[i].id.substr(4));
					if (pageDIV!= null) pageDIV.className="tabpage";
				}
			}

			li.className="selected";
			pageDIV = getElem('tabpage_'+li.id.substr(4));
			if (pageDIV!= null) pageDIV.className="tabpage_selected";
		}
	}
	
}
/*
function iFForm(item)
{
	var st = '';

	if (document.frm.message.createTextRange && document.frm.message.caretPos)
	{
		var c = document.frm.message.caretPos;
		document.frm.message.focus();
	}
	else
	{
		document.frm.message.value += item;
		document.frm.message.focus();
	}
}
*/