
/********************************************************************
	Functions needed to implement validation
********************************************************************/

	/********************************************************
	Function: addProps
	Purpose:	Adds an area to be validated for an element.
		The strProperty, varValue section can be continued
		optionally to add multiple properties with one call.
	********************************************************/
function addProps(objElement, strProperty, varValue){
	if (!objElement) return;
	if (!objElement.validationProps) objElement.validationProps = new Array();

	for (i=1;i<arguments.length;i+=2)
		objElement.validationProps[arguments[i]] = arguments[i + 1];

	//objElement.validationProps[strProperty] = varValue;
}
/********************************************************************
********************************************************************/
/********************************************************************
	Traditional data validation functions. Take care when modifying
	parameters or return values, these are used below.
********************************************************************/

	//returns true if value is a number, else false
function isNumeric(varValue){
	return (!isNaN(varValue));
}

	//returns boolean indicating that varValue is numeric and contains no more than intNumDecimalsAllowed decimal places
function allowedDecimals(varValue, intNumDecimalsAllowed){
	if (isNaN(varValue)) return false;
	return (!(idx = String(varValue).indexOf(".") + 1) ? true : (varValue.substr(idx).length <= intNumDecimalsAllowed));
}

	//returns a Number value of the value passed in after stripping dollar signs and commas
function rootValue(varValue){
	return Number(String(varValue).replace(/\$/g, "").replace(/\,/g, ""));
}

	//returns a formatted ($#,###.##) string of the currency passed in, or empty string if not valid currency
function formatCurrency(curValue, blnShowDollarSign, blnShowCommas){
	var strUse = trim(String(curValue).replace(/\$/g, "").replace(/\,/g, ""));
	if (strUse.length==0) return "";							//short circuit on no value
	if (!allowedDecimals(strUse, 2)) return "";		//short circuit when not valid currency

	strUse = String(Math.round(Number(strUse) * 100));
	if (strUse=="0") return (blnShowDollarSign? "$" : "") + "0.00";

	var iLen = strUse.length - 2;
	var strChange = strUse.substr(iLen);
	var strDollars = strUse.substr(0, iLen)

	if (blnShowCommas && (iLen >= 3)){
		var numCommas = Math.round((iLen - 1) / 3 - .5);
		var retValue = "";

		for (i=1; i<=numCommas; i++){
			retValue = "," + strDollars.substr(iLen - i * 3, 3) + retValue;
		}
		retValue = strDollars.substr(0, iLen - numCommas * 3) + retValue;
		return (blnShowDollarSign? "$" : "") + retValue + "." + strChange;
	}else{
		return (blnShowDollarSign? "$" : "") + (iLen==0 ? "0" : strDollars) + "." + strChange;
	}
}

	//returns boolean indicating parameter is a valid currency
function isCurrency(curValue){
	return (formatCurrency(curValue, false, false).length > 0);
}

	//returns boolean indicating parameter is a valid military time
function formatMTime(timeStr){
	if(!timeStr) return '';
	if(timeStr.replace(/^(([01][0-9])|([2][0-3])):?([0-5][0-9])$/, '').length != 0) return '';
	var stringTime = timeStr.replace(':','');
	return stringTime.substr(0,2) + ":" + stringTime.substr(2,2);
}

function formatTime(timeStr){
	if(!timeStr) return '';
	if(timeStr.replace(/^(([01][0-9])|([1][0-2])):?([0-5][0-9])$/, '').length != 0) return '';
	var stringTime = timeStr.replace(':','');
	return stringTime.substr(0,2) + ":" + stringTime.substr(2,2);
}

