// 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){ 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(); }
}


function getScrollPos(){
	if(Nav.esOp) return {y:window.pageYOffset, x:window.pageXOffset};
	else return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
}
function getWindowDims(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
}
function getBodyWHAvaible(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
}
function getBodyDims(){
	if(Nav.esOp) return {w:document.body.clientWidth, h:document.body.clientHeight};
	else return {w:document.body.offsetWidth, h:document.body.offsetHeight};
}

function WScreen(){ return (Nav.esIE)? document.documentElement.clientWidth : window.innerWidth; }
function HScreen(){ return (Nav.esIE)? document.documentElement.clientHeight : window.innerHeight; }
function YPos(){ return (Nav.esIE)? document.documentElement.scrollTop : window.pageYOffset; }
function XPos(){ return (Nav.esIE)? document.documentElement.scrollLeft : window.pageXOffset; }
function HBody(){ return document.documentElement.scrollHeight; }
function WBody(){ return document.documentElement.scrollWidth; }


var centrarContenido = function(contenido){
	if(contenido && typeof(contenido) == "string")contenido = $(contenido);
	if(!contenido){
		alert("Error en funcion centrarContenido: Contenido inexistente");
		return false;
	}
	var scrll = getScrollPos();
	var dims = getBodyWHAvaible();
	var top = (Math.round((dims.h - contenido.offsetHeight)/2)+scrll.y);
	if(top <= 10)top = 10;
	contenido.style.top = top+"px";
	contenido.style.left = (Math.round((dims.w - contenido.offsetWidth)/2)+scrll.x)+"px";
}
var MostrarContenido = function(contenido,e){
	if(contenido && typeof(contenido) == "string")contenido = $(contenido);	
	if(!contenido){
		alert("Error en funcion MostrarPopUp: Contenido inexistente");
		return false;
	}
	centrarContenido(contenido);
	
	contenido.style.visibility = "visible";
	if(e)StopEvent(e);
	
}
var OcultarContenido = function(contenido,e){
	if(contenido && typeof(contenido) == "string")contenido = $(contenido);	
	contenido.style.visibility = "hidden";
	contenido.style.top = '-'+(contenido.offsetHeight+100)+"px";
	if(e)StopEvent(e);
}
var blockeadorGeneral = null;
var mostrarBlockeador = function(mostrar){
	if(!blockeadorGeneral){
		blockeadorGeneral = $("layerBgGral");
		if(Nav.esIE || Nav.esIE7) blockeadorGeneral.style.filter = 'alpha(opacity=45)';
		else blockeadorGeneral.style.MozOpacity = ".45";
		
	}
	if(mostrar){
		var alto = HScreen();
		if(alto < HBody())alto = HBody();
		var scrn = getBodyWHAvaible();
		blockeadorGeneral.style.display = "block";
		blockeadorGeneral.style.height = alto+"px";
		blockeadorGeneral.style.width = scrn.w+"px";
	}
	else blockeadorGeneral.style.display = "none";
}

function getElementPos(ele){
	var p = ele.style.position;
	ele.style.position = 'relative';
	var x = ele.offsetLeft;
	var y = ele.offsetTop;
	ele.style.position = p;
	return {'x':x, 'y':y};
}
	
function setOpacity(opa, ele){
	if(!window.innerWidth){ ele.style.filter = 'alpha(opacity='+opa+')'; }
	else{ ele.style.opacity = (opa / 100); }
}
	
function strongEaseInOut(t,b,c,d){
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
}
function pintarMapa(codigo){
	var o = document.getElementById('mapaARG');
	o.desactivarProvincia(codigo);	
}		
function mostrarLineaGaleria(e){
	var men = $('listaLineasGaleria');	
	if(men.style.display == 'block')men.style.display = 'none';
	else men.style.display = 'block';
	if(e)StopEvent(e);
}


var mostrarOcultarDiv = function(nomDiv){
	var divTemp = $(nomDiv);
	if(divTemp){
		if(divTemp.style.display != 'inline')divTemp.style.display = 'inline';
		else divTemp.style.display = 'none';
	}
	
}
var mostrarSubMenu = function(){
	var men = $('menuPS');
	if(men)men.style.display = 'inline';
}
var ocultarSubMenu = function(){
	var men = $('menuPS');
	if(men)men.style.display = 'none';
}

var mostrarCategoria = function(id, e){
	var desde = hasta = 0, obj = $(id);
	//
	if(obj && (e || e == 'init')){
		if(parseInt(obj.style.height) == 0 || obj.style.height=='') desde = 0, hasta = obj.scrollHeight;
		else if(parseInt(obj.style.height) == obj.scrollHeight || obj.style.height=='auto') desde = obj.scrollHeight, hasta = 0;
		
		if(desde != hasta){
			var tm = new Tween(obj.style, 'height', Tween.strongEaseOut, desde, hasta, 2, 'px');
			tm.start();
		}
	}
	if(e && e != 'init')StopEvent(e);
}


var cargarInfo = function(contInfo,infoPop){
	if(infoPop && contInfo)contInfo.innerHTML = infoPop.innerHTML;
}



//FUNCIONES

var oPregunta = new Object();
oPregunta.mostrarCuadro = function(){return false}
var oCalculadora = new Object();
oCalculadora.mostrarCuadro = function(){return false}
var oConsulta = new Object();
oConsulta.mostrarCuadro = function(){return false}
var oRecomendar = new Object();
oRecomendar.mostrarCuadro = function(){return false}
var oSol = new Object();
oSol.cambiarSolapa = function(){return false}
