
var myConn = new XHConn();

if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

var include_terminado = function (oXML) { document.getElementById('include').innerHTML = oXML.responseText; };
var dataNUEVA = function (oXML) { document.getElementById('dataNEW').innerHTML = oXML.responseText; };

function getNEWS(id)
{

	app  = "/site/app/getNEWS.php";
	send = "db=libros";
	myConn.connect(app, "POST", send, dataNUEVA);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function showRECORD(id)
{
	app  = "/site/app/search.php";
	send = "db=libros&from=1&exp="+id;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}


function cambiarLETRA(buscar,cambiar,exp)
{
    
    while (true) {
    
        if (exp.indexOf(buscar)==-1) break;
        else {
            exp = exp.replace(buscar,cambiar);
        }
    }
    
    return exp;

}

function limpiarACENTOS(exp)
{
    exp = cambiarLETRA("á","a",exp);
    exp = cambiarLETRA("é","e",exp);
    exp = cambiarLETRA("í","i",exp);
    exp = cambiarLETRA("ó","o",exp);
    exp = cambiarLETRA("ú","u",exp);
    exp = cambiarLETRA("ñ","n",exp);
    exp = cambiarLETRA("Ñ","N",exp);

    return exp;
}

function include_dinamicoMORE (url)
{
	if (trim(document.buscar.exp.value)=="" && trim(document.buscar.exp1.value)=="") {
		alert("Debe ingresar palabra(s) para la búsqueda");
		return;
	}

    from = document.buscar.from.value;
    idx  = document.buscar.db.selectedIndex; idx  = (idx<0 ? 0 : idx);
	db   = document.buscar.db.options[idx].value;

	exp = limpiarACENTOS(document.buscar.exp.value);
        idx  = document.buscar.item.selectedIndex; idx  = (idx<0 ? 0 : idx);
 	    campo = document.buscar.item.options[idx].value;
        idx  = document.buscar.cnx1.selectedIndex; idx  = (idx<0 ? 0 : idx);
 	    cnx1 = document.buscar.cnx1.options[idx].value;

	exp1 = limpiarACENTOS(document.buscar.exp1.value);
        idx  = document.buscar.item1.selectedIndex; idx  = (idx<0 ? 0 : idx);
	    campo1 = document.buscar.item1.options[idx].value;

        
	app  = "/site/app/searchMORE.php";
	send = "db="+db+"&from="+from+"&exp="+exp+"&item="+campo+"&cnx1="+cnx1+"&exp1="+exp1+"&item1="+campo1;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}


function include_avanzado (url)
{
	if (trim(document.buscar.exp1.value)=="" && trim(document.buscar.exp2.value)=="" && trim(document.buscar.exp3.value)=="" ) {
		alert("Debe ingresar palabra(s) para la búsqueda");
		return;
	}

    from = document.buscar.from.value;
    tipo = document.buscar.tipo.value;
	exp1 = limpiarACENTOS(document.buscar.exp1.value);
	exp2 = limpiarACENTOS(document.buscar.exp2.value);
	exp3 = limpiarACENTOS(document.buscar.exp3.value);

	idx = document.buscar.db.selectedIndex; idx = (idx<0 ? 0 : idx);
	db  = document.buscar.db.options[idx].value;

	idx = document.buscar.filtro1.selectedIndex; idx = (idx<0 ? 0 : idx);
	ft1 = document.buscar.filtro1.options[idx].value;
    
	idx = document.buscar.filtro2.selectedIndex; idx = (idx<0 ? 0 : idx);
	ft2 = document.buscar.filtro2.options[idx].value;

	idx = document.buscar.filtro3.selectedIndex; idx = (idx<0 ? 0 : idx);
	ft3 = document.buscar.filtro3.options[idx].value;
    
	idx = document.buscar.conector1.selectedIndex; idx = (idx<0 ? 0 : idx);
	cn1 = document.buscar.conector1.options[idx].value;
    
	idx = document.buscar.conector2.selectedIndex; idx = (idx<0 ? 0 : idx);
	cn2 = document.buscar.conector2.options[idx].value;

    id1 = (document.buscar.idi1.checked ? document.buscar.idi1.value : "");
    id2 = (document.buscar.idi2.checked ? document.buscar.idi2.value : "");
    id3 = (document.buscar.idi3.checked ? document.buscar.idi3.value : "");
    id4 = (document.buscar.idi4.checked ? document.buscar.idi4.value : "");
    id5 = (document.buscar.idi5.checked ? document.buscar.idi5.value : "");
    
	app  = "/site/app/searchAVANZADA.php";
	send = "tipo="+tipo+"&db="+db+"&from="+from+"&exp1="+exp1+"&exp2="+exp2+"&exp3="+exp3+ "&ft1="+ft1+"&ft2="+ft2+"&ft3="+ft3+"&cn1="+cn1+"&cn2="+cn2+"&id1="+id1+"&id2="+id2+"&id3="+id3+"&id4="+id4+"&id5="+id5;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}

function include_dinamico (url)
{
	if (trim(document.buscar.exp.value)=="") {
		alert("Debe ingresar palabra(s) para la búsqueda");
		return;
	}

	exp = limpiarACENTOS(document.buscar.exp.value);

    tipo = document.buscar.tipo.value;
    from = document.buscar.from.value;
	idx = document.buscar.db.selectedIndex;
	idx = (idx<0 ? 0 : idx);
	db  = document.buscar.db.options[idx].value;
    
	app  = "/site/app/search.php";
	send = "tipo="+tipo+"&db="+db+"&from="+from+"&exp="+exp;
    
	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}

function irPAGINA(pag)
{
	app  = "/site/app/search.php";
	send = "db="+ document.paginar.db.value +"&categoria="+document.paginar.categoria.value+"&from="+pag+"&exp="+ document.paginar.exp.value;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}


function fastSEARCH(db,exp)
{
    from = 1;
	app  = "/site/app/search.php";
	send = "db="+db+"&from="+from+"&exp="+exp;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}


function imprimir()
{
    winPRINT = window.open("","winPRINT","WIDTH=500,HEIGHT=550,menubar=no,resizable=no,scrollbars=yes,status=yes,location=no,toolbar=no");
    winPRINT.moveTo(0,0);
    document.imprimir.submit();
}


function mail()
{

    if (mail = prompt("Ingrese su E-mail: ","")) {
        document.mail.textoMAIL.value = document.getElementById("include").innerHTML;
        document.mail.mailTO.value = mail;
        winMAIL = window.open("","winMAIL","WIDTH=1,HEIGHT=1,menubar=no,resizable=no,scrollbars=yes,status=yes,location=no,toolbar=no");
        winMAIL.moveTo(800,800);
        document.mail.submit();
    }
}


function evaluaTECLA()
{
    if(event.keyCode==13){
        include_dinamico('resultado');
    }
}

function evaluaTECLA_1()
{
    if(event.keyCode==13){
        include_avanzado ('resultado');
    }
}

/*****************************************
TEMAS
*/
function quitSEARCH(exp,idx)
{
	app  = "/site/app/search.php";
	send = "db=all&from=1&categoria=Si&exp="+exp+"&idx="+idx;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}

function fastSEARCH_TEMA(db,exp)
{
    from = 1;
	app  = "/site/app/search.php";
	send = "db="+db+"&categoria=Si&from="+from+"&exp="+exp;

	document.getElementById('include').innerHTML = "<img src='loading_ani2.gif' />";
	myConn.connect(app, "POST", send, include_terminado);
}


function controlSELECT(objSELECT)
{

    tablaPUBLICACIONES = "articulo:art;publicacion:pub;revistas:rev";

    idx = objSELECT.selectedIndex;
    idx = (idx==-1 ? 0 : idx);
    
    key = objSELECT.options[idx].value;
    
    if (tablaPUBLICACIONES.indexOf(key)==-1) {
        addSELECT(document.buscar.filtro1,"autnom","Autor");
        addSELECT(document.buscar.filtro2,"autnom","Autor");
        addSELECT(document.buscar.filtro3,"autnom","Autor");
    } else  {
        removeSELECT(document.buscar.filtro1,"autnom");    
        removeSELECT(document.buscar.filtro2,"autnom");    
        removeSELECT(document.buscar.filtro3,"autnom");    
    }
    
    

}

function removeSELECT(objSELECT,key)
{

    for (ix=0; ix < objSELECT.length; ix++) {
    
        if (objSELECT.options[ix].value == key) {
            objSELECT.options[ix] = null;
        }
    
    }
}


function addSELECT(objSELECT,key,texto)
{

    addOPC = new Option(texto,key);
    objSELECT.options[objSELECT.length] = addOPC;
    
}