<?
$_GET["ptv"]?$b=$_GET["ptv"]:$b="0"; // set current button; if no button set, use 0 as default.
echo "var activeButton = \"button".$b."\"";
?>

function init(){
	buttonOn(document.getElementById("button<?=$b?>"));
}

function buttonOn(obj){
	obj.className = "buttonPressed";		
}

function buttonOff(obj){
	if (activeButton != obj.id){
		obj.className = "buttonNormal";		
	}
}

function buttonClick(obj){
	//activate the newly pressed button and goto prefered link
	//todo: get this stuff from db!
	
	buttonOn(obj);
	activeButton = obj.id;
	buttonNr = activeButton.substring(7); //substring is id minus the word "button"
  document.location.href = "./index.php?p="+buttonNr;
	
	//deselect all other items, so only the newly selected one will be "active"
	menu = document.getElementById('menu');
	els = menu.getElementsByTagName('div');
	for (var i=0; i<els.length; i++){
		if ((els[i].innerHTML != "&nbsp;") && (els[i].id != obj.id)){
			buttonOff(els[i]);
		}
	}
}

function emptystr(string) {
	var x = 0;
	var chr;
	var empty = true;
	if (string.length) {
		do {
			chr = string.substring(x, x + 1);
			x++;
			empty = (chr == ' ' || chr == '\t' || chr == '\n' || chr == '\r');
		} while (empty && x < string.length);
	}
	return empty;
}

function checkEmail(){
  var pattern=/(^[\-_\.a-zA-Z0-9]+)@((([0-9]{1,3}\.){3}([0-9]{1,3})((:[0-9])*))|(([a-zA-Z0-9\-]+)(\.[a-zA-Z]{2,})+(\.[a-zA-Z]{2})?((:[0-9])*)))/;
  if (document.contactForm.email.value.search(pattern) == -1){
  	return false;
  }
  else{
	  return true;
  }
}

function checkForm(){
		var error = "";
		if (emptystr(document.contactForm.naam.value)) error += "Uw naam moet ingevuld worden !\n";
		if (emptystr(document.contactForm.onderwerp.value)) error += "U dient een onderwerp te kiezen !\n";
		if (emptystr(document.contactForm.email.value)) error += "U moet een e-mail adres opgeven !\n";
		else if (checkEmail() == false){ error += "Het opgegeven e-mail adres klopt niet !\n"; }
		if (emptystr(document.contactForm.bericht.value)) error += "Het bericht moet ingevuld worden !\n";
		if (error){
			alert(error);
			return false;
		}
		else return true;
}

