/*Event.observe(document, 'dom:loaded', convertSelectToList);*/

function convertSelectToList(containerDivId, baseURL){
	//alert ('entring function');
	if (document.getElementById(containerDivId)){
		var containerDiv = document.getElementById(containerDivId);
		
		// This captures all hidden fields from the form nested inside the div
		var inputAry = containerDiv.getElementsByTagName("input");
		var irParams = { };
		
		for (i = 0; i < inputAry.length; i++){
			if (inputAry[i].type.match(/hidden/)){
				irParams[inputAry[i].name] = escape(inputAry[i].value);
			}
		} 
		
		var selectAry = containerDiv.getElementsByTagName("select");
		if (selectAry.length){			
			var currentNode = containerDiv;
			for (i = 0; i < selectAry.length; i++){
				var theSelect = selectAry[i];
				for (j = 0; j < theSelect.options.length; j++){
					
					// build the query string
					if (theSelect.options[j].text) irParams["question"] = escape(theSelect.options[j].text);
					irParams["id"] = theSelect.options[j].value;
					
					var urlString = baseURL + "?";
					var ampersand = "";
					for (k in irParams){
						urlString += ampersand + k + "=" + irParams[k];
						ampersand = "&";
					}
					
					// add the anchor tags, each in their own P tag.
					var newNode = document.createElement("p");
					//newNode.setAttribute("class", "linkList");
					var att = document.createAttribute("class");
					att.value = "linkList";
					newNode.setAttributeNode(att);
					newNode = insertAfter(currentNode, newNode);
					currentNode = newNode;
					
					newNode = document.createElement("a");
					currentNode.appendChild(newNode);
					newNode.href = urlString; //alert (urlString);
					
					newNode.appendChild(document.createTextNode(theSelect.options[j].text));					
				}
			}
			
			// hide the Form's DIV
			containerDiv.style.display = "none";
			//alert ('exiting function');
					
		} else {
			//alert ("convertSelectToList error: no <select> tags found within div ID \"" + containerDivId + "\".");
		}
	} else {
		alert ("convertSelectToList error: div ID \"" + containerDivId + "\" not found in page code.");
	}
}

// from: http://soopergeek.blogspot.com/
// courtesy, Jon Wire
// modified to include a return value, changed order of parameters
function insertAfter(existing_node, new_node) {  
	if (existing_node.nextSibling) {
		return existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling);
	} else {
		return existing_node.parentNode.appendChild(new_node);
	}
} // insertAfter()


//Remove all the double quote Characters (") from the question
var newval = new String();
var frdefaultStr = 'Inscrivez votre question ici';
function clearQuotes(){
	var d = document.AskUsSearch;
	if (d.question.value!=frdefaultStr){
		newval = d.question.value.replace(/\"/g, "");
		d.question.value = newval;
	}
	/*alert(" "+d.question.value);*/
	/*alert(" "+newval);*/
	return true;
}