/* Auteur: John Septer (CGEY - Telecom Media Networks -   Advanced Content Solutions
 * Naam File: Methode.js
 * Creatie datum: 20-08-2002
 * Doel: Verzameling van all generieke Javascript binnen methode sites
 * Historie: 20-08-2002, creatie (MH)
*/

function doSortClick(columnName)
{
	var sortDir;

	if(document.selectionForm.sort.value!=columnName)
	{
		document.selectionForm.sortdirection.value=0;
	}
	else
	{
		if(document.selectionForm.sortdirection.value==0)
		{
			document.selectionForm.sortdirection.value=1;
		}
		else
		{
			document.selectionForm.sortdirection.value=0;
		}
	}
	document.selectionForm.sort.value = columnName;
	document.selectionForm.submit();
}

function doSelectChange(fieldName) {
	if(fieldName == "niveau"){	
		document.selectionForm.kwalificatie.selectedIndex=-1;
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
		document.selectionForm.module.selectedIndex=-1;
	}
	else if (fieldName == "kwalificatie") {
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
		document.selectionForm.module.selectedIndex=-1;
	}
	else if (fieldName == "opheffen") {
		document.selectionForm.niveau.selectedIndex=-1;
		document.selectionForm.kwalificatie.selectedIndex=-1;
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
		document.selectionForm.module.selectedIndex=-1;
		document.selectionForm.uitgave.selectedIndex=-1;
		document.selectionForm.onlineleren.defaultchecked;
		document.selectionForm.downloadable.defaultchecked;
		document.selectionForm.resultaat.value=0;
	}
	document.selectionForm.submit();
}

function doSelectChangeCatalogus(fieldName) {
	if(fieldName == "niveau"){	
		document.selectionForm.kwalificatie.selectedIndex=-1;
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
	}
	else if (fieldName == "kwalificatie") {
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
	}
	else if (fieldName == "opheffen") {
		document.selectionForm.niveau.selectedIndex=-1;
		document.selectionForm.kwalificatie.selectedIndex=-1;
		document.selectionForm.deelkwalificatie.selectedIndex=-1;
		document.selectionForm.uitgave.selectedIndex=-1;
		document.selectionForm.onlineleren.defaultchecked;
		document.selectionForm.downloadable.defaultchecked;
		document.selectionForm.resultaat.value=0;
	}
	document.selectionForm.submit();
}

function doSelectChangeVO(fieldName) {
	if(fieldName == "onderwijstype"){	
		document.selectionForm.materiaal.selectedIndex=-1;
		document.selectionForm.uitgave.selectedIndex=-1;
	}
	document.selectionForm.submit();
}

// Functie naam: showInformatieImage
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showInformatieImage(afbeelding) {
var imagepage = '/informatie/popup.asp?afbeelding=' + afbeelding;
window.open(imagepage,'','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=400');
}


// Functie naam: showDisclaimer
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showDisclaimer() {
window.open('/informatie/disclaimer/index.asp','disclaimer','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=300');
}

// Functie naam: showHelpBijVrijZoeken
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showHelpBijVrijZoeken() {
window.open('helpbijvrijzoeken.asp','helpbijvrijzoeken','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=300');
}

// Functie naam: showBijdrageInKosten
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showBijdrageInKosten() {
window.open('bijdrageinkosten.asp','bijdrageinkosten','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=380,height=400,left=25,top=25');
}

// Functie naam: showLeveringsvoorwaarden
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showLeveringsvoorwaarden() {
window.open('leveringsvoorwaarden.asp','leveringsvoorwaarden','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes, width=400,height=300,left=25,top=25');
}

// Functie naam: showBexGexRex
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showBexGexRex() {
window.open('bexgexrex.asp','bexgexrex','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=380,height=380,left=25,top=25');
}

// Functie naam: showBestelformulier
// Doel functie: Openen van bestelformulier op corporate site
// Input: - 
// Output: geopend window met formlulier (pdf)
function showBestelformulier() {
window.open('http://catalogus.nijghversluys.nl/centralebestellingen1.pdf','formulier','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=600,left=25,top=25');
}

// Functie naam: showDocument
// Doel functie: Openen van een document (PDF bijvoorbeeld) in eigen venster
// Input: - 
// Output: geopend window met document 
function showDocument(docurl) {
window.open(docurl,'document','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=600,left=25,top=25');
}

// Functie naam: showBeperktLeverbaar
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showBeperktLeverbaar() {
window.open('beperktleverbaar.asp','beperktleverbaar','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=380,height=200,left=25,top=25');
}

// Functie naam: showWaarschuwing
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showWaarschuwing() {
window.open('waarschuwing.asp','waarschuwing','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=380,height=380,left=25,top=25');
}

// Functie naam: showBrowserEisen
// Doel functie: openen van een nieuw browser window in de vorm van een popup
// Input: - 
// Output: geopend window
function showBrowserEisen() {
window.open('/algemeen/browsereisen.asp','waarschuwing','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=500,height=380,left=25,top=25');
}

// Functie naam: closeButton
// Doel functie: sluiten van een nieuw browser window
// Input: - 
// Output: afgesloten window
function closeButton() {
window.close();
}

// Functie naam: go
// Doel functie: redirect (history) naar pagina
// Input: url
// Output: geopende pagina
function go(url) {
    if (document.images)
        location.replace(url);
    else
        location.href = url;
}
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// ===================================================================


var use_css=false;
var use_layers=false;   

if (document.all)    { use_css    = true; }
if (document.layers) { use_layers = true; }

var sort_object;
var sort_column;
var reverse=0;

