function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function logincheck() {
	var form = document.loginform;
	if (form) {
		form.onsubmit = function() {
			return (validateLogin(this)) ;
		}		
	}
	var form2 = document.loginform2;
	if (form2) {
		form2.onsubmit = function() {
			return (validateLogin2(this)) ;
		}		
	}
}

function validateLogin(theForm) {
	if(theForm.user_name.value=="" || theForm.password.value=="") {
		alert(lbl_login_invullen);
		return false;
	}
	return true;
}

function validateLogin2(theForm) {
	if(theForm.user_name.value=="" || theForm.password.value=="") {
		alert(lbl_login_invullen);
		return false;
	}
	return true;
}


function loginError() {
	alert(lbl_login_verkeerd);
}


function mailcheck() {
	var form = document.wachtwoordform;
	if (form) {
		form.onsubmit = function() {
			return (validatemail(this)) ;
		}		
	}
}

function validatemail(form) {
	var msg = "";
	if (form.email.value == ""){
		msg += "-" + lbl_contact_email + "\n";	
	}
	if (msg != ""){
		msg = lbl_contact_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function contactcheck() {
	var form = document.contactformulier;
	if (form) {
		form.onsubmit = function() {
			return (validatecontact(this)) ;
		}		
	}
	var form2 = document.uitschrijfformulier;
	if (form2) {
		form2.onsubmit = function() {
			return (validateUitschrijven(this)) ;
		}		
	}
	var form3 = document.emailform;
	if (form3) {
		form3.onsubmit = function() {
			return (validateEmailPagina(this)) ;
		}		
	}
}

function validateEmailPagina(theForm) {
	var msg = ""
	if(theForm.to.value == lbl_emailpagina_naamontvanger) {
		msg += "-" + lbl_emailpagina_naamontvanger + "\n";	
	}
	if(theForm.from.value == lbl_emailpagina_naamafzender) {
		msg += "-" + lbl_emailpagina_naamafzender + "\n";	
	}
	if(theForm.email.value == lbl_emailpagina_emailontvanger) {
		msg += "-" + lbl_emailpagina_emailontvanger + "\n";
	}
	if (msg != "") {
		msg = lbl_contact_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}


function validateUitschrijven(theForm) {
	var msg = ""
	if(theForm.email.value == "") {
		msg += "-" + lbl_contact_email + "\n";	
	}
	if (msg != "") {
		msg = lbl_contact_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function validatecontact(theForm) {
	var msg = ""
	
	if(theForm.aantal_personen && theForm.aantal_personen.value == "") {
		msg += "-" + lbl_aantal_personen + "\n";	
	}
	
	if(theForm.naam.value == "") {
		msg += "-" + lbl_contact_naam + "\n";	
	}
	if(theForm.voornaam.value == "") {
		msg += "-" + lbl_contact_voornaam + "\n";	
	}
	if(theForm.straat.value == "") {
		msg += "-" + lbl_contact_straat + "\n";
	}
	if(theForm.nummer.value == "") {
		msg += "-" + lbl_contact_nummer + "\n";
	}
	if(theForm.postcode.value == "") {
		msg += "-" + lbl_contact_postcode + "\n";
	}
	if(theForm.gemeente.value == "") {
		msg += "-" + lbl_contact_gemeente + "\n";	
	}
	if(theForm.telefoon.value == "") {
		msg += "-" + lbl_contact_telefoon + "\n";
	}
	if(theForm.email.value == "") {
		msg += "-" + lbl_contact_email + "\n";	
	}
	if (msg != "") {
		msg = lbl_contact_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function registratiecheck() {
	var form = document.userform;
	if (form) {
		form.onsubmit = function() {
			return (validateData(this)) ;
		}		
	}
}

function validateData(theForm) {
	var msg = ""
	if(theForm.naam.value == "") {
		msg += "-" + lbl_contact_naam + "\n";	
	}
	if(theForm.voornaam.value == "") {
		msg += "-" + lbl_contact_voornaam + "\n";	
	}
	if(theForm.straat.value == "") {
		msg += "-" + lbl_contact_straat + "\n";	
	}
	if(theForm.nummer.value == "") {
		msg += "-" + lbl_contact_nummer + "\n";
	}
	if(theForm.postcode.value == "") {
		msg += "-" + lbl_contact_postcode + "\n";
	}
	if(theForm.gemeente.value == "") {
		msg += "-" + lbl_contact_gemeente + "\n";	
	}
	if(theForm.telefoon.value == "") {
		msg += "-" + lbl_contact_telefoon + "\n";
	}
	if(theForm.email.value == "") {
		msg += "-" + lbl_contact_email + "\n";
	}
	if(theForm.gebruikersnaam.value == "") {
		msg += "-" + lbl_contact_gebruikersnaam + "\n";	
	}
	if(theForm.paswoord.value == "") {
		msg += "-" + lbl_contact_paswoord + "\n";	
	}
	if (msg != "") {
		msg = lbl_contact_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	if(theForm.email.value != theForm.email2.value) {
		alert(lbl_contact_emailcontrole);
		return false;
	}
	return true;
}

function wedstrijdcheck() {
	var form = document.wedstrijdform;
	if (form) {
		form.onsubmit = function() {
			return (validateWedstrijdData(this)) ;
		}		
	}
}

function validateWedstrijdData(theForm) {
	var msg = ""
	if(theForm.email.value == "") {
		msg += "-" + lbl_wedstrijd_email + "\n";	
	}
	if(theForm.naam.value == "") {
		msg += "-" + lbl_wedstrijd_naam + "\n";	
	}
	if(theForm.voornaam.value == "") {
		msg += "-" + lbl_wedstrijd_voornaam + "\n";	
	}
	if(theForm.straat.value == "" || theForm.nr.value == "") {
		msg += "-" + lbl_wedstrijd_straatnr + "\n";	
	}
	if(theForm.postcode.value == "" || theForm.gemeente.value == "") {
		msg += "-" + lbl_wedstrijd_pcgemeente + "\n";	
	}
	if (msg != "") {
		msg = lbl_wedstrijd_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function welkomcheck() {
	var form = document.welkomform;
	if (form) {
		form.onsubmit = function() {
			return (validateWelkomData(this)) ;
		}		
	}
}

function validateWelkomData(theForm) {
	var msg = ""
	if(theForm.email.value == "") {
		msg += "-" + lbl_welkom_email + "\n";	
	}
	if(theForm.naam.value == "") {
		msg += "-" + lbl_welkom_naam + "\n";	
	}
	if(theForm.voornaam.value == "") {
		msg += "-" + lbl_welkom_voornaam + "\n";	
	}
	if(theForm.straat.value == "" || theForm.nr.value == "") {
		msg += "-" + lbl_welkom_straatnr + "\n";	
	}
	if(theForm.postcode.value == "" || theForm.gemeente.value == "") {
		msg += "-" + lbl_welkom_pcgemeente + "\n";	
	}
	if(theForm.naam1.value == "") {
		msg += "-" + lbl_welkom_naam + "1\n";	
	}
	if(theForm.voornaam1.value == "") {
		msg += "-" + lbl_welkom_voornaam + "1\n";	
	}
	if(theForm.email1.value == "") {
		msg += "-" + lbl_welkom_email + " 1\n";	
	}
	if(theForm.naam2.value == "") {
		msg += "-" + lbl_welkom_naam + "2\n";	
	}
	if(theForm.voornaam2.value == "") {
		msg += "-" + lbl_welkom_voornaam + "2\n";	
	}
	if(theForm.email2.value == "") {
		msg += "-" + lbl_welkom_email + " 2\n";	
	}
	if(theForm.naam3.value == "") {
		msg += "-" + lbl_welkom_naam + "3\n";	
	}
	if(theForm.voornaam3.value == "") {
		msg += "-" + lbl_welkom_voornaam + "3\n";	
	}
	if(theForm.email3.value == "") {
		msg += "-" + lbl_welkom_email + " 3\n";	
	}
	if(theForm.naam4.value == "") {
		msg += "-" + lbl_welkom_naam + "4\n";	
	}
	if(theForm.voornaam4.value == "") {
		msg += "-" + lbl_welkom_voornaam + "4\n";	
	}
	if(theForm.email4.value == "") {
		msg += "-" + lbl_welkom_email + " 4\n";	
	}
	if(theForm.naam5.value == "") {
		msg += "-" + lbl_welkom_naam + "5\n";	
	}
	if(theForm.voornaam5.value == "") {
		msg += "-" + lbl_welkom_voornaam + "5\n";	
	}
	if(theForm.email5.value == "") {
		msg += "-" + lbl_welkom_email + " 5\n";	
	}
	if (msg != "") {
		msg = lbl_welkom_verplichtinvullen + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}


function printpagina() {
	var printlink = document.getElementById("printlink");
	if(printlink) {
		printlink.onclick = function() {
			//winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=yes,copyhistory=0,width=700,height=525";
			//openPopup(this.href,winopts);
			print();
			return false;
		}
	}
}

function openPopup(href,winopts) {
	smallwindow=window.open(href,"Popup",winopts);
	smallwindow.focus();
}

function CreateBookmarkLink() {
	var bookmarklink = document.getElementById("favoriet");
	if(bookmarklink) {
		bookmarklink.onclick = function() {
			var title = "HANZEVAST CAPITAL";
			var url = "http://www.mpccapital.be";
			
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			} else if( window.external ) { // IE Favorite
				window.external.AddFavorite( url, title); 
			} else if(window.opera && window.print) { // Opera Hotlist
				return true; 
			}
			return false;	
		}					
	}
}
 

addLoadEvent(wedstrijdcheck);
addLoadEvent(welkomcheck);
addLoadEvent(printpagina);
addLoadEvent(logincheck);
addLoadEvent(CreateBookmarkLink);
addLoadEvent(registratiecheck);
addLoadEvent(mailcheck);
addLoadEvent(contactcheck);

addLoadEvent(beschikbare_info);

function beschikbare_info() {
	var frmBIstap1 = document.getElementById("BIstap1");
	if(frmBIstap1){
		var lnkVerder = document.getElementById("verder");
		if(lnkVerder) {
			lnkVerder.onclick = function() {
				if(validateBIStap1()) {
					frmBIstap1.submit();
				}
				return false;
			}
		}
		frmBIstap1.onsubmit = function() {
			return validateBIStap1();
		}
		var inputs = frmBIstap1.getElementsByTagName("input");
		for(var i=0;i<inputs.length;i++) {
			if(inputs[i].type=="text") {
				inputs[i].onclick = function() {
					var theCheckbox = document.getElementById("inschrijvingen"+this.id.replace("aantal_personen",""))
					if(theCheckbox) {
						theCheckbox.checked=true;
					}
				}
			}
		}
	}
	
	var frmBIstap2 = document.getElementById("BIstap2");
	if(frmBIstap2){
		frmBIstap2.onsubmit = function() {
			return validateBIStap2();
		}
	}

	var lnkTerug = document.getElementById("terug");
	if(lnkTerug) {
		lnkTerug.onclick = function() {
			history.back();
			return false;
		}
	}

}
function validateBIStap1() {
	var theForm = document.getElementById("BIstap1");
	var inputs = theForm.getElementsByTagName("input");
	var checked = 0;
	for(var i=0;i<inputs.length;i++) {
		if(inputs[i].type=="checkbox") {
			if(inputs[i].checked) {
				checked++;
			}
		}
	}
	if(!checked) {
		alert(lbl_minstens_1_checkbox);
		return false;
	}
	
	var aantal_niet_ingevuld = 0;
	var aantal_niet_aangevinkt = 0;
	for(var i=0;i<inputs.length;i++) {
		if(inputs[i].name.substring(0,14)=="inschrijvingen") {
			var fieldID = "aantal_personen"+inputs[i].id.replace("inschrijvingen","");
			if(inputs[i].checked && document.getElementById(fieldID).value.length==0) {
				aantal_niet_ingevuld++;
			}
		}
		if(inputs[i].name.substring(0,15)=="aantal_personen") {
			var fieldID = "inschrijvingen"+inputs[i].id.replace("aantal_personen","");
			if(!document.getElementById(fieldID).checked && inputs[i].value.length>0) {
				aantal_niet_aangevinkt++;
			}
		}
	}
	if(aantal_niet_ingevuld) {
		alert(lbl_aantal_invullen_voor_inschri);
		return false;
	}
	if(aantal_niet_aangevinkt) {
		alert(lbl_inschr_aanvinken_voor_aantal);
		return false;
	}
	return true;
}
function validateBIStap2() {
	
	var theForm = document.getElementById("BIstap2")
	var msg = ""
		
	if(theForm.naam.value == "") {
		msg += "-" + lbl_contact_naam + "\n";	
	}
	if(theForm.voornaam.value == "") {
		msg += "-" + lbl_contact_voornaam + "\n";	
	}
	if(theForm.straat.value == "") {
		msg += "-" + lbl_contact_straat + "\n";
	}
	if(theForm.nummer.value == "") {
		msg += "-" + lbl_contact_nummer + "\n";
	}
	if(theForm.postcode.value == "") {
		msg += "-" + lbl_contact_postcode + "\n";
	}
	if(theForm.gemeente.value == "") {
		msg += "-" + lbl_contact_gemeente + "\n";	
	}
	if(theForm.telefoon.value == "") {
		msg += "-" + lbl_contact_telefoon + "\n";
	}
	if(theForm.email.value == "") {
		msg += "-" + lbl_contact_email + "\n";	
	}
	if (msg != "") {
		alert(lbl_contact_verplichtinvullen + " : \n" + msg);
		return false;
	}
	
	if(theForm.gebruikersnaam.value != "" || theForm.paswoord.value != "") {
		if(theForm.gebruikersnaam.value == "" || theForm.paswoord.value == "") {
			alert(lbl_gebruiker_en_paswoord);
			return false;
		}
	}
	return true;
}