//funcion para mostrar/ocultar popup css
//Catalago_Productos_Form
function popup(id){
	if (document.getElementById(id).style.display) document.getElementById(id).style.display = '';
	else document.getElementById(id).style.display = 'none';
	return false;
}

//array con las categorias
var cat = new Array();
cat[234] = "Arranque de material";
cat[111] = "Deformación de material";
cat[467] = "Máquinas de soldadura y corte";
cat[212] = "Tratamientos técnicos y acabados de superficie";

//array con las subcategorias
var subcat_1 = new Array();
subcat_1[358] = "Herramientas de corte";
subcat_1[900] = "Equipos y utillajes para máquina-herramienta";
subcat_1[767] = "Equipos hidráulicos";
subcat_1[354] = "Equipos neumáticos";

var subcat_2 = new Array();
subcat_2[358] = "PHP";
subcat_2[900] = "CSS";
subcat_2[767] = "DOM";
subcat_2[354] = "Ruby";

//array con los productos
var subcat_1_1 = new Array();
subcat_1_1[123] = "Brocas, brochas, cuchillas, escariadores, machos de roscar, fresas";
subcat_1_1[542] = "Herramientas con plaquetas de metal duro";
subcat_1_1[654] = "Sierras";
subcat_1_1[865] = "Otras herramientas";

var subcat_1_2 = new Array();
subcat_1_2[345] = "Tamudo";
subcat_1_2[664] = "Kameni";
subcat_1_2[999] = "Harke";
subcat_1_2[454] = "Ito";

var subcat_1_3 = new Array();
subcat_1_3[555] = "Aimar";
subcat_1_3[654] = "Vicente";
subcat_1_3[233] = "Baraja";
subcat_1_3[322] = "Angulo";


//funcion para generar las categorias desde el inicio
function generateCategories(contenedor){
	var numCat = cat.length;
	var result = "";
	j=0;
	for (var i in cat){
		j++;
		if (typeof cat[i] == 'string'){
			result += '<li id="cat_'+j+'"><a href="#" onclick="add(this.parentNode.id); return false;"><img src="./img/add.gif" /></a> <a href="#" onclick="generateSubcategories(\'l_2\','+i+','+j+'); return false;">'+cat[i]+'</a></li>';
	 	}
	}
	//introducimos el codigo en el contenedor que le pertoca
	document.getElementById(contenedor).innerHTML = result;
}

//funcion para generar las subcategorias de una categoria
function generateSubcategories(contenedor,codcategoria,poscategoria){
	switch (codcategoria){
		case 234: subcat = subcat_1; break; //Herramientas de corte
		case 111: subcat = subcat_2; break;
	}
	var numCat = subcat.length;
	var result = "";
	j=0;
	for (var i in subcat){
		j++;
		if (typeof subcat[i] == 'string') result += '<li id="subcat_'+j+'_'+poscategoria+'"><a href="#" onclick="add(this.parentNode.id); return false;"><img src="./img/add.gif" /></a> <a href="#" onclick="generateProducts(\'l_3\','+i+','+poscategoria+','+j+'); return false;">'+subcat[i]+'</a></li>';
	}
	document.getElementById(contenedor).innerHTML = result;
}

//funcion para generar los productos de una subcategorias
function generateProducts(contenedor,codsubcat,poscategoria,possubcat){
	switch (codsubcat){
		case 358: product = subcat_1_1;  break; //brocas,...
		case 900: product = subcat_1_2; break;
		case 767: subcat = subcat_1_3; break;
	}
	var numCat = product.length;
	var result = "";
	j=0;
	for (var i in product){
		j++;
		if (typeof product[i] == 'string') result += '<li id="prod_'+j+'_'+poscategoria+'_'+possubcat+'"><a href="#" onclick="add(this.parentNode.id); return false;">'+product[i]+'</a></li>';
	}
	document.getElementById(contenedor).innerHTML = result;
}

