
function CopiaSelect (select_origen, select_destino)
{
	var valor = select_destino.value;
	var indice_bueno = 0

	while (select_destino.length > 0)
		select_destino.remove(0);

	for (var i=0; i<select_origen.length; i++)
	{
		if (select_origen.options[i].value == valor)
			indice_bueno = i
		select_destino.options[i] = new Option (select_origen.options[i].text,select_origen.options[i].value,false,false)
	}

	select_destino.options[indice_bueno].selected = true
}
// -------------------------------------------------------

function CompruebaInputNumerico (componente)
{
	var actual = componente.value
	var nuevo  = ""
	var escritos = 0;

	for (var i=(actual.length-1); i>=0; i--)
	{
		if ( (actual.charAt(i) >= '0') && (actual.charAt(i) <= '9') )
		{
			nuevo = actual.charAt(i) + nuevo
			escritos++
			if ((escritos%3) == 0)
				nuevo = "." + nuevo
		}
	}

	if (nuevo.charAt(0) == ".")
		nuevo = nuevo.substring(1)

	componente.value = nuevo;
}
// -------------------------------------------------------

function CompruebaInputPorcentaje (componente)
// Sólo admite número, puntos y comas
// Las comas las transforma en puntos
// No separa en miles
{
	var actual = componente.value
	var nuevo  = ""

	for (var i=0; i<actual.length; i++)
	{
		if ( ( (actual.charAt(i) >= '0') && (actual.charAt(i) <= '9') ) ||
			   (actual.charAt(i) == '.') ||
			   (actual.charAt(i) == ',') )
		{
			if (actual.charAt(i) == ",")
				nuevo += "."
			else
				nuevo += actual.charAt(i)
		}
	}

	componente.value = nuevo;
}
// -------------------------------------------------

function CompruebaFormAltaAlertas ()
{
	if (
		(document.form_alta_alertas.nombre.value == "") ||
		(document.form_alta_alertas.email.value == "") )
	{
		alert ("Debe rellenar todos los datos")
		return false;
	}

	return true;
}

function MuestraCapaSuperior ()
{
	var id_top = document.getElementById ("capa_superior");
	var pos_web = getAbsoluteElementPosition("web");
	var top = scroll_top();

	id_top.style.top = top+90;
	id_top.style.left = pos_web.left+230;
	
	parent.document.getElementById ("fondo_capa_superior").style.width = parent.document.getElementById("body").offsetWidth;
	parent.document.getElementById ("fondo_capa_superior").style.height = parent.document.getElementById("body").offsetHeight;

	parent.document.getElementById ("fondo_capa_superior").style.display="";
	parent.document.getElementById ("capa_superior").style.display="";
	
}
// -------------------------------------------------

function CompruebaPedidoNotaSimple ()
{
	if ( (document.form_solicitud_nota_simple.nombre.value == "") ||
		 (document.form_solicitud_nota_simple.email.value == "") ||
		 (document.form_solicitud_nota_simple.telefono.value == "") )

	{
		alert ("Por favor, asegúrese de rellenar todos los campos obligatorios")
		return false;
	}
	
	return true
}
// -------------------------------------------------

function OcultaCapaSuperior ()
{
	document.getElementById ("fondo_capa_superior").style.display = "none";
	document.getElementById ("capa_superior").style.display = "none";
}

function CompruebaSubastaVoluntaria ()
{
	var form = document.getElementById ("form_subastadores");

	if ( (form.superficie.value == "") ||
		 (form.cp.value == "") ||
		 (form.direccion.value == "") ||
		 (form.descripcion.value == "") ||
		 (form.foto0.value == "") ||
		 (form.precio_salida.value == "") ||
		 (form.tasacion.value == "") ||
		 (form.nombre_apellido.value == "") ||
		 (form.telefono.value == "") ||
		 (form.email.value == "") )
	{
		alert ("Por favor, asegúrese de rellenar todos los campos obligatorios")
		return false;
	}
	
	return true
}

function CapaEsperaSubastasVoluntarias ()
{
	var id_top = parent.document.getElementById ("div_superpuesto");
	var pos_web = getAbsoluteElementPosition("web");
	var top = scroll_top();

	id_top.style.top = top+90;
	id_top.style.left = pos_web.left+230;
	
	parent.document.getElementById ("fondo_div_superpuesto").style.width = parent.document.getElementById("body").offsetWidth;
	parent.document.getElementById ("fondo_div_superpuesto").style.height = parent.document.getElementById("body").offsetHeight;

	parent.document.getElementById ("fondo_div_superpuesto").style.display="";
	parent.document.getElementById ("div_superpuesto").style.display="";
}

