/* author: Montserrat Buend�a Ruiz */
/* Creation date: 14/11/2005 */

/* <![CDATA[ */
var req;
               
function loadXMLDoc(url) 
{
	req = false;

	if (window.XMLHttpRequest) {		// branch for native XMLHttpRequest Object
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	} else if (window.ActiveXObject) {	// branch for IE/Windows ActiveX version
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
     
	if (req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}
  
function processReqChange() 
{
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			rellenaDirecciones();
		} else {
			alert("There was a problem retrieving the XML data:\n" +
			req.statusText);
		}
	}
}
  
function limpiaDirecciones()
{
	var select = document.incidencia.direccion;
	while (select.length > 0) {
		select.remove(0);
	}
}
   
// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index)
{
	var result = "";
	if (prefix && isIE) {
		// IE/Windows way of handling namespaces
		result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
	} else {
		// the namespace versions of this method 
		// (getElementsByTagNameNS()) operate
		// differently in Safari and Mozilla, but both
		// return value with just local name, provided 
		// there aren't conflicts with non-namespace element
		// names
		result = parentElem.getElementsByTagName(local)[index];
	}
	if (result) {
		// get text, accounting for possible
		// whitespace (carriage return) text nodes 
		if (result.childNodes.length > 1) {
			return result.childNodes[1].nodeValue;
		} else {
			return result.firstChild.nodeValue;       
		}
	} else {
		return "n/a";
	}
}
    
function appendToSelect(select, value, content) 
{
	var opt = new Option(content, value);
	opt.value = value;
	select.options[select.length] = opt;
}


function rellenaDirecciones()
{
	var select = document.incidencia.direccion;
	select.options.length = 0;
	var items = req.responseXML.getElementsByTagName("item");

	// loop through <item> elements, and add each nested
	// <title> element to Topics select element
	appendToSelect( select, "", "Especificar direcci�n");
	for (var i = 0; i < items.length; i++) {
		appendToSelect(select, getElementTextNS("", "nombre", items[i], 0),
		getElementTextNS("", "nombre", items[i], 0));
	}
  
	fijaDireccion();	
}
  
  // Coge la direccion de la cookie
  
function cargarDirecciones()
{
	var val = document.incidencia.provincia.value;
	limpiaDirecciones();
	if ( val != 0 ) {
		loadXMLDoc( "xml/" + val + ".xml" );
	}	 
}
  
function verOtraDireccion()
{
	var val = document.incidencia.direccion.value;
	if (val == 'Otra direcci�n') {
		otradireccion.style.display='block';
	} else {
		otradireccion.style.display='none';
	}	
}
	
               
/* ]]> */