// JavaScript Document
function nuevoAjax(xmlhttp){

   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 buscarscripts(elemento_res) 
{
	var script = document.getElementById(elemento_res).innerHTML;
	script = script.extractScripts();
	for(i=0;i<script.length;i++)
		instalar(script[i]);
}


function instalar(script) 
{
	script = script.replace("<!--","");
	script = script.replace("//-->","");
	if (window.execScript)
		window.execScript(script);
	else
		window.setTimeout(script, 0);
}

//tiny es falso o bien el id del mce a activar en destino
function llamar_php(pagina, destino, valor, funcion){
   var contenedor;
   var ajax;
   
   
   ajax = nuevoAjax(ajax);
   ajax.open("POST",pagina,true);
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
      	if (destino != false)
      	{
      	 contenedor = document.getElementById(destino);
         contenedor.innerHTML = "";
         contenedor.innerHTML = ajax.responseText;
      	}
         //recuperar posibles scripts de javascript y ejecutarlos.
					scripts= ajax.responseText;
					while (scripts.indexOf("<script>")!=-1)
					{
					  restohtml= scripts.substring(scripts.indexOf("/script")+7, scripts.length);
					  scripts= scripts.substring(scripts.indexOf("<script>")+8, scripts.indexOf("/script")-1);
					  eval(scripts);
					  scripts= restohtml;
					}
      }
   }
   ajax.send("vari="+valor+"&func"+"="+funcion);
}





function busqueda(mthis, tipo)
{
  cadena = "";
  
  n_ele = mthis.elements.length-1;
    for (i=0; i <= (n_ele-1); i++)
    {
    if (cadena != "")
      { 
        cadena = cadena + "|";
      }
        cadena = cadena + '%'+mthis.elements[i].value+'%';
    }
  
  cadena = cadena.replace(/\%/g, '%25');
  cadena = cadena.split(",").join("%2C");
  cadena = cadena.split("+").join("%20");
  
  
  llamar_php("./vista/manejador.php", "resultados_no", cadena, tipo);
  return false;

}



function URL_encode(sStr) {
    return sStr
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27')
              .replace(/\=/g, '%3D')	
               .replace(/\&/g, '%26');
  }

function email(elemento)
{
	datos = URL_encode(elemento.innerHTML);
	
	llamar_php('./vista/manejador.php','noticia','PR|Solicitud asoc. SPM|'+datos+'|asime@asime.es','send_mail');
}

