var browser = "";
var agent = navigator.userAgent.toLowerCase();
if(agent.indexOf("ie") != -1){
	browser = "IE";
}
if(agent.indexOf("firefox") != -1){
	browser = "Firefox";
}
if(agent.indexOf("netscape") != -1){
	browser = "Netscape";
}

function obj(id)
{
    return document.getElementById(id);
}

function objP(id)
{
    return window.parent.document.getElementById(id);
}

function buscar(caller,start,secc)
{
    var valor     = obj('buscar').value.replace(/ /g, "+");
    var limit     = (obj('limit') ? obj('limit').value : 10);
    var orden     = (obj('orden') ? obj('orden').value : "DESC");
    var feeder    = (obj('feeder') ? obj('feeder').value : "");
    var seccion   = (obj('seccion') ? obj('seccion').value : "");
	var tipoNota  = (obj('tipoNota') ? obj('tipoNota').value : "");
	var reportero = (obj('reportero') ? obj('reportero').value : "no");

	if(obj('buscarGoogle')){
		if(obj('buscarGoogle').checked){
			window.location.href = "http://www.google.com.mx/search?hl=es&q=" + valor + "&btnG=Buscar+con+Google&meta=";
			return 0;
		}
	}
    else{
        if(obj('tipoBuscar')){
            if(obj('tipoBuscar').value == "google"){
                window.location.href = "http://www.google.com.mx/search?hl=es&q=" + valor + "&btnG=Buscar+con+Google&meta=";
                return 0;
            }
            if(obj('tipoBuscar').value == "yahoo"){
                window.location.href = "http://mx.search.yahoo.com/search?p=" + valor + "&fr=yfp&toggle=1&cop=&ei=UTF-8&rd=r1";
                return 0;
            }
        }
    }

	if(start){
        if(caller == "solr"){
            valor += "&offset=" + start;
        }
        else{
            valor += "&start=" + start;
        }
	}
    if(secc){
        valor += "&secc=" + secc;
    }

	var params = "";
	if(obj('fechaIni')){
		params += "&fechaIni=" + obj('fechaIni').value;
	}
	if(obj('fechaFin')){
		params += "&fechaFin=" + obj('fechaFin').value;
	}
	if(obj('tipoNota')){
		params += "&tipoNota=" + obj('tipoNota').value;
	}
    if(feeder != ""){
        params += "&feeder=" + feeder;
    }
    if(reportero != ""){
        params += "&reportero=" + reportero;
    }
    if(seccion != ""){
        params += "&secc=" + seccion;
    }
    if(caller == "/look/buscarEv"){
        window.location.href = caller + ".php?buscar=" + valor + "&limit=" + limit + "&orden=" + orden + "&tipoBuscar=" + obj('tipoBuscar').value + params;
    }
    else{
        if(caller == "solr"){
            window.location.href = '/buscar/?q=' + valor + "&limit=" + limit + "&orden=" + orden + params;
        }
        else{
            window.location.href = caller + '.php?buscar=' + valor + "&limit=" + limit + "&orden=" + orden + params;
        }
    }

    return 0;
}

function enterKey(evt,caller)
{
	var code;
	if(!evt){
		evt = window.event;
	}

	if(evt.keyCode)				// IE
		code = evt.keyCode;
	else{
		if(evt.which)			// Firefox, Netscape
			code = evt.which;
		}
	if(code == 13){
		if(caller == 'defecto') {
			obj('datos').submit();
		}
		else if(caller == 'passChat') {			
			validaPassword(event,'password');
			validaDatosChat();
		}
		else {
			buscar(caller);
		}
	}
	return 0;
}

function updatePage()
{
    window.setTimeout("history.go(0)", 600000);
}

function eligeTipo(opcion)
{
	if(opcion == 1){ obj('tipoBuscar').value  = 'evento'; }
  	if(opcion == 2){ obj('tipoBuscar').value  = 'persona'; }
    return 0;
}

function toggleHideShow(id) {
	if (obj(id).style.display == 'none') {
		obj(id).style.display = 'block'
	} else {
		obj(id).style.display = 'none'
	}
}

var idEventoActual;
var handleSuccess2 = function(o){
	if(o.responseText !== undefined){
		obj('imgEventoHomepage'+idEventoActual).src = o.responseText;
	}
}
var callback2 = { success:handleSuccess2 };
function activarHomepage(idEvento) {
	idEventoActual = idEvento;
	obj('imgEventoHomepage'+idEventoActual).src = "/img/ajax12x12.gif";
	var request = YAHOO.util.Connect.asyncRequest("GET", "services/lookActivarHomepage.php?idEvento="+idEvento, callback2);
}



var idRevistaDigital;
var handleSuccessRevistaDigital = function(o){
	if(o.responseText !== undefined){
		obj('imgRevistaDigital'+idRevistaDigital).src = o.responseText;
	}
}
var callbackRevistaDigital = { success:handleSuccessRevistaDigital };
function activarLookDigital(id) {
	idRevistaDigital = id;
	obj('imgRevistaDigital'+idRevistaDigital).src = "/img/ajax12x12.gif";
	var request = YAHOO.util.Connect.asyncRequest("GET", "services/lookActivarRevistaDigital.php?id="+idRevistaDigital, callbackRevistaDigital);
}




function showPopUp(el) {
	var cvr = document.getElementById("cover");
	var dlg = document.getElementById(el);
	cvr.style.display = "block";
	dlg.style.display = "block";
	document.body.style.overflow = 'hidden';
	if (document.body.style.overflow == 'hidden') {
	  cvr.style.width = "100%";
	  cvr.style.height = "100%";
	}
	scroll(0, 0);
}

function closePopUp(el) {
	var cvr = document.getElementById("cover");
	var dlg = document.getElementById(el);
	cvr.style.display = "none";
	dlg.style.display = "none";
	document.body.style.overflowY = "scroll";
}

var handleSuccessPortadasDigital = function(o){
	if(o.responseText !== undefined){
		obj('divTodasRevistasPortadas').innerHTML = o.responseText;
	}
}
var callbackPortadasDigital = { success:handleSuccessPortadasDigital };
function cargaPortadasDigital(pag) {
	obj('divTodasRevistasPortadas').src = "/img/ajax12x12.gif";
	var request = YAHOO.util.Connect.asyncRequest("GET", "/look/ajax/portadasDigital.php?pag="+pag, callbackPortadasDigital);
}

