/**
 * eCommunities ECMS RPC Class 
 * 
 * This class is called by the RPC functions within ECMS to update the target bin within 
 * the consoles current page.  The val content is url encoded when passed to this script
 * and so unescaped when provided back to the console.
 *
 * @author Kevin Farley
 * @version 2.0
 */

// Declare the required ECMS namespaces if they do not already exist
if (ECMS == null || typeof(ECMS) != "object") { var ECMS = new Object(); }
if (ECMS.ECORE == null || typeof(ECMS.ECORE) != "object") { ECMS.ECORE = new Object(); }
if (ECMS.ECORE.rpc == null || typeof(ECMS.ECORE.rpc) != "object") { ECMS.ECORE.rpc = new Object(); }

ECMS.ECORE.rpc = {

	init: function() {
		// Nothing to do.
	},
	
	handleResponse: function (val,target) {
		if (target > '') {
			document.getElementById('rpc_bin_'+target).innerHTML = unescape(val);
		} else {
			document.getElementById('rpc_bin').innerHTML = unescape(val);
		}
	},
	
	returnSelected: function (selected,label,target) {
		try {
			// Get the parent forms field ID.  
			fieldID = parent.ECMS.ECORE.selector.selectField;

			// Set the parent forms fields to the selected values.
			parent.document.getElementById(fieldID + '_label').value = label;
			parent.document.getElementById(fieldID).value = selected;
		} catch(err) { alert(err); }
		parent.document.getElementById(target).style.display = "none";
	},
	
	returnSelectedSrc: function (target,path) {
		try {
			// Set the parent forms fields to the selected values.
			parent.document.getElementById(target).src = path;
		} catch(err) { alert(err); }
	},

	cancelSelect: function (target) {
		parent.document.getElementById(target).style.display = "none";
	}
}
