function ltrim(s) { return s.replace( /^\s*/, "" ); }
function rtrim(s) { return s.replace( /\s*$/, "" ); } 
function trim(s)  { return rtrim(ltrim(s)); }  
function emailCheck(seml) {
 var emailPat=/^(.+)@(.+)$/
 var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
 var validChars="\[^\\s" + specialChars + "\]"
 var quotedUser="(\"[^\"]*\")"
 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
 var atom=validChars + '+'
 var word="(" + atom + "|" + quotedUser + ")"
 var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
 var matchArray=seml.match(emailPat)
 var msg = "The form cannot be processed because\n";
 if (matchArray==null) {
	alert(msg + "the email address is invalid.");
	return false;
 }
 var user=matchArray[1];
 var domain=matchArray[2];
 if (user.match(userPat)==null) {
	alert(msg + "the email address is invalid.");
	return false;
 }
 var IPArray=domain.match(ipDomainPat);
 if (IPArray!=null) {
	for (var i=1;i<=4;i++) { if (IPArray[i]>255) {
	 alert(msg + "the email address is invalid.");
	 return false; }
	}
	return true;
 }
 var domainArray=domain.match(domainPat);
 if (domainArray==null) {
	alert(msg + "the email address is invalid.\n");
	return false;
 }
 var atomPat=new RegExp(atom,"g");
 var domArr=domain.match(atomPat);
 var len=domArr.length;
 if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
	alert(msg + "the email address is invalid.");
	return false;
 }
 if (len<2) {
	alert(msg + "the email address is invalid.");
	return false;
 }
 return true;
}
function checkValues(fmode) {
	var det = trim(document.contact.elements["detalii"].value);
	var nu = trim(document.contact.elements["nume"].value);
	var tel = trim(document.contact.elements["telefon"].value);	
	var ta = trim(document.contact.elements["tara"].value);
	var em = trim(document.contact.elements["emailc"].value);


 
	var ret = "The contact form cannot be processed because there are required fields which are not filed:\n\n";
	var cnt = 0;
	var sel = 0;
	
	if (fmode==1) {



	 if (det == "") {
		ret = ret + "- Please provide your details.\n"; 
		document.contact.elements["detalii"].focus(); sel = 1;
		if (isIE){document.contact.elements["detalii"].style.background="#CC9999";}
	 } else {
		cnt = cnt + 1; 
		if (isIE){document.contact.elements["detalii"].style.background="#ebebeb";}
	 }
	} else { cnt = cnt + 1; }

	

	if (nu == "") {
	 ret = ret + "- Please provide your name.\n";
	 if (sel != 1) document.contact.elements["nume"].focus(); sel = 1;
	 if (isIE){document.contact.elements["nume"].style.background="#CC9999";}
	} else {
	 cnt = cnt + 1;
	 if (isIE){document.contact.elements["nume"].style.background="#ebebeb";}
	}



	if (tel == "") {
	 ret = ret + "- Please provide your telefon.\n";
	 if (sel != 1) document.contact.elements["telefon"].focus(); sel = 1;
	 if (isIE){document.contact.elements["telefon"].style.background="#CC9999";} 
	} else {
	 cnt = cnt + 1;
	 if (isIE){document.contact.elements["telefon"].style.background="#ebebeb";}
	}
	

	if (ta == "") {
	 ret = ret + "- Please provide your country.\n";
	 if (sel != 1) document.contact.elements["tara"].focus(); sel = 1;
	 if (isIE){document.contact.elements["tara"].style.background="#CC9999";} 
	} else {
	 cnt = cnt + 1;
	 if (isIE){document.contact.elements["tara"].style.background="#ebebeb";}
	}
	



	if (em  == "") {
	 ret = ret + "- Please provide your e-mail address.\n";
	 if (sel != 1) document.contact.elements["emailc"].focus(); sel = 1;
	 if (isIE){document.contact.elements["emailc"].style.background="#CC9999";} 
	} else { 
	 if (emailCheck(em)) { 
	  cnt = cnt + 1;
	  if (isIE){document.contact.elements["emailc"].style.background="#ebebeb";} 
	 } else { 
	   document.contact.elements["emailc"].focus(); sel = 1; cnt = 6;
	   if (isIE){document.contact.elements["emailc"].style.background="#CC9999";}		
	 }
	}
	
	

	
 
	




	 

	if (cnt < 5) {
	 alert(ret); 	 
	 return false;
	} else { 
	 if (cnt == 5) { return true; } else { return false; }
	}
}