
function checkWholeForm(theForm)
{

	var why = "";
	why += isEmpty(theForm.name.value);
	why += checkPhone(theForm.tel.value);
	why += checkEmail(theForm.email.value);
	why += isEmpty(theForm.about.value);
	why += isEmpty(theForm.description.value);
	
	if (why != "")
	{
		alert(why);
		return false;
	}
	/*alert('Вашето запитване беше успешно изпратено');*/
	return true;
}

function isEmpty(strng)
{
	var error = "";
	if (strng == "") {
		error = "Има незапълнени полета.\n";
	}
	return error;
}

function checkPhone(strng)
{
	var error = "";
	if (strng == "") {
		error = "Има незапълнени полета.\n";
	}
	else
	{
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped)))
		{
			error = "Неправилен телефонен номер.\n";
		}
		
		/*if (!(stripped.length == 10)) {
			error = "The phone number is the wrong length.
			  Make sure you included an area code.\n";
		}*/
	}
	return error;
}

function checkEmail(strng)
{
	var error = "";
	if (strng == "") {
		error = "Има незапълнени полета.\n";
		return error;
	}
/*	var emailFilter='/^([a-zA-Z0-9_\.\-])+\at(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
	if (!(emailFilter.test(strng))) 
	{ 
		error = "Please enter a valid email address.\n";
		return error;
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) 
	{
		error = "The email address contains illegal characters.\n";
		return error;
	}*/
	var at="@"
	var dot="."
	var lat=strng.indexOf(at)
	var lstr=strng.length
	var ldot=strng.indexOf(dot)
	
	if (strng.indexOf(at)==-1)
	{
	   error = "Невалиден E-mail адрес \n";
	   return error
	}
	if (strng.indexOf(at)==-1 || strng.indexOf(at)==0 || strng.indexOf(at)==lstr)
	{
	   error = "Невалиден E-mail адрес \n";
	   return error
	}
	if (strng.indexOf(dot)==-1 || strng.indexOf(dot)==0 || strng.indexOf(dot)==lstr)
	{
	    error = "Невалиден E-mail адрес \n";
	    return error
	}
	if (strng.indexOf(at,(lat+1))!=-1)
	{
		error = "Невалиден E-mail адрес \n";
		return error
	}
	if (strng.substring(lat-1,lat)==dot || strng.substring(lat+1,lat+2)==dot)
	{
		error = "Невалиден E-mail адрес \n";
		return error
	}
	if (strng.indexOf(dot,(lat+2))==-1)
	{
		error = "Невалиден E-mail адрес \n";
		return error
	}
	if (strng.indexOf(" ")!=-1)
	{
		error = "Невалиден E-mail адрес \n";
		return error
	}
	return error
}
