// JavaScript Document
function CheckEmailAddress(txtBox,txtMsg) 
{
	
	var email = txtBox.value;
	txtMsg="";

	if(email == "") {
		txtMsg="\nEmail address can not be left blank."
		return txtMsg;
	}
	var exclude=/[^@\-\.\w\_]|^[_@\.\-\_]|[\._\-\_]{2}|[@\.\_]{2}|(@)[^@\_]*\1/;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	
//	alert(email.search(exclude));
	// Are there any invalid characters in the address?
	if((email.search(exclude) != -1) || (email.search(checkend) == -1)) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	atPos = email.indexOf("@",0);
	pPos1 = email.indexOf(".",0);
	periodPos = email.indexOf(".",atPos);

	// Are there consecutive periods?
	pos1 = pPos1;
	pos2 = 0;
	while (pos2 > -1) {
		pos2 = email.indexOf(".",pos1+1);
		if (pos2 == pos1+1) {
			txtMsg="Please enter a valid Email address.";
			return txtMsg;
		} else {
			pos1 = pos2;
		}
	}

	// Is there an @ symbol in the address?
	if (atPos == -1) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Is the @ symbol in the first position?
	if (atPos == 0) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Is there a period in the first position?
	if (pPos1 == 0) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Is there more than one @ symbol in the address?
	if(email.indexOf("@",atPos+1) > -1) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Is there a period after the @ symbol?
	if (periodPos == -1) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Is the period imediately after the @ symbol?
	if (atPos+1 == periodPos) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}

	// Are there at least 2 characters after the period?
	if (periodPos+3 > email.length) {
		txtMsg="Please enter a valid Email address.";
		return txtMsg;
	}
	return txtMsg;
}

function onlyAlphabets(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
// control keys
if ((keynum==null) || (keynum==0) || (keynum==8) || 
    (keynum==9) || (keynum==13) || (keynum==27) )
   return true;
else if((keynum>=65 && keynum<=91) || (keynum>=97 && keynum<=122))
	return true;
else if((keychar==" "))
	return true;
else if ((keychar == "."))
   return false;
else if ((keychar == "-"))
   return false;   
else
   return false;
}

function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
//numcheck = /\d/;
//return !numcheck.test(keychar);
//keychar = String.fromCharCode(keynum);
//alert(keychar);
// control keys
if ((keynum==null) || (keynum==0) || (keynum==8) || 
    (keynum==9) || (keynum==13) || (keynum==27) )
   return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if ((keychar == "."))
   return false;
else if ((keychar == "-"))
   return false;   
else
   return false;
}

function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;

}

function CheckAlphabetsNumeric(txtBox,txtMsg)
{
	//1st argument is the Textbox object
	//2nd argument is the Message to be shown
	//remaining are the arguments for special characters which are to be included
	
	var str = txtBox.value;	
	var i, j;
	
	if (str == "")
	{
		txtMsg = "Cannot be Blank .\nPlease Re-Enter Your Data."
		return false;
	}
	
	if (str.charAt(0)==" ")
	{
		txtMsg = "Cannot start with blank"
		return false;
	}
	
	if (str.indexOf("'") >= 0 || str.indexOf('"') >= 0)
	{
		txtMsg = " Cannot Contain Quots.\nPlease Re-Eenter Your Data."
		return false;
	}
	
	//to create the condition fo special characters to be included
	var args = CheckAlphabetsNumeric.arguments
	var strCondition, ch
	
	strCondition = "";
	ch="";
	
	for (i = 0; i < str.length; i++)
	{
		ch = str.substring(i, i + 1);
		
		for (j=2; j< args.length; j++)
		{
			if (strCondition == "")
			{
				strCondition = '("' + ch + '" != "' + args[j] + '")'
			}
			else
			{
				strCondition = strCondition + ' && ("'  + ch + '" != "' + args[j] + '")'
			}
		}

		//&& (ch!="7") && (ch!="8") && (ch!="9")
		//alert(((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) + " " + ch)
		//alert((ch < "0" || "9" < ch) + " " + ch)
		//alert(eval(strCondition) + " " + ch)
		
		strCondition = (strCondition != "")?"(" + strCondition + ")":"('" + ch + "' != null)"
	//	alert(strCondition)
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && eval(strCondition))
		{
			txtMsg="You Have Entered Invalid Characters!\nSpecial Characters are Not Allowed."
			return false;
		}
		strCondition = "";
	}
	return true;
}

function Trim(strString, strTrimType)
{
	//trim Trailing Spaces
	while('' + strString.charAt(strString.length - 1) == ' ') 
	{
		strString = strString.substring(0, strString.length - 1);
	}
	
	//trim Leading Spaces
	while('' + strString.charAt(0) == ' ')
	{
		strString = strString.substring(1, strString.length);
	}
	
	return strString;
}

function IsAllSpace(strField)
{

	for(i=0;i<strField.length;i++)
	{
		if(strField.charAt(i) != " " )
		{
			return false;
		}
	}
	return true;
}


//===========================================================
// 		Check Special Character 
//=========================================================== 

function IsSpecialChar(strField)
{
	var strFieldVal=strField.value;	
	var i;
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

  for (var i = 0; i < strFieldVal.length; i++) {
  	if (iChars.indexOf(strField.value.charAt(i)) != -1) {
  	//alert ("Special characters not allowed");
  	return true;
  	}
  }
  return false;
}