// JavaScript Document
function showDelivery()
{
		if (document.form.delivery_address.checked == true)
		{
			//alert('no display');
			document.getElementById('delivery').style.display = 'none';
		}
		else
			//alert('display');
			document.getElementById('delivery').style.display = 'block';
}

//--Returns the current date in mm/dd/yyyy format as a string.
function todayStr() {
var today=new Date()
var day = today.getDate()
day = ((day < 10) ? "0" : "") + day
month = (today.getMonth()+1)
month = ((month < 10) ? "0" : "") + month
return day +"/"+ month+"/"+(today.getFullYear())
}

//--Returns the current system time as a string .
function nowStr() {
var nowStr=new Date()
var minutes = nowStr.getMinutes()
minutes=((minutes < 10) ? "0" : "") + minutes
return nowStr.getHours() + ":" + minutes
} 

function checkChequeNbr(x)
{
	if(x >40) 
	{alert('het aantal cheques per omslag mag niet hoger zijn dan 40'); }
}

function CalculateTotal(x,y,z,a)
{
	//total per line
	a.value = (x*y*z)
	
	//general total
	total1 = (document.form.total_value_1.value*1)
	total2 = (document.form.total_value_2.value*1)
	total3 = (document.form.total_value_3.value*1)
	total4 = (document.form.total_value_4.value*1)
	total5 = (document.form.total_value_5.value*1)
	total6 = (document.form.total_value_6.value*1)
	total7 = (document.form.total_value_7.value*1)
	total8 = (document.form.total_value_8.value*1)
	total9 = (document.form.total_value_9.value*1)
	total10 = (document.form.total_value_10.value*1)
	document.form.total_value.value = (total1+total2+total3+total4+total5+total6+total7+total8+total9+total10);
}


function checkForm() {
	var strMsg;
	strMsg = "";
	if (document.form.company_name.value=="")
		strMsg += "\De naam van de onderneming";
	if ((document.form.vat[0].checked==false)&&(document.form.vat[1].checked==false))
		strMsg += "\nHet ondernemingsnummer";
	else
	{
		if ((document.form.vat[1].checked==true)&&(document.form.company_nbr.value!=""))
		{
			var vatnumber = document.form.company_nbr.value;
			// Remove spaces from the VAT number to help validation
			var chars = [" ","-",",","."];
			for ( var i=0; i<chars.length; i++) {
				while (vatnumber.indexOf(chars[i])!= -1) {
				  vatnumber = vatnumber.slice (0,vatnumber.indexOf(chars[i])) + vatnumber.slice (vatnumber.indexOf(chars[i])+1);
				}
			}
			
			// First character of 10 digit numbers should be 0
			if (vatnumber.length == 10 && vatnumber.slice(0,1) != "0") 
			  	strMsg += "\nOngeldig ondernemingsnummer";
			// Nine digit numbers have a 0 inserted at the front.
			if (vatnumber.length == 9) vatnumber = "0" + vatnumber;
			  
			// Modulus 97 check on last nine digits
			if (97 - vatnumber.slice (0,8) % 97 != vatnumber.slice (8,10)) 
				strMsg += "\nOngeldig ondernemingsnummer";
		}
	}
	if (document.form.lastname.value=="")
		strMsg += "\nUw naam";
	if (document.form.fonction.value=="")
		strMsg += "\nUw functie";
	if (document.form.email.value=="")
		strMsg += "\nUw e-mail";
	else
	{
		var x = document.form.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x) == false)
		{ 
			strMsg += "\nOngeldige e-mail";
		}
	}
	if (document.form.address.value=="")
		strMsg += "\nUw adres";
	if (document.form.zip_code.value=="")
		strMsg += "\nUw postcode";
	if (document.form.city.value=="")
		strMsg += "\nUw gemeente";
	if (document.form.phone.value=="")
		strMsg += "\nUw telefoon";
	if (document.form.contact_pers.value=="")
		strMsg += "\nDe contactpersoon";
	if ((document.form.payement[0].checked==false)&&(document.form.payement[1].checked==false))
		strMsg += "\nUw betaalwijze";
	if (document.form.envelop_nbr_1.value=="")
		strMsg += "\nHet aantal omslagen";
	if (document.form.cheque_envelop_nbr_1.value=="")
		strMsg += "\nHet aantal cheques per omslag";
	if (document.form.facial_value_1.value=="")
		strMsg += "\nDe zichtwaarde per cheque";
	if ((document.form.lang_1[0].checked==false)&&(document.form.lang_1[1].checked==false))
		strMsg += "\nDe taal van de cheques";
	if (strMsg=="")
		return (true);
	else{
		alert("Vul de volgende velden :\n" + strMsg);
		return (false);
	}
}

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event)
	 	key = window.event.keyCode;
	else if (e)
	 	key = e.which;
	else
	 	return true;
		keychar = String.fromCharCode(key);
		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
 			return true;
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
 			return true;
		// decimal point jump
		else if (dec && (keychar == "."))
 		{
 			myfield.form.elements[dec].focus();
 			return false;
 		}
		else
 			return false;
}


function checkFriendForm()
{
		if (document.form1.nom.value=="")
		{
			alert("Vul uw naam");
			return false;
		}
		if (document.form1.email.value=="")
		{
			alert("Vul de e-mail van uw vriend");
			return false
		}
		else
		{
			var x = document.form1.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x) == false)
			{ 
				alert("Ongeldige e-mail");
				return false
			}
		}
 
}


function checkNumeric(value)
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(value))
		return true;
	else
	{ alert("Alleen getallen");
		return false;
	}
}

// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

