////////// Type your message
var clickedItCmt = false;
var firstCmt = true;
function cleartextareaCmt(id)
{
	if (clickedItCmt == false)
	{
		if(id.value!="Please type your message" || firstCmt==true)
		{
			id.value="";
			clickedItCmt=true; 
		}
	}
}	


function settextCmt(id)
{

    var txt= LTrim(id.value)
	if(id.value=="Please type your message" ||  txt=="")
		{
		id.value="Please type your message";
			clickedItCmt = false;
			}
}	


////////////////////////////////

////////// Email
var clickedItEml = false;
var firstEml = true;
function cleartextareaEml(id)
{
	if (clickedItEml == false)
	{
		if(id.value!="e-mail" || firstEml==true)
		{
			id.value="";
			clickedItEml=true; 
		}
	}
}	


function settextEml(id)
{

    var txt= LTrim(id.value)
	if(id.value=="e-mail" ||  txt=="")
		{
		id.value="e-mail";
			clickedItEml = false;
			}
}	


////////////////////////////////




////////// Name
var clickedItNme = false;
var firstNme = true;
function cleartextareaNme(id)
{
	if (clickedItNme == false)
	{
		if(id.value!="name" || firstNme==true)
		{
			id.value="";
			clickedItNme=true; 
		}
	}
}	


function settextNme(id)
{

    var txt= LTrim(id.value)
	if(id.value=="name" ||  txt=="")
		{
		id.value="name";
			clickedItNme = false;
			}
}	
function settextph(id)
{

    var txt= LTrim(id.value)
	if(id.value=="ph" ||  txt=="")
		{
		id.value="ph";
			clickedItNme = false;
			}
}	

////////////////////////////////



function LTrim(value) {
	
	//alert(value);
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

function trim( value ) {
	
	
	return LTrim(RTrim(value));
	
}


// Form Validation


function isValid()
{
	//if (document.formindex.name1.value=="name")
	//{
	//alert("Please enter your Name.");
	//document.formindex.name1.focus();
	//return false;
	//}
	
	    var txt= LTrim(document.formindex.name1.value)
		if((txt=="") || (document.formindex.name1.value=="name"))
		{
			alert("Please enter your Name.");
			document.formindex.name1.focus();
			return false;
		}
		if((txt=="") || (document.formindex.ph.value=="phone no."))
		{
			alert("Please enter your Phone No.");
			document.formindex.ph.focus();
			return false;
		}
		if(!validateString(document.formindex.name1.value))
		{
			alert("Name should not contain digits and special symbols.");
			document.formindex.name1.focus();
			return false;
		}
		
		
		txt= LTrim(document.formindex.email.value)
		if((txt=="") || (document.formindex.email.value=="e-mail"))
		{
			alert("Please enter your email address.");
			document.formindex.email.focus();
			return false;
		}
		
		
		 if(!isValidEmail(document.formindex.email.value))
         {	
			document.formindex.email.focus();
			document.formindex.email.select();
			return false;
		}
		
		
		txt= LTrim(document.formindex.request.value)
		if((txt=="") || (document.formindex.request.value=="Please type your message"))
		{
			alert("Please enter your Messaged.");
			document.formindex.request.focus();
			return false;
		}

		
		return true;
	
}


/// Email Valid Expression


function isValidEmail(emailStr) 
	{
			var checkTLD=1;
			var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		//	var emailPat=/^(.+)@(.+)$/;
			var emailPat=/^(.+)@(.+)$/;
			var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
			var validChars="\[^\\s" + specialChars + "\]";
			var quotedUser="(\"[^\"]*\")";
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
			var atom=validChars + '+';
			var word="(" + atom + "|" + quotedUser + ")";
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			var matchArray=emailStr.match(emailPat);
			if (matchArray==null) {
				//alert("Email address seems incorrect (check @ and .'s)");
				alert("Please enter valid Email address.");
				return false;
			}
			var user=matchArray[1];
			var domain=matchArray[2];
			// Start by checking that only basic ASCII characters are in the strings (0-127).
			for (i=0; i<user.length; i++) {
				//alert(user.charCodeAt(i))
				if (user.charCodeAt(i)<65) {
					if ((user.charCodeAt(i)<45)|| (user.charCodeAt>57)) {
				//	alert("Ths Email address contains invalid characters.");
					alert("Please enter valid Email address.");
					return false;
					}
				}
				
			}
			for (i=0; i<domain.length; i++) {
				if (domain.charCodeAt(i)>127) {
				//	alert("Ths Email address contains invalid characters.");
					alert("Please enter valid Email address.");
					return false;
				}
			}
			if (user.match(userPat)==null) {
			//	alert("The Email address doesn't seem to be valid.");
				alert("Please enter valid Email address.");
				return false;
			}
			var IPArray=domain.match(ipDomainPat);
			if (IPArray!=null) {
				for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						//alert("Email address is invalid!");
						alert("Please enter valid Email address.");
						return false;
					}
				}
				return true;
			}
			var atomPat=new RegExp("^" + atom + "$");
			var domArr=domain.split(".");
			var len=domArr.length;
			for (i=0;i<len;i++) {
				if (domArr[i].search(atomPat)==-1) {
					//alert("Email address does not seem to be valid.");
					alert("Please enter valid Email address.");
					return false;
			   }	
			}
			if (checkTLD && domArr[domArr.length-1].length!=2 && 
				domArr[domArr.length-1].search(knownDomsPat)==-1) {
				//alert("The address must end in a well-known domain or two letter " + "country.");
				alert("Please enter valid Email address.");
				return false;
			}
		
		// Make sure there's a host name preceding the domain.
		
			if (len<2) {
				//alert("This Email address is missing a hostname!");
				alert("Please enter valid Email address.");
				return false;
			}	
			return true;
	}

//////
    
	function valid1()
	{		
		if((trim(document.formindex.name1.value)=="") || (document.formindex.name1.value=="name"))
		{
			alert("Please enter your Name.");
			document.formindex.name1.focus();
			return false;
		}
		
		if(!validateString(document.formindex.name1.value))
		{
			alert("Name should not contain digits and special symbols.");
			document.formindex.name1.focus();
			return false;
		}
		
		if((trim(document.formindex.email.value)=="") || (document.formindex.email.value=="e-mail"))
		{	
			alert("Please enter your Email address.");
			document.formindex.email.focus();
			return false;
		}
	

		if(!isValidEmail(document.formindex.email.value))
		{				
			document.formindex.email.focus();
			document.formindex.email.select();
			return false;
		} 


		
		if((trim(document.formindex.request.value)=="") || (document.formindex.request.value=="Please type your message"))
		{	
		
			alert("Please enter your Message.");
			document.formindex.request.focus();
			return false;
		}

	}
	
	function validateString( strValue ) {
  var strMatchPattern =  /^[a-zA-Z\'\- ]+$/;

  var objRegExp = new RegExp( strMatchPattern);
	
	//check if string matches pattern
	return objRegExp.test(strValue);
}
	
