/* ------------------------------------------------------------
 * Dependency: validateImpl.js
 *
 * ------------------------------------------------------------
 */



/*
 * -------------------------------------------------------------
 *
 * Usage:
 *     parmLayer = the SPAN that used to locate the validation error gif
 *
 *     this = the HTML object
 *
` *     parmValidateStr =
 *       { 1.  req ................... validate for mandatory field
 *         2.  maxlen=XX ............. validate for the max length of the field value
 *         3.  minlen=XX ............. validate for the min length of the field value
 *         4.  fixlen=XX ............. validate for the length of the field value
 *         5.  alphanumeric .......... the field value must be A-Z | a-z | 0-9
 *         6.  numeric ............... the field value must be 0-9
 *         7.  float ................. the field value must be numeric or float
 *         8.  alphabetic ............ the field value must be A-Z | a-z
 *         9.  alnumhyphen ........... the field value msut be A-Z | a-z | 0-9 | - | _
 *         10. email ................. validate for email address
 *         11. emails ................ validate for multiple emails separated by , | ;
 *         12. gt=XX ................. the field value must be greater than a specific value
 *         13. lt=XX ................. the field value must be less than a specific value
 *         14. regexp=XX ............. a specific regular expression
 *         15. dontselect=XX ......... validate if the selected index of a list is a specific value
 *         16. date .................. validate for a date value (refer to datetime)
 *         17. time .................. validate for a time value (refer to datetime)
 *         18. datetime .............. validate for datetime value
 *                                     {
 *                                      yyyy-mm-dd hh24:mi:ss
 *                                      yyyy/mm/dd hh24:mi:ss
 *                                      yyyy.mm.dd hh24:mi:ss
 *                                      
 *                                      yyyy-mm-dd hh12:mi:ss am
 *                                      yyyy/mm/dd hh12:mi:ss am
 *                                      yyyy.mm.dd hh12:mi:ss am
 *                                      
 *                                      yyyy-mm-dd hh12:mi:ss pm
 *                                      yyyy/mm/dd hh12:mi:ss pm
 *                                      yyyy.mm.dd hh12:mi:ss pm
 *                                     }
 *         19. ipaddress ............. validate for an IP address
 *         20. ipaddresses ........... validate for multiple IP addresses separated by , | ;
 *         21. creditcard ............ validate for a credit card no with correct check digit
 *         22. printable ............. validate printable characters
 *                                      ( ie. ASCII 32 - 126, refer to www.lookuptables.com )
 *		   23. contact ............... validate for a contact number
 *         24. radioReq .............. validate to ensure the one of the radio button is checked
 *         25. textAreaMaxByte ....... validate for max len (in term of byte) of text area (including Chinese text)
 *         26. le=XX ................. the field value must be less than or equal to a specific value
 *         27. ge=XX ................. the field value must be greater than or equal to a specific value
 *		   28. geByElementID=XX:XX ... the field value must be greater than or equal to a value of specific element ID
 *		   29. leByElementID=XX:XX ... the field value must be less than or equal to a value of specific element ID
 *         30. checkboxReq .............. validate to ensure the one of the checkbox is checked
 *         31. checkboxReqOnlyOne .............. validate to ensure the only one of the checkbox is checked
 *         32. pwd .............. validate to ensure at least 2 alphabetic and 2 numeric characters.
 *         33. maxFraction .............. validate to ensure less than or equal to the number of fractional digits.
 		   34. weekdayExclude=x........... validate to ensure the weekday cannot be selected and separated by "," (Sunday = 0, Monday = 1......Saterday=6) 
 *       }
 *
 *     strErr = the error message, in case of validation failure
 *
 * Example:
 *     jsValidate('span1', this, 'maxlen=2', 'The max length is 2');
 * -------------------------------------------------------------
 */

function jsValidate(parmLayer, parmObject, parmValidateStr, parmError) {

    r = wttValidateData(parmLayer, parmObject, parmValidateStr, parmError);
    return r;
}




function jsMultiValidate(parmLayer, parmObject, parmValidateStrArray, parmErrorArray) {
    for (i=0; i<parmValidateStrArray.length; i++) {
      if (! wttValidateData(parmLayer, parmObject, parmValidateStrArray[i], parmErrorArray[i]) ) {
        return false;
      } // end if 
    } // end for
    return true;
}



function jsValidateForm(parmForm) {
	
    var f = document.getElementById(parmForm);
    var noOfElement = f.elements.length;
    var validateResult = true;
    for (var i=0; i<noOfElement; i++){
        if (f.elements[i].type=="text" || f.elements[i].type=="textarea" || f.elements[i].type=="select-one"
        	|| f.elements[i].type=="file"  || f.elements[i].type=="radio" || f.elements[i].type=="checkbox" 
        	|| f.elements[i].type=="password") {
            if (f.elements[i].onblur) {

                if (!f.elements[i].onblur()) {
                    validateResult = false;
                } // end if
            } // end if
        } // end if
    } // end for
    return validateResult;
}