//returns a formatted (m/d/yyyy) string of the date passed in, or empty string if not valid date.
// Renamed formatDate to reformatDate(name conflict with struts-layout version of formatDate)
function reformatDate(strDate){
	if (strDate.length < 6) return "";
	var c = (strDate.indexOf("/")>=0?"/":null);
	var ary = null;

	if (!c) c = (strDate.indexOf("-")>=0?"-":null);
	if (!c || ((ary = strDate.split(c)).length != 3)){
		ary = new Array(3)
		ary[0] = strDate.substr(0, 2);
		ary[1] = strDate.substr(2, 2);
		ary[2] = strDate.substr(4);
	}

	if (isNaN(ary[0] + ary[1] + ary[2])) return "";
	ary[0] = parseInt(ary[0], 10);
	ary[1] = parseInt(ary[1], 10);
	ary[2] = parseInt(ary[2], 10);
	if (ary[2] < 50) ary[2] += 2000;
	else if (ary[2] < 100) ary[2] += 1900;

	var dte = new Date(ary[2], ary[0] - 1, ary[1]);

	if ((dte.getMonth()+1)==ary[0] && dte.getDate()==ary[1] && dte.getFullYear()==ary[2])
		return (dte.getMonth()+1) + "/" + dte.getDate() + "/" + dte.getFullYear();
	else
		return "";
}

	//returns boolean indicating parameter is a valid date
function isDate(strDate){
	return (reformatDate(strDate).length > 0);
}

	//returns a formatted (###-##-####) string of the SSN passed in, if valid
function formatSSN(strSSN){
	var sNumbers = strSSN.replace(/-/g,"");
	return (isNaN(sNumbers) || (sNumbers.length!=9) ? "" : sNumbers.substr(0,3) + "-" + sNumbers.substr(3,2) + "-" + sNumbers.substr(5));
}

	//returns boolean indicating that the parameter is a valid SSN
function isSSN(strSSN){
	return (formatSSN(strSSN).length > 0);
}

  //returns the parameter with leading spaces removed
function lTrim(strValue){
	for (i=0;strValue.charAt(i)==" ";i++);
	return strValue.substr(i);
}

	//returns the parameter with trailing spaces removed
function rTrim(strValue){
	for (j=strValue.length - 1;strValue.charAt(j)==" ";j--);
	return strValue.substr(0, j + 1);
}

	//returns the parameter with leading and trailing spaces removed
function trim(strValue){
	return rTrim(lTrim(String(strValue)));
}

	//returns the parameter with enough charPadWith characters appended to make the length intPadToLength
function rPad(strValue, intPadToLength, charPadWith){
	if (strValue.length >= intPadToLength) return strValue;
	return strValue + (new Array(intPadToLength - strValue.length + 1)).join(charPadWith);
}

	//returns the parameter with enough charPadWith characters prepended to make the length intPadToLength
function lPad(strValue, intPadToLength, charPadWith){
	if (strValue.length >= intPadToLength) return strValue;
	return (new Array(intPadToLength - strValue.length + 1)).join(charPadWith) + strValue;
}

	/* returns a positive 1 if the first date is greater,
		 -1 if the second, 0 if they are the same, and
		 null if one or the other is not a date */
function compareDates(strDate, strDate2){
	if ((strDate = reformatDate(strDate)).length * (strDate2 = reformatDate(strDate2)).length == 0) return null;
	if (strDate == strDate2) return 0;
	return (Date.parse(strDate) > Date.parse(strDate2) ? 1 : -1);
}


function setValueIf(r_objElem, r_ptrFunc){
	var sRet = r_ptrFunc(r_objElem.currVal());
	if(sRet)r_objElem.setVal(sRet);
}

/********************************************************************
********************************************************************/


/********************************************************************
	Standard default functions to avoid creating new Functions
********************************************************************/
function stdCurrVal_value(){return this.value;}
function stdSetVal_value(varNewValue){this.value = varNewValue;}
function stdCurrVal_checked(){return this.checked;}
function stdSetVal_checked(varNewValue){this.checked = (varNewValue);}
function stdHasChanged(){return (this.origVal != this.currVal());}
function stdReturnTrue(){return true;}
/********************************************************************
********************************************************************/



/********************************************************************
	Functions used internally
********************************************************************/
var newline = "\n";

	/********************************************************
	Function: setCurrVal
	Purpose:	Assigns currVal() and setVal() functions to the
		object based on type. Sets the origVal property to the
		current value returned from currVal() and assigns the
		hasChanged() function to identify if the currVal() is
		different than the origVal.
	********************************************************/