//funcion para añadir un item a la lista de resultados
function add(product){
	//alert(product)
	tmp = product.split('_');
	tmp.shift();
	id=tmp.join('_');
	li = document.getElementById(product).lastChild.firstChild.nodeValue;
	var tipo='';
    var i=0;
	if (li!='') {
		if (document.getElementById('resultado').innerHTML != '') {
			//miramos cuantos items hay y seguims la cuenta
			num = document.getElementById('resultado').firstChild.childNodes.length;
			num++;
			//la metodologia es la siguiente, añado un ultimo li a la lista y ahi dentro con innerHTML le pongo lo que quiera.
			document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
			document.getElementById('resultado').firstChild.lastChild.setAttribute('id','r_'+num+'_'+id);
			switch (tmp.length) {
				case 1: tipo='<em>categoria</em> &raquo; '; 
					//eliminamos la opcion de añadir
					document.getElementById(product).removeChild($(product).childNodes[0]);
					//añadimos
					document.getElementById('resultado').firstChild.lastChild.innerHTML=tipo+li+'<a href="#" class="inline" onclick="restaurar(\'cat_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
					break;
				case 2: 
					tipo='<em>subcategoria</em> &raquo; '; 
					//eliminamos la opcion de añadir
					document.getElementById(product).removeChild($(product).childNodes[0]);
					//añadimos
					document.getElementById('resultado').firstChild.lastChild.innerHTML=tipo+li+'<a href="#" class="inline" onclick="restaurar(\'subcat_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
					break;
				case 3:
					tipo='<em>producto</em> &raquo; ';
					//añadimos
					document.getElementById('resultado').firstChild.lastChild.innerHTML=tipo+li+'<a href="#" class="inline" onclick="restaurar(\'prod_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
					//deshabilito enlace
					document.getElementById(product).innerHTML=li;
					break;
			}
		} 
		else {
			switch (tmp.length) {
				case 1: 
					tipo='<em>categoria</em> &raquo; '; 
					//eliminamos la opcion de añadir
					document.getElementById(product).removeChild($(product).childNodes[0]);
					//añadimos a resultado
					document.getElementById('resultado').innerHTML='<ul><li id="r_1_'+id+'">'+tipo+li+'<a href="#" class="inline" onclick="restaurar(\'cat_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
					break;
				case 2: 
					tipo='<em>subcategoria</em> &raquo; '; 
					//eliminamos la opcion de añadir
					document.getElementById(product).removeChild($(product).childNodes[0]);
					//añadimos a resultado
					document.getElementById('resultado').innerHTML='<ul><li id="r_1_'+id+'">'+tipo+li+'<a href="#" class="inline" onclick="restaurar(\'subcat_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
					break;
				case 3: 
					tipo='<em>producto</em> &raquo; ';
					cat = id.split('_');
					//añadimos
					document.getElementById('resultado').innerHTML='<ul><li id="r_1_'+id+'">'+tipo+li+'<a href="#" class="inline" onclick="restaurar(\'prod_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
					//deshabilito enlace
					document.getElementById(product).innerHTML=li;
					break;
			}
			//$('resultado').innerHTML='<ul><li id="r_1_'+id+'">'+tipo+li+'<a href="#" class="inline" onclick="restaurar(\'l_'+id+'\'); this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
		}
	}
	return false;
}

//funcion para comprobar si un ul tiene hijos
function comprobar_hijos(){
	//si no tiene hijos la lista, me la cargo
	if (!document.getElementById('resultado').firstChild.hasChildNodes()){
		document.getElementById('resultado').innerHTML='';
	}
}

//funcion para restaurar el enlace del producto cuando lo borramos de la lista de resultados
function restaurar(elem){
	if (document.getElementById(elem)){
		li = document.getElementById(elem).firstChild.nodeValue;
		switch (elem.split('_').length){
			case 2:
				//categoria
				document.getElementById(elem).innerHTML='<a href="#" onclick="add(this.parentNode.id); return false;"><img src="./img/add.gif" /></a>'+document.getElementById(elem).innerHTML;				
				break;
			case 3:
				//subcategoria
				document.getElementById(elem).innerHTML='<a href="#" onclick="add(this.parentNode.id); return false;"><img src="./img/add.gif" /></a>'+document.getElementById(elem).innerHTML;
				break;
			case 4:
				//producto
				document.getElementById(elem).innerHTML='<a href="#" onclick="add(\''+elem+'\')">'+li+'</a>';
				break;
		}
	}
}

