
function ValidPhoneNumber(phone)
{
   if(phone.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format (Ex: 123-456-7890).");
      return false;
   }
   else
   {
   	return true;
   }
}

function filterInput(e) {
	regAllow = (e)?eval(e.allow):eval(event.srcElement.allow);
		if (event.keyCode == 13) { } else {
			if (!String.fromCharCode(event.keyCode).match(regAllow)) event.returnValue=false;
		}
	}

function isValidEmail(emstr)
	{
	var vEMailID=emstr
	var atPos= vEMailID.indexOf("@") + 1
	var lastDotPos= vEMailID.lastIndexOf(".") + 1
	var firstDotPos = vEMailID.indexOf(".") + 1
	var atInstances=0
	var dotInstances=0
	var inValid = new Array()
	var errorMessages = new Array()
	var errNo = 0
		
	for(var i=0;i<vEMailID.length;i++)
		{   
		if(vEMailID.charAt(i)=="@" )
		   atInstances+=1
		else if(vEMailID.charAt(i)==".")
		   dotInstances=1
		}

	inValid[errNo] = (atInstances==0)
	errorMessages[errNo] = "@ symbol is missing"
	errNo++

	inValid[errNo] = (dotInstances==0)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (atInstances>1)
	errorMessages[errNo] = "@ symbol should not repeat"
	errNo++

	inValid[errNo] = (Math.abs(firstDotPos-atPos)==1)
	errorMessages[errNo] = "@ and . symbols can't come together"
	errNo++

	inValid[errNo] = ((lastDotPos-atPos)<=1)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (atPos==vEMailID.length)
	errorMessages[errNo] = "@ symbol can't appear at end"
	errNo++

	inValid[errNo] = (lastDotPos==vEMailID.length)
	errorMessages[errNo] = ". symbol can't appear at end"
	errNo++

	inValid[errNo] = (atPos==0)
	errorMessages[errNo] = "@ symbol is missing"
	errNo++

	inValid[errNo] = (atPos==1)
	errorMessages[errNo] = "@ symbol should not appear at first position"
	errNo++

	inValid[errNo] = (firstDotPos==0)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (firstDotPos==1)
	errorMessages[errNo] = ". symbol should not appear at first position"
	errNo++

	inValid[errNo] = (vEMailID.indexOf(" ")>=0)
	errorMessages[errNo] = "E-mail can't contain blank spaces."
	errNo++

	inValid[errNo] = (vEMailID.indexOf("/")>=0) || (vEMailID.indexOf("\\")>=0)
	errorMessages[errNo] = "E-mail can't contain \\ or /"
	errNo++

	var fullErrorMessage = "Invalid " + name + " email address.\n"
	for(var ind=0; ind<errNo; ind++)
	{
		if(inValid[ind])
		{
			fullErrorMessage += errorMessages[ind] + "\n"
			alert(fullErrorMessage)			
			return false
		}
	}
		var SingleQuotePos = vEMailID.indexOf("'") 
		if(SingleQuotePos!=-1)
		{
					alert("Enter valid characters.Single Quotes ( ' ) are not allowed.")					
					return false

		} 
	return true;
	}


function trim(inputString) 
	{
	if (typeof inputString != "string") 
		{
		return inputString; 
		}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{ // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	//while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	//retValue = retVal
	//}
	return retValue;
	}
	

function accountValidation(frm1)
	{ 
	//alert(frm1.email.value); return false;

	
	if(!isValidEmail(frm1.email.value))
		{
		frm1.email.focus();
		return false;
		}

	if(trim(frm1.account_loginname.value).length < 1)
		{
		alert("Login name must be at least 1 characters.");
		frm1.account_loginname.value=trim(frm1.account_loginname.value);
		frm1.account_loginname.focus();
		return false;	
		}

	if(trim(frm1.account_password.value).length < 6)
		{
		alert("Password must be at least 6 characters");
		frm1.account_password.value=trim(frm1.account_password.value);
		frm1.account_password.focus();
		return false;
		}
	
	if(trim(frm1.account_password2.value).length < 6)
		{
		alert("Password must be at least 6 characters");
		frm1.account_password2.value=trim(frm1.account_password2.value);
		frm1.account_password2.focus();
		return false;	
		}		

	if(trim(frm1.account_password.value)!== trim(frm1.account_password2.value))
		{
		alert("Passwords mismatched");
		frm1.account_password.value="";
		frm1.account_password2.value="";
		frm1.account_password.focus();
		return false;	
		}

	if(trim(frm1.aname.value).length < 6)
		{
		alert("Please specify name.");
		frm1.aname.value=trim(frm1.aname.value);
		frm1.aname.focus();
		return false;	
		}

	return true;
	}



