// JavaScript Document
Idiomas={
	href:null,
	Body:null,
	form:null,
	btnEnviar:null,
	divsVta:null,
	divsAlq:null,
	chVta:null,
	chAlq:null,
	selectDP:null,
	
	inicio:function(){
		this.form=document.getElementById('buscadorForm');
		if(this.form){
			this.form.setAttribute('method','get');
			this.form.setAttribute('action','resultados.php');
		}
		this.btnEnviar=document.getElementById('btnEnviar');
		this.selectDP=document.getElementById('destinoProp');
		agregarEscuchaEvento(this.selectDP,'change',
							 function(){
								 if(parseInt(Idiomas.selectDP.value)>0){
									 Idiomas.sacarError();
								}}, false);
		
		this.chVta=document.getElementById('chVta');
		if(this.chVta){
			this.chVta.onclick=function(){
				Idiomas.mostrarOcultarVta(this,true);
			}
		}
		this.chAlq=document.getElementById('chAlq');
		if(this.chAlq){
			this.chAlq.onclick=function(){
				Idiomas.mostrarOcultarVta(this);
			}
		}
		this.divsVta=new Array();
		this.divsVta.push(document.getElementById('divPrecio'));
		this.divsAlq=new Array();
		this.divsAlq.push(document.getElementById('divDestinoProp'));
		this.divsAlq.push(document.getElementById('divCapacidad'));
		if(this.btnEnviar){
			this.btnEnviar.onclick=function(){
				Idiomas.validar();
			}
		}
		var ulIdioma=document.getElementById('lang_selector');
		var bodies=document.getElementsByTagName('body');
		this.Body=bodies[0];
		if(this.href){
			this.href=null;
		}
		this.href=window.location.href;
		if(ulIdioma){
			enlaces=ulIdioma.getElementsByTagName('a');
			if(enlaces && enlaces.length>0){
				for(i=0;i<enlaces.length;i++){
					enlaces[i].onclick=function(){
						return Idiomas.cambiarIdioma(this.id);
					}
				}
			}
		}
	},
	mostrarOcultarVta:function(chBox,esVta){
		var claseVta='';
		var claseAlq='';
		var chCheckeado='';
		if(chBox.checked){
			chCheckeado=chBox.id;
			if(chCheckeado=='chVta'){
				this.chAlq.checked=false;
			}else{
				this.chVta.checked=false;
			}
			if(esVta){
				claseVta='selectItem mostrar';
				claseAlq='selectItem ocultar';
			}else{
				claseVta='selectItem ocultar';
				claseAlq='selectItem mostrar';
			}
			
			for(i=0;i<this.divsVta.length;i++){
				this.divsVta[i].className=claseVta;
			}
			for(i=0;i<this.divsAlq.length;i++){
				this.divsAlq[i].className=claseAlq;
			}
		}
	},	
	validar:function(){
		var msgError='';
		if(this.chAlq.checked){
			if(parseInt(this.selectDP.value)==0){
				msgError=errorJS;
			}
		}
		var envio=false;
		if(msgError==''){
			this.sacarError();
			envio=true;
		}else{
			this.mostrarError(msgError);
		}
		this.enviarForm(envio);
	},
	sacarError:function(){
		var span=document.getElementById('spanError');
		if(span){
			span.innerHTML='';		
		}
	},
	mostrarError:function(error){
		this.sacarError();
		var span=document.getElementById('spanError');
		if(span){
			span.innerHTML=error;
		}
	},
	enviarForm:function(enviar){
		if(this.form){
			this.form.onsubmit=function(){
				return enviar;
			}
		}
	},
	cambiarIdioma:function(codigo){
		this.Body.style.opacity='.5';
		this.Body.style.filter='alpha(opacity=50)';
		var params=new Array();
		params.variables='cambiar='+escape(codigo);	
		params.metodo='GET';		
		params.urlArchivo='jx/jxIdiomas.php';
		params.funcionProceso='Idiomas.recargar';
		params.leerXML=false;	
		objetoXMLRequest(params);
		return false;
	},
	recargar:function(objResp){
		if(!objResp.error){
			if(parseInt(objResp.datos)==1){
				window.location=this.href;
			}else{
				this.Body.style.opacity='1';
				this.Body.style.filter='alpha(opacity=100)';
			}
		}		
	}
}
agregarEscuchaEvento(window, 'load',function(){Idiomas.inicio();}, false);
