var strErrorMessage="";
var isError=false;

function checkSupportForm()
{
	strErrorMessage="";
	isError=false;
	checkUserInfor();
	checkDropdownlist(document.getElementById("dpSupport"),"Type of Support");
	
	if(isError)
	{
		document.getElementById("showErrorMessage").innerHTML= strErrorMessage;
		return false;
	}
	return true;
}

function checkContactForm()
{
	strErrorMessage="";
	isError=false;
	checkUserInfor();
	
	if(isError)
	{
		document.getElementById("showErrorMessage").innerHTML= strErrorMessage;
		return false;
	}
	return true;
}

function checkUserInfor()
{
	if(checkText(document.getElementById("txtFirstName").value,"First Name"))
	{
		checkName(document.getElementById("txtFirstName").value,"First Name");
	}	
	
	if(checkText(document.getElementById("txtLastName").value,"Last Name"))
	{
		checkName(document.getElementById("txtLastName").value,"Last Name");
	}
	
	if(checkText(document.getElementById("txtEmail").value,"Email"))
	{
		checkEmail(document.getElementById("txtEmail").value);
	}
	
	if(checkText(document.getElementById("txtTitle").value,"Title"))
	{
		checkTextLengh(document.getElementById("txtTitle").value,20,"Title");
	}
	
	if(checkText(document.getElementById("txtPhone").value,"Cell/Phone"))
	{
		checkPhone(document.getElementById("txtPhone").value);
	}
	
	if(checkText(document.getElementById("txtCompany").value,"Company"))
	{
		checkTextLengh(document.getElementById("txtCompany").value,25,"Company");
	}
	
	if(checkText(document.getElementById("txtCity").value,"City"))
	{
		checkTextLengh(document.getElementById("txtCity").value,10,"City");
	}
	
	if(checkText(document.getElementById("txtMessage").value,"Message"))
	{
		checkTextLengh(document.getElementById("txtMessage").value,3000,"Message");
	}
}

function checkDropdownlist(dpDownlist,strControlName)
{
	if( ""== dpDownlist.options[dpDownlist.selectedIndex].value)
	{
		buildError(strControlName + " can not be null.");
		return false;
	}
	return true;
}

 /**
 * Check strText
 */ 
function checkText(strText,strControlName)
{
    strText=trim(strText);
	if(strText=="")
	{
	  buildError(strControlName+" can not be null."); 
	  return false;
	}
	return true;
}

 /**
 * Build Error message.
 */ 
function buildError(strError)
{
	strErrorMessage=strErrorMessage+ "* " + strError +"<br>";
	if(!isError)
	{
		isError=true;
	}
}

 /**
 * Check Name. z-z or A-Z, just 15 chars
 */ 
 function checkName(strText,strControlName) 
 { 
 strText=trim(strText);
 var patrn=/^[a-zA-Z]{1,15}$/; 
 if (!patrn.exec(strText)) 
 	{
		buildError(strControlName+" should be 15 a-z or A-Z.");
 		return false ;
	}
 return true
 }
  
 function checkPhone(strText)
 {
  strText=trim(strText);
  var patrn=/^([0-9]|[-]){1,20}$/;  
  if (!patrn.exec(strText)) 
 	{
		buildError("Cell/Phone should be numbers");
 		return false ;
	}
  return true
 }
 
 function checkEmail(strText)
 {
  strText=trim(strText);
   var patrn=/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;  
  if (!patrn.exec(strText)) 
 	{
		buildError("Email format error.");
 		return false ;
	}
  return true
 }
 
 function checkTextLengh(strText,nLength,strControlName)
 {
 strText=trim(strText);
/*  var strTemp="^\\w{1,"+ nLength +"}$";
  var patrn=new RegExp(strTemp); */
  
  if (strText.length>nLength) 
 	{
		buildError(strControlName + " should be less than " + nLength + " characters.");
 		return false ;
	}
  return true
 }
 
 /**
 * Trims leading and trailing whitespaces.
 */ 
function trim(strText) {
   var temp = strText;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { 
     temp = temp.replace(obj, '$2'); 
   }
   return temp;
}