//funcion para insertar contenido generando una lista
//Catalogo_Marcas_Form
function insertar(id){
	//aqui miro si es un string o es una agrupacion de string mediante comas,
	/*
	quito los espacios con la expresion regular, las dos lineas siguientes son equivalentes a la de despues del comentario
	var pattern = new RegExp("m", "gi");
	str = document.getElementById(id).value.replace(pattern,'hor');*/
	str = document.getElementById(id).value.replace(/ /gi,''); //parametro gi (g: buscar en toda la cadena, i: sin distinguir mayusculas y minusculas)
	str = str.split(',');
	if (document.getElementById(id).value !=''){
		if (document.getElementById('resultado').innerHTML != '') {
				for(var j=0; j<str.length; j++){
						id = document.getElementById('resultado').firstChild.lastChild.getAttribute('id');
						tmp = id.split('_');
						i = parseInt(tmp[1])+1;
						document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
						document.getElementById('resultado').firstChild.lastChild.setAttribute('id','m_'+i);
						document.getElementById('resultado').firstChild.lastChild.innerHTML=str[j]+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
					}
		} 
		else {
			if (str.length == 1) {
				document.getElementById('resultado').innerHTML='<ul><li id="m_1">'+str[0]+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
				//popup('m_1');
			}
			else {
				for(var j=0; j<str.length; j++){
					if (j==0) document.getElementById('resultado').innerHTML='<ul><li id="m_1">'+str[0]+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
					else {
						id = document.getElementById('resultado').firstChild.lastChild.getAttribute('id');
						tmp = id.split('_');
						i = parseInt(tmp[1])+1;
						document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
						document.getElementById('resultado').firstChild.lastChild.setAttribute('id','m_'+i);
						document.getElementById('resultado').firstChild.lastChild.innerHTML=str[i-1]+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
					}
				}
			}
			
		}
	}
	return false; 
}

//funcion para añadir a una persona
//montaje_pases_form
function insertar_persona(nombre, nif){
	if (!nombre) nombre='nombre';
	if (!nif) nif='nif';
	nombre = document.getElementById(nombre).value;
	nif = document.getElementById(nif).value;
	
	if (nombre != '' && nif != ''){
		if (document.getElementById('resultado').innerHTML != '') {
			//miro el numero del li anterior para poner el id que pertoca
			id = document.getElementById('resultado').firstChild.lastChild.getAttribute('id');
			tmp = id.split('_');
			i = parseInt(tmp[1])+1;
			document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
			document.getElementById('resultado').firstChild.lastChild.setAttribute('id','p_'+i);
			//document.getElementById('resultado').firstChild.lastChild.setAttribute('style','display:none');
			document.getElementById('resultado').firstChild.lastChild.innerHTML=nombre+' ('+nif+') <a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
			//popup('p_'+i);
		} 
		else {
			document.getElementById('titulo_resultado').innerHTML = '<strong>Personas introducidas</strong>';
			/* alternativa más estándar al innerHTML
			texto = document.createElement("strong").appendChild(document.createTextNode('Personas introducidas'));
			document.getElementById('titulo_resultado').appendChild(texto);*/
			document.getElementById('resultado').innerHTML='<ul><li id="p_1">'+nombre+' ('+nif+') <a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
			//efecto('p_1');
		}
	}
	return false; 
}

