// E-mail Form - Validator
function checkData(){
	var correct = true
	var regexpemail =/^[a-zA-Z0-9\-\.\_]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; //regexp for e-mail address
	var str = document.form.email.value; // value to compare
	if (document.form.naam.value == '') {correct = false; alert("Vul a.u.b. uw naam in.");document.form.naam.focus(); return correct}
	if (regexpemail.test(str) == false){
	correct = false; alert("Vul s.v.p een geldig e-mail adres in.");document.form.email.focus(); return correct}
	if (document.form.opmerking.value == '') {correct = false; alert("Vul s.v.p. uw vraag of opmerking in.");document.form.opmerking.focus(); return correct}
	return correct;
}

function showHideNext(theEl){
	theEl.nextSibling.style.display=(theEl.nextSibling.style.display=='none')?"":"none";
	theEl.nextSibling.nextSibling.style.display=(theEl.nextSibling.nextSibling.style.display=='none')?"":"none";
}

function setFilter(theInput){
	var value=theInput.checked?1:0;
	makeCookie(theInput.name,value,7);
	makeCookie('filterenabled',1,7);
}
function setSelectFilter(theSelect){ // how to get select filter value...
	var value = theSelect.options[theSelect.selectedIndex].value
	//var value=theInput.value;
	makeCookie(theSelect.name,value,7);
	makeCookie('filterenabled',1,7);
}

function stopFilter(){
	theItems=document.getElementsByTagName('INPUT');
	for (i=0;i<theItems.length;i++) {
        theItem = theItems[i];
		if(theItem.getAttribute('type')=='checkbox'){
			makeCookie(theItem.name,0,7);
			theItem.checked=false;
		}
	}
	theEl=document.getElementById('select_soort');
	theEl.selectedIndex=0;
	theEl.value=-1;
	theEl=document.getElementById('select_branche');
	theEl.selectedIndex=0;
	theEl.value=-1;
	theEl=document.getElementById('select_cat');
	theEl.selectedIndex=0;
	theEl.value=-1;
	makeCookie('select_soort',-1,7);
	makeCookie('select_branche',-1,7);
	makeCookie('select_cat',-1,7);
	makeCookie('filterenabled',0,7);
	location.reload(true);
}

function stopFilter2(){
	theItems=document.getElementsByTagName('INPUT');
	for (i=0;i<theItems.length;i++) {
        theItem = theItems[i];
		if(theItem.getAttribute('type')=='checkbox'){
			makeCookie(theItem.name,0,7);
			theItem.checked=false;
		}
	}
	theEl=document.getElementById('select_tipbranche');
	theEl.selectedIndex=0;
	theEl.value=-1;
	makeCookie('select_tipbranche',-1,7);
	makeCookie('filterenabled',0,7);
	location.reload(true);
}

function startFilter(){
	makeCookie('filterenabled',1,7);
	location.reload(true);
}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure) {
	if (Expiry != null) {
		var datenow = new Date();
		   //get a date
		datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
		   //mutiply the number to make it represent days
		Expiry = datenow.toGMTString();
		   //convert to GMT time
	}

	Expiry = (Expiry != null) ? '; expires='+Expiry : '';
	   //has an expiration?
	Path = (Path != null)?'; path='+Path:'/';
	   //has a path?
	Domain = (Domain != null) ? '; domain='+Domain : '';
	   //has a domain?
	Secure = (Secure != null) ? '; secure' : '';
	   //Secure?
	document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;
	   //Make the cookie!
}

function openWaardering(theEle){
	// Toon de waardering div op de muispositie
	document.getElementById('con_waardering').style.left=findPosX(theEle) + 'px';
	document.getElementById('con_waardering_back').style.left=findPosX(theEle) + 'px';
	// Het Y-coordinaat corrigeren met -213 vanwege de positionering IN de contentcontainer!
	document.getElementById('con_waardering').style.top=findPosY(theEle)-213-180 + 'px';
	document.getElementById('con_waardering_back').style.top=findPosY(theEle)-213-180 + 'px';
	document.getElementById('con_waardering').style.display='block';
	document.getElementById('con_waardering_back').style.display='block';
}

function saveWaardering(){
	setTimeout("hideWaardering()",400);
}
function hideWaardering(){
	document.getElementById('con_waardering').style.display='none';
	document.getElementById('con_waardering_back').style.display='none';
	theRadio=document.waarderingform.waardering;
	unsetCheckedValue(theRadio);
}

function unsetCheckedValue(radioObj) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
	}
	radioObj[radioLength-1].checked = true;
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// POPUP

var win = null;

function openPopup(theURL,winName,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no'
	win = window.open(theURL,winName,settings)
}

var zuinigIctWindow=0;
function popUpWindow(URLStr){
  if(zuinigIctWindow){
    if(!zuinigIctWindow.closed) zuinigIctWindow.close();
  }
  zuinigIctWindow = open(URLStr, 'zuinigIctWindow', 'scrollbars=yes,height=600,width=840,resizable=no');
  zuinigIctWindow.focus();
}

var W3CDOM = document.createElement && document.getElementsByTagName;
	
window.onload = setMaxLength;
	
function setMaxLength() {
	if (!W3CDOM) return;
	var textareas = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<textareas.length;i++) {
		if (textareas[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.innerHTML = 'karakters in reactie: <span>0</span> (max: '+textareas[i].getAttribute('maxlength')+')';
			textareas[i].parentNode.insertBefore(counterClone,textareas[i].nextSibling);
			textareas[i].relatedElement = counterClone.getElementsByTagName('span')[0];
			textareas[i].onkeyup = textareas[i].onchange = checkMaxLength;
			textareas[i].onkeyup();
		}
	}
}
	
function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';	
	this.relatedElement.firstChild.nodeValue = currentLength;
}
