
var ctrlAJAX = 'divppal';
var IE = document.all?true:false;
var al_completar='';

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;
        case 'MSGREDIR':
            alert(originalRequest.split('_')[1]);
            window.location = originalRequest.split('_')[2];
            break;
        case 'WIN':
            window.open(originalRequest.split('_')[1]);
            break;
        case 'TAB':
            var w = window.open();
                w.opener = null;
                w.document.location = originalRequest.split('_')[1];
        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";
		$('imgwork').style.visibility= 'visible';
		//var myFx = new Fx.Style('imgwork', 'opacity',{duration: 200}).start(0,1);
	}
	else
	{
		document.body.style.cursor = "default";
		//var myFx = new Fx.Style('imgwork', 'opacity',{duration: 200}).stop(0);
		$('imgwork').style.visibility= 'hidden';
	}
}

function atras(){window.history.back()}

function fade(cual,desde,hasta,time)
{
    //var myEffects = $(cual).effects({duration: 2000, transition: Fx.Transitions.sineInOut});
    //myEffects.start({'height': 100, 'width': 300});

    var myFx = new Fx.Style(cual, 'opacity').start(0.7);
    //myFx.start(1,0).chain(function(){myFx.start(0,1);}).chain(function(){myFx.start(1,0);}).chain(function(){myFx.start(0,1);});
    //var myEffects = $(cual).effects({duration: 1000, transition: Fx.Transitions.elasticInOut}).start({'width': 500});
    //var myEffect = new Fx.Style(cual, 'width', {duration: 1000, transition: Fx.Transitions.elasticInOut}).start(500);
//    if ($('logoppal').height < hasta)
//        {
//            var myEffect = new Fx.Style(cual, 'height', {duration: time, transition: Fx.Transitions.elasticOut}).start(hasta);
//        }
//    else
//        {
//            var myEffect = new Fx.Style(cual, 'height', {duration: time, transition: Fx.Transitions.elasticIn}).start(desde);
//        }

    //var myEffect = new Fx.Style(cual, 'opacity', {duration: 2500}).start(0,1);
}

function cargascript(nscript)
{
    new Asset.javascript(nscript,{onload: function(){alert('script cargado!');}});
}

function toggle_ver(cual){

    $(cual).style.display = ($(cual).style.display == 'none' | $(cual).style.display == '')?'block':'none';
    //var mySlider = new Fx.Slide(cual);
    //mySlider.toggle(); //toggle the slider up and down.
}

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 avisos(){

		// Pick your classes
		var myBox = $$('.new_tit');
		var myBoxOpen = $$('.new_tx');

		// Create the accordion
		var myAccordion = new Accordion(
			myBox, myBoxOpen, {opacity: false, duration:200,start:'first-close',alwaysHide:true, 
				onActive: function(tog){
					tog.setStyles({color: '#fff', background: '#333'});
				},
				onBackground: function(tog){
					tog.setStyles({color: '#000', background: '#efefef'});
				} 
			}
		);
}

function situa(origen,pop,parriba,titulo,widt,foco)
{

    var top = $(origen).getTop() + ($(origen).getCoordinates().height / 2);
    var left = $(origen).getLeft() + ($(origen).getCoordinates().width / 2);

    if (parriba==1){
        top = top - $(pop).getCoordinates().height;
    }
    
    if (widt==null){widt='250'}

    $('pop_tit').innerHTML=titulo;
    $('pop_tit').setStyle('width', (widt-7) + 'px'); 
    $(pop).setStyle('width', widt + 'px');
    $(pop).setStyle('top', top + 'px');
    $(pop).setStyle('left', left + 'px');

    var myEffect = new Fx.Style(pop, 'opacity', {duration: 500, onComplete:function(){
        if (foco!=null)
            {
                $(foco).focus();
            }
        }
    }).start(0,1);

}