// Constructor for SortTable object
function SortTable(name) {
	// Properties
	this.name = name;
	this.sortcolumn="";
	this.dosort=true;
	this.tablecontainsforms=false;
	// Methods
	this.AddLine = AddLine;
	this.AddColumn = AddColumn;
	this.WriteRows = WriteRows;
	this.SortRows = SortRows;
	this.AddLineProperties = AddLineProperties;
	this.AddLineSortData = AddLineSortData;
	// Structure
	this.Columns = new Array();
	this.Lines = new Array();
	this.LineProperties = new Array();
	}
// Add a line to the grid
function AddLine() {
	var index = this.Lines.length;
	this.Lines[index] = new Array();
	for (var i=0; i<arguments.length; i++) {
		this.Lines[index][i] = new Object();
		this.Lines[index][i].text = arguments[i];
		this.Lines[index][i].data = arguments[i];
		}
	}
// Define properties for the <TR> of the last line added
function AddLineProperties(prop) {
	var index = this.Lines.length-1;
	this.LineProperties[index] = prop;
	}
// Define sorting data for the last line added
function AddLineSortData() {
	var index = this.Lines.length-1;
	for (var i=0; i<arguments.length; i++) {
		if (arguments[i] != '') {
			this.Lines[index][i].data = arguments[i];
			}
		}
	}

// Add a column definition to the table
// Arguments:
//   name = name of the column
//   td   = any arguments to go into the <TD> tag for this column (ex: BGCOLOR="red")
//   align= Alignment of data in cells
//   type = type of data in this column (numeric, money, etc) - default alphanumeric
function AddColumn(name,td,align,type) {
	var index = this.Columns.length;
	this.Columns[index] = new Object;
	this.Columns[index].name = name;
	this.Columns[index].td   = td;
	this.Columns[index].align=align;
	this.Columns[index].type = type;
	if (type == "form") {
		 this.tablecontainsforms=true; 
		 if (use_layers) { 
		 	this.dosort=false;
			}
		}
	}
// Print out the original set of rows in the grid
function WriteRows() {
	var open_div = "";
	var close_div = "";
	for (var i=0; i<this.Lines.length; i++) {
	document.write("<TR "+this.LineProperties[i]+">");
		for (var j=0; j<this.Columns.length; j++) {
			var div_name = "d"+this.name+"-"+i+"-"+j;
			if (use_css) {
				if (this.Columns[j].align != '') {
					var align = " ALIGN="+this.Columns[j].align;
					}
				else {
					var align = "";
					}
				open_div = "<DIV ID=\""+div_name+"\" "+align+">";
				close_div= "</DIV>";
				}
			if (use_layers) {
				// If the table contains form elements, don't use <LAYER> tags or the
				// form will be forced closed.
				if (!this.dosort) {
					if (this.Columns[j].align != '') {
						open_div="<SPAN CLASS=\""+this.Columns[j].align+"\">";
						}
					}
				else {
					open_div = "<ILAYER NAME=\""+div_name+"\" WIDTH=100%>";
					open_div+= "<LAYER NAME=\""+div_name+"x\" WIDTH=100%>";
					if (this.Columns[j].align != '') {
						open_div+= "<SPAN CLASS=\""+this.Columns[j].align+"\">";
						}
					}
				if (this.Columns[j].align != '') {
	 				close_div = "</SPAN>";
					}
				if (this.dosort) {
					close_div += "</LAYER></ILAYER>";
					}
				}
			document.write("<TD "+this.Columns[j].td+">"+open_div+this.Lines[i][j].text+close_div+"</TD>");
			}
		document.write("</TR>");
		}
	}
// Sort the table and re-write the results to the existing table
function SortRows(table,column) {
	sort_object = table;
	if (!sort_object.dosort) { return; }
	if (sort_column == column) { reverse=1-reverse; }
	else { reverse=0; }
	sort_column = column;

	// Save all form column contents into a temporary object
	// This is a nasty hack to keep the current values of form elements intact
	if (table.tablecontainsforms) {
		var iname="1";
		var tempcolumns = new Object();
		for (var i=0; i<table.Lines.length; i++) {
			for (var j=0; j<table.Columns.length; j++) {
				if(table.Columns[j].type == "form") {
					var cell_name = "d"+table.name+"-"+i+"-"+j;
					tempcolumns[iname] = document.all[cell_name].innerHTML;
					table.Lines[i][j].text = iname;
					iname++;
					}
				}
			}
		}
	
	if (table.Columns[column].type == "numeric") {
		// Sort by Float
		table.Lines.sort(	function by_name(a,b) {
									if (parseFloat(a[column].data) < parseFloat(b[column].data) ) { return -1; }
									if (parseFloat(a[column].data) > parseFloat(b[column].data) ) { return 1; }
									return 0;
									}
								);
		}
	else if (table.Columns[column].type == "money") {
		// Sort by Money
		table.Lines.sort(	function by_name(a,b) {
									if (parseFloat(a[column].data.substring(1)) < parseFloat(b[column].data.substring(1)) ) { return -1; }
									if (parseFloat(a[column].data.substring(1)) > parseFloat(b[column].data.substring(1)) ) { return 1; }
									return 0;
									}
								);
		}
	else if (table.Columns[column].type == "date") {
		// Sort by Date
		table.Lines.sort(	function by_name(a,b) {
									if (Date.parse(a[column].data) < Date.parse(b[column].data) ) { return -1; }
									if (Date.parse(a[column].data) > Date.parse(b[column].data) ) { return 1; }
									return 0;
									}
								);
		}

	else {
		// Sort by alphanumeric
		table.Lines.sort(	function by_name(a,b) {
									if (a[column].data+"" < b[column].data+"") { return -1; }
									if (a[column].data+"" > b[column].data+"") { return 1; }
									return 0;
									}
								);
		}

	if (reverse) { table.Lines.reverse(); }
	for (var i=0; i<table.Lines.length; i++) {
		for (var j=0; j<table.Columns.length; j++) {
			var cell_name = "d"+table.name+"-"+i+"-"+j;
			if (use_css) {
				if(table.Columns[j].type == "form") {
					var iname = table.Lines[i][j].text;
					document.all[cell_name].innerHTML = tempcolumns[iname];
					}
				else {
					document.all[cell_name].innerHTML = table.Lines[i][j].text;
					}
				}
			if (use_layers) {
				var cell_namex= "d"+table.name+"-"+i+"-"+j+"x";
				if (table.Columns[j].align != '') {
					document.layers[cell_name].document.layers[cell_namex].document.write("<SPAN CLASS=\""+table.Columns[j].align+"\">");
					}
				document.layers[cell_name].document.layers[cell_namex].document.write(table.Lines[i][j].text);
				if (table.Columns[j].align != '') {
					document.layers[cell_name].document.layers[cell_namex].document.write("</SPAN>");
					}
				document.layers[cell_name].document.layers[cell_namex].document.close();
				}
			}
		}
	}

