/* funcio per deshabilitar el botó dret a les imatges */
document.oncontextmenu = function(){return false}

function ratoli_sobre_tancar (img, inicio)
{
	obj=document.getElementById(img);
	obj.src='../imatges/x1.gif';
	if(inicio){
		obj.src='imatges/x1.gif';
	}
}

function ratoli_fora_tancar (img, inicio)
{
	obj=document.getElementById(img);
	obj.src='../imatges/x.gif';
	if(inicio){
		obj.src='imatges/x.gif';
	}
}

function ratoli_clic_tancar (img, inicio)
{
	obj=document.getElementById(img);
	obj.src='../imatges/x2.gif';
	if(inicio){
		obj.src='imatges/x2.gif';
	}
}

function tancarFinestra (boto, capa)
{
	desactivaCapa (capa);
	
	obj=document.getElementById(boto);
	obj.style.visibility='visible';
}

function obrirFinestra (boto, capa)
{
	obj=document.getElementById(boto);
	obj.style.visibility='hidden';

	activaCapa (capa);
	
}

function activaCapa (capa)
{
	obj=document.getElementById(capa);
	obj.style.visibility='visible';
}

function desactivaCapa (capa)
{
	obj=document.getElementById(capa);
	obj.style.visibility='hidden';
}

/////////////////////////////////////////////////////////////////////////////
// funcio canviar fons galeria
function canvia_foto_galeria(foto_seleccionada, num_fotos)
{	
	//img_galeria = "img_galeria" + foto_seleccionada;
	//obj = document.getElementById(img_galeria);
	//obj.src = "../imatges/inmuebles/pisos/galeria" + foto_seleccionada + ".jpg";
	foto = "foto" + foto_seleccionada;
	obj = document.getElementById(foto);
	if (obj.style.visibility != "visible")
	{
		obj.style.visibility = "visible";
		//initImage(foto);
	
		for (i=1;i<=num_fotos;i++)
		{
			it = String(i);
			foto_noseleccionada = "foto" + it;
			if (foto != foto_noseleccionada)
			{	
				obj = document.getElementById(foto_noseleccionada);
				obj.style.visibility = "hidden";
			}
		}
	}
}

/////////// FUNCIONS EFECTE PASSAR PER SOBRE LINKS INDEX PRODUCTOS VIVIENDAS.PHP /////////

function rollOver(capa)
{
	obj = document.getElementById(capa+"Ref");
	obj.style.backgroundColor = "#999999";
	obj = document.getElementById(capa+"Zona");
	obj.style.backgroundColor = "#999999";
	obj = document.getElementById(capa+"Metraje");
	obj.style.backgroundColor = "#999999";
	obj = document.getElementById(capa+"Precio");
	obj.style.backgroundColor = "#999999";
}

function noRollOver(capa)
{
	obj = document.getElementById(capa+"Ref");
	obj.style.background = "none";
	obj = document.getElementById(capa+"Zona");
	obj.style.background = "none";
	obj = document.getElementById(capa+"Metraje");
	obj.style.background = "none";
	obj = document.getElementById(capa+"Precio");
	obj.style.background = "none";
}

///////////////////////////////// FUNCIONS FOTOS FADE IN /////////////////////////////////
function initImage(imageId) {
  //imageId = 'thephoto';
  image = document.getElementById(imageId);
  //posem la opacitat de la imatge a 0. Segons el navegador és un atribut o un altre, per això ho fem en aquesta funció nostra
  setOpacity(image, 50);
  //Posem la capa de la imatge  com a visible
  image.style.visibility = 'visible';
  //La funció encarregada de fer l'efecte fade in en sí
  fadeIn(imageId,50);
}

function setOpacity(obj, opacity) {

  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";

  // Safari menor que 1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
	obj = document.getElementById(objId);
	if (opacity != 110) {
	  setOpacity(obj, opacity);
	  opacity += 10;
	  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 5);
	}
  }
}

//borra el text quan es clica sobre el camp euros
function borraEuros(formulario){
	valor = eval("document." + formulario + ".euros.value");
	if (valor == '&euro;')
		eval("document." + formulario + ".euros.value = ''");
}

//borra el text quan es clica sobre el camp Ptas
function borraPtas(formulario){
	valor = eval("document." + formulario + ".ptas.value");
	if (valor == 'Ptas')
		eval("document." + formulario + ".ptas.value = ''");
}