//funcion para construir el programa de actividades
//Actividades_Form
function actividad(titulo, fecha_inicio, fecha_fin, inicio, fin, desc){
	
	if (!titulo) var titulo='titulo_actividad';
	if (!fecha_inicio) var fecha_inicio='fecha_inicio';
	if (!fecha_fin) var fecha_fin='fecha_fin';
	if (!inicio) var inicio='hora_inicio';
	if (!fin) var fin='hora_fin';
	if(!desc) var desc='descripcion_actividad';
	
	titulo=document.getElementById(titulo).value;
	fecha_inicio=document.getElementById(fecha_inicio).value;
	fecha_fin=document.getElementById(fecha_fin).value;
	inicio = document.getElementById(inicio).value;
	fin = document.getElementById(fin).value;
	desc = document.getElementById(desc).value;
	
	if (desc !='' && inicio !='' && fin !=''){
		if (document.getElementById('resultado').innerHTML != '') {
			//miro el numero del li anterior para poner el id que pertoca
			id = document.getElementById('resultado').firstChild.lastChild.getAttribute('id');
			tmp = id.split('_');
			i = parseInt(tmp[1])+1;
			document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
			document.getElementById('resultado').firstChild.lastChild.setAttribute('id','m_'+i);
			//document.getElementById('resultado').firstChild.lastChild.setAttribute('style','display:none');
			document.getElementById('resultado').firstChild.lastChild.innerHTML='<p>· <strong>'+titulo+'</strong>, <span>del</span> '+fecha_inicio+' <span>al</span> '+fecha_fin+'</p><p><span>de</span>'+inicio+' <span>a</span> '+fin+' <span>&rsaquo;</span> '+desc+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></p>';
			//popup('m_'+i);
		}
		else {
			document.getElementById('resultado').innerHTML='<ul><li id="m_1"><p>· <strong>'+titulo+'</strong>, <span>del</span> '+fecha_inicio+' <span>al</span> '+fecha_fin+'</p><p><span>de</span> '+inicio+' <span>a</span> '+fin+' <span>&rsaquo;</span> '+desc+' <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></p></ul>';
			//popup('m_1');
		}
	}
	return false;
}

//funcion para construir las llegadas de los camiones
//ficha_logistica
function llegada(llegada, uds, tipo){
	
	if(!uds) var uds=1;
	uds = document.getElementById(uds).value;
	if (uds==1) uds_text = 'unidad';
	else uds_text = 'unidades';
	llegada = document.getElementById(llegada).value;
	auto = document.getElementById(tipo).firstChild.firstChild.nodeValue;
	if (uds !='' && llegada !=''){
		if (document.getElementById('resultado').innerHTML != '') {
			//miro el numero del li anterior para poner el id que pertoca
			id = document.getElementById('resultado').firstChild.lastChild.getAttribute('id');
			tmp = id.split('_');
			i = parseInt(tmp[1])+1;
			document.getElementById('resultado').firstChild.appendChild(document.createElement('li'));
			document.getElementById('resultado').firstChild.lastChild.setAttribute('id','envio_'+i);
			//document.getElementById('resultado').firstChild.lastChild.setAttribute('style','display:none');
			document.getElementById('resultado').firstChild.lastChild.innerHTML=' <span>'+auto+':</span> '+uds+' <span>'+uds_text+'</span> el</span> <strong>'+llegada+'</strong> <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a>';
			//popup('envio_'+i);
		}
		else {
			document.getElementById('resultado').innerHTML='<ul><li id="envio_1"> <span>'+auto+':</span> '+uds+' <span>'+uds_text+' el</span> <strong>'+llegada+'</strong> <a href="#" class="inline" onclick="this.parentNode.parentNode.removeChild(this.parentNode); comprobar_hijos();  return false">eliminar</a></li></ul>';
			//popup('envio_1');
		}
	}
	return false;
}

