/**
 * eCommunities ECMS Form Tools Class 
 * @author Kevin Farley
 * @version 2.0
 */

// Declare the required ECMS namespaces if they do not already exist
if (ECMS == null || typeof(ECMS) != "object") { var ECMS = new Object(); }
if (ECMS.ECORE == null || typeof(ECMS.ECORE) != "object") { ECMS.ECORE = new Object(); }
if (ECMS.ECORE.form == null || typeof(ECMS.ECORE.form) != "object") { ECMS.ECORE.form = new Object(); }

ECMS.ECORE.form = {
		
	skip: false,
	
	skipVerify: function() {
		this.skip = true;
	},
	
	verify: function() {
 		if (this.skip) {
 			return true;
 		} else {
 			return confirm("Are you ready to submit this form?");
 		}
    },
    
    charCounter: function (fid,maxchars) {
    	var counter = document.getElementById(fid+'_counter');
    	var txtField = document.getElementById(fid);
    	if (txtField.value.length > maxchars) {
    		txtField.value = txtField.value.substring(0, maxchars);
    	} else {
    		counter.value = maxchars - txtField.value.length;
    	}
    },
    
    /**
     * Verify that a radio group selection has been made using the supplied group elements name attribute.
     * @param $group string
     * @return boolean
     */
    checkRadio: function (group) { 
    	group = document.getElementsByName(group);
    	for(var k=0; k < group.length; k++) { if(group[k].checked) { return true; } }
    	return false; 
    } 
}