// Formuliercheck t.b.v. het aanlogproces (Homepage AA)
function formchecklogon() {
	var veld;
	var msg = "";
	var empty_fields = "";
	
	for(var i = 0; i < loginForm.length; i++) {
		var veld = loginForm.elements[i];
		if (veld.value == "") { 
			empty_fields += "\n- " + veld.name;
			continue;
		}
	}
	if (!empty_fields) return true;
	
	if (empty_fields) {
		msg +=  "De volgende verplichte velden zijn niet ingevuld:\n"
				+ empty_fields + "\n\n"
				+ "Bent u uw inlognaam en/of wachtwoord vergeten, neem dan\n"
				+ "contact op met het Customer Contact Center, 035 - 548 24 70";
	
	}
	alert(msg);
	return false;
}

// Formuliercheck t.b.v. het nieuwe aanlogproces voor Webmu
function webmuformcheck() {
	var f = document.loginForm;
	if ( f.Username.value == "" || f.Password.value == "" ) {
		alert("Zowel Gebruikersnaam als Wachtwoord invullen.");
		return false;
	}
	else
		return true;
}

// Formuliercheck t.b.v. het registratieproces
function formcheck() {
	var registratie;
	var msg = "";
	var empty_fields = "";
	var pcerror = "";
	var emailerror = "";
	var veld;
	var pcvalid;
	var tekstveld = "";
	var telefoonlengte = 0;
	var input = "";
			
	registratie = document.forms['registratie'];
	
	for(var i = 0; i < registratie.length; i++) {
		var veld = registratie.elements[i];
		if ((veld.type == "text") && !veld.optional) {
			if ((veld.name == "postcode") || (veld.name == "schoolpostcode")) {
				if (veld.name == "postcode") {
					pcvalid = CheckPC(registratie.postcode.value);

				}
				else if (veld.name == "schoolpostcode") {
					pcvalid = CheckPC(registratie.schoolpostcode.value);
				}
				if (pcvalid == "" ) {
					pcerror += "\n- de " + veld.name + " heeft niet het juiste formaat";
					pcvalid = "";
					if (tekstveld == "") {
						tekstveld = veld.name;
					}
				}	
			}
			else if (veld.name == "email") {
				 if (!CheckEmail(registratie.email.value)) {
					emailerror += "\n- het emailadres heeft niet het juiste formaat";
					if (tekstveld == "") {
						tekstveld = veld.name;
					}
				}		
			}
			else if ((veld.value == null) || (veld.value == "")) {
				if (tekstveld == "") {
					tekstveld = veld.name;
				}
				empty_fields += "\n- " + veld.name;
				continue;
			}
		}
	}
	telefoonlengte = registratie.netnummer.value.length + registratie.abonneenummer.value.length;
	
	input = registratie.netnummer.value + registratie.abonneenummer.value;
	if (telefoonlengte != 10) {
		if (!checkTelefoonFormat(input, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n\n- Het Telefoonummer is onjuist samengesteld";
			if (tekstveld == "") {
				tekstveld = "netnummer";
			}
		}
	}
	
	if (!empty_fields && !pcerror && !emailerror) return true;
	
	if (empty_fields) {
		msg +=  "De volgende verplichte velden zijn niet ingevuld:\n"
				+ empty_fields;
	
	}
	msg += pcerror;
	msg += emailerror;
	alert(msg);
	document.registratie[tekstveld].focus();
	return false;
}

// Postcodeformaat check
function CheckPC(str)
{
  var s;
  var re = new RegExp("^[ ]*([0-9]{4,4})[ ]*([a-z]{2,2})$","ig");
  s = re.exec(str);
  if(s!=null)
	return(s[1] + ' ' + s[2].toUpperCase());
  else
	return '';
}

// Emailformaat check OUD!!
//function CheckEmail(str)
//{
//  var s;
//  var re = new RegExp("^[a-z0-9_:.]*@[a-z0-9_]*([.][a-z0-9_]*)+$","ig");
//  return re.test(str);
//}


// Emailformaat check
// http://www.juicystudio.com/tutorial/javascript/regexp.html
function CheckEmail(str)
{
 //var re = new RegExp("^[a-z0-9_:.]*@[a-z0-9_]*([.][a-z0-9_]*)+$","ig");
  var s;
  var re;
  // Rules for the email regular expression:
 // The start of the email must have at least one character 
 // before the @ sign
 // There may be either a . or a -, but not together before the @ sign
 // There must be an @ sign
 // At least once character must follow the @ sign
 // There may be either a . or a -, but not together in the address
 // The address must end with a and either 2 or 3 characters
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  return re.test(str);
}


// Formuliercheck t.b.v. emailformulier
function formcheckemail() {
	var emailbericht;
	var msg = "";
	var empty_fields = "";
	var emailerror = "";
	var veld;
		
	emailbericht = document.forms['emailForm'];
	
	for(var i = 0; i < emailbericht.length; i++) {
		var veld = emailbericht.elements[i];
		if (veld.name == "email") {
			if (!CheckEmail(emailbericht.email.value))
				emailerror += "- Het emailadres heeft niet het juiste formaat";
		}
		else if ((veld.value == null) || (veld.value == "")) {
			empty_fields += "\n- " + veld.name;
			continue;
		}
	}
		
	if (!empty_fields && !emailerror) return true;
	
	if (empty_fields) {
		msg +=  "De volgende verplichte velden zijn niet ingevuld\n"
				+ empty_fields + "\n";
	
	}
	msg += emailerror;
	alert(msg);
	return false;
}

//Geeft ISBN nummer mee dat gewist moet worden van bestelform
function doSelectWis(isbn, laatste) {
	if (laatste == "True") {
		document.bestelForm.laatstebestelregel.value=true;
	}
	document.bestelForm.isbn.value=isbn;
	document.bestelForm.submit();
}

//checkt of het bex of gex betreft. Is uitsluitend, 1 van beide is mogelijk.
function bex_gexcontrole(veld){
	var andereNaam = null;
	var isbn = veld.name.substring(4,veld.name.length);
				
	if(veld.name.substring(0,3) == "bex"){
		andereNaam="gex";
	}else{
		andereNaam="bex";
	}
				
	if(veld.selectedIndex == 1){
		anderVeld = andereNaam + "_" + isbn;
		document.bestelForm[anderVeld].selectedIndex = 0;
	}
}

//check of minimaal 1 product is gelecteerd voor de bestelling
function highlight(field, blnShowAlert) {
   var strMelding;
   if (blnShowAlert == "True")
   {
        //document.bestelForm.geldige_bestelling.value='False';
        strMelding = "U moet tenminste één exemplaar van een product bestellen om verder te kunnen gaan met de bestelprocedure.\nProducten die u niet wilt bestellen kunt u met de knop wis van het bestelformulier verwijderen.\nProducten met de volgende ISBN-nummers moeten worden gewist of toegevoegd aan de bestelling:\n" + field ;
        alert(strMelding);
   }
   else     
  	{
  		//document.bestelForm.geldige_bestelling.value='True';
    }
}


//er moet minstens 1 uitgave zijn aangevinkt om te kunnen bestellen.
function checkISBN(form) {
	var checkflag = "false";
	var msg = "";
	for (i = 0; i < form.length; i++) {
		if (form[i].checked == true) {
			checkflag = "true";
		
		}
	}
	if (checkflag == "true") return true;
	if (checkflag == "false") {
		msg = "U hebt geen product geselecteerd.\n"
			+ "Vink het product van uw keuze aan in de kolom 'bestel'.";	
	}
	alert(msg);
	return false;	
}	


//checkt of persoonsgegevens bekend zijn en/of vervangingsjaar is geselecteerd 
function checkBestelformulier(blnProfiel, blnIsgewijzigd, blnBexGexBesteld, blnPriveAdres) {
	var msg = "";
	
	// er is geen bex of gex besteld, geen vervangingsjaar alleen op adresgegevens aanwezig testen
	if (blnBexGexBesteld == "false") {
		if (blnProfiel == "true" || blnIsgewijzigd == "true") {
			document.bestelForm.submit();
		}
		else if (blnProfiel == "false" && blnIsgewijzigd == "false") {
				msg += "U dient eerst uw persoonsgegevens in te vullen voor u verder kan met bestellen.\n";	
		}
	}
	// Versturen naar Schooladres is aangevinkt
	// Er is een Bex, Gex of een Rex besteld, wel een vervangingsjaar en testen op adresgegevens aanwezig
	else if (document.bestelForm.VerstuurNaarPrive[0].checked == true) {
		if ((document.bestelForm.Vervangingsjaar.value != -1) && (blnProfiel == "true" || blnIsgewijzigd == "true")) {
			document.bestelForm.submit();
		}
		if (document.bestelForm.Vervangingsjaar.value == -1) {
			msg += "Er is geen vervangingsjaar geselecteerd.\n";
		}	
		// methode en rapportcijfer verwijders november 2007, GvT
		if (blnProfiel == "false" && blnIsgewijzigd == "false") {
			msg += "U dient eerst uw persoonsgegevens in te vullen voor u verder kan met bestellen.\n";	
		}
	}
	// Versturen naar Priveadres is aangevinkt
	// Er is een Bex, Gex of een Rex besteld, wel een vervangingsjaar en testen op adresgegevens aanwezig
	else if (document.bestelForm.VerstuurNaarPrive[1].checked == true) {
		if ((document.bestelForm.Vervangingsjaar.value != -1 && blnPriveAdres == "true") && (blnProfiel == "true" || blnIsgewijzigd == "true")){
			document.bestelForm.submit();
		}
		else {
			if (blnPriveAdres == "false") {
					msg += "U dient eerst uw adresgegevens in te vullen.\n";
			}
			if (document.bestelForm.Vervangingsjaar.value == -1) {
				msg += "Er is geen vervangingsjaar geselecteerd.\n";	
			}
		
			if (blnProfiel == "false" && blnIsgewijzigd == "false") {
				msg += "U dient eerst uw persoonsgegevens in te vullen voor u verder kan met bestellen.\n";	
			}
	
		}
	}
	
	
	if (msg != "") {
		alert(msg);	
		return false;			
	} 
	return false;	
}
	
//checkt of ISBN is gevuld, zodat andere velden op default worden gezet.
//onderscheid VO en BVE omdat het andere velden betreft.	
function checkISBNvalue(fieldName,soort) {
	if (document.selectionForm.isbn.value != "") { 
		
		if (document.selectionForm.soort.value == "VO") {
			document.selectionForm.onderwijstype.selectedIndex=-1;
			document.selectionForm.soortboek.selectedIndex=-1;
			}
		else
			{
			document.selectionForm.niveau.selectedIndex=-1;
			document.selectionForm.soortboek.selectedIndex=-1;
			document.selectionForm.kwalificatie.selectedIndex=-1;
			document.selectionForm.deelkwalificatie.selectedIndex=-1;
		
			}
		}	
	document.selectionForm.submit();	
}

// functie voor doorlinksen naar pagina http://www.assu.nl/passwordvergeten.asp
// met de nodige paramaterstring
function wwvergeten() {
	var un = document.loginForm.Username.value;
	var page = "http://www.assu.nl/passwordvergeten.asp?Uitgever=ThiemeMeulenhoff&Id_nummer=03&Website=webmu.nijghversluys.nl/dtrein.asp&un=" + un;
	document.location = page;
}

//functie voor melden dat inloggen niet correct is gegaan
function highlightlogin(field, blnShowAlert) {
  field.focus();
  field.select();
   if (blnShowAlert == "True"){
        alert("Inlognaam en/of wachtwoord onjuist");
    }
}

function remove_XS_whitespace(item) {
	var tmp = "";
	var item_length = item.value.length;
	var item_length_minus_1 = item.value.length - 1;
	for (index = 0; index < item_length; index++) {
		if (item.value.charAt(index) != ' ') {
			tmp += item.value.charAt(index);
		}
		else {
			if (tmp.length > 0) {
				if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1) {
					tmp += item.value.charAt(index);
				}
			}
		}
  }
  item.value = tmp;
}

