/*
 * $Id: Action.java 502296 2007-02-01 17:33:39Z niallp $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
        var found = false;
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1){
			el[j++] = tags[i];
                        found = true;
                }
	}
        if (found == false)
            el = null;
	return el;
}

function clearErrorMessages(form, errorClass) {
    var errorDivs = null;
    if ( errorClass )
      errorDivs = getElementsByClass(errorClass);
  
    if ( errorDivs == null )
      errorDivs = form.getElementsByTagName("div");  
  
    for (var i = 0; i < errorDivs.length; i++) {

        if (errorDivs[i].getAttribute("class")=="formError" || errorDivs[i].getAttribute("className")=="formError")
        {
            errorDivs[i].style.display="none";
        }
        
        if ( errorClass && (errorDivs[i].getAttribute("class")== errorClass || errorDivs[i].getAttribute("className")== errorClass))
        {
            errorDivs[i].style.display="none";
        }
            
    }
}

function addError(e, errorText, div_id, errorClass) {
    try {
        var div = null;
        var divError = document.createElement("div");
        
        if (div_id)
          div = document.getElementById(div_id);
        else
          div = e.parentNode;
          
        if (errorClass){
            divError.setAttribute("class", errorClass);
            divError.setAttribute("className", errorClass);
          }
        else {         
          divError.setAttribute("class", "formError");
          divError.setAttribute("className", "formError");
        }
        
        divError.innerHTML = errorText;

        div.appendChild(divError);
        
    } catch (e) {
        alert(e);
    }
}