function setCurrVal(obj){
	//alert(obj.name);
	switch (obj.type){
		case "hidden":
		case "text":
		case "password":
		case "textarea":
			obj.currVal = stdCurrVal_value;
			obj.setVal = stdSetVal_value;
			break;

		case "checkbox":
		case "radio":
			obj.currVal = stdCurrVal_checked;
			obj.setVal = stdSetVal_checked;
			break;

		case "select-one":
			obj.currVal = new Function("return this.selectedIndex;");
			obj.setVal = new Function("varNewValue", "this.options[varNewValue].selected = true;");
			break;

		case "select-multiple":
			obj.currVal = new Function("var sRet=''; for(i=0;i<this.options.length;i++){if(this.options[i].selected)sRet+=':'+i+':';}return sRet;");
			obj.setVal = new Function("varNewValues", "for(i=0;i<this.options.length;i++) this.options[i].selected = (varNewValue.indexOf(':'+i+':')>=0);");
			break;

		default:
			obj.currVal = stdCurrVal_value;
			obj.setVal = stdSetVal_value;
	}

	obj.origVal = obj.currVal();
	obj.hasChanged = stdHasChanged;
}

	/*************************************************************
	Function: formValidatorSetup
	Purpose:	This function gets called on the page load event of
		the window, or anytime after the controls have all been
		rendered and initialized with values.
	Parameters:
	Effects:
		Sets element.currVal() function to return a the value of
				control. Adds validate(), validateOther() functions to
				controls.
	*************************************************************/
function formValidatorSetup(){
	var iFrmCount = window.document.forms.length;
	var oFrm = null;
	var iElemCount = 0;
	var iElem = null;
	var oElem = null;

	if (iFrmCount == 0) return true;	//there are no forms exit function

	//loop through the forms on the page
	for (iFrm=0; iFrm<iFrmCount; iFrm++){
		oFrm = window.document.forms[iFrm];		//get pointer to form
		if (!oFrm.validateOther) oFrm.validateOther = stdReturnTrue;	//add default validateOther function
		oFrm.validate = new Function("return validateForm(this, (arguments.length?arguments[0]:true));");									//add validate Function

		iElemCount = oFrm.elements.length;		//get the number of elements
		if (iElemCount == 0) continue;				//no elements goto next form

		//loop through elements
		for (iElem=0; iElem<iElemCount; iElem++){
			oElem = oFrm.elements[iElem];				//get pointer to element
			setCurrVal(oElem);									//set props and functions to use
			if (!oElem.validateOther) oElem.validateOther = stdReturnTrue;	//add default validateOther function
			oElem.validate = new Function("return validateElement(this);");								//add validate Function
		}

	}
}

	// run the formValidatorSetup function on the window_onLoad event
//window.attachEvent("onload", formValidatorSetup);
//window.onload = formValidatorSetup;


	/********************************************************
	Function: validateForm
	Purpose:	This is the validate() method of the form
		objects. It calls the validate() and validateOther()
		functions of all of the controls, as well as the
		validateOther() function of the form. A return value
		of false from any of them will result in a false return.
	Parameters:
		objForm: The form object. This is passed in automatically
			when validate() is called.
		blnDisplayErrors: This is optionally passed in when
			calling validate() to indicate that the function
			should display the errors(if any) rather than using
			the validationError property of the form to access.
	Effects:
		Sets the validationError property to a string detailing
		the errors.
	********************************************************/
function validateForm(objForm, blnDisplayErrors){
	var iElemCount = objForm.elements.length;
	var oElem = null;
	var blnValid = true;
	var strError = "The following errors occurred:\n";


	//loop through elements
	for (iElem=0; iElem<iElemCount; iElem++){
		oElem = objForm.elements[iElem];
		if (!oElem.validate()){
			if (blnValid) oElem.focus();
			blnValid = false;
			strError += oElem.validationError;
		}
	}

	objForm.validationError = strError;
	blnValid = (objForm.validateOther() && blnValid);
	if (blnDisplayErrors && !blnValid) alert(objForm.validationError);
	objForm.isValid = blnValid;
	return blnValid;
}

	/********************************************************
	Function: validateElement
	Purpose:	This is the validate() method of the controls.
		It calls the validate() and validateOther()
		functions of the control. A return value of false from
		either of them will result in a false return.
	Parameters:
		objElement: The control object. This is passed in
			automatically when validate() is called.
	Effects:
		Sets the validationError property to a string detailing
		the errors. Sets the isValid property to a boolean
		indicating the return value from the last validation.
	********************************************************/
