
var xsl_param = new Array(9);
for (i = 0; i < 9; ++ i)
	xsl_param [i] = new Array(2);

function inicializa_parametros_XSL()
{
  var i;

	for (i = 0; i < 9; i++) {
		xsl_param [i][0]='';	<!-- nombre parametro -->
		xsl_param [i][1]='';	<!-- valor parametro -->
	}
}

function formatea_XML_con_XSL (xmlfile, xslfile, id_div)
{
	var xsl, xml, xsltProcessor, xsltCache;
	
	if (window.ActiveXObject)
  { // code for IE
		// instantiate and load the xml document
		xml = new ActiveXObject("MSXML2.DOMDocument");
		xml.async = false;
		xml.load(xmlfile);
		// instantiate and load the xsl document
		xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		xsl.async = false;
		xsl.load(xslfile);
		// prepare the xsl document for transformation
		xsltCache = new ActiveXObject("MSXML2.XSLTemplate");
		xsltCache.stylesheet = xsl;
		// instantiate the document processor and submit the xml document
		xsltProcessor = xsltCache.createProcessor();
		xsltProcessor.input = xml;
		xsltProcessor.transform();
		document.getElementById(id_div).innerHTML=xsltProcessor.output;
  }
  else if (document.implementation && document.implementation.createDocument)
  { // code for Mozilla, Firefox, Opera, etc.
		// instantiate and load the xml document
    xml=document.implementation.createDocument("","",null);
		xml.async=false;
		xml.load(xmlfile);
		// instantiate and load the xsl document
    xsl=document.implementation.createDocument("","",null);
		xsl.async=false;
		xsl.load(xslfile);
		// instantiate the document processor and submit the xml document
	  xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById(id_div).appendChild(resultDocument);
  }
  else
	{ // Browser desconocido
		alert("Navegador de Internet desconocido");
	}
}

function formatea_XML_con_XSL_Param(xmlfile, xslfile, num_param, id_div)
{
	var xsl, xml, xsltProcessor, xsltCache;
	var num;
	
	if (window.ActiveXObject)
  { // code for IE
		// instantiate and load the xml document
		xml = new ActiveXObject("MSXML2.DOMDocument");
		xml.async = false;
		xml.load(xmlfile);
		// instantiate and load the xsl document
		xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		xsl.async = false;
		xsl.load(xslfile);
		// prepare the xsl document for transformation
		xsltCache = new ActiveXObject("MSXML2.XSLTemplate");
		xsltCache.stylesheet = xsl;
		// instantiate the document processor and submit the xml document
		xsltProcessor = xsltCache.createProcessor();
		xsltProcessor.input = xml;
		for (num = 0; num < num_param; num++) {
			xsltProcessor.addParameter(xsl_param [num][0], xsl_param [num][1]);
		}
		xsltProcessor.transform();
		document.getElementById(id_div).innerHTML=xsltProcessor.output;
  }
  else if (document.implementation && document.implementation.createDocument)
  { // code for Mozilla, Firefox, Opera, etc.
		// instantiate and load the xml document
    xml=document.implementation.createDocument("","",null);
		xml.async=false;
		xml.load(xmlfile);
		// instantiate and load the xsl document
    xsl=document.implementation.createDocument("","",null);
		xsl.async=false;
		xsl.load(xslfile);
		// instantiate the document processor and submit the xml document
	  xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
		for (num = 0; num < num_param; num++) {
			xsltProcessor.setParameter(null, xsl_param [num][0], xsl_param [num][1]);
		}
    resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById(id_div).appendChild(resultDocument);
  }
  else
	{ // Browser desconocido
		alert("Navegador de Internet desconocido");
	}
}

function servicio_seleccionado(valor_seleccionado, id_div)
{
	servicio_pf = valor_seleccionado;
	document.getElementById(id_div).innerHTML = "";
	xsl_param [0][0]='servicio_pf';
	xsl_param [0][1]=servicio_pf;
	xsl_param [1][0]='accion_pf';
	xsl_param [1][1]=accion_pf;
	formatea_XML_con_XSL_Param ("contenidos/preguntas_frecuentes.xml", "plantillas/detalle_preguntas_frecuentes.xsl", 2, "detalle_preguntas_frecuentes");
}

function accion_seleccionado(valor_seleccionado, id_div)
{
	accion_pf = valor_seleccionado;
	document.getElementById(id_div).innerHTML = "";
	xsl_param [0][0]='servicio_pf';
	xsl_param [0][1]=servicio_pf;
	xsl_param [1][0]='accion_pf';
	xsl_param [1][1]=accion_pf;
	formatea_XML_con_XSL_Param ("contenidos/preguntas_frecuentes.xml", "plantillas/detalle_preguntas_frecuentes.xsl", 2, "detalle_preguntas_frecuentes");
}

function enviar_consulta(email, consulta, servicio, accion, titulo, texto)
{
	if (validarEmail(email) == false) {
		alert("La dirección de email no es correcta.");
	} else if (consulta == "Selecciona") {
		alert("Por favor selecciona el tipo de consulta");
	} else if (servicio == "Selecciona") {
		alert("Por favor selecciona el servicio o producto relacionado con la consulta");
	} else if (accion == "Selecciona") {
		alert("Por favor selecciona el tipo de acción relacionada con la consulta");
	} else if (titulo == "") {
		alert("Por favor defina el título de la consulta");
	} else if (texto == "") {
		alert("Por favor detalle la consulta para poder darle una solución como respuesta, gracias");
	} else {
		return true;
	}
	return false;
}

function validarEmail(valor)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor))
	{
		return (true);
	} else {
		return (false);
	}
}

function validarEmail2(valor) // Teoricamente mejorada
{
	if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)) {
		return (true);
	} else {
		return (false);
	}
}