function validaFormularioCompra() {
	tipo = document.formComprar.tipo.value;
	euros = document.formComprar.euros.value;
	ptas = document.formComprar.ptas.value;
	metros = document.formComprar.metros.value;
	zona = document.formComprar.zona.value;
	comentarios = document.formComprar.comentarios.value;

	nombre = document.formComprar.nombre.value;
	telf = document.formComprar.telf.value;
	mail = document.formComprar.email.value;
	
	if(!document.formComprar.aceptarPolitica.checked) {
		obj = document.getElementById("aceptarPoliticaBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "235px";
		return false;
	}
	else if ( (tipo == '') || (euros == '' && ptas == '') || (metros == '') || (zona == '') )
	{
		obj = document.getElementById("datosInmuebleBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "235px";
		return false;
	}
	else
	{
		if ( (nombre == '') || (telf == '') ){
			obj = document.getElementById("datosPersBlanc");
			obj.style.visibility = "visible";
			obj.style.left = "235px";
			return false;
		}
		if (mail != '')
		{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)))
			{
				obj = document.getElementById("mailIncorrecto");
				obj.style.visibility = "visible";
				obj.style.left = "235px";
				return false;
			}
		}
	}
	return true;
}

function validaFormularioVenta() {
	tipo = document.formVender.tipo.value;
	euros = document.formVender.euros.value;
	ptas = document.formVender.ptas.value;
	metros = document.formVender.metros.value;
	zona = document.formVender.zona.value;
	comentarios = document.formVender.comentarios.value;
	
	nombre = document.formVender.nombre.value;
	telf = document.formVender.telf.value;
	mail = document.formVender.email.value;
	
	if(!document.formVender.aceptarPolitica.checked) {
		obj = document.getElementById("aceptarPoliticaBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "511px";
		return false;
	}
	else if ( (tipo == '') || (euros == '' && ptas == '') || (metros == '') || (zona == '') )
	{
		obj = document.getElementById("datosInmuebleBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "511px";
		return false;
	}
	else
	{
		if ( (nombre == '') || (telf == '') ){
			obj = document.getElementById("datosPersBlanc");
			obj.style.visibility = "visible";
			obj.style.left = "511px";
			return false;
		}
		if (mail != '')
		{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)))
			{
				obj = document.getElementById("mailIncorrecto");
				obj.style.visibility = "visible";
				obj.style.left = "511px";
				return false;
			}
		}
	}
	return true;
}

function validaFormularioInmueble() {
	nombre = document.formContactar.nombre.value;
	telf = document.formContactar.telf.value;
	mail = document.formContactar.email.value;
	
	if(!document.formContactar.aceptarPolitica.checked) {
		obj = document.getElementById("aceptarPoliticaContactoBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "5px";
		obj.style.top = "300px";
		obj.style.width = "195px";
		obj.style.height = "95px";
		return false;
	}
	else if ( (nombre == '') || (telf == '') ){
		obj = document.getElementById("datosPersContactoBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "5px";
		obj.style.top = "320px";
		obj.style.width = "195px";
		return false;
	}
	if (mail != '')
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)))
		{
			obj = document.getElementById("mailContactoIncorrecto");
			obj.style.visibility = "visible";
			obj.style.left = "5px";
			obj.style.top = "320px";
			obj.style.width = "195px";
			return false;
		}
	}
	
	desactivaCapa('capaInmueble');
	desactivaCapa('contactar');
	return true;
}

/* formulari de la newsletter */
function validaFormularioNews() {
	mail = document.formNews.email.value;
	
	if(!document.formNews.aceptarPolitica.checked) {
		obj = document.getElementById("aceptarPoliticaBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "368px";
		return false;
	}
	else if ( !document.getElementById("tipo1").checked && !document.getElementById("tipo2").checked && !document.getElementById("tipo3").checked && !document.getElementById("tipo4").checked && !document.getElementById("tipo5").checked ) {
		obj = document.getElementById("datosInmuebleBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "368px";
		return false;
	}
	else if ( !document.getElementById("zona1").checked && !document.getElementById("zona2").checked && !document.getElementById("zona3").checked && !document.getElementById("zona4").checked && !document.getElementById("zona5").checked && !document.getElementById("zona6").checked && !document.getElementById("zona7").checked && !document.getElementById("zona8").checked && !document.getElementById("zona9").checked && !document.getElementById("zona10").checked && !document.getElementById("zona11").checked && !document.getElementById("zona12").checked && !document.getElementById("zona13").checked && !document.getElementById("zona14").checked ) {
		obj = document.getElementById("datosInmuebleBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "368px";
		return false;
	}
	else if (mail == '') {
		obj = document.getElementById("datosPersBlanc");
		obj.style.visibility = "visible";
		obj.style.left = "368px";
		return false;
	}
	if (mail != '')
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)))
		{
			obj = document.getElementById("mailIncorrecto");
			obj.style.visibility = "visible";
			obj.style.left = "368px";
			return false;
		}
	}
	return true;
}