qm_create(0,false,0,500,false,false,false,false,false);

function formValidator()
{
	var txtName = document.getElementById('txtName');
	var txtDesign = document.getElementById('txtDesign');
	var txtEmail = document.getElementById('txtEmail');
	var txtCode = document.getElementById('txtCode');
	var txtPhone = document.getElementById('txtPhone');
	var txtSubject = document.getElementById('txtSubject');
	var txtMessage = document.getElementById('txtMessage');
	
	if(notEmpty(txtName, "Please enter your name"))
	{
		if(lengthRestriction(txtName, 5, 25))
		{				
			if(notEmpty(txtDesign, "Please enter your designation"))
			{
				if(emailValidator(txtEmail, "Please enter a valid email address"))
				{
					if(isNumeric(txtPhone, "Please enter a valid phone number"))
					{
						if(lengthRestriction(txtPhone, 7, 8))
						{
							if(isNumeric(txtCode,"Please enter a valid phoneline code"))
							{
								if(lengthRestriction(txtCode, 2, 3))
								{
									if(notEmpty(txtSubject,"Please enter subject"))
									{
										if(lengthRestriction(txtSubject, 5, 40))
										{
											if(notEmpty(txtMessage,"Please enter message"))
											{
												if(lengthRestriction(txtMessage, 10, 1000))
												{
													return true;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return false;
}
		  
function notEmpty(elem, helperMsg)
{
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg)
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg)
{
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max)
{
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max)
	{
		return true;
	}
	else
	{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg)
{
	if(elem.value == "Please Choose")
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function emailValidator(elem, helperMsg)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}	
