// JavaScript Document
var whitespace = " \t\n\r";
function charInString (c, s)
{
    for( i = 0 ; i < s.length ; i++ )
    {   
		if( s.charAt(i) == c ) return true;
    }
    return false;
}
function stripInitialWhitespace (s)
{
    var i = 0;
    while( (i < s.length) && charInString(s.charAt(i), whitespace) )
    {
	   i++;
    }
    return s.substring (i, s.length);
}
function trim( str )
{
	for( lspace=0 ; lspace<str.length ; lspace++ )
		if( str.charAt(lspace)!=' ' )
			break;
	str = str.substring( lspace );
	for( rspace=str.length-1 ; rspace>=0 ; rspace-- )
		if( str.charAt(rspace)!=' ' )
			break;
	str = str.substring( 0, rspace+1 );
	return str;
}
function checkEmail()
{
	var t1 = trim(form1.Email.value);
	invalidChars = " /:~!#$%^&*()+|{}[]'";
	for (i=0; i < invalidChars.length; i++) 
	{
		badChar = invalidChars.charAt(i);
		if (t1.indexOf(badChar,0) != -1) 
		{
			alert('In Email Address ' + badChar + ' is not allowed.\nPlease Enter Again.');
			form1.Email.focus();
			return false;
		}
	}
	atPos = t1.indexOf('@', 1);
	periodPos = t1.lastIndexOf('.');
	
	if( atPos == -1 || periodPos == -1 || ((periodPos+2)>(t1.length-1)) ) 
	{
		alert('Invalid EMAIL Address.\nPlease Enter Again.');
		form1.Email.focus();
		return false;
	}
	else
		return true;
}
function check()
{
	if(trim(form1.UName.value)=="")
	{
		alert("Please fill in your Contact Name.");	
		form1.UName.value = "";
		form1.UName.focus();
		return false;
	}
	else
	{
		if(!isValidName(trim(form1.UName.value)))
		{
			alert("Please enter only Alphabets.");
			form1.UName.focus();
			return false;
		}
	}
	
	if(trim(form1.Email.value)=="")
	{
		alert("Please fill in the Email");	
		form1.Email.value = "";
		form1.Email.focus();
		return false;
	}
	else
	{
		if( !checkEmail())
			return false;
	}
	if(stripInitialWhitespace(form1.comments.value)=="")
	{
		alert("Please fill in the value.");	
		form1.comments.value = "";
		form1.comments.focus();
		return false;
	}
	if(stripInitialWhitespace(form1.comments.value).length>2000)
	{
		alert('Please enter maximum 2000 characters.');
		return false;
	}
	return true;
}
function isValidName( str )
{
	for( i=0 ; i<str.length ; i++ )
	{
		if( !((str.charAt(i)>='a' && str.charAt(i)<='z') || (str.charAt(i)>='A' && str.charAt(i)<='Z') || (str.charAt(i)==' ')|| (str.charCodeAt(i)==39) ) )
			return false;
	}
	return true;
}