function trim(str) { 
     str = str.replace( /^\s+/g, "" ); // strip leading 
     str = str.replace( /\s+$/g, "" ); // strip trailing 

     return str; 
} 
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Adresa e-mail incorecta. Va rugam corectati")
		    return false
		 }

 		 return true					
}


function httpcheck(str1) {

		var sir="http:"
		if (str1.indexOf(sir) >= 0){
		   alert("Numele si telefonul nu pot contine \"http:\"")
		   return false
		}
 		 return true					
}

function validate_form()
{
var _divnume = document.getElementById("divnume");
var _divemail = document.getElementById("divemail");
var _divmesaj = document.getElementById("divmesaj");
var _divtel = document.getElementById("divtel");

	valid = true;
	var emailID=document.oemProSubscription.FormValue_Email;
    var numeID=document.oemProSubscription.FormValue_CustomField5;
	var telID=document.oemProSubscription.FormValue_CustomField6;    
		if ( trim(document.oemProSubscription.FormValue_CustomField5.value) == "" )
        {
                valid = false;
				_divnume.style.color = "#FF0000";
        } else _divnume.style.color = "#000000";
		if ( trim(document.oemProSubscription.FormValue_CustomField6.value) == "" )
        {
                valid = false;
				_divtel.style.color = "#FF0000";
        } else _divtel.style.color = "#000000";
		if ( trim(document.oemProSubscription.FormValue_Email.value) == "" )
        {
                valid = false;
				_divemail.style.color = "#FF0000";
        } else _divemail.style.color = "#000000";
		if ( trim(document.oemProSubscription.mesaj.value) == "" )
        {
                valid = false;
				_divmesaj.style.color = "#FF0000";
        } else _divmesaj.style.color = "#000000";
		
		if ( valid == false ) {alert ( "Va rugam sa completati toate campurile obligatorii" ); }
		else {
			   if (echeck(emailID.value)==false)
			   {
				emailID.focus();
				valid = false;
				_divemail.style.color = "#FF0000";
			   }
			   else {
			   			if (httpcheck(numeID.value)==false)
						{
						numeID.focus();	
						valid = false;
						_divnume.style.color = "#FF0000";
						}
						else {
			   					if (httpcheck(telID.value)==false)
								{
								telID.focus();	
								valid = false;
								_divtel.style.color = "#FF0000";
								}
						     }	
				    }	
		    }
return valid;
}
