
var ctrlAJAX = 'divppal';
var al_completar='';
var busy = false;

function ajax_req(strurl,salida,pbody,oncomplet)
	{
        ctrlAJAX = salida;
        if (oncomplet==undefined){oncomplet=''}
        
        al_completar=oncomplet;
		work(1);
		var myAjax = new Ajax(strurl, {method: 'post', postBody: pbody, onComplete:showResponse, evalScripts:true});
		myAjax.request();
	}

function showResponse(originalRequest)
	{
        switch (originalRequest.split('_')[0])
        {
            case 'MSG':
                alert(originalRequest.split('_')[1]);
                break;
            case 'REDIR':
                window.location = originalRequest.split('_')[1];
                break;
            default:
                if (ctrlAJAX != '') {$(ctrlAJAX).innerHTML = originalRequest;}
                break;
        }

        if (al_completar.length >0) {
            eval(al_completar);
            al_completar='';
        }

		work(0);
	}

function work(si)
{
	if (si==1)
	{
		document.body.style.cursor = "wait";
		if ($('imgwork')) {$('imgwork').setStyle('display','block')};
	}
	else
	{
		document.body.style.cursor = "default";
		if ($('imgwork')) {$('imgwork').setStyle('display','none')};
	}
	informa();
}

function atras(){window.history.back()}

function fade(cual,desde,hasta,time)
{
    var myFx = new Fx.Style(cual, 'opacity').start(0.7);
}

function toggle_ver(cual){
    $(cual).style.display = ($(cual).style.display == 'none' | $(cual).style.display == '')?'block':'none';
}

function aladrillazo(cabecera,contenido){
    var myBox = $$(cabecera);

	myBox.each(function(element) {
		var fx = new Fx.Styles(element, {duration:200, wait:false});

		element.addEvent('mouseenter', function(e){
			e = new Event(e).stop();
			fx.start({
				'backgroundColor':'#ddd'
			});
		});

		element.addEvent('mouseleave', function(e){
			e = new Event(e).stop();
			fx.start({
				'backgroundColor':'#eee'
			});
		});

		element.addEvent('click', function(e){
			e = new Event(e).stop();
			conti = element.getNext(contenido);
			if (conti.getStyle('display')=='block'){
				element.setStyle('fontWeight','normal');
				new Fx.Styles($(conti), {duration: 450, wait:false,onComplete:function(){conti.setStyle('display','none');}}).start({'opacity':0});
			}
			else
			{
				element.setStyle('fontWeight','bold');
				conti.setStyles({opacity: 0,display:'block'});
				new Fx.Styles($(conti), {duration: 350, wait:false}).start({'opacity':1});
			}
		});
	});
}

function aladrilla(cabecera,contenido){

    var myBox = $$(cabecera);
    var myBoxOpen = $$(contenido);
//start:'first-close',

    var myAccordion = new Accordion(
	    myBox, myBoxOpen, {opacity: true,alwaysHide:true,show:1, start:'first-close',
		    onActive: function(tog){
			    tog.setStyles({color: '#003366',backgroundColor:'#eee',backgroundImage:'url(/img/gral/tic_dw.png)'});
		    },
		    onBackground: function(tog){
			    tog.setStyles({color: '#222',backgroundColor:'#eee',backgroundImage:'url(/img/gral/mark.png)'});
		    } 
	    }
    );
}

function cargascript(nscript)
{
    new Asset.javascript(nscript,{onload: function(){alert('script cargado!');}});
}

function situa(origen,pop,wid)
{

	wid=$(origen).getCoordinates().width;

	if (wid<150){wid=150}

	$(pop).setStyles({
			top:$(origen).getTop() + $(origen).getCoordinates().height,
			left:$(origen).getLeft(),
			width:wid
		});

}

function seltab(cual){

    $E('.TabCellSelLeft').className = 'TabCellLeft';
    $E('.TabCellSel').className = 'TabCell';
    $E('.TabCellSelRight').className = 'TabCellRight';
    $E('.pn_sel').className = 'pn_nosel';

    $('sl_' + cual + '_1').className = 'TabCellSelLeft';
    $('sl_' + cual + '_2').className = 'TabCellSel';
    $('sl_' + cual + '_3').className = 'TabCellSelRight';
    $('sol_' + cual).className = 'pn_sel';

}

function informa(tx){

	if ($('dv_wait')){
        var ef = new Fx.Styles('dv_wait', {duration: 150, wait:true,onComplete:function(){busy=false;}});

        if ($('dv_wait').getTop()<-1 && busy==false) {
            busy=true;
            
            $('dv_wait').setStyles({
                    'backgroundColor':'#888',
                    'display':'block',
                    'margin-top':'-30'
             });

		    ef.start({
			    'margin-top':0,
			    'backgroundColor':'#eee'
		    });
		    if (tx!=null){$('dv_wait').setText(tx);}
        }
        else
        {
	        ef.start({
		        'margin-top':-30,
		        'backgroundColor':'#888'
	        });
	        $('dv_wait').setText('Espere por favor...');
	    }
	}
}

var biblioteca={

	search_biblio:function(){
		tx = escape($('tx_busca').value)
		if (tx==''){
			$('busqui').innerText='Indique el texto de la búsqueda';
		}
		else
		{
			$('busqui').innerText='Espere por favor...';
			//window.location='http://cb.villanueva.edu/asp/biblioteca/resultado_ext.asp?pagina=0&tx='+tx;
			window.location='http://cb.villanueva.edu/biblioteca/index.aspx?txt='+tx;
		}
	}
}