function validateElement(objElement){
	var blnValid = true;
	var strError = "";
	var objValRout = null;
	var props = objElement.validationProps;

	if (props){
		if (props["trim"]) objElement.setVal(trim(objElement.currVal()));  //this should be done before other validation
			//if not required and empty then do nothing else
		if (props["isRequired"] || objElement.currVal().length){			
			for (prop in props){
				objValRout = objValidMap[prop];
				if (objValRout){
					if (!objValRout.validate(objElement, props[prop])){
						blnValid = false;
						strError += objValRout.message(objElement, props[prop]);
					}
				}
			}
		}
	}

	objElement.validationError = strError;
	blnValid = (blnValid && objElement.validateOther());
	objElement.isValid = blnValid;
	return blnValid;
}

	//standard default functions for the validationRoutine objects
function stdValidate(objElem, varPropVal){return this.routine(objElem.currVal(), varPropVal);}
function stdMessage(objElem, varPropVal){return getLabel(objElem.currVal()) + ' is not valid.' + newline;}
	//declaration for the validationRoutine object
function validationRoutine(ptrFunction){
	this.routine = ptrFunction;
	this.validate = stdValidate;
	this.message = stdMessage;
	return this;
}

/*********** Not used yet **********************
function resultObject(varValue, strMessage){
	this.value = varValue;
	this.message = strMessage;
	return this;
}
***********************************************/

	/*returns the label associated with an element if the property has been set
		otherwise returns the value of the element.*/
function getLabel(objElement){
	return (objElement.validationProps.label && (objElement.validationProps.label.length > 0)?objElement.validationProps.label:objElement.currVal());
}

	/********************************************************
	Object:		validationMapper
	Purpose:	Maps the validationProps to the proper validation
		function. This is where new validation properties need
		to be registered. Each validationProp has a
		validationRoutine object as a property named the exact
		same as the property. The validationRoutine object has
		3 functions:
			routine: returns a pointer to the base function.
			validate: returns T/F if the given element is valid
				with respect to the give validation property.
			message: returns the error message for the element
				that does is not valid.
	********************************************************/
