/**
* Err validation object constructor
*
* @author Incysive Media - Frederic Naslis
* @version 1.0
* @see radClient.js radServer.js
* @lastmodified : 25/03/2001
*/
Validation.prototype.Err = new Object();
Validation.prototype.Err.items = new Array();
Validation.prototype.Err.divs = new Object();

/**
* Clear values from Error object
*/
Validation.prototype.Err.clear = function (){
	this.items = new Array();
	this.divs = new Object();
}

/**
* Adds error to Error object
* @param		oSrc				element name
* @param		sMsg				error message
*/
Validation.prototype.Err.add=function (oSrc,sMsg) {
	var oErr = new Object();
	oErr.source = oSrc.title;
	oErr.message = sMsg;
	oErr.div = oSrc.div;
	oErr.gridIndex = (isNaN(oSrc.gridIndex) ? 0 : oSrc.gridIndex);
	this.items[this.items.length++] = oErr;
	this.divs[oErr.div + "_" + oErr.gridIndex] = oErr;
}
	
/**
 * Display Errors message in <DIV> Tags
 */
Validation.prototype.Err.displayDiv=function(){

	var i,iForms=document.forms.length;
	for(i=0; i<iForms; i++){
		var oForm=document.forms[i];	
		if (!(oValidation.browserVer <= 4 && oValidation.browserName == "Netscape")) {
			for(ind=0; ind<oForm.elements.length; ind++){
				var object=oForm.elements[ind];
				var sDiv = new String(object.div);
				if (sDiv != "undefined") {
					//document.getElementById(object.div).innerHTML = '';
					for(indDiv = 0 ; indDiv< document.getElementsByName(object.div).length; indDiv++)
						document.getElementsByName(object.div)[indDiv].innerHTML = '';
				}	
			}	
		}
	}
	for(ind=0; ind<this.items.length; ind++){
		var object=this.items[ind];
		var sMsg = object.source + ' : ' + object.message;
		if (oValidation.browserVer <= 4 && oValidation.browserName == "Netscape") {
			alert(sMsg);
		}
		else {
			//document.getElementById(object.div).innerHTML = sMsg;
			document.getElementsByName(object.div)[object.gridIndex].innerHTML = sMsg;			
		}
	}
	this.clear();
}	

/**
 * Display Errors message in formatted string
 */
 Validation.prototype.Err.dumpErrors=function(){
	var strProperties = new String();
	strProperties = "";
	for(ind=0; ind<this.items.length; ind++){
		var object=this.items[ind];
		strProperties+= object.source + ' : ' + object.message + '<br>';
	}
	this.clear();
	return strProperties;
}

/**
 * Transform all errors to xml
 */
 Validation.prototype.Err.toXml=function(){
	var str = new String("");
	
	for(ind=0; ind<this.items.length; ind++){
		var object = this.items[ind];
		str += "<error id='" + object.div.replace("'","&apos;") + "' title='" + object.source.replace("'","&apos;") + "' description='" + object.message.replace("'","&apos;") + "'/>";
	}

	return str;
}

/**
 * Transform all errors to xml
 */
 Validation.prototype.Err.getErrorForDiv=function(sDiv, index){
	index = (index ? index : 0);
	if (this.divs[sDiv + "_" + index])
		return this.divs[sDiv + "_" + index].source + " : " + this.divs[sDiv + "_" + index].message;
	else
		return "";
}
