// This function would be used for email validation
function ValidateEmail(txtemail)
{
    // check if the client has provided an email...
    var email = trims(txtemail.value);
    if (email == "") return true;

    for (var i = 0; i < email.length; i++)
    {
        var chr = email.charAt(i);

        if (!(((chr >= 'a') && (chr <= 'z')) || ((chr >= 'A') && (chr <= 'Z')) ||
            (chr == '.') || (chr == '@') || (chr == '_') || (chr == '-') ||
            ((chr >= '0') && (chr <= '9'))))
        {
            alert("Please specify a valid email address.");
            txtemail.focus();
            return false;
        }
    }
    if ((email == "") || (email.indexOf('@', 0) == -1) ||
        (email.indexOf('@', 0) == 0) || (email.indexOf('.', 0) == -1) ||
        (email.indexOf('.', 0) == (email.length - 1)) ||
        (email.indexOf('@', 0) == (email.length - 2)) ||
        (email.charAt(0) == '.') || (email.charAt(email.length - 1) == '.'))
    {
        alert("Please specify a valid email address.");
        txtemail.focus();
        return false;
    }
    // Added by Riz... 241201 checking for invalid emails due to '.' placement
    var temp = email.substring(email.indexOf('@', 0) + 1, email.length);

    if (temp.length > 2)
    {
        if (temp.indexOf('.', 1) == -1)
        {
            alert("Please specify a valid email address.");
            txtemail.focus();
            return false;
        }
        else
        {
            if (temp.indexOf('.', 1) == temp.length - 1)
            {
	            alert("Please specify a valid email address.");
                txtemail.focus();
	            return false;
            }
        }
    }
    else
    {
        alert("Please specify a valid email address.");
        txtemail.focus();
        return false;
    }

    var charIndex = email.indexOf('@', 0);
    if (email.indexOf('@', charIndex + 1) != -1)
    {
        alert("Please specify a valid email address.");
        txtemail.focus();
        return false;
    }
    else
    {
        charIndex = email.indexOf('@', 0);
        if (email.charAt(charIndex - 1) == '.')
        {
            alert("Please specify a valid email address.");
            txtemail.focus();
            return false;
        }
    }
    // This case checks that 2 dots can't be consective
    var previousChar;
    var currentChar;

    for (var i = 0; i < email.length; i++)
    {
        currentChar = email.charAt(i);
        if (currentChar == '.')
        {
            if (currentChar == previousChar)
            {
	            alert("Please specify a valid email address.");
                txtemail.focus();
	            return false;
            }
        }
        previousChar = currentChar;
    }
    return true;
}
function checkEmailAddress(email,JAlertSpecifyEmailAddress,JAlertInvalidEmailAddress)
{
	// check if the client has provided an email...
	if (email == "") {
		alert (JAlertSpecifyEmailAddress);
		return false;
	}
	
	for (var i = 0; i < email.length; i++)
	{
		var chr = email.charAt(i);

		if (!(((chr >= 'a') && (chr <= 'z')) || ((chr >= 'A') && (chr <= 'Z')) ||
			(chr == '.') || (chr == '@') || (chr == '_') || (chr == '-') ||
			((chr >= '0') && (chr <= '9'))))
		{
			alert(JAlertInvalidEmailAddress);
			return false;
		}
	}
	if ((email == "") || (email.indexOf('@', 0) == -1) ||
		(email.indexOf('@', 0) == 0) || (email.indexOf('.', 0) == -1) ||
		(email.indexOf('.', 0) == (email.length - 1)) ||
		(email.indexOf('@', 0) == (email.length - 2)) ||
		(email.charAt(0) == '.') || (email.charAt(email.length - 1) == '.'))
	{
		alert(JAlertInvalidEmailAddress);
		return false;
	}
	// Added by Riz... 241201 checking for invalid emails due to '.' placement
	var temp = email.substring(email.indexOf('@', 0) + 1, email.length);

	if (temp.length > 2)
	{
		if (temp.indexOf('.', 1) == -1)
		{
			alert(JAlertInvalidEmailAddress);
			return false;
		}
		else
		{
			if (temp.indexOf('.', 1) == temp.length - 1)
			{
				alert(JAlertInvalidEmailAddress);
				return false;
			}
		}
	}
	else
	{
		alert(JAlertInvalidEmailAddress);
		return false;
	}

	var charIndex = email.indexOf('@', 0);
	if (email.indexOf('@', charIndex + 1) != -1)
	{
		alert(JAlertInvalidEmailAddress);
		return false;
	}
	else
	{
		charIndex = email.indexOf('@', 0);
		if (email.charAt(charIndex - 1) == '.')
		{
			alert(JAlertInvalidEmailAddress);
			return false;
		}
	}
	// This case checks that 2 dots can't be consective
	var previousChar;
	var currentChar;

	for (var i = 0; i < email.length; i++)
	{
		currentChar = email.charAt(i);
		if (currentChar == '.')
		{
			if (currentChar == previousChar)
			{
				alert(JAlertInvalidEmailAddress);
				return false;
			}
		}
		previousChar = currentChar;
	}
	return true;
}

