function maskPhone(fldVal,objField)
{
    var isNamedFone;
    var keyCnt;
    var tmpStr = "(";

    keyCount = fldVal.length;
    keyEntered =fldVal.substring(keyCount-1,keyCount);

    if (keyCount <= 1)   isNamedFone = false;
    if (!isNamedFone) 
        keyCount++;

    switch (keyCount)
    {
        case 2: 
            tmpStr +=  fldVal;
            objField.value = tmpStr;
            break;

        case 5:
            objField.value += ")" ;
            break;

        case 9:
            objField.value += "-" ;
            break;//upto this general
    }

    keyvalue=window.event.keyCode;

    if(keyvalue < 48 || keyvalue > 57)
    {
        event.returnValue = false;
        if(document.all)
            window.event.keyCode=0;
            return false;
    }
}

function echeck(str)
{
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    
    if (str.indexOf(at) == -1)
    {
       alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
    {
       alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
    {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at,(lat+1)) != -1)
    {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot)
    {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot,(lat+2)) == -1)
    {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1)
    {
        alert("Invalid E-mail ID")
        return false
    }

    return true
}

//function to validate phone numbers
function ValidatePhone(objPhone)
{
	var sPhone = objPhone.value;
	
	var sValidPhone = "";
	var sFormatPhone = "";
	var sRegExp = "";
	sRegExp = /\(|\)|-/g

	sValidPhone = trim(sPhone.replace(sRegExp,""));

	if (sValidPhone > 0)
	{
	    FormatPhone(objPhone);
	    sPhone = objPhone.value;
		if (isUSPhoneNumber(sPhone) == false)
		{
			if (sValidPhone.length != 10)
			{
				alert("Please enter a valid Phone Number of 10 digits");
				objPhone.value = "";
				objPhone.focus();
				return false;
			}
			if (isNaN(sValidPhone) == true)
			{
				alert("Please enter a valid Phone Number of 10 digits");
				objPhone.value = "";
				objPhone.focus();
				return false;
			}
			if ((sValidPhone.indexOf(".") == -1) || (sValidPhone.indexOf("'") == -1) || (sValidPhone.indexOf('"') == -1))
			{
				alert("Please enter a valid Phone Number of 10 digits");
				objPhone.value = "";
				objPhone.focus();
				return false;
			}
			return true;
		}
	}
	else
	{
		if (sValidPhone.length > 0)
		{
			alert ("Please enter a valid Phone Number of 10 digits");
			objPhone.value="";
			objPhone.focus();
			return false;
		}
	}
}

function FormatPhone(objPhone)
{
	var sPhone = objPhone.value;
		
	if (isUSPhoneNumber(sPhone) == false)
	{
		var sValidPhone = "";
		var sFormatPhone = "";
		var sRegExp = "";
		sRegExp = /\(|\)|-/g
		sValidPhone = trim(sPhone.replace(sRegExp,""));
	
		if (sValidPhone.length == 10)
		{
			sFormatPhone = "(" + sValidPhone.substring(0,3) + ")"
			sFormatPhone = sFormatPhone + sValidPhone.substring(3,6) + "-" + sValidPhone.substring(6)
		}
		else
		{
			sFormatPhone = sPhone;
		}
		objPhone.value = sFormatPhone;
		return true;
	}
}

function trim(strInput)
{
// for trimLeft
	var strTemp = strInput
	while(strTemp.charAt(0) == " ")
	{
		strTemp = strTemp.slice(1);
	}
// for TrimRight
	var iLength = strTemp.length;
	iLength--;// accounts for zero based index
	while(strTemp.charAt(iLength) == " ")
	{
		strTemp = strTemp.slice(0,iLength--);
	}
	return strTemp;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

function isUSPhoneNumber(s)
{
	reDigit = /\(\d{3}\)\d{3}\-\d{4}$/
	
	if (reDigit.test(s) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}
