// JavaScript Document
var imgRollOver = function(img, over){
	img = (typeof(img)=='object')? img : $(img);
	
	img.__over = over;
	img.__out = img.src;
	
	AddEvent(img, 'mouseover', function(){
		this.src = this.__over;
	}.closure(img));
	AddEvent(img, 'mouseout', function(){
		this.src = this.__out;
	}.closure(img));
}

//
var Layers = function(sId){ this.init(sId); }
var p = Layers.prototype;
p.oLay = null;
p.showed = 0;
p.init = function(sId){
	this.oLay = $('lay'+ sId);
	if(!this.oLay){ return alert('Layers.init: Error al localizar el objeto.'); }
	if(this.oLay.id == 'layBlocker'){ AddEvent(window, 'resize', function(){ this.resize(false); }.closure(this)); }
}
p.show = function(){
	if(this.showed < 0){ this.showed = 0; } 
	if(this.oLay.id == 'layLoader'){
		this.oLay.style.marginTop = (document.documentElement.scrollTop - Math.ceil(this.oLay.offsetHeight / 2)) + 'px';
		this.oLay.style.marginLeft = '-' + Math.ceil(this.oLay.offsetWidth / 2) + 'px';
	}
	else{ this.resize(true); }
	//
	this.oLay.style.visibility = 'visible';
	this.showed++;
}
p.hide = function(){
	this.showed--;
	if(this.oLay.id == 'layLoader'){ this.oLay.style.marginTop = '-10000px'; }
	else{ this.oLay.style.height = 0; }
	
	if(this.showed == 0){ this.oLay.style.visibility = 'hidden'; }
}
p.resize = function(b){
	if(!b && this.oLay.style.visibility == 'hidden'){ return false; }
	this.oLay.style.width = WScreen() + 'px';
	this.oLay.style.height = ((HScreen() > document.body.offsetHeight)? HScreen():document.body.offsetHeight) + 'px';
}

//
var Messages = function(sType){ this.init(sType); }
var p = Messages.prototype;

p.oEle = null;
p.oAcept = null;
p.oCancel = null;
p.oClose = null;
p.oMessage = null;
p.onAcept = null;
p.onCancel = null;
p.message = null;

p.init = function(sType){
	var sId = 'lay' + sType;
	this.oEle = $(sId);
	if(!this.oEle){ return alert('Messages.init: Error al localizar el objeto.'); }
	//
	this.oAcept = $(sId + 'BtnAceptar');
	
	if(this.oAcept){
		if(!this.oAcept){ return alert('Messages.init: Error al localizar el boton aceptar.'); }
		AddEvent(this.oAcept, 'click', this.acept.closure(this));
		imgRollOver(this.oAcept, this.oAcept.src.replace('ff'+ID_IDIOMA+'.gif', 'n'+ID_IDIOMA+'.gif'));
	}
	//
	if(sType == 'Confirm'){
		this.oCancel = $(sId + 'BtnCancelar');
		if(!this.oCancel){ return alert('Messages.init: Error al localizar el boton cancelar.'); }
		AddEvent(this.oCancel, 'click', this.cancel.closure(this));
		imgRollOver(this.oCancel, this.oCancel.src.replace('ff'+ID_IDIOMA+'.gif', 'n'+ID_IDIOMA+'.gif'));
	}
	//
	this.oClose = $(sId + 'BtnCerrar');
	if(!this.oClose){ return alert('Messages.init: Error al localizar el boton cerrar.'); }
	this.oMessage = $(sId + 'Msj');
	if(!this.oMessage){ return alert('Messages.init: Error al localizar el cuadro del mensaje.'); }
	AddEvent(this.oClose, 'click', this.cancel.closure(this));
	//
	AddEvent(this.oEle, 'keypress', function(e){ if(e.keyCode==27){ this.cancel(); }}.closure(this));
};
p.show = function(){
	if(!!this.message){ this.oMessage.innerHTML = this.message; }
	this.oEle.style.marginTop = (document.documentElement.scrollTop - Math.ceil(this.oEle.offsetHeight / 2)) + 'px';
	this.oEle.style.marginLeft = '-' + Math.ceil(this.oEle.offsetWidth / 2) + 'px';
	this.oEle.style.visibility = 'visible';
	
	try{ if(!this.oCancel){ this.oAcept.focus(); }else{ this.oCancel.focus(); } }catch(e){ };
}
p.hide = function(){
	this.oEle.style.visibility = 'hidden';
	this.oEle.style.marginTop = '-10000px';
}
p.acept = function(){
	if(typeof(this.onAcept) == 'function'){ this.onAcept(); }
}
p.cancel = function(){
	this.hide();
	if(typeof(this.onCancel) == 'function'){ this.onCancel(); }
}

var oSelectedMenu = null;
function selectMenu(o, s, e){
	if(!!oSelectedMenu){
		if(oSelectedMenu['s']){ oSelectedMenu['s'].style.display = 'none'; }
		oSelectedMenu['o'].className = '';
	}
	oSelectedMenu = new Object;
	oSelectedMenu['o'] = o;
	oSelectedMenu['s'] = s;
	o.className = 'on';
	if(s){
		s.style.display = 'block';
		if(e){ StopEvent(e); }
	}
}
var oBorrador = new Object();
oBorrador.cancelar = function(){
	return false;	
}