function nuevoAjax () {
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function refrescarMenus (idmenu) {
	var ajaxMenus;
	var respuestaXml;
	var navegacionPrincipal = document.getElementById('navegacionprincipal');
	var navegacionSecundaria = document.getElementById('navegacionsecundaria');
	var rastro = document.getElementById('rastro');
	var titulo = document.getElementById('titulo');
	var subtitulo = document.getElementById('subtitulo');
	var contenido = document.getElementById('contenido');

	ajaxMenus = nuevoAjax ();
	ajaxMenus.open("POST", "ajaxindexv2.php",true);
	ajaxMenus.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxMenus.send("tag=refrescarMenus&idmenu=" + idmenu);

	ajaxMenus.onreadystatechange = function(){
		if (ajaxMenus.readyState == 4) {
			//Ahora tengo que procesar el xml de respuesta...
			if (ajaxMenus.status == 200) {
				respuestaXml = ajaxMenus.responseXML;
				navegacionPrincipal.innerHTML = respuestaXml.getElementsByTagName("navegacionPrincipal")[0].firstChild.nodeValue;
				if (respuestaXml.getElementsByTagName("navegacionSecundaria")[0].firstChild.nodeValue != '') {
					ver = '';
				} else {
					ver = 'none';
				}
				navegacionSecundaria.innerHTML = respuestaXml.getElementsByTagName("navegacionSecundaria")[0].firstChild.nodeValue;
				document.getElementById('bs').style.display = ver;
				rastro.innerHTML = respuestaXml.getElementsByTagName("rastro")[0].firstChild.nodeValue;
				titulo.innerHTML = respuestaXml.getElementsByTagName("titulo")[0].firstChild.nodeValue;
				subtitulo.innerHTML = respuestaXml.getElementsByTagName("subtitulo")[0].firstChild.nodeValue;
				contenido.innerHTML = respuestaXml.getElementsByTagName("contenido")[0].firstChild.nodeValue;
			} else {
				alert("Estado: " + ajaxMenus.status + "\nMotivo: " + ajaxMenus.statusText);
			}
		}
	}

}

function enviarform (idform, idmenu, accion, idelem) {
	var formulario;
	var longitudformulario;
	var cadenaformulario;
	var sepcampos;
	var ajaxMenus;
	var respuestaXml;
	var navegacionPrincipal = document.getElementById('navegacionprincipal');
	var navegacionSecundaria = document.getElementById('navegacionsecundaria');
	var rastro = document.getElementById('rastro');
	var titulo = document.getElementById('titulo');
	var subtitulo = document.getElementById('subtitulo');
	var contenido = document.getElementById('contenido');

	if (idform != "noform") {
		//Serializamos el formulario.
		formulario = document.getElementById(idform);
		longitudformulario = formulario.elements.length;
		cadenaformulario = "";
		sepcampos = "";
		for (var i = 0; i <= formulario.elements.length - 1; i++) {
			if (formulario.elements[i].type == "radio"){
				if (formulario.elements[i].checked == true){
				cadenaformulario += sepcampos+formulario.elements[i].name+'='+encodeURI(formulario.elements[i].value);
				sepcampos = "&";
				}
			}else{
				cadenaformulario += sepcampos+formulario.elements[i].name+'='+encodeURI(formulario.elements[i].value);
				sepcampos = "&";
			}
		}
	}

	//Creamos el objeto ajax y le enviamos los parametros.
	ajaxMenus = nuevoAjax ();
	ajaxMenus.open("POST", "ajaxindexv2.php",true);
	ajaxMenus.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxMenus.send("tag=refrescarMenus&idmenu=" + idmenu + "&accion=" + accion + "&" + cadenaformulario + "&idelem=" + idelem);
	var_estadoactual = null;
	if (document.getElementById('estadoactual')) {
		var_estadoactual = document.getElementById ('estadoactual');
		textito = document.getElementById ('textomensaje');
		var_estadoactual.style.display= '';
		textito.style.background='#FF9900';
		textito.innerHTML = "Procesando, por favor aguarde...";
	}
	ajaxMenus.onreadystatechange = function() {

		if (ajaxMenus.readyState == 4) {
			//Ahora tengo que procesar el xml de respuesta...
			if (ajaxMenus.status == 200) {
				respuestaXml = ajaxMenus.responseXML;
				navegacionPrincipal.innerHTML = respuestaXml.getElementsByTagName("navegacionPrincipal")[0].firstChild.nodeValue;
				if (respuestaXml.getElementsByTagName("navegacionSecundaria")[0].firstChild.nodeValue != '') {
					ver = '';
				} else {
				ver = 'none';
				}
				navegacionSecundaria.innerHTML = respuestaXml.getElementsByTagName("navegacionSecundaria")[0].firstChild.nodeValue;
				document.getElementById('bs').style.display = ver;
				rastro.innerHTML = respuestaXml.getElementsByTagName("rastro")[0].firstChild.nodeValue;
				titulo.innerHTML = respuestaXml.getElementsByTagName("titulo")[0].firstChild.nodeValue;
				subtitulo.innerHTML = respuestaXml.getElementsByTagName("subtitulo")[0].firstChild.nodeValue;
				contenido.innerHTML = respuestaXml.getElementsByTagName("contenido")[0].firstChild.nodeValue;
			} else {
				alert("Estado: " + ajaxMenus.status + "\nMotivo: " + ajaxMenus.statusText);
			}
		} else {
			if (var_estadoactual != null) {
				var_estadoactual.style.display= '';
				textito.style.background='#FF9900';
				textito.innerHTML = "Procesando, por favor aguarde...";
			}
		}
	}

}
