/**
 * Notify SRS modification to the server
 */
function notifySRSModification(ObjRef) {
	// Build the request
	var request = 
		{
			method : "modifySRS", 
			srs: config.objects.mainMap.getSRS()
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify Bbox modification to the server
 */
//With MB 1.5 the "bbox" listener is call 2 times for the same bbox when we change the SRS , this variable prevents useless server call
var oldBbox;
function notifyBBoxModification(objRef) {
	// Build the request
	var firstTime=false;
	if(!oldBbox){
		oldBbox =config.objects.mainMap.getBoundingBox();
		firstTime=true;
	}
	var bbox=config.objects.mainMap.getBoundingBox();
	if(oldBbox.toString()!=bbox.toString() || firstTime){
		oldBbox = bbox;
		var request = 
			{
				method : "modifyBBox", 
				minX: bbox[0],
				maxX: bbox[2],
				minY : bbox[1],
				maxY : bbox[3]
			};
		
		// Send it to the server side
		dojo.xhrGet({
			url: "wsControler",
			content: request
		});
	}
}

/**
 * Notify context renaming to the server
 */
function notifyContextRenaming(newName) {
	// Build the request
	var request = 
		{
			method : "renameContext", 
			newName : newName
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify opacity modification to the server
 */
function notifyOpacityModification(uuid, opacity) {
	// Build the request
	var request = 
		{
			method : "modifyOpacity", 
			uuid: uuid,
			opacity: opacity
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify visibility modification to the server
 */
function notifyVisibilityModification(uuid, visibility) {
	// Build the request
	var request = 
		{
			method : "modifyVisibility", 
			uuid: uuid,
			visibility: visibility
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify catalog layer addition to the server
 */
function notifyCatalogLayerAddition(objRef,layerNode) {
	// Build the request
	var uuidValue = layerNode.selectSingleNode("wmc:Extension/wmc:Infoterre/wmc:UUID").firstChild.nodeValue;
	var underlyingUuidValue = layerNode.selectSingleNode("wmc:Extension/wmc:Infoterre/wmc:UnderlyingUUID").firstChild.nodeValue;
	var request = 
		{
			method : "addCatalogLayer", 
			uuid: uuidValue,
			underlyingUuid: underlyingUuidValue
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify external layer addition to the server
 */
function notifyExternalLayerAddition(objRef,layerNode) {
	// Build the request
	var serverUrl = layerNode.selectSingleNode("wmc:Server/wmc:OnlineResource").getAttribute("xlink:href");
	var uuidValue = layerNode.selectSingleNode("wmc:Extension/wmc:Infoterre/wmc:UUID").firstChild.nodeValue;
	var nameValue = layerNode.selectSingleNode("wmc:Name").firstChild.nodeValue;
	var request = 
		{
			method : "addExternalLayer", 
			uuid: uuidValue,
			name: nameValue,
			serverUrl: encodeURIComponent(serverUrl)
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	})
}

/**
 * Notify external layer addition to the server
 */
function notifyGeocatalogLayerAddition(objRef,layerNode) {
	// Build the request
	var nameValue = layerNode.selectSingleNode("wmc:Name").firstChild.nodeValue;
	var request = 
		{
			method : "addGeocatalogLayer", 
			name: nameValue
		};
	
	// Send it to the server side
	dojo.xhrGet({
		url: "wsControler",
	    content: request
	 })
}

/**
 * Notify layer deletion to the server
 */
function notifyLayerDeletion(uuid) {
	// Build the request
	var request = 
		{
			method : "deleteLayer", 
			uuid: uuid
		};
		
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify layer move up to the server
 */
function notifyLayerMoveUp(uuid) {
	// Build the request
	var request = 
		{
			method : "moveUpLayer", 
			uuid: uuid
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}

/**
 * Notify layer move down to the server
 */
function notifyLayerMoveDown(uuid) {
	// Build the request
	var request = 
		{
			method : "moveDownLayer", 
			uuid: uuid
		};
	
	// Send it to the server side
	dojo.xhrGet({
        url: "wsControler",
        content: request
	});
}