function enviar_formulario_inversores ()
{
	var nombre = document.getElementById ("nombre").value;
	var telefono = document.getElementById ("telefono").value;
	var email = document.getElementById ("email").value;
	
	if (nombre=="")
	{
		alert ("El nombre es obligatorio");
	}
	else
	{
		if (telefono=="" && email=="")
		{
			alert ("Debe rellenar el teléfono o el email");
		}
		else
		{
			form_postData("enviar_email_inversores.php","","formulario_inversores","","callback_enviar_formulario_inversores()");
		}
	}
}

function enviar_formulario_franquiciados ()
{
	var nombre = document.getElementById ("nombre").value;
	var telefono = document.getElementById ("telefono").value;
	var email = document.getElementById ("email").value;
	var comentarios = document.getElementById ("comentarios").value;
	
	if (nombre=="")
	{
		alert ("El nombre es obligatorio");
	}
	else
	{
		if (telefono=="" && email=="")
		{
			alert ("Debe rellenar el teléfono o el email");
		}
		else
		{
			if (comentarios=="")
			{
				alert ("Debe rellenar el campo \"Comentarios y breve currículum\"");
			}
			else
			{
				form_postData("enviar_email_franquiciados.php","","formulario_franquiciados","","callback_enviar_formulario_franquiciados()");
			}
		}
	}
}

function enviar_formulario_contacto ()
{
	var nombre = document.getElementById ("nombre").value;
	var telefono = document.getElementById ("telefono").value;
	var email = document.getElementById ("email").value;
	
	if (nombre=="")
	{
		alert ("El nombre es obligatorio");
	}
	else
	{
		if (telefono=="" && email=="")
		{
			alert ("Debe rellenar el teléfono o el email");
		}
		else
		{
			form_postData("enviar_email_contacto.php","","formulario_contacto","","callback_enviar_formulario_contacto()");
		}
	}
}

function resaltar_provincia (nombre_provincia)
{
	var provincias = new Array ("alava","albacete","alicante","almeria","asturias","avila","badajoz","baleares","barcelona","burgos","caceres","cadiz","cantabria","castellon","ceuta","ciudad_real","cordoba","coruna","cuenca","gerona","gipuzcoa","granada","guadalajara","huelva","huesca","jaen","la_rioja","las_palmas","leon","lerida","lugo","madrid","malaga","melilla","murcia","navarra","orense","palencia","pontevedra","salamanca","sc_tenerife","segovia","sevilla","soria","tarragona","teruel","toledo","valencia","valladolid","vizcaya","zamora","zaragoza");
	
	for (var a=0;a<provincias.length;a++)
	{
		if (nombre_provincia == provincias[a])
		{
			document.getElementById(nombre_provincia).style.fontWeight="bold";
			document.getElementById(nombre_provincia).style.color="#D35A00";
		}
		else
		{
			document.getElementById(provincias[a]).style.fontWeight="";
			document.getElementById(provincias[a]).style.color="#045593";
		}
	}
}

function no_resaltar_provincia (nombre_provincia)
{
	document.getElementById(nombre_provincia).style.fontWeight="";
	document.getElementById(nombre_provincia).style.color="#045593";
}

function cp_provincia (cp)
{
	var cp_provincias = new Array (01,02,03,04,33,05,06,07,08,09,10,11,39,12,51,13,14,15,16,17,20,18,19,21,22,23,26,35,24,25,27,28,29,52,30,31,32,34,36,37,38,40,41,42,43,44,45,46,47,48,49,50);	

	if (cp!="")
	{
		cp = cp.slice (0,2);
		
		for (i=0; i<53; i++)
			if (cp==cp_provincias[i])
				document.getElementById("form_subastadores").provincia.options[i].selected = true
	}
}
// -------------------------------------------------

function provincia_cp (provincia)
{
	var cp_provincias = new Array ("01","02","03","04","33","05","06","07","08","09","10","11","39","12","51","13","14","15","16","17","20","18","19","21","22","23","26","35","24","25","27","28","29","52","30","31","32","34","36","37","38","40","41","42","43","44","45","46","47","48","49","50");	

	for (i=0; i<53; i++)
		if (cp_provincias[provincia-1]==cp_provincias[i])
			document.getElementById("form_subastadores").cp.value = cp_provincias[i] + "000"
}


