// JavaScript Document
if (top.location != self.location) { 
	top.location = self.location.href 
}

function fillField(fieldId,fieldValue) {
  var obj = document.getElementById(fieldId);
  if (obj) {
    obj.value=fieldValue;
  }
}
function fillAction(fieldValue) {
  fillField("action",fieldValue);
}
function fillType(fieldValue) {
  fillField("type",fieldValue);
}
function fillId(fieldValue) {
  fillField("id",fieldValue);
}
function RemoveDot()
{
  for (a in document.links) document.links[a].onfocus = document.links[a].blur;
}

function antispam (name, domain) {
	document.write('<a class=lightlink href=\"mailto:' + name + '@' + domain + '\">');
	document.write(name + '@' + domain + '</a>');
}
/* submits a specific form
*/
function doSubmit(formName) {
  document.forms[formName].submit();
}

// IF condition THEN fieldset1 ELSE fieldset2 will be enabled
function conditionalEnable(conditionElement, fieldSet1, fieldSet2) {
	eval("var condition = document.getElementById('"+conditionElement+"').checked");
	flipfields(condition, fieldSet1);
	flipfields(!condition, fieldSet2);
}

// enable or disable certain fields
function flipfields(mode, theFields) {
	for (var i=0; i < theFields.length; i++) {
		if (document.getElementById(theFields[i])) {
			eval("var erst = document.getElementById('"+theFields[i]+"')");
			erst.disabled = !mode;
		} else {
			//alert(theFields[i]);
		}	
	}
}
function flipdisplay (id,type) { // to check for el, prevent (rare) errors
	var el = document.getElementById(id);
	if (el) {
		if (el.style.display == 'none') vis = type;
		else vis = 'none';
		el.style.display = vis;
	}
}
function increaseNotesHeight(thisTextarea, add) {
	if (thisTextarea) {
		newHeight = parseInt(thisTextarea.style.height) + add;
		thisTextarea.style.height = newHeight + "px";
	}
}
function decreaseNotesHeight(thisTextarea, subtract) {
	if (thisTextarea) {
		if ((parseInt(thisTextarea.style.height) - subtract) > 30) {
			newHeight = parseInt(thisTextarea.style.height) - subtract;
			thisTextarea.style.height = newHeight + "px";
		}
		else {
			newHeight = 30;
			thisTextarea.style.height = "30px";
		}			
	}
}

// It opens every link inside the element with the id content that has the 
// attribute rel="external" in a new window (circumventing the illegal 
// "target") and adds the class "extlink" to these links. Furthermore it 
// adds a title that tells the user that this link will open in a new window.
function externallinks()
{
	if (document.all){document.onmousedown = RemoveDot;}
    var c=document.getElementById('content');
    if(c) {
        var ls=c.getElementsByTagName('a');
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external') {
                ls[i].className+=ls[i].className?' extlink':'extlink';
                ls[i].title += ' (wordt in een nieuw window geopend)';
				// openen in nieuw window gebeurd nu in event handler (catch)
				// ls[i].onclick=function(){window.open(this.href);return false}
            }
            if(ls[i].getAttribute('rel')=='scrollgallery') {
                ls[i].title+=' (selecteer het plaatje)';
            }
        }
    }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function trim(value) {
 startpos=0;
 while((value.charAt(startpos)==" ")&&(startpos<value.length)) {
   startpos++;
 }
 if(startpos==value.length) {
   value="";
 } else {
   value=value.substring(startpos,value.length);
   endpos=(value.length)-1;
   while(value.charAt(endpos)==" ") {
     endpos--;
   }
   value=value.substring(0,endpos+1);
 }
 return(value);
}
function handleClick(e) {
	var event = e || window.event;
	if(event.ctrlKey || event.shiftKey || event.altKey) return true;
	if(event.which && event.which != 1) return true;

	var target = event.target || event.srcElement;
	while(target && !/^a$/i.test(target.nodeName)) {
		target = target.parentNode;
	}

	if(!target || !target.getAttribute('rel')) return true;

   var rel		= target.getAttribute('rel');
   var href 	= target.getAttribute('href');
   var mainimg	= target.getAttribute('main');

   switch(rel) {
		case 'gallery':

			document.getElementById('gallerycaption').childNodes[0].nodeValue = target.getAttribute('title');
			//document.getElementById('galleryauthor').childNodes[0].nodeValue = target.getAttribute('author');
			document.getElementById('placeholder').src = href;
 			var c=document.getElementById('displayarea');
    		if(c) {
				var ls=c.getElementsByTagName('a');
        		for(var i=0;i<ls.length;i++){
					if (ls[i].className == 'scrollimage') { 
						ls[i].style.backgroundImage= 'url('+href+')';
						ls[i].href=mainimg;
					}
				}
			}
			break;
		default:
			return true;
   }

   try { event.preventDefault(); } catch(e){}
   return false;
}

function initCommon (){
    externallinks();
	//addCustomEvent(document,'click', handleClick, false);
}
addLoadEvent (initCommon);
