/*function validName(theField)
{
	alert("name : "+theField);
	var theInput=theField;
	//alert("your nameggggg : "+theInput);
	var theLength=theInput.length;
	//var goodname=true;
	
	if(theField.value==""){goodname=false;}
	if(theLength<3 && theLength!="0"){goodname=false;}
	 
	for(var j=0;j<theLength;j++)
	{
	  var theChar=theInput.substring(j,j+1);
	  var theChar2=theInput.substring(j+1,j+2);
		
 	  if((theChar < "a"  && theChar !=" ") && (theChar < "A" && theChar !=" ")){goodname=false;}

	  if((theChar > "z" && theChar !=" ") && (theChar > "z" && theChar !=" ")){goodname=false;}

	  if(theChar== " " && theChar2==" " ){goodname=false;}

	  if(theChar== " " && j<1){goodname=false;}
	
	  if(theChar== "^"){goodname=false;}
        
        }

	if(goodname==false)
	{
	   alert("Invalid Name String"); 
	   return false;
	}
}*/
function rm_trim(inputString){
	if (typeof inputString != "string") { return inputString;}

	var temp_str = '';
	temp_str = inputString.replace(/[\s]+/g,"");
	if(temp_str == '')
		return "";
	
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " "){
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " "){
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1){
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

function isEmail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var ldot=str.indexOf(dot);
	var lstr=str.length;
	var extBody = str.split('.')

	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(" ")!=-1){
		return false;
	}
	if(str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if(str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if(extBody[1] == ''){
		return false;
	}
	return true;
}

function sendMail(){
	var cName 	= document.getElementById("textfield").value;
	cName		= rm_trim(cName);
	if(cName == ''){
		var str  = 'Provide relevant information for this field.';
		str 	+= "\n-------------------------------------------------\n";
		str 	+= "Please enter your name.";
		alert(str);
		document.getElementById("textfield").value = '';
		document.getElementById("textfield").focus();
		return false;
	}
	var emailId = document.getElementById("textfield5").value; 
	emailId		= rm_trim(emailId);
	if(emailId == ''){
		var str  = 'Provide relevant information for this field.';
		str 	+= "\n-------------------------------------------------\n";
		str 	+= "Please enter your email.";   
		alert(str);
		document.getElementById("textfield5").value = '';
		document.getElementById("textfield5").focus();
		return false;
	}
	else{
		var msg = isEmail(emailId);
		
		if(msg == false){
			var str  = 'Provide relevant information for this field.';
			str 	+= "\n-------------------------------------------------\n";
			str 	+= "Please enter your correct email.";   
			alert(str);			
			document.getElementById("textfield5").select();
			return false;
		}
	}
	var comment = document.getElementById("textarea").value; 
	comment		= rm_trim(comment);
	if(comment == ''){
		var str  = 'Provide relevant information for this field.';
		str 	+= "\n-------------------------------------------------\n";
		str 	+= "Please enter your Comment.";   
		alert(str);
		document.getElementById("textarea").value = '';
		document.getElementById("textarea").focus();
		return false;
	}

}