/**
 * Set focus on the element of the given id.
 * @param id The id of the element to set focus on.
 */
function setFocus(form, id) {
	var element = document.getElementById(id);
    if (element && element.focus) {   
        element.focus();
        return;
    }
    for (var i=1; i < form.elements.length; i++) {
    	   var formElement = form.elements[i];
    	   if(formElement && formElement.focus && !formElement.disabled){
    		   if(formElement.value == null || formElement.value == ""){
    			   
    			   formElement.focus();
        		   return;
        	   }    		   
    	   }
	}
}



/**
 * Set highlight on the elements of the given ids. It basically sets the classname of the elements
 * to 'highlight'. This require at least a CSS style class '.highlight'.
 * @param ids The ids of the elements to be highlighted, comma separated.
 */
function setHighlight(ids) {
    var idsArray = ids.split(",");    
    for (var i = 0; i < idsArray.length; i++) {
        var elementByID = document.getElementById(idsArray[i]);
        if (elementByID) {
        	alert(elementByID.id);
        	elementByID.className = 'fieldError';
        }
    }
}

/**
 * Select/unselect all the checkboxes of the form of the current form
 */
function selectAllCheckBoxes(current) {
	var tags = document.getElementsByTagName("input"), i = 0;
	var isChecked = current.checked;
	for(i=0; i<tags.length;i++){
		if(tags[i].type == 'checkbox'){
		      if (isChecked) {
		    	  tags[i].checked = true;
		      } else {
		    	  tags[i].checked = false;
		      }
		}
	}
}