// FP_toggleObjectValByID(id):
//  determines the current value of a property of element 'id', and toggles it to a
//	new value.
//	The first parameter contains the element's id
//	Following parameters are passed as groups of three:
//	In each group:
//		The first argument is the property of the element
//		The second and third argument are the two possible values
//		The second argument is chosen when the object's property is unassigned
// example:
// 		FP_toggleObjectValByID('ans1',
//			'style.position','absolute','relative',
//			'style.visibility','hidden','visible');
//	
function toggleProperty(id) {
	var el, prop, val1, val2;
	el = document.getElementById(id);

 	for(i = 1; i < arguments.length; i += 3) {
 		prop = arguments[i];
 		val1 = arguments[i + 1];
 		val2 = arguments[i + 2];
 		
		if (eval("el." + prop) == val1)
			eval("el." + prop + "=val2");
		else eval("el." + prop + "=val1");
	}
}

function getElementProperty(id, prop) {
	var el;
	el = document.getElementById(id);
	return eval("el." + prop);
}

/**
 * setAll(layerid, cls, prop1, val1, prop2, val2, ...., propN, valN)
 *
 * Sets the specified properties to the specified values for all
 * elements of class 'cls' that are a direct child of the element e
 * with e.id = layerid
**/
function setAll(layerid, cls) {
	var layer;
	var child;
	var prop, val;
	layer = document.getElementById(layerid);
	
	for (i = 0; i < layer.childNodes.length; i++) {
		child = layer.childNodes[i];
		if (child.className == cls) {
			for (k = 2; k < arguments.length; k += 2) {
				prop = arguments[k];
				val = arguments[k + 1];
				
				eval("child." + prop + "=val");
			}
		}
	}
}

/**
 * setProperty(id, prop1, val1, prop2, val2, ....., propN, valN)
 *
 * Sets the specified properties to the specified values for
 * the element e with e.id = 'id'
**/
function setProperty(id) {
	var el;
	el = document.getElementById(id);
	
	for (k = 1; k < arguments.length; k += 2) {
		prop = arguments[k];
		val = arguments[k + 1];
		
		eval("el." + prop + "=val");
	}
}

function condSetAll(layerid, cls) {
	var layer;
	var child;
	var prop, cond, val;
	layer = document.getElementById(layerid);
	
	for (i = 0; i < layer.childNodes.length; i++) {
		child = layer.childNodes[i];
		if (child.className == cls) {
			for (k = 2; k < arguments.length; k += 3) {
				prop = arguments[k];
				cond = arguments[k + 1];
				val = arguments[k + 2];
				
				alert("child." + prop + " == " + eval("child." + prop));
				
				if (eval("child." + prop) == cond) {
					alert("child." + prop + " = " + val);
					eval("child." + prop + "=val");
				}
			}
		}
	}
}


