//	sterge spatiile de la inceput
function LTrim(value) {
	var re = /\s*((\S+\s*)*)/ ;
	return value.replace(re, "$1") ;
}

//	sterge spatiile de la sfarsit
function RTrim(value) {
	var re = /((\s*\S+)*)\s*/ ;
	return value.replace(re, "$1") ;
}

//	sterge spatiile de la inceput si de la sfarsit
function trim(value) {
	return LTrim(RTrim(value)) ;	
}

function my_$(element) {
  	return document.getElementById(element);  	 
}

function checkemail(id) {
	var testresults ;
	var str = my_$(id).value ;
	var filter=/^.+@.+\..{2,3}$/ ;
	
	if (filter.test(str))
		return true ;
	else		
		return false ;	
}

function validate_form_contact() {
	var nume = trim(my_$('nume').value) ;
	if (!nume) {
       	alert("Please complete the field 'Name' !!!") ;
		my_$('nume').focus() ;	
		return false;
	}
	if (nume.length > 255) {
		alert("Please complete the field 'Name' with maxim 255 characters !!!") ;
		my_$('nume').select() ;		
		return ;
	}
	
	var email = trim(my_$('email').value) ;
	if (!email) {
       	alert("Please complete the field 'E-mail address' !!!") ;
		my_$('email').focus() ;	
		return ;
	}
	if (email.length > 255) {
		alert("Please complete the field 'E-mail address' with maxim 255 characters !!!") ;
		my_$('email').select() ;		
		return ;
	}
	if (!checkemail('email')) {
		alert("Please complete the field 'E-mail address' with a valid e-mail address !!!") ;
		my_$('email').select() ;
		return ;
	}
	
	var tel = trim(my_$('tel').value) ;
	if (!tel) {
       	alert("Please complete the field 'Telephone' !!!") ;
		my_$('tel').focus() ;	
		return false;
	}
	if (tel.length > 255) {
		alert("Please complete the field 'Telephone' with maxim 255 characters !!!") ;
		my_$('tel').select() ;		
		return ;
	}
	
	var mesaj = trim(my_$('mesaj').value) ;
	if (mesaj.length > 30000) {
		alert("Please complete the field 'Message' with maxim 30000 characters !!!") ;
		my_$('mesaj').select() ;		
		return ;
	}
	
	my_$('form_contact').submit() ;
}