// This function would be used for verifying the password and confirm password fields...
function VerifyPassword(password, confirmPassword,message1,message2,message3)
{
	if (trims(password.value) == "")
	{
		alert(message1);
		password.value = "";
		confirmPassword.value = "";
		password.focus();
		return false;
	}
	//fd 5-25-2010
	//if (trims(password.value).length < 8)
	if (trims(password.value).length < 4)
	{
		alert(message2);
		password.value = "";
		confirmPassword.value = "";
		password.focus();
		return false;
	}
	if (password.value != confirmPassword.value)
	{
		alert(message3);
		password.value = "";
		confirmPassword.value = "";
		password.focus();
		return false;
	}
	return true;
}	// End of function

/*
// This function would be used for text field validation
function CheckInValidChars(object)
{
	testString = new String;
	testString = object;
	var regX = /{/gi;
	var Position;
	Position = testString.search(regX);
	if ( Position > -1 )
	{
		alert("Invalid Character '{' at position " +  Position );
		return false;
	}
	return true;
}	// End of function
*/


function CheckInValidChars(name,field,pattern,message	)
{
	var test = new String;
	test = name;
	var regEx;   // Create variable.
	var  regEx = new RegExp(pattern);   // Create a regular expression.
		
	ichar = regEx.exec(test);
	ipos = test.search(regEx);
	if (ipos > -1)	
	{
		alert(message);
		return false;
	}
	return true;
}

function isValidPhone(phone) 
{
	if (phone.length != 14) return false;
	if (phone.charAt(0) != '(') return false;
	if (phone.charAt(4) != ')') return false;
	if (phone.charAt(5) != ' ') return false;
	if (phone.charAt(9) != '-') return false;
	return true;
}

function isValidNumber(number) 
{
	var chr;
	for(var i=0;i<number.length;i++ ) {
		chr=number.charAt(i);
		if(chr< '0' || chr>'9') {
			return false;
		}
	}
	return true;
}

function isValidAlphanumeric(number) 
{
	var chr;
	for(var i=0;i<number.length;i++ ) {
		chr=number.charAt(i);
		if (!((chr>='0' && chr<='9') || (chr>='A' && chr <='Z' || chr>='a' && chr <='z'))) {
			return false;
		}
	}
	return true;
}

function isValidDecimalNumber(number1) 
{
	var chr;
	
	num = new String (number1);
	occurance = new Number(0);
	for(var i=0;i<num.length;i++ ) {
		chr=num.charAt(i);
		if(chr< '0' || chr>'9' ) {
			if (chr=='.'){
				occurance = occurance + 1;
				if(occurance>1){
					return false;
				}
			}else{
				return false;
			}
		}
	}
	return true;
}

function GetDate()
{
var m_TODAY = new Date();
var m_Day = m_TODAY.getDate();
var m_Month = (m_TODAY.getMonth()+1)
var MY_DATE = m_Month + "/" + m_Day + "/" + m_TODAY.getYear();

return MY_DATE;
}