/**
 * SUPPORT FOR THE ELEMENT ID NAMING SCHEME
 */
 
var Names = { 
	/**
	 * Deprecated by prototype.js 1.5.x support
	 */
	endsWith: function(str, s){
		var regex = new RegExp(s + "$");
		return regex.test(str);
	},
	
	/**
	 * Strip the scope prefix from an element id attribute
	 */
	stripScopePrefix: function(id, prefix) {
		return id.slice(prefix.length, id.length);
	},

	/**
	 * Remove scope prefix from an element id attribute in order to identify an
	 * entity instance
	 */
	removeInstanceScopePrefix: function(id) {
		var parts = id.split(Service.SCOPE_SEPARATOR);
		return parts[parts.length - 1];
	},
	
	
	/**
	 * Remove scope prefix from an element id attribute in order to identify an
	 * entity instance
	 */
	getInstanceID: function(elementID) {
		var parts = elementID.split(Service.SCOPE_SEPARATOR);
		return parts[parts.length - 1];
	},
	
	getIDInstance: function(id){
		var parts = "";
		if(id.indexOf(Service.INSTANCE_SEPARATOR)<0){
			return parts
		}
		parts = id.split(Service.INSTANCE_SEPARATOR);
		parts = parts[1].split(Service.SCOPE_SEPARATOR);
		if(parts[0].indexOf(',')<0){
			return parts[0];
		}
		parts = parts[0].split(',');
		return parts[0];
	},
	
	
	/**
	 * Remove the scope prefix from an element id attribute in order to identify an
	 * entity instance
	 */
	removeIDScopePrefix: function(id) {
		var parts = id.split(Service.SCOPE_SEPARATOR);
		return parts[parts.length - 1];
	},
	
	getContext: function(id) {
		var parts = id.split(Service.SCOPE_SEPARATOR);
		return parts[0];
	},
	
	getEntity: function(id) {
		var parts = id.split(Service.SCOPE_SEPARATOR);
		if(parts[2].indexOf(Service.INSTANCE_SEPARATOR)>=0){
			parts = parts[2].split(Service.INSTANCE_SEPARATOR);
			return parts[0];
		}
		return parts[2];
	},
	/**
	 * Get the scope prefix of an element
	 */
	getScopePrefix: function(id) {
		var parts = id.split(Service.SCOPE_SEPARATOR);
		parts.splice(parts.length - 1, parts.length - 1);
		return parts.join(Service.SCOPE_SEPARATOR);
	}
}



