function LTrim(str) {
	if (str.length == 0) {return str};
	intSpaceFound = str.indexOf(" ");
	while (intSpaceFound == 0 ) {
		str = str.substring(1,str.length);
		intSpaceFound = str.indexOf(" ");
	}	
	return str;
}

function RTrim(str) {
	if (str.length == 0) {return str};
	intSpaceFound = str.lastIndexOf(" ");
	while (intSpaceFound > 0 && intSpaceFound == str.length - 1) {
		str = str.substring(0,str.length - 1);
		intSpaceFound = str.lastIndexOf(" ");
	}	
	return str;
}

function Trim(str) {
	str = LTrim(str);
	str = RTrim(str);
	return str;
}

function BrowserCheck(){
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	IE5plus = IE5 || IE6;
	IEMajor = 0;
	Mozilla = navigator.userAgent.indexOf('Mozilla')!=-1?true:false;

	if (IE4plus){
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
	
	// Mac = 0 
	// Netscape = 1
	// IE = 2
	if (isMac || IEmac) ret = 0;
	if (NS4 || NS6 || Mozilla) ret = 1;
	if (IE4 || IE5 || IE6 || IE4plus || IE5plus) ret = 2;

	return ret;
}

function CheckForm(){
	var n = -1;
	var msg = "";
	if (Trim(document.inschrijfadam.Naam.value) == "" ){
		msg = "Vul a.u.b. je naam in";
		n = 11;
	}
	if (n == -1){
		if (Trim(document.inschrijfadam.Adres.value) == ""){
			msg = "Vul a.u.b. je adres in";
			n = 14;
		}
	}
	if (n == -1){
		if (Trim(document.inschrijfadam.Postcode.value) == ""){
			msg = "Vul a.u.b. je postcode in";
			n = 15;
		}
	}
	if (n == -1){
		if (Trim(document.inschrijfadam.Woonplaats.value) == ""){
			msg = "Vul a.u.b. je woonplaats in";
			n = 16;
		}
	}
	if (n == -1){
		if (Trim(document.inschrijfadam.Emailadres.value) == ""){
			msg = "Vul a.u.b. je email adres in";
			n = 21;
		}
	}
	if (brw == 1){
		if (n > -1){
			document.inschrijfadam.elements[n].focus();
			alert (msg);
			return false;
		}
	}else{
		if (n > -1){
			document.inschrijfadam.elements[11].style.backgroundColor = "#FFFFFF";
			document.inschrijfadam.elements[14].style.backgroundColor = "#FFFFFF";
			document.inschrijfadam.elements[15].style.backgroundColor = "#FFFFFF";
			document.inschrijfadam.elements[16].style.backgroundColor = "#FFFFFF";
			document.inschrijfadam.elements[21].style.backgroundColor = "#FFFFFF";
			document.inschrijfadam.elements[n].style.backgroundColor = "orange";
			document.inschrijfadam.elements[n].focus();
			alert (msg);
			return false;
		}
	}
}



function chkMateriaal(){

	var n = -1;
	var msg = "";
	if (document.forms[0].Cursusboek_beginners_1.value == "-" && document.forms[0].CD_cursusboek_beginners_1.value == "-" && document.forms[0].Cursusboek_beginners_2.value  == "-" && document.forms[0].CD_cursusboek_beginners_2.value  == "-" && document.forms[0].Cursusboek_beginners_3.value == "-" && document.forms[0].CD_cursusboek_beginners_3.value == "-" && document.forms[0].Cursusboek_medio_1.value == "-" && document.forms[0].Begeleiding_beginners_1.value  == "-" && document.forms[0].Begeleiding_beginners_2.value  == "-" && document.forms[0].Begeleiding_beginners_3.value  == "-" && document.forms[0].Begeleiding_halfgevorderd_1.value == "-"){
		msg = "Vul a.u.b. je bestelling in (minstens 1 exemplaar van 1 titel, of huiswerkbegeleiding)";
		n = 0;
	}

	if (n == -1){
			if (Trim(document.forms[0].naam.value) == ""){
				msg = "Vul a.u.b. je naam in";
				n = 11;
			}
	}
	if (n == -1){
			if (Trim(document.forms[0].adres.value) == ""){
				msg = "Vul a.u.b. je adres in";
				n = 12;
			}
	}
	if (n == -1){
			if (Trim(document.forms[0].postcode.value) == ""){
				msg = "Vul a.u.b. je postcode in";
				n = 15;
			}
	}
	if (n == -1){
			if (Trim(document.forms[0].woonplaats.value) == ""){
				msg = "Vul a.u.b. je woonplaats in";
				n = 16;
			}
	}
	if (n == -1){
			if (Trim(document.forms[0].land.value) == ""){
				msg = "Vul a.u.b. het land in";
				n = 19;
			}
	}
	if (n == -1){
			if (Trim(document.forms[0].emailadres.value) == ""){
				msg = "Vul a.u.b. je emailadres in";
				n = 20;
			}
	}
	

	if (n > -1){
			document.forms[0].elements[0].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[11].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[14].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[15].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[16].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[19].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[20].style.backgroundColor = "#FFFFFF";
			document.forms[0].elements[n].style.backgroundColor = "orange";
			document.forms[0].elements[n].focus();
			alert (msg);
			return false;
	}
}