//funcion para agregar documentacion, archivos o imagenes
function doc(tipus,limite){
	
	if (tipus == 'doc'){
		block = document.getElementById('docs');
		tags = block.getElementsByTagName('li');
		id = tags.length;
		id++;
		block.appendChild(document.createElement('li'));
		block.lastChild.setAttribute('id','doc_'+id);
		block.lastChild.setAttribute('style','clear:left');
		block.lastChild.innerHTML='<p><strong>Documento <span>'+id+'</span></strong></p><div><label for="titulo_doc">Título del documento</label><input type="text" id="titulo_doc" name="titulo_doc" /></div><div><label for="archivo">Archivo</label><input class="text-file" type="file" id="archivo" name="archivo" /></div><div><a title="Borrar documento" href="#images" onclick="del(\'doc\',this)" style="margin-right:1em">Borrar documento</a><a href="#images" title="Añadir documento" onclick="doc(\'doc\')" >Añadir documento</a></div>';
	}
	else {
		block = document.getElementById('imgs');
		tags = block.getElementsByTagName('li');
		id = tags.length;
		id++;
		if (id <= limite){
			block.appendChild(document.createElement('li'));
			block.lastChild.setAttribute('id','doc_'+id);
			block.lastChild.setAttribute('style','clear:left');
	
			if (id == limite) { block.lastChild.innerHTML='<strong>Imagen <span>'+id+'</span></strong><div><label for="imagen">Imágen o logo</label><input class="text-file" type="file" id="imagen_'+id+'" name="imagen" /><p class="nota">Formato : +.jpg – Tamaño máximo : 200x200 Pix</p></div><div><a title="Borrar imagen" onclick="del(\'img\',this,'+limite+')" href="#images" style="margin-right:1em" >Borrar imagen</a></div>';}
			else if (id < limite) {block.lastChild.innerHTML='<strong>Imagen <span>'+id+'</span></strong><div><label for="imagen">Imágen o logo</label><input class="text-file" type="file" id="imagen_'+id+'" name="imagen" /><p class="nota">Formato : +.jpg – Tamaño máximo : 200x200 Pix</p></div><div><a title="Borrar imagen" onclick="del(\'img\',this,'+limite+')" href="#images" style="margin-right:1em" >Borrar imagen</a><a href="#images" title="Añadir imagen" onclick="doc(\'img\','+limite+')" >Añadir imagen</a></div>';}
		}
	}
	
	color_principal();
}

//funcion optimizada y unida para borrar documentos
function del(tipo,object,limite){
		//el problema esta en que el fade no lo elimina, sino que deja de mostrarlo y si luego lo borro no da tiempo a verse el efecto fade
		//Effect.Fade(object.parentNode);
		object.parentNode.parentNode.parentNode.removeChild(object.parentNode.parentNode);
		reorder_doc(tipo,limite);
		return false;
}

//funcion para saber si puedo borrar un documento o no, ya que siempre debe haber uno como mínimo
function del_doc(id){
	tmp = id.split('_');
	i = parseInt(tmp[1]);
	if (i>1) return true;
	else return false;
}

//funcion para reordenar los documentos cuando el usuario ha borrado alguno de estos documentos
function reorder_doc(tipo,limite){
	if (tipo == 'doc') block = document.getElementById('docs');
	else block = document.getElementById('imgs');
	tags = block.getElementsByTagName('li');
	var j=0;
	for (i=0;i<tags.length;i++){
		j=i+1;
		tmp = tags[i].id.split('_');
		id = parseInt(tmp[1]);
		if (id != j) {
			tags[i].setAttribute('id','doc_'+j);
			//imagen = document.getElementById('imagen_'+id).value;
			//cuando añado esto se pierde el valor del input imagen, y no me deja colocar el valor despues...
			//if (j<limite) {tags[i].innerHTML += '<input type="button" class="button" value="Añadir imagen" onclick="doc(\'img\','+limite+')" />';}
			
			span = tags[i].getElementsByTagName('span');
			//alert('id='+id+', j='+j+', valor span='+span[0].firstChild.nodeValue);
			span[0].firstChild.nodeValue = j;
		}
	}
}

//funcion para recoger por parametro el action de los formularios de los bloques estándares
function action(){
	var url = document.location.href;
	var parametro = url.substring(url.indexOf('?')+1,url.length);
	document.getElementById('form').action = parametro.substring(parametro.indexOf('=')+1,parametro.length);
}

//funcion para filtrar los fieldsets del paso 2 segun la eleccion del paso 1
function solicitud_espacio(){
	var url = document.location.href;
	var parametro = url.substring(url.indexOf('?')+1,url.length);
	var tipo = parametro.substring(parametro.indexOf('=')+1,parametro.length);
	switch (tipo){
		case 'espacio_interior' : mostrar('espacio_interior','total','equipamiento_adicional','seguro','canon_montaje','ecotasa'); break;
		case 'espacio_exterior' : mostrar('espacio_exterior','total','equipamiento_adicional','seguro','canon_montaje','ecotasa'); break;
		case 'stand_tipo' : mostrar('stand','seguro','total'); break;
		case 'stand_design' : mostrar('form_design','seguro'); break;
	}
}

