function iosEditRules(oRef){
// Required Field Labels
oRef.txtName.label 		= 'Name';
oRef.txtPHArea.label		= 'Area Code';
oRef.txtPHPrefix.label		= 'Phone Prefix';
oRef.txtPHSuffix.label		= 'Phone Suffix';
oRef.txtEmail.label  		= 'E-mail';
oRef.txtComments.label	 	= 'Comments';

// Required Fields
oRef.txtName.required 		= true;
oRef.txtPHArea.required 	= true;
oRef.txtPHPrefix.required 	= true;
oRef.txtPHSuffix.required 	= true;
oRef.txtEmail.required 		= true;
oRef.txtComments.required 	= true;

// Email Requirements
oRef.txtEmail.email		= true;

// Numeric Requirements
oRef.txtPHArea.numeric	 	= true;
oRef.txtPHArea.min	 	= -1;
oRef.txtPHArea.max	 	= 1000;

oRef.txtPHPrefix.numeric 	= true;
oRef.txtPHPrefix.min	 	= -1;
oRef.txtPHPrefix.max	 	= 1000;

oRef.txtPHSuffix.numeric	= true;
oRef.txtPHSuffix.min	 	= -1;
oRef.txtPHSuffix.max	 	= 10000;

return oRef;
}

function isRequiredMissing(sValue){

	for(var iSub = 0; iSub < sValue.length; iSub++) {
        	var iPos = sValue.charAt(iSub);        
		if ((iPos != ' ') && (iPos != '\n') && (iPos != '\t')) return false;
    	}

    	return true;

}

function isEmailValid(sValue){
	var bIsValid   = true;
	var sAtSign    = sValue.indexOf('@');
	var sDot       = sValue.lastIndexOf('.');
	var sSpace     = sValue.indexOf(' ');
	var iLength    = sValue.length - 1;  

	if ((sAtSign < 1) || (sDot < 1) || (sDot <= sAtSign + 1) || (sDot == iLength) || (sAtSign == iLength) || (sSpace != -1))
   		{
		bIsValid = false;
   		}
	return bIsValid;
}



function isMinValid(vValue1,vValue2){
	var bMinValid = false;
	return bMinValid = (vValue1 < vValue2) ? true : false;
}

function isMaxValid(vValue1,vValue2){
	var bMaxValid = false;
	return bMaxValid = (parseFloat(vValue1) > vValue2) ? true : false;
}


function ValidateFields(oFrmRef){
    var sMsg;
    var sEmpty = "";
    var sErrors = "";


// hold first field in error in focus

    oRef = new iosEditRules(oFrmRef);

    for(var iSub = 0; iSub < oRef.length; iSub++) { 

	var oElem = oRef.elements[iSub];

        if (((oElem.type == "text") || (oElem.type == "textarea")) && oElem.required)
	{

            if ((oElem.value == null) || (oElem.value == sEmpty) || isRequiredMissing(oElem.value))
	    {
                sEmpty += "\n          " + oElem.label;
		continue;
            }


            if (oElem.email)
	    {
		if (!isEmailValid(oElem.value))
		{
			sErrors += "\n          " + oElem.label + " must contain a valid address";
		}
	    }

            if (oElem.numeric)
	    {
		if (isNaN(oElem.value)) 
		{
			sErrors += "\n          " + oElem.label + " must be a number";
		}
		else 
		{
		    if (oElem.min != null) 
		    {
			if (!isMinValid(oElem.min, oElem.value)) 
			{
				sErrors += "\n          " + oElem.label + " must be greater than " + oElem.min;
			}
		    }
		    else if (oElem.max != null)
	    	    { 

			if (!isMaxValid(oElem.max, oElem.value)) 
			{
				sErrors += "\n          " + oElem.label + " must be less than " + oElem.max;
			}
		    }
		}
	    }

        }
    }

    if (!sEmpty && !sErrors) return true;

    sMsg  = "______________________________________________________\n\n"
    sMsg += "The form was not submitted because of the following error(s).\n";
    sMsg += "Please correct these error(s) and re-submit.\n";
    sMsg += "______________________________________________________\n\n"
    
    if (sEmpty) {
	sMsg += "- The following required field(s) are empty:" + sEmpty + "\n";
        if (sErrors)sMsg += "\n";
    }
    sMsg += sErrors;
    alert(sMsg);
    return false;

}

