
/*
 * @version Id: XMLWrapper.js 28/mar/07
 * @package Parcelle
 * @copyright Copyright (C) 2007 Andrea Bizzotto - Tecnobit S.R.L. All rights reserved.
 * @license 
 * Created on 28/mar/07
 */

/*
 * This XML wrapper converts control data to be posted to the server into a plain string with delimiter-separated values
 * The resulting string is sent if the browser is the worst browser even: Internet Explorer
 * <controls>
 *    <attribute id="attribute 1 id" type="attribute 1 type" value="attribute 1 value" [change="slave control"]/>
 *   ....
 * </controls>
 */
function wrapXML(xml) {

	var str = "";
	var doc = createDomParser(xml);	
	if (doc == null)
		return;
	var root = doc.getDocumentElement();
	
	var i, childs = root.getChildNodes();
	
	for (i = 0; i < childs.getLength(); i++) {
	
		var attributes = childs.item(i).getAttributes();
		var id = attributes.getNamedItem(TAG_CONTROL_ID).getNodeValue();
		var type = attributes.getNamedItem(TAG_CONTROL_TYPE).getNodeValue();
		if (type == TAG_CONTROL_TYPE_SELECT)
			type = "s";
		else if (type == TAG_CONTROL_TYPE_EDIT)
			type = "e";
		else if (type == TAG_CONTROL_TYPE_CHECKBOX)
			type = "c";
		else if (type == TAG_CONTROL_TYPE_RADIO)
			type = "r";
		var value = attributes.getNamedItem(TAG_CONTROL_VALUE).getNodeValue();
		var changeAttr = attributes.getNamedItem(TAG_CONTROL_CHANGE);
		if (changeAttr != null) {
			var change = changeAttr.getNodeValue();
	
			str = str + id + "|" + type + "|" + value + "|" + change + "\n";			
		}
		else {
			var groupAttr = attributes.getNamedItem(TAG_CONTROL_GROUP);
			if (groupAttr != null) {
				var group = groupAttr.getNodeValue();
		
				str = str + id + "|" + type + "|" + value + "|" + group + "\n";
			}
			else{
				str = str + id + "|" + type + "|" + value + "\n";			
			}
		}
	}
	return str;
}