//funcion para comprobar que un radio esté activo antes de enviar el formulario
function comprobar(id){
	if (!id) id='aceptacion';
	if (document.getElementById(id).checked == true) document.forms[0].submit();
	else alert('lee y acepta las condiciones legales');
}

//funcion para bloquear los campos ya rellenados con anterioridad 
function bloquear(origen, id){
	if (!id) id = 'bloqueado';
	if (!origen) origen = 'modificar_datos';
	document.getElementById(origen).checked = true; 
	target = document.getElementById(id);
	inputs = document.getElementById(id).getElementsByTagName('input');
	selects = document.getElementById(id).getElementsByTagName('select');
	//al poner un input en disabled se eliminan los eventos asociados, asi que utilizamos readonly
	//for (i=0; i<inputs.length; i++) inputs[i].disabled = true;
	//for (i=0; i<selects.length; i++) selects[i].disabled = true;
	for (i=0; i<inputs.length; i++) inputs[i].disabled = true;
	for (i=0; i<selects.length; i++) selects[i].disabled = true;
}

//funcion para editar datos ya rellenados
function desbloquear(origen, id, clase){
	if (!id) id = 'bloqueado';
	if (!origen) origen = 'modificar_datos';
	if (!clase) clase = ' grupo';
	//alert(document.getElementById(origen).checked)
	/*if (document.getElementById(origen).checked) {
		document.getElementById(origen).checked = false;
		target = document.getElementById(id);
		target.className='enabled'+clase;
		inputs = target.getElementsByTagName('input');
		selects = target.getElementsByTagName('select');
		for (i=0; i<inputs.length; i++) inputs[i].disabled = false;
		for (i=0; i<selects.length; i++) selects[i].disabled = false;
	}
	else {
		document.getElementById(origen).checked = true;
		target = document.getElementById(id);
		target.className='disabled'+clase;
		inputs = target.getElementsByTagName('input');
		selects = target.getElementsByTagName('select');
		for (i=0; i<inputs.length; i++) inputs[i].disabled = true;
		for (i=0; i<selects.length; i++) selects[i].disabled = true;
	}*/
	document.getElementById(origen).checked = false; //esto no funciona, no de desactiva el checkbox
	target = document.getElementById(id);
	target.className='enabled'+clase;
	inputs = target.getElementsByTagName('input');
	selects = target.getElementsByTagName('select');
	for (i=0; i<inputs.length; i++) inputs[i].disabled = false;
	for (i=0; i<selects.length; i++) selects[i].disabled = false;
}

//funcion para asignar un foco cuando se clickea algo
function foco(id){
	document.getElementById(id).focus();
}

//funcion para activar un radio o checkbox al clickar sobre algun elemento
function radio(id, status){
	if (!status) status = true;
	document.getElementById(id).checked = status;
}

//funcion que comprueba si un input esta vacio y desmarca el radio asociado
function empty(input,radio){
	values=document.getElementById(input,radio);
	if (values[0].value == '') values[1].checked = false;
}

//funcion para ocultar n objetos con style="display:none", si no hay parametros, ocultar los elementos del array, sino los parametros pasados
function ocultar(){
	if (arguments.length == 0) {
		obj = new Array('espacio_unico','form_design','equipamiento_adicional','ecotasa','canon_montaje','seguro');
		for (var i=0; i<obj.length; i++) document.getElementById(obj[i]).style.display="none";
	}
	else { for (var i=0; i<arguments.length; i++) document.getElementById(arguments[i]).style.display="none"; }
}

//funcion para mostrar los n objetos pasados por parametros
function mostrar(){
	if (arguments.length == 0) return;
	else {
			for (var i=0; i<arguments.length; i++) {
				//Effect.Appear(target);
				document.getElementById(arguments[i]).style.display="";
			}
	}
}