function clsQUERY()
{

    msgTXT = document.getElementById("msg");
    msgTXT.style.visibility = "hidden";

    msgRES = document.getElementById("result");
    msgRES.style.visibility = "hidden";

    msgINT = document.getElementById("introduccion");
    msgINT.style.visibility = "visible";

    document.buscar.expresion.value = "";

}


function changeLETRA(exp,expBUSCAR,expCAMBIAR)
{
	

    exp = exp.replace(expBUSCAR,expCAMBIAR);
    return exp;

}



function runQUERY()
{

	ubiPUB = "";
	ubiINF = "";
	ubiDIR = "";
	idx = document.buscar.idSEARCH.selectedIndex;
	idx = (idx < 0 ? 0 : idx);
	idSEARCH = document.buscar.idSEARCH.options[idx].value;
	if (idSEARCH!="") idSEARCH = "[" + idSEARCH + "[";

  	if (document.buscar.pub.checked) ubiPUB = "[" + document.buscar.pub.value + "]";
  	if (document.buscar.inf.checked) ubiINF = "[" + document.buscar.inf.value + "]";
  	if (document.buscar.dir.checked) ubiDIR = "[" + document.buscar.dir.value + "]";

    	exp = document.buscar.expresion.value;
    	exp = exp.toUpperCase();

 	exp = changeLETRA(exp,"Á","A");
 	exp = changeLETRA(exp,"É","E");
 	exp = changeLETRA(exp,"Í","I");
 	exp = changeLETRA(exp,"Ó","O");
 	exp = changeLETRA(exp,"Ú","U");
 	exp = changeLETRA(exp,"Â","A");
 	exp = changeLETRA(exp,"Ä","A");
 	exp = changeLETRA(exp,"À","A");
 	exp = changeLETRA(exp,"Å","A");
 	exp = changeLETRA(exp,"Ç","C");
 	exp = changeLETRA(exp,"Ê","E");
 	exp = changeLETRA(exp,"Ë","E");
 	exp = changeLETRA(exp,"È","E");
 	exp = changeLETRA(exp,"Ï","I");
 	exp = changeLETRA(exp,"Î","I");
 	exp = changeLETRA(exp,"Ì","I");
 	exp = changeLETRA(exp,"Í","I");
 	exp = changeLETRA(exp,"Û","U");
 	exp = changeLETRA(exp,"Ù","U");
 	exp = changeLETRA(exp,"Ú","U");
 	exp = changeLETRA(exp,"Ö","O");
 	exp = changeLETRA(exp,"Õ","O");
 	exp = changeLETRA(exp,"ñ","N");
 	exp = changeLETRA(exp,"Ñ","N");
	exp = changeLETRA(exp,"ç","C");
        exp = changeLETRA(exp,"Ã","A");
        exp = changeLETRA(exp,"ã","A");



    if (exp.length==0) return;

	tbusq = (document.buscar.tbusq[0].checked ? "and" : "or");
	
    //msgTXT = document.getElementById("msg");
    //msgTXT.style.visibility = "visible";

    msgRES = document.getElementById("result");
    msgRES.style.visibility = "visible";
    msgRES.innerHTML = "<img src='buscando.gif' >buscando información...";

    msgINT = document.getElementById("introduccion");
    msgINT.style.visibility = "hidden";

/********************
 * Ubica los registros
 ********************/

    res = ""; arrEXP = exp.split(" "); idxRES="";totREG = 0;
    totDATA = document.cdDATA.keyWORD.length;

//alert(document.cdDATA.recDATA.length);

    for(ix=0;ix<totDATA;ix++)
    {
        addRECORD=(tbusq=="and" ? true : false);

        for (ax=0;ax<arrEXP.length;ax++)
        {
            keyWORD = " "+document.cdDATA.keyWORD.options[ix].value;
			expUBIC = arrEXP[ax];
			
			if (tbusq=="and"){
		            if (keyWORD.indexOf(expUBIC)==-1){
					 addRECORD = false; ax = arrEXP.length + 1;
					 }
				
			} else {
	            	if (keyWORD.indexOf(expUBIC)>=0) addRECORD = true;
			}

        }

        if (addRECORD==true){

			 stPUB = false;
			 stINF = false;
			 stDIR = false;

			 if (ubiPUB != ""){
			 	stPUB = true;
			   	if (keyWORD.indexOf(ubiPUB)==-1)  stPUB = false;
			 }

			 if (ubiINF != ""){
			 	stINF = true;
			   	if (keyWORD.indexOf(ubiINF)==-1)  stINF = false;
			 }

			 if (ubiDIR != ""){
			 	stDIR = true;
			   	if (keyWORD.indexOf(ubiDIR)==-1)  stDIR = false;
			 }

		 	 addRECORD = (stPUB || stINF || stDIR);

			 if (idSEARCH!=""){
			   if (keyWORD.indexOf(idSEARCH)==-1)  addRECORD = false;
			 }

			 if (addRECORD) {
		            totREG++; 
		            res = res + "<b>" + totREG + ".</b> " +document.cdDATA.recDATA.options[ix].value +"<p>";
			 }
			 
        }
    }

   // msgTXT.style.visibility = "hidden";
    msgSEARCH = "No se recuperaron registros";
    if (document.buscar.idioma.value=="I") msgSEARCH = "No records found";
    if (document.buscar.idioma.value=="P") msgSEARCH = "Registros não recuperados";

    msgRESULT = "Total Registros";
    if (document.buscar.idioma.value=="I") msgRESULT = "Hits";
    if (document.buscar.idioma.value=="P") msgRESULT = "Total Registros";

    if (res=="") result.innerHTML = msgSEARCH + " <br><br><hr size=1 color=#c5960a>";
    else result.innerHTML = "<b>" + msgRESULT + ":</b> " + totREG + "<br><br>\n" + res + "<hr size=1 color=#c5960a>";

}


function inputTEC(e)
{
    if (e.keyCode==13) runQUERY();
}