// JavaScript Document

function checkEmail(fObj) 
{
	var div = document.getElementById(fObj.name+"-"+fObj.email_adres.name+"-error");
	
	if (!fObj.email_adres.value.match(/^[^@]+@[^@]+\.[a-zA-Z]{2,3}/)) {
		
		if(div)
			div.style.display="block";
		else
			alert("Vul een geldig e-mailadres in.")
		
		return false
	}
	
	if(div)
		div.style.display="none";

	return true;
}

function checkEmailAndRewriteAction(fObj,theme) 
{
	//alert("Action now: "+fObj.action);

	if(!checkEmail(fObj))
		return false;
		
	var newsletter = "AutokompasNieuws";
	if(theme.length>0)
		newsletter = newsletter+"-"+theme;
		
	var email = fObj.email_adres.value;
	//fObj.action="/nieuwsbrief/subscribe/"+email+"/"+newsletter"/Production/Final";
	fObj.action="/nieuwsbrief/subscribe/"+email+"/"+newsletter+"/Development/Local";
	
	alert("Action now: "+fObj.action);
	
	return true;
}

function printDocument()
{
	var div = document.getElementById('document');
	if(div)
	{
		var newwin = window.open('/print.html','print','width=436,height=450,scrollbars=yes,resizable=yes,menubar=no');
		newwin.focus();
	}
}

function showErrorDiv(fObj,flag)
{
	var div = document.getElementById(fObj.form.name+"-"+fObj.name+"-error");
	if(div)
	{
		if(flag)
			div.style.display="inline";
		else
			div.style.display="none";
			
		return true;
	}
	
	return false;
}


function ValidateForm(form)
{
	if(form.naam!=null)
	{		
		if(IsEmpty(form.naam)) 
		{ 
			if(!showErrorDiv(form.naam,true))
				alert('Vul een naam in.');
			form.naam.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.naam,false);
	}

	if(form.adres!=null)
	{		
		if(IsEmpty(form.adres)) 
		{ 
			if(!showErrorDiv(form.adres,true))
				alert('Vul een adres in.');
			form.adres.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.adres,false);
	}

	if(form.postcode!=null)
	{		
		if(IsEmpty(form.postcode)) 
		{ 
			if(!showErrorDiv(form.postcode,true))
				alert('Vul een postcode in.');
			form.postcode.focus(); 
			return false; 
		} 
		else
			showErrorDiv(form.postcode,false);
	}

	if(form.plaats!=null)
	{
		if(IsEmpty(form.plaats)) 
		{ 
			if(!showErrorDiv(form.plaats,true))
				alert('Vul een plaats in.');
			form.plaats.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.plaats,false);
	}

	if(form.email!=null){
		
		if (!isValidEmail(form.email.value)) 
		{ 
			if(!showErrorDiv(form.email,true))
				alert('Vul een geldig e-mailadres in.');
			form.email.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.email,false);
	}
	
	if(form.emailto!=null){
		
		if (!isValidEmail(form.emailto)) 
		{ 
			if(!showErrorDiv(form.emailto,true))
				alert('Vul een geldig e-mailadres in.');
			form.emailto.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.emailto,false);
	}

	if(form.opmerking!=null)
	{		
		if(IsEmpty(form.opmerking)) 
		{ 
			if(!showErrorDiv(form.opmerking,true))
				alert('Vul uw reactie in.');
			form.opmerking.focus(); 
			return false; 
		}
		else
			showErrorDiv(form.opmerking,false);
	}
	
	return true; 


} 

function IsEmpty( aTextField ) 
{
   if ((aTextField.value.length==0) ||   (aTextField.value==null)) 
   {
      return true;
   }
   else { return false; }
}	

function isValidEmail(str) 
{
   var s = str.match(/^[^@]+@[^@]+\.[a-zA-Z]{2,3}/);
   var ret = !s;
   return !ret;
}


