
	function setSelection(pAdvert, pAssoc) { 

		strError = "";

		if (document.getElementById('selectAlerts' + pAdvert) != null) {
		
			objSelectAlerts = document.getElementById('selectAlerts' + pAdvert);
			objSelectedItem = objSelectAlerts[objSelectAlerts.selectedIndex];
			strAgentAdvertAlert = objSelectedItem.value; 

			arrayAgentAdvertAlert = strAgentAdvertAlert.split("|");
			iAgent = arrayAgentAdvertAlert[0];
			strAssoc = arrayAgentAdvertAlert[1];
			iAlert = arrayAgentAdvertAlert[2];
			
			pText = objSelectedItem.text; 
			if ( pText.indexOf(" (Ajoutée)") > 0 ) {
				alert("Cette annonce éxiste déjà dans cette sélection");
			} else {
				//window.location = "HttpSelectionAdd.asp?agent=" + iAgent + "&assoc=" + strAssoc + "&alert=" + iAlert
				doHttpRequest("HttpSelectionAdd.asp", "agent=" + iAgent + "&assoc=" + strAssoc + "&alert=" + iAlert);
				if (strError == "") {
					objSelectedItem.text = pText + " (Ajoutée)";
					if (iAgent == document.getElementById("agent").value) {
						setSelectionCount("ADD");
					}
				}
			}
		} else {
			iAgent = document.getElementById("agent").value;
			doHttpRequest("HttpSelectionAdd.asp", "agent=" + iAgent + "&assoc=" + pAssoc + "&alert=0"); 
			if (strError == "") {
				objAdvertRowSelection = document.getElementById('advertRowSelection' + pAdvert);
				objAdvertRowSelection.innerHTML = "Ajoutée à la sélection";
				setSelectionCount("ADD");
			}
		}

	}

	function deleteSelection(pR, pId) { 
	
		strError = "";

		var answer = confirm ("Voulez-vous vraiment désélectionner cette annonce ?")
		if (answer) {
			doHttpRequest("HttpSelectionDelete.asp", "selection=" + pId ); 
			if (strError == "") {
				objAdvert = document.getElementById("advert" + pR);
				objAdvert.style.display = "none";
				setSelectionCount("DEL");
			}
		}			

	}
	

	function setSelectionCount(pStatus) {

		objSelectionCountTitleBar = document.getElementById('selectionCountTitleBar');
		iSelection = objSelectionCountTitleBar.innerHTML;
		iSelection = iSelection.replace("(", "");
		iSelection = iSelection.replace(")", "");
		iSelection = parseInt(iSelection);

		if (pStatus == "ADD") {
			iSelection = iSelection + 1;
		} else if (pStatus == "DEL") {
			iSelection = iSelection - 1;
		} else if (pStatus == "DELALL") {
			iSelection = 0;
		}

		objSelectionCountTitleBar.innerHTML = "(" + iSelection + ")";

		if (document.getElementById('selectionCount') != null) {
			objSelectionCount = document.getElementById('selectionCount');
			objSelectionCount.innerHTML = iSelection + " annonce(s)";
		}
	
	}
	

	function emptySelection() {

		strError = "";

		answer = confirm("Voulez-vous vraiment vider toutes les annonces dans votre sélection?")
		if (answer) {

			pAgent = document.getElementById('agent').value;
			doHttpRequest("HttpSelectionDeleteAll.asp", "agent=" + pAgent ); 

			if (strError == "") {
				document.getElementById('selection').style.display = "none";
				setSelectionCount("DELALL");
			}
		}

	}