// Formuliercheck t.b.v. het registratieproces >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   VO
function registratiecheckVO() {
	var registratie;
	var msg = "";
	var empty_fields = "";
	var pcerror = "";
	var emailerror = "";
	var veld;
	var pcvalid;
	var tekstveld = "";
	var functieerror = "";
	var onderbouw = "";
	var vmbobovenbouw = "";
	var havovwobovenbouw = "";
	var geslacht = "";
	var checkflag = false;
	var SchoolTelefoonlengte = 0;
	var MobielTelefoonlengte = 0;
	var PriveTelefoonlengte = 0;
	var Schoolinput = "";
	var MobielInput = "";
	var PriveInput = "";
		
	registratie = document.forms['registratie'];
	
	for(var i = 0; i < registratie.length; i++) {
		var veld = registratie.elements[i];
		remove_XS_whitespace(veld)
		if (((veld.type == "text") || (veld.type == "checkbox") || (veld.type == "password"))  && !veld.optional) {
			if (veld.name == "functie"){
				if (veld.checked == true) {
					checkflag = true;
				}
			}
			else if (veld.name == "email") {
				if (!CheckEmail(registratie.email.value)) {
					emailerror += "\n- E-mailadres (onjuist formaat)";
					if (tekstveld == "") {
						tekstveld = veld.name;
					}
				}		
			}
			else if ((veld.name == "onderbouw") && (veld.value != "")) {
				if (document.registratie.onderbouwtevredenheid.value == -1) {
					onderbouw += "\n- Tevredenheid bij onderbouw";
				}
				if (document.registratie.onderbouwaanschafjaar.value == -1) {
					onderbouw += "\n- Aanschafjaar bij onderbouw";
				}
				if (document.registratie.onderbouwvervangingsjaar.value == -1) {
					onderbouw += "\n- Vervangingsjaar bij onderbouw";
				}
				
			}
			else if ((veld.name == "vmbobovenbouw") && (veld.value != "")) {
				if (document.registratie.vmbobovenbouwtevredenheid.value == -1) {
					vmbobovenbouw += "\n- Tevredenheid bij VMBO bovenbouw"; 
				}
				if (document.registratie.vmbobovenbouwaanschafjaar.value == -1) {
					vmbobovenbouw += "\n- Tevredenheid bij VMBO bovenbouw";
				}
				if (document.registratie.vmbobovenbouwvervangingsjaar.value == -1) {
					vmbobovenbouw += "\n- Vervangingsjaar bij VMBO bovenbouw";
				}
			}
			else if ((veld.name == "havovwobovenbouw") && (veld.value != "")) {
				if (document.registratie.havovwobovenbouwtevredenheid.value == -1) {
					havovwobovenbouw += "\n- Tevredenheid bij HAVO VWO bovenbouw";
				}
				if (document.registratie.havovwobovenbouwaanschafjaar.value == -1) {
					havovwobovenbouw += "\n- Tevredenheid bij HAVO VWO bovenbouw";
				}
				if (document.registratie.havovwobovenbouwvervangingsjaar.value == -1) {
					havovwobovenbouw += "\n- Vervangingsjaar bij HAVO VWO bovenbouw";
				}
			}
			else if ((veld.value == null) || (veld.value == "")) {
				if (tekstveld == "") {
					tekstveld = veld.name;
				}

				if ((veld.name != "anders_vak") && (veld.name != "onderbouw") && (veld.name != "vmbobovenbouw") && (veld.name != "havovwobovenbouw")) {
					var lblnFunctieVakVeld = false;
//Remove check on functierows docent and anders
					for (var rowNum = 1;rowNum<=gintFunctionRowCount;rowNum++)
					{
						lblnFunctieVakVeld = ( ("docent_vak_" + rowNum)==veld.name );
						if (lblnFunctieVakVeld)
							break;
					}
					
					if (!lblnFunctieVakVeld)
						empty_fields += "\n- " + veld.name;
				}
				continue;
					
			}
		}
	}


	
	if (!document.registratie.geslacht[0].checked && !document.registratie.geslacht[1].checked) {
		geslacht += "\n- Geslacht"; 
	} 
	
	PriveTelefoonlengte = registratie.Prive_netnummer.value.length + registratie.Prive_abonneenummer.value.length;
	PriveInput = registratie.Prive_netnummer.value + registratie.Prive_abonneenummer.value;
	
	if (PriveTelefoonlengte != 10) {
		if (!checkTelefoonFormat(PriveInput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- Privé telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "Prive_netnummer";
			}
		}          
	}
	
	MobielTelefoonlengte = registratie.Mobiel_abonneenummer.value.length;
	MobielInput = registratie.Mobiel_netnummer.value + registratie.Mobiel_abonneenummer.value;
    
	if (MobielTelefoonlengte != 8 && MobielTelefoonlengte != 0) {
		if (!checkTelefoonFormat(MobielInput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- Mobiel telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "Mobiel_abonneenummer";
			}
		}
	}
	
	SchoolTelefoonlengte = registratie.School_netnummer.value.length + registratie.School_abonneenummer.value.length;
	Schoolinput = registratie.School_netnummer.value + registratie.School_abonneenummer.value;
    
	if (SchoolTelefoonlengte != 10) {
		if (!checkTelefoonFormat(Schoolinput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- School telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "School_netnummer";
			}
		}
	}


//Check on functierows dependencies
	if (!checkflag){
			functieerror += "\n- Functie/rol (minimaal één)"
	}
	else
	{
		var frmRegistratie = document.registratie;
		var numRows;
		var lblnValidRowEntered;
		var cbOB = eval("frmRegistratie.functie_OBBB");
		
		//Docent		
		if (frmRegistratie.functie[0].checked)
		{
			lblnValidRows = true;
			lblnRowsEntered = false;
			for (numRows = 1;numRows<=gintFunctionRowCount;numRows++)
			{
				var lblnEmptyRow = false;
				var lblnValidRow = false;
				var selOpleiding = eval("frmRegistratie.docent_opleiding_" + numRows);
				var txtVak = eval("frmRegistratie.docent_vak_" + numRows);
				
				//Is at least 1 of the OB and BB checkboxexs checked for this row?			
				var lblnCheckOBBB = ( (cbOB[2*numRows - 2].checked) || (cbOB[2*numRows - 1].checked) );
				remove_XS_whitespace(txtVak);

				//Check for an empty row
				lblnEmptyRow = (selOpleiding.value.length==0) && (txtVak.value.length==0) && (!lblnCheckOBBB);
				if (!lblnEmptyRow)
				{
					lblnRowsEntered = true;
					//If the row is not empty then check wether it is valid
					lblnValidRow = (selOpleiding.value.length>0) && (txtVak.value.length>0) && (lblnCheckOBBB);
					lblnValidRows = lblnValidRows && lblnValidRow;
				}
			}
			if (!lblnRowsEntered)
				functieerror += "\n- Nog geen gegevens bij de functie/rol 'Docent' ingevuld."
			if (!lblnValidRows)
				functieerror += "\n- Gegevens bij de functie/rol 'Docent' incompleet."
		}
		
		//Coordinator
		if (frmRegistratie.functie[1].checked)
		{
			lblnValidRows = true;
			lblnRowsEntered = false;
			for (numRows = 1;numRows<=gintFunctionRowCount;numRows++)
			{
				var lblnEmptyRow = false;
				var lblnValidRow = false;
				var selFunctie = eval("frmRegistratie.coordinator_functie_" + numRows);
				var selOpleiding = eval("frmRegistratie.coordinator_opleiding_" + numRows);
				
				//Is at least 1 of the OB and BB checkboxexs checked for this row?
				var lblnCheckOBBB = ( (cbOB[2*gintFunctionRowCount + 2*numRows - 2 ].checked) || (cbOB[2*gintFunctionRowCount + 2*numRows - 1].checked) );
				//Check for an empty row
				lblnEmptyRow = (selFunctie.value.length==0) && (selOpleiding.value.length==0) && (!lblnCheckOBBB);
				if (!lblnEmptyRow)
				{
					lblnRowsEntered = true;
					//If the row is not empty then check wether it is valid
					lblnValidRow = (selFunctie.value.length>0) && (selOpleiding.value.length>0) && (lblnCheckOBBB);
					lblnValidRows = lblnValidRows && lblnValidRow;
				}
			}
			if (!lblnRowsEntered)
				functieerror += "\n- Nog geen gegevens bij de functie/rol 'Coõrdinator' ingevuld."
			if (!lblnValidRows)
				functieerror += "\n- Gegevens bij de functie/rol 'Coõrdinator' incompleet."
		}
		
		//Directie
		if (frmRegistratie.functie[2].checked)
		{
			lblnValidRows = true;
			lblnRowsEntered = false;
			for (numRows = 1;numRows<=gintFunctionRowCount;numRows++)
			{
				var lblnEmptyRow = false;
				var lblnValidRow = false;
				var selFunctie = eval("frmRegistratie.directie_functie_" + numRows);
				var selOpleiding = eval("frmRegistratie.directie_opleiding_" + numRows);
				
				//Is at least 1 of the OB and BB checkboxexs checked for this row?
				var lblnCheckOBBB = ( (cbOB[4*gintFunctionRowCount + 2*numRows - 2 ].checked) || (cbOB[4*gintFunctionRowCount + 2*numRows - 1].checked) );
				//Check for an empty row
				lblnEmptyRow = (selFunctie.value.length==0) && (selOpleiding.value.length==0) && (!lblnCheckOBBB);
				if (!lblnEmptyRow)
				{
					lblnRowsEntered = true;
					//If the row is not empty then check wether it is valid
					lblnValidRow = (selFunctie.value.length>0) && (selOpleiding.value.length>0) && (lblnCheckOBBB);
					lblnValidRows = lblnValidRows && lblnValidRow;
				}
			}
			if (!lblnRowsEntered)
				functieerror += "\n- Nog geen gegevens bij de functie/rol 'Directie' ingevuld."
			if (!lblnValidRows)
				functieerror += "\n- Gegevens bij de functie/rol 'Directie' incompleet."
		}
		
		//Anders
		if (frmRegistratie.functie[3].checked)
		{
			var veld = document.registratie.anders_vak;
			remove_XS_whitespace(veld);
			if (veld.value.length==0)
				functieerror += "\n- Nog geen functie/rol ingevuld bij 'Anders'."
		}
		
	}
	
	if (!empty_fields && !emailerror && !functieerror && !geslacht && !onderbouw && !vmbobovenbouw && !havovwobovenbouw) return true;
	
//	msg += "U bevindt zich op de registratiepagina van de methodesite.\n"
//	msg += "U heeft een of meer verplichte velden niet ingevuld.\n"
//	msg += "Vul deze alsnog in en druk opnieuw op de knop aanmelden.\n"
//	msg += "Als u niet over alle verplichte informatie beschikt \n"
//	msg += "en u zich wel wilt laten registreren, neem dan contact op \n"
//	msg += "met het Customer Contact Center, 035 - 548 24 70 \n"
	
	if (empty_fields) {	
		msg +=  "\n\nDe volgende velden zijn niet of onjuist ingevuld:\n"
				+ empty_fields;
	}
	msg += geslacht;		
	msg += onderbouw;
	msg += vmbobovenbouw;
	msg += havovwobovenbouw;
	msg += functieerror;
	msg += emailerror;
	msg = msg.replace(/_/g," ");
	// String.replace(/text to find/options, replacement text)
	// for all(g option) occurences, without g: first occurence is replaced.
	alert(msg);
	if (empty_fields) {
		document.registratie[tekstveld].focus();
	}	
	return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Formuliercheck t.b.v. het registratieproces >>>>>>>>>>>>>>> 	BVE
function registratiecheckBVE() {
	var registratie;
	var msg = "";
	var empty_fields = "";
	var emailerror = "";
	var veld;
	var pcvalid;
	var tekstveld = "";
	var sectorerror = "";
	var functieerror = "";
	var geslacht = "";
	var checkflag = false;
	var checkflagfunctie = false;
	var docentvalidatie = "";
	var coordinatorvalidatie = "";
	var functieandersvalidate = "";
	var ROCTelefoonlengte = 0;
	var PriveTelefoonlengte = 0;
	var MobielTelefoonlengte = 0;
	var ROCinput = "";
	var PriveInput = "";
	var MobielInput = "";
		
	registratie = document.forms['registratie'];
	
	for(var i = 0; i < registratie.length; i++) {
		var veld = registratie.elements[i];
		remove_XS_whitespace(veld)
		if (((veld.type == "text") || (veld.type == "checkbox") || (veld.type == "password"))  && !veld.optional) {
			if (veld.name == "sector"){
				if (veld.checked == true) {
					checkflag = true;
				}
			}			
			else if (veld.name == "docent") {
				if (veld.checked == true) {
					checkflagfunctie = true;
					if ((document.registratie.niveau1d.value == "") || (document.registratie.opleiding1d.value == "") || (document.registratie.deelkwalificatie1d.value == "") || ((document.registratie.BOL1d.checked == false) && (document.registratie.BBL1d.checked == false))) {
						docentvalidatie += "\n- Functie/Docent (a.u.b. minimaal één volledige regel invullen:\n niveau, opleiding, deelkwalificatie, BOL of BBL of beide)."
					}
				}
			}
			else if (veld.name == "coordinator") {
				if (veld.checked == true) {
					checkflagfunctie = true;
					if ((document.registratie.niveau1c.value == "") || (document.registratie.opleiding1c.value == "")) {
						coordinatorvalidatie += "\n- Functie/Coördinator (a.u.b. minimaal één volledige regel invullen:\n niveau, opleiding/afdeling)."
					}
				}
			}
			else if (veld.name == "functieanders") {
				if (veld.checked == true) {
					checkflagfunctie = true;
					if (document.registratie.omschrijvinganders.value == "") {
						functieandersvalidate += "\n- Functie/Anders (a.u.b. dit veld invullen)."
					}
				}				
			}
			else if (veld.name == "email") {
				if (!CheckEmail(registratie.email.value)) {
					emailerror += "\n- E-mailadres (onjuist formaat)";
					if (tekstveld == "") {
						tekstveld = veld.name;
					}
				}		
			}			
			else if ((veld.value == null) || (veld.value == "")) {
				if (tekstveld == "") {
					tekstveld = veld.name;
				}
				empty_fields += "\n- " + veld.name;
				continue;
					
			}
		}
	}
	if (!document.registratie.geslacht[0].checked && !document.registratie.geslacht[1].checked) {
		geslacht += "\n- Geslacht"; 
	} 
		
	PriveTelefoonlengte = registratie.Prive_netnummer.value.length + registratie.Prive_abonneenummer.value.length;
	PriveInput = registratie.Prive_netnummer.value + registratie.Prive_abonneenummer.value;
	
	if (PriveTelefoonlengte != 10) {
		if (!checkTelefoonFormat(PriveInput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- Privé telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "Prive_netnummer";
			}
		}
	}
	
	MobielTelefoonlengte = registratie.Mobiel_abonneenummer.value.length;
	MobielInput = registratie.Mobiel_netnummer.value + registratie.Mobiel_abonneenummer.value;
    
	if (MobielTelefoonlengte != 8 && MobielTelefoonlengte != 0) {
		if (!checkTelefoonFormat(MobielInput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- Mobiel telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "Mobiel_abonneenummer";
			}
		}
	}
	
	ROCTelefoonlengte = registratie.ROC_netnummer.value.length + registratie.ROC_abonneenummer.value.length;
	ROCinput = registratie.ROC_netnummer.value + registratie.ROC_abonneenummer.value;
    
	if (ROCTelefoonlengte != 10) {
		if (!checkTelefoonFormat(ROCinput, "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "0")){
			empty_fields += "\n- ROC Telefoonummer (onjuist samengesteld)";
			if (tekstveld == "") {
				tekstveld = "ROC_netnummer";
			}
		}
	}
	
	if (!checkflag){
		sectorerror += "\n- Sector (minimaal één)."
	}
	if (!checkflagfunctie) {
		functieerror += "\n- Functie (minimaal één)"
	}
	
	if (!empty_fields && !emailerror && !docentvalidatie && !coordinatorvalidatie && !functieandersvalidate && !geslacht && checkflagfunctie && checkflag) return true;
	
	if (empty_fields) {
		msg +=  "\n\nDe volgende verplichte velden zijn niet of onjuist ingevuld:\n"
				+ empty_fields;
	}
	msg += geslacht;
	msg += sectorerror;
	msg += docentvalidatie;
	msg += coordinatorvalidatie;
	msg += functieandersvalidate;
	msg += emailerror;
	msg += functieerror;
	msg = msg.replace(/_/g," ");
	// String.replace(/text to find/options, replacement text)
	// for all(g option) occurences, without g: first occurence is replaced.
	alert(msg);
	if (empty_fields) {
		document.registratie[tekstveld].focus();
	}
	return false;
}

function checkTelefoonFormat(input) {
  var ok = true;
  for (var i = 0; i < input.length; i++) {
    var chr = input.charAt(i);
    var found = false;
    for (var j = 1; j < checkTelefoonFormat.length; j++) {
      if (chr == checkTelefoonFormat[j]) found = true;
    }
    if (!found) ok = false;
  }
  return ok;
}

// Functie naam: newFrame
// Doel functie: openen van een nieuw browser window met aangegeven pagina / url erin
//		Equivalent van target="_blank"
// Input: URL
// Output: geopend window
function newFrame(page) {
window.open(page,'','');
}

// Functie naam: newTotalFrame
// Doel functie: openen van een nieuw browser window die gemaximaliseerd wordt
// Input: - 
// Output: geopend window
function newTotalFrame(url) {
	var w = screen.width - 10;
	var h = screen.height - 10;
	var sAttribs;
	sAttribs = "'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes,left=0,top=0,width=";
	sAttribs += w;
	sAttribs += ",height=";
	sAttribs += h;
	sAttribs += "'";
	window.open(url,'',sAttribs);
	}

// Functie naam: addFav
// Doel: toevoegen van een pagina aan gebruikers favorieten na een klik op een hyperlink
// Eenvoudige aanroep, waarbij automatisch de url en titel v/d pagina worden gebruikt:
// <a href="javascript:addFav(document.title);"> ... </a>
// Bij andere gwenste titel deze als ('parameter') meegeven
function addFav(sTitel) {
	if (document.all) {
	window.external.AddFavorite(location.href, sTitel);
	}
	else
	{
	alert('Voeg deze pagina toe aan je favorieten/bookmarks.')
	}
}

function trim(s) {
	 while (s.substring(0,1) == ' ') {
	   s = s.substring(1,s.length);
	 }
	 while (s.substring(s.length-1,s.length) == ' ') {
	   s = s.substring(0,s.length-1);
	 }
	 return s;
	}

// checkWWs: Formuliercheck t.b.v. wactwoord wijzigen
function checkWWs() {
	var msg ;
	if ( trim(NwWWform.ww1.value).length < 3) {
		msg = "Het wachtwoord moet minimaal 3 karakters bevatten." ;
		alert(msg);
		NwWWform.ww1.focus();
		NwWWform.ww1.select();
		return false;
		}
	else if ( NwWWform.ww1.value != NwWWform.ww2.value ) {
		msg = "Het controlewachtwoord (Nogmaals) is niet gelijk aan het Wachtwoord." ;
		alert(msg);
		NwWWform.ww2.focus();
		NwWWform.ww2.select();
		return false;
	}
	else
		return true;
}

//functie voor melden dat wachtwoord gewijzigd is.
function alertNwWW(blnShowAlert) {
   if (blnShowAlert == "true"){
        alert("  Uw wachtwoord is gewijzigd.  ");
    }
}
