// JavaScript Document

function test() {
	alert("test");
	return true;
}

function CheckForm( theform ) {
	
	
	var bMissingFields = false;
	var strFields = "";
	
	if( theform.naam.value == '' ){
		bMissingFields = true;
		strFields += "     naam\n";
	}
	
	if( theform.adres.value == '' ){
		bMissingFields = true;
		strFields += "     adres\n";
	}
	
	if( theform.plaats.value == '' ){
		bMissingFields = true;
		strFields += "     woonplaats\n";
	}
	
	if( theform.email.value == '' ){
		bMissingFields = true;
		strFields += "     email\n";
	}
	if( theform.email.value != '' ){
		var pos1 = theform.email.value.indexOf("@", 0);
		var pos2 = theform.email.value.indexOf(".", 0);
		if (pos1 <= 0 || pos2 <= 0) {
			bMissingFields = true;
		 	strFields += "     email\n";
		}
	}
	
	if( bMissingFields ) {
		alert( "Er onbreekt informatie, de volgende velden zijn niet (of niet volledig) ingevuld:\n" + strFields );
		return false;
	} 
	
	return true;
}

/* ==========================================================================
	 Functienaam:			zetVerzend
	 Functiefunctie:	Zet verzendkosten
	 ========================================================================== */
function zetVerzend() {
	
	// alert("302. zetVerzend()" );
	
	var h_verzend	= document.getElementById("verzend");
	var h_landv	= document.getElementById("land_verzend");
	var h_land = document.getElementById("land");
	
	var h_totaal_ex = document.getElementById("totaalex");
	var h_ordertotaal = document.getElementById("ordertotaal");
	
	if (h_landv.value == "N.v.t.") {
		if (h_land.value == "Nederland") {
			h_verzend.value = "n.v.t.";
			
			h_ordertotaal.value = h_totaal_ex.value;
		} else {
			h_verzend.value = "10,00";
			
			var tot_ex = h_totaal_ex.value.replace(".","");
			tot_ex = tot_ex.replace(",",".");
			//
			h_ordertotaal.value = parseFloat(tot_ex) + 10;
			h_ordertotaal.value = maakBedrag(h_ordertotaal.value); // Maak mooi bedrag
		}
	} else {
		if (h_landv.value == "Nederland") {
			h_verzend.value = "n.v.t.";
			h_ordertotaal.value = h_totaal_ex.value;
		} else {
			h_verzend.value = "10,00";
			
			var tot_ex = h_totaal_ex.value.replace(".","");
			tot_ex = tot_ex.replace(",",".");
			//
			h_ordertotaal.value = parseFloat(tot_ex) + 10;
			h_ordertotaal.value = maakBedrag(h_ordertotaal.value); // Maak mooi bedrag
		}
	}
	
}

/* ===============================================================================
	 Functienaam:			maakBedrag
	 Functiefunctie:	Zet evt. duizendpunt in getal en vul evt. aan met cent-cijfers
	 =============================================================================== */
function maakBedrag (in_getal) {
	
	var uit_bedrag = in_getal; // Initieel
	var hulp_cent = in_getal.split(".");
	var euros  = hulp_cent[0]; // Initieel
	var centen = "00";
	// Eerst de centen ------------------------
	if (hulp_cent.length == 2) {
		if (hulp_cent[1].length == 2) {
			centen = hulp_cent[1];
		} else if (hulp_cent[1].length == 1) {
			centen = hulp_cent[1] + "0";
		}
	}
	// Dan de duizendpunt ---------------------
	if (hulp_cent[0].length == 4) {
		euros = hulp_cent[0].substr(0,1) + "." + hulp_cent[0].substr(1);
	} else if (hulp_cent[0].length == 5) {
		euros = hulp_cent[0].substr(0,2) + "." + hulp_cent[0].substr(2);
	}
	//
	uit_bedrag = euros + "," + centen;
	return uit_bedrag;
	
}

// ===============================================================================
