var oldClassNames = new Array();
var highlightedObject;

function highlight(object, retainer, xpath, className, value){

	if(value==null)
		value='xpath';
		
	if(highlightedObject != object)	{
		oldClassNames[object] = object.className;
		object.className = className;
		if(highlightedObject != null)
			highlightedObject.className = oldClassNames[highlightedObject];
		highlightedObject = object;
		retainer.value = "true";
	}else{
		object.className = oldClassNames[object];
		highlightedObject = null;	
		retainer.value = "";
	}
	xpath.value = extractField(highlightedObject, value);
	//alert(xpath.value);
}

function extractField(object, field){
	if(object != null){//instance of table row?
		var cells = object.cells;
		for(i=0; i<cells.length; i++){
			var className = cells[i].className;
			if(className == null)
				continue;			
			var classes = className.split(" ");
			for(j=0; j<classes.length; j++)
				if(classes[j] == field)
					return cells[i].innerHTML.replace(/^[\s\n\t]+|[\n\t\s]+$/g,"");			
		}
	}
	return null;
}
