function $(id){
	var obj = document.getElementById(id);
	return(obj);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
////                      Funcion para situar un objeto sobre otro                                 ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var ret = new Array(curleft,curtop);
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
////               Funcion para situar una capa sobre otra con desplazamiento x e y                ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function situa_capa(kual,donde,dondex,dondey){
	var obj = $(kual);
	var obj_donde = $(donde);
	
	var xy = findPos(obj_donde);
	
	if (dondex!=-1){
		obj.style.left = (xy[0]*1+dondex*1) + 'px';
//		alert(xy[0]);
	}
	if (dondey!=-1){
		obj.style.top = (xy[1]*1+dondey*1) + 'px';
//		alert(xy[1]);
	}
}

function mostrar(id){
	var capa = $(id);
	if(capa.style.display=="block"){
		capa.style.display="none";
	}
	else{
		capa.style.display="block";
	}
}
function metecontenido(id,contenido){

	var inst = tinyMCE.getInstanceById(id);
	inst.execCommand('mceInsertContent',false,contenido);

}
/*
function teclaintro(e){
    var evento = e || window.event;

    var caracter = evento.charCode || evento.keyCode;
    var letra = String.fromCharCode(caracter);
    var codigo = letra.charCodeAt(0);
	
	if(codigo==13){ //Tecla Intro
//		document.login.submit();
	}
}
*/
function checkbox(id){
	var img = $(id);
	var hidden = $(id+"_hidden");
	if(hidden.value==0){
		img.src="imagenes/checkbox_on.png";
		hidden.value = 1;
	}
	else{
		img.src="imagenes/checkbox_off.png";
		hidden.value = 0;
	}
}
function limpia_buscador(modo){
	var caja = $("busqueda");
	if(modo==1){
		caja.value = "";	
	}
	else if(caja.value==""){
		caja.value = $("restaura_texto").value;
	}
}
function mapa(cual){
	var b = document.documentElement;
	var pos = b.scrollTop;
	var capa_proyecto = document.getElementById('capa_over_'+cual);
/*	capa_proyecto.style.width=(ancho*1 +40)+"px";
	capa_proyecto.style.height=(alto*1 +240)+"px";*/
	var capa_opaca = document.getElementById('capa_opaca');

	var dimensiones = getPageSize();
	capa_opaca.style.height = (dimensiones[1]*1 +500)+"px";
	if(capa_proyecto.style.display=="block"){
		capa_proyecto.style.display="none";
		capa_opaca.style.display="none";
	}
	else{
		capa_proyecto.style.display="block";
		capa_opaca.style.display="block";
	}
}
function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
function check_desuscribir(id){
	var email = $(id).value;
	if(email!=""){
		document.location.href="index.php?email="+email;	
	}
	else{
		alert("Debes introducir la direccion para darte de baja.");	
	}
}
function check_boletin(){
	var email = $('email_boletin').value;
	var box =  $('condiciones_hidden').value;
	if(email!="" && box==1){
		document.form_boletin.submit();
	}
	else{
		alert("Debes introducir un email y aceptar las condiciones");
	}
}
function check_boletin_b(){
	var email = $('email_boletin_b').value;
	var box =  $('condiciones_b_hidden').value;
	if(email!="" && box==1){
		document.form_boletin_b.submit();
	}
	else{
		alert("Debes introducir un email y aceptar las condiciones");
	}
}
function check_bajo_contacto(){
	var datos = new Array('nombre_form_bajo','territorio_form_bajo', 'consulta_form_bajo');
	var continua = true;
	for(i=0;i<datos.length;i++){
		if($(datos[i]).value=="" && continua){
/*			$(datos[i]).focus();
			$(datos[i]).select();
			$(datos[i]).style.border="#FF0000 1px solid";
			$(datos[i]).style.background="#ffb7b7";*/
			alert("No has rellenado los campos obligatorios");
			continua = false;
		}
	}
/*	if(continua){
		if($('condiciones').checked==false){
			alert("Es necesario aceptar las condiciones de uso");
			continua=false;
		}
	}*/
	if(continua){
		document.bajo_contacto.submit();
	}	
}