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){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}

function submit_cform()
{	
	if (document.getElementById('w_name').value.length == 0 || document.getElementById('w_message').value.w_message == 0 || document.getElementById('sec_code').value.length == 0)
	{
		document.getElementById('e_error').innerHTML='Error: All fields are mandatory!'; 
		return false;				
	}
	
	if (!echeck(document.getElementById('w_email').value)) 
	{
		document.getElementById('e_error').innerHTML='Error: Valid email address is required!'; 
		return false;
	};	

	JsHttpRequest.query('/contacts.php', 
		{
			'email': document.getElementById('w_email').value, 
			'name': document.getElementById('w_name').value,
			'body': document.getElementById('w_message').value,
			'sec_code': document.getElementById('sec_code').value
		}, 
		function (result, errors) {
			if (result) 
				{
					if (result['res'] == 1)
					{
						document.getElementById('c_body').style.display = 'none';
						document.getElementById('e_error').innerHTML='Request send!'; 
					}	
					else if (result['res'] == 2)
					{
						document.getElementById('e_error').innerHTML='Error: All fields are mandatory!'; 
					}
					else if (result['res'] == 3)
					{
						document.getElementById('e_error').innerHTML='Error: Wrong security code!'; 
					}
					
						
				}
		}, true); 
	
	return false; 	
}