function validationMapper(){

	this.isRequired = new validationRoutine(null);
	this.isRequired.validate = new Function("objElem", "blnRequired", "return ((objElem.type==\"select-one\"?(objElem.options[objElem.currVal()].value.length > 0):(String(objElem.currVal()).length > 0)) || !blnRequired);");
	this.isRequired.message = new Function("objElem", "return getLabel(objElem) + ' is required.' + newline;");

	this.isNumeric = new validationRoutine(isNumeric);
	this.isNumeric.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid number.' + newline;");

	this.allowedDecimals = new validationRoutine(allowedDecimals);
	this.allowedDecimals.message = new Function("objElem", "intNumAllowedDecimals", "return getLabel(objElem) + ' must be a number containing no more ' + intNumAllowedDecimals + ' places after the decimal.' + newline;");

	this.isCurrency = new validationRoutine(formatCurrency);
	this.isCurrency.validate = new Function("objElem", "var strCur = this.routine(objElem.currVal(), objElem.validationProps['showDollar'], objElem.validationProps['showCommas']); if (strCur.length == 0) return false; objElem.setVal(strCur); return true;");
	this.isCurrency.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid currency.' + newline;");

	this.isMTime = new validationRoutine(formatMTime);
	this.isMTime.validate = new Function("objElem", "var strCur = this.routine(objElem.currVal()); if (strCur.length == 0) return false; objElem.setVal(strCur); return true;");
	this.isMTime.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid format. (HH:MM)' + newline;");

	this.isTime = new validationRoutine(formatTime);
	this.isTime.validate = new Function("objElem", "var strCur = this.routine(objElem.currVal()); if (strCur.length == 0) return false; objElem.setVal(strCur); return true;");
	this.isTime.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid format. (HH:MM)' + newline;");

	this.maxValue = new validationRoutine(null);
	this.maxValue.validate = new Function("objElem", "varMaxValue", "return (rootValue(objElem.currVal()) <= Number(varMaxValue));");
	this.maxValue.message = new Function("objElem", "varMaxValue", "return getLabel(objElem) + ' may not be greater than ' + varMaxValue + '.' + newline;");

	this.minValue = new validationRoutine(null);
	this.minValue.validate = new Function("objElem", "varMinValue", "return (rootValue(objElem.currVal()) >= parseInt(varMinValue));");
	this.minValue.message = new Function("objElem", "varMinValue", "return getLabel(objElem) + ' may not be less than ' + varMinValue + '.' + newline;");

	this.maxLength = new validationRoutine(null);
	this.maxLength.validate = new Function("objElem", "intMaxLength", "return (objElem.currVal().length <= parseInt(intMaxLength));");
	this.maxLength.message = new Function("objElem", "intMaxLength", "return getLabel(objElem) + ' may not exceed ' + intMaxLength + ' characters.' + newline;");

	this.minLength = new validationRoutine(null);
	this.minLength.validate = new Function("objElem", "intMinLength", "return (objElem.currVal().length >= parseInt(intMinLength));");
	this.minLength.message = new Function("objElem", "intMinLength", "return getLabel(objElem) + ' must be at least ' + intMinLength + ' characters.' + newline;");

	this.reqLength = new validationRoutine(null);
	this.reqLength.validate = new Function("objElem", "intLength", "return (objElem.currVal().length == parseInt(intLength));");
	this.reqLength.message = new Function("objElem", "intLength", "return getLabel(objElem) + ' must be ' + intLength + ' character(s).' + newline;");

	this.isDate = new validationRoutine(reformatDate);
	this.isDate.validate = new Function("objElem", "var strDate = this.routine(objElem.currVal()); if (strDate.length == 0) return false; objElem.setVal(strDate); return true;");
	this.isDate.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid date.' + newline;");

	this.minDate = new validationRoutine(compareDates);
	this.minDate.validate = new Function("objElem", "strMinDate", "var outcome = this.routine(objElem.currVal(), strMinDate); return (outcome==0 || outcome==1);");
	this.minDate.message = new Function("objElem", "strMinDate", "return getLabel(objElem) + ' may not be before ' + strMinDate + '.' + newline;");

	this.maxDate = new validationRoutine(compareDates);
	this.maxDate.validate = new Function("objElem", "strMaxDate", "var outcome = this.routine(objElem.currVal(), strMaxDate); return (outcome==0 || outcome==-1);");
	this.maxDate.message = new Function("objElem", "strMaxDate", "return getLabel(objElem) + ' may not be after ' + strMaxDate + '.' + newline;");

	this.isSSN = new validationRoutine(formatSSN);
	this.isSSN.validate = new Function("objElem", "var strSSN = this.routine(objElem.currVal()); if (strSSN.length == 0) return false; objElem.setVal(strSSN); return true;");
	this.isSSN.message = new Function("objElem", "return getLabel(objElem) + ' is not a valid Social Security Number.' + newline;");

	this.notAllowed = new validationRoutine(null);
	this.notAllowed.validate = new Function("objElem", "varNotAllowedChars", "for (i=0,s=objElem.currVal();i<s.length;i++){if (varNotAllowedChars.indexOf(s.substr(i,1))>=0) return false;} return true;");
	this.notAllowed.message = new Function("objElem", "varNotAllowedChars", "return getLabel(objElem) + ' may not contain any of the following characters:' + newline + varNotAllowedChars + newline;");

	this.onlyAllowed = new validationRoutine(null);
	this.onlyAllowed.validate = new Function("objElem", "varOnlyAllowedChars", "for (i=0,s=objElem.currVal();i<s.length;i++){if (varOnlyAllowedChars.indexOf(s.substr(i,1))==-1) return false;} return true;");
	this.onlyAllowed.message = new Function("objElem", "varOnlyAllowedChars", "return getLabel(objElem) + ' may only contain the following characters:' + newline + varOnlyAllowedChars + newline;");

	this.pattern = new validationRoutine(null);
	this.pattern.validate = new Function("objElem", "objRegExp", "var strValue = String(objElem.currVal()); if (strValue.replace(objRegExp, '').length == 0) return true; return false;");
	this.pattern.message = new Function("objElem", "return getLabel(objElem) + ' is not in a valid format.' + newline;");

	return this;
}

/****************************************************************************
' Purpose:		To format a date when a user navigates off of a date field.
' Parameters: obj
'***************************************************************************/
function fixDate(r_objDateField) {
	var sDate = reformatDate(r_objDateField.value);
	if(sDate) r_objDateField.value = sDate;
}

/****************************************************************************
' Purpose:		To format a SSN when a user navigates off of a SSN field.
' Parameters: obj
'***************************************************************************/		
function fixSSN(r_objSSNField) {
	var sSSN = formatSSN(r_objSSNField.value);
	if(sSSN) r_objSSNField.value = sSSN;
}


function isLetter (c){
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c){
   return ((c >= "0") && (c <= "9"))
}

// Is Numeric
function isNumeric (s){
   var i;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);
        if (! (isDigit(c) ) )
        return false;
    }
    // All characters are numbers.
    return true;
}

// checking for number between 0 and 9		
function isNum(passedVal) {
	if (passedVal == "") return (false);
	for (i=0; i<passedVal.length; i++){
		if (passedVal.charAt(i) < "0") return (false);
		if (passedVal.charAt(i) > "9") return (false);
	}
	return (true);
}

function stripCharsInBag (s, bag){
	var i;
   	var returnString = "";
   	// Search through string's characters one by one.
   	// If character is not in bag, append to returnString.
   	for (i = 0; i < s.length; i++){
		// Check that current character isn't whitespace.
    	var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function reformatSSN (SSN){
   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}

function reformat (s){
	var arg;
    var sPos = 0;
    var resultString = "";
    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
	   if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

// Email check
function emailcheck(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					
}

	//Create an instance of the validationMapper object.
var objValidMap = new validationMapper();
/********************************************************************
********************************************************************/


// Email check

function emailcheck2(emailStr) {

       if (emailStr.length == 0) {

           return true;

       }

       var emailPat=/^(.+)@(.+)$/;

       var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

       var validChars="\[^\\s" + specialChars + "\]";

       var quotedUser="(\"[^\"]*\")";

       var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;

       var atom=validChars + '+';

       var word="(" + atom + "|" + quotedUser + ")";

       var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

       var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");

       var matchArray=emailStr.match(emailPat);

       if (matchArray == null) {

           return false;

       }

       var user=matchArray[1];

       var domain=matchArray[2];

       if (user.match(userPat) == null) {

           return false;

       }

       var IPArray = domain.match(ipDomainPat);

       if (IPArray != null) {

           for (var i = 1; i <= 4; i++) {

              if (IPArray[i] > 255) {

                 return false;

              }

           }

           return true;

       }

       var domainArray=domain.match(domainPat);

       if (domainArray == null) {

           return false;

       }

       var atomPat=new RegExp(atom,"g");

       var domArr=domain.match(atomPat);

       var len=domArr.length;

       if ((domArr[domArr.length-1].length < 2) ||

           (domArr[domArr.length-1].length > 3)) {

           return false;

       }

       if (len < 2) {

           return false;

       }

       return true;

}

function checkPhoneNumber(phoneNo) {
 //var phoneRE = /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
  var phoneRE = /^(\(?\d{3}\)?)(-|)?(\d{3})(-|)?(\d{4})((x|x|ext|ext)\d{1,5}){0,1}$/;
 
 if (phoneNo.match(phoneRE)) {
   return true;
 } else {
   return false;
 }
}

