// FUNCIONES JAVASCRIPT BASE MOOTOOLS 1.2.2 BY JHUENUMAN
/*<script src="mootools-core-1.3.1-full-compat.js" type="text/javascript"></script>
//<script src="../../mocha_v.0.9.6/scripts/mootools-more-1.3.1.1.js" type="text/javascript"></script> */

function loadLink(div, url, msgLOAD){ //loadlink('myDiv','req_mootools.php', '');
	if (msgLOAD == ""){ msgLOAD = 'Loading...'; } else { msgLOAD = msgLOAD; }
	var myElement = $(div);
	var myRequest = new Request({
    url: url,    method: 'post', evalScripts: true,
    onRequest: function(){
        myElement.set('html', '<img src=images/loading.gif border=0><font size=1 color=red>&nbsp;' + msgLOAD +'</font>');
    },
    onSuccess: function(responseText){
        myElement.set('html', responseText);
    },
    onFailure: function(){
        myElement.set('text', 'Error, this request failed.');
    }
	})
	myRequest.send();
}//fin loadlink

function sendForm(div, idFORM, msgLOAD){  //sendform('myDiv','myForm', '');
	if (msgLOAD == ""){ msgLOAD = ' Loading...'; } else { msgLOAD = msgLOAD; }
	var myElement = $(div);
	var myRequest = new Request({
    url: $(idFORM).get('action'), method: 'post', evalScripts: true, data: $(idFORM),
    onRequest: function(){
        myElement.set('html', '<img src=images/loading.gif border=0><font size=1 color=red>&nbsp;' + msgLOAD +'</font>');		 	//if (idBOTON != "") { $(idBOTON).set('disabled', true); }
    },
    onSuccess: function(responseText){
        	myElement.set('html', responseText);			//$('b1').set('disabled', false);		  
    },
    onFailure: function(){
        myElement.set('text', 'Error, this request failed.');
    }
	})
	myRequest.send();
}//fin sendform

function ShowHide(ndiv, mode){ //slide
	if (mode == "v"){ 
		var myVerticalSlide = new Fx.Slide(ndiv);
		myVerticalSlide.toggle();
	}
	if (mode == "h"){ 
		var myHorizontalSlide = new Fx.Slide(ndiv, {mode: 'horizontal'});
		myHorizontalSlide.toggle();
	}
}//fin ShowHide

//Ventanas MOCHA UI
window.addEvent('load', function(){ //using load instead of domready for IE8
	MUI.Desktop.initialize();
	MUI.Dock.initialize();
});

function makeWindow(url, titleWIN){
	new MUI.Window({
		id: 'window',	title: titleWIN,	loadMethod: 'iframe',	contentURL: url,  //iframe, xhr, html
		shadowBlur: 10,	width: 600,			height: 350
	});
}

function makeWindowBig(url, titleWIN){
	new MUI.Window({
		id: 'windowB',	title: titleWIN,	loadMethod: 'iframe',	contentURL: url,
		shadowBlur: 10,	width: 800,			height: 405
	});
}

function makeModal(url, titleWIN){
		new MUI.Modal({
			id: 'modal',	loadMethod: 'iframe',	title: titleWIN,		contentURL: url, 	//iframe, xhr, html
			width: 500,			height: 250
		});
}

function makeModalBig(url, titleWIN){
		new MUI.Modal({
			id: 'modalB',	loadMethod: 'iframe',	title: titleWIN,		contentURL: url,	 //iframe, xhr, html
			width: 800,			height: 405
		});
}

//Fin ventanas mocha UI

///// Inicia Div-Layer flotante
function layerFlotante() {
	elem = document.getElementById('layerFlotante');
	if (elem != null){  	C = elem.style;	C.top=PS();  }
	return false;
}

function PS(){
	var v=0;
	var NAV=0;
	if(document.layers){  NAV=1;	} else if(document.all){  NAV=2;	}	
	switch(NAV) {
		case 0: {v=window.pageYOffset;} break;
		case 1: {v=document.documentElement.scrollTop;} break;
		case 2: {v=document.body.scrollTop;} break;
		default: { v=0;}
	}
	return v;
}
///// Fin Div-Layer Flotante => <body onScroll="layerFlotante();" >
/////////<div id="layerFlotante" style="position:relative; left:0px; top:0px; z-index:9; background:#CFF">
/////////contenido de la capa</div>

window.onload=window.onresize=window.onscroll= function() {  
	espacioDisponibleVentana = window.getSize(); //Obtiene espacio visible de la ventana x,y Mootools
	tamanoBody = window.getScrollSize(); //Obtiene tamaņo del body x,y
	posScroll = window.getScroll(); // obtiene la posicion del scroll x,y
	//w = window.innerWidth || document.documentElement.clientWidth || screen.width;
	//h = window.innerHeight || document.documentElement.clientHeight || screen.height;
	w = espacioDisponibleVentana.x;	
	h = espacioDisponibleVentana.y;
	//alert('Espacio visible de la ventana: '+w+'x'+h+' Tamaņo del body: '+tamanoBody.x+'x'+tamanoBody.y+' Posicion Scroll: '+posScroll.x+'x'+posScroll.y);
	alto = h - 146;
	ancho = 1000 - 188 - 188 - 32;  //para ajustar al ancho total de la pantalla, reemplazar 1000 por la variable w
	$('mainContent').setStyle('height', alto).setStyle('width', ancho);	
};  


///////////////////////////////////////////////////////////////////////////////////////////////////////
function closeWIN(){
	document.getElementById('popUp').style.display='none';
	document.getElementById('base').style.display='none';
	document.getElementById('contenido').innerHTML = '';
}

function openWIN(url){
	var h, w, x, y;
		w = window.innerWidth || document.documentElement.clientWidth || screen.width;
		h = window.innerHeight || document.documentElement.clientHeight || screen.height;
		x = document.body.scrollLeft || self.pageXOffset || window.document.documentElement.scrollLeft;
		y = document.body.scrollTop || self.pageYOffset || window.document.documentElement.scrollTop;
	carga_link(url, 'contenido', '');		
	document.getElementById('popUp').style.display='block';
	document.getElementById('base').style.display='block';
	document.getElementById('popUp').style.left = (w/8) + 'px';
	document.getElementById('popUp').style.top = y + (h/8) + 'px';		
	document.getElementById('base').style.left = '0px';
	document.getElementById('base').style.top = y + 0 + 'px';	
/*
function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth;
        heightViewport= window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
}
function $(id){
return document.getElementById(id);
}
window.onload=window.onresize=window.onscroll=function(){
var data=getWindowData();
$('popUp').style.left=data[0]/2+data[2]-parseInt($('popUp').style.width)/2+'px';
$('popUp').style.top=data[1]/2+data[3]-parseInt($('popUp').style.height)/2+'px';
$('base').style.left=0+'px';
$('base').style.top=data[1]+data[3]+'px';
}
///*/
}

