//GENERACION DE NUMERO ALEATORIO PARA MOSTRAR LOS BANNERS.            
imagen1 = new Image(60,60);
imagen2 = new Image(60,60);
imagen3 = new Image(60,60);
imagen4 = new Image(60,60);

imagen1.src = "./Content/images2/bannertoc.jpg";
imagen2.src = "./Content/images2/bannerabrera.jpg";
imagen3.src = "./Content/Images2/bannerquer.jpg";
imagen4.src = "./Content/Images2/banner-Valencia.gif";

imagen1.alt="TOC";
imagen2.alt="Abrera"
imagen3.alt="Oportunidad Naves Logisticas"
imagen4.alt="Valencia"
              
enlace1="./inmuebles/4-toc.html";
enlace2="./inmuebles/103-abrera.html";              
enlace3="./Detalle_NavePortalWeb.asp?id=1549";
enlace4="./index.asp?id_comunidad=10"



var randomnumber=Math.floor(Math.random()*6); 
if(randomnumber==1){
	document.getElementById('fotoCambia2').src=imagen1.src;
	document.getElementById('fotoCambia3').src=imagen2.src;
	document.getElementById('fotoCambia4').src=imagen3.src;
	document.getElementById('enlaceCambia2').href=enlace1;
	document.getElementById('enlaceCambia3').href=enlace2;
	document.getElementById('enlaceCambia4').href=enlace3; 
	
	document.getElementById('fotoCambia2').alt=imagen1.alt;
	document.getElementById('fotoCambia3').alt=imagen2.alt;
	document.getElementById('fotoCambia4').alt=imagen3.alt; 
	               
} 
else if(randomnumber==2){
	document.getElementById('fotoCambia2').src=imagen2.src;
	document.getElementById('fotoCambia3').src=imagen3.src;
	document.getElementById('fotoCambia4').src=imagen4.src;
	document.getElementById('enlaceCambia2').href=enlace2;
	document.getElementById('enlaceCambia3').href=enlace3;
	document.getElementById('enlaceCambia4').href=enlace4;                 
	
	document.getElementById('fotoCambia2').alt=imagen2.alt;
	document.getElementById('fotoCambia3').alt=imagen3.alt;
	document.getElementById('fotoCambia4').alt=imagen4.alt;
} 
else if(randomnumber==3){
	document.getElementById('fotoCambia2').src=imagen3.src;
	document.getElementById('fotoCambia3').src=imagen4.src;
	document.getElementById('fotoCambia4').src=imagen1.src;
	document.getElementById('enlaceCambia2').href=enlace3;
	document.getElementById('enlaceCambia3').href=enlace4;
	document.getElementById('enlaceCambia4').href=enlace1;  
	
	document.getElementById('fotoCambia2').alt=imagen3.alt;
	document.getElementById('fotoCambia3').alt=imagen4.alt;
	document.getElementById('fotoCambia4').alt=imagen1.alt;               
}
else if(randomnumber==4){
	document.getElementById('fotoCambia2').src=imagen4.src;
	document.getElementById('fotoCambia3').src=imagen1.src;
	document.getElementById('fotoCambia4').src=imagen2.src;
	document.getElementById('enlaceCambia2').href=enlace4;
	document.getElementById('enlaceCambia3').href=enlace1;
	document.getElementById('enlaceCambia4').href=enlace2;                 
		
	document.getElementById('fotoCambia2').alt=imagen4.alt;
	document.getElementById('fotoCambia3').alt=imagen1.alt;
	document.getElementById('fotoCambia4').alt=imagen2.alt;
}
else if(randomnumber==4){
	document.getElementById('fotoCambia2').src=imagen1.src;
	document.getElementById('fotoCambia3').src=imagen2.src;
	document.getElementById('fotoCambia4').src=imagen3.src;
	document.getElementById('enlaceCambia2').href=enlace1;
	document.getElementById('enlaceCambia3').href=enlace2;
	document.getElementById('enlaceCambia4').href=enlace3;   
	
	document.getElementById('fotoCambia2').alt=imagen1.alt;
	document.getElementById('fotoCambia3').alt=imagen2.alt;
	document.getElementById('fotoCambia4').alt=imagen3.alt;              
}
// Script para cambiar el formulario de solicitar mas info por el de enviar a un amigo, en las fichas de productos
function formularios() {
	if ( document.getElementById('form_solicitar_info').style.display == 'none' ) {
		document.getElementById('form_solicitar_info').style.display = 'block'
		document.getElementById('form_enviar_amigo').style.display = 'none'
		document.getElementById('botonamigo').value = 'Envía esta oferta a un amigo'			
	}
	else {
		document.getElementById('form_solicitar_info').style.display = 'none'
		document.getElementById('form_enviar_amigo').style.display = 'block'
		document.getElementById('botonamigo').value = 'Solicitar información'
	}				
}
// Script para mostar la celda de documentos, en las fichas de productos
function mostrar_documentos() {
	if (document.getElementById('divdocumentos').style.display == 'block')
		document.getElementById('divdocumentos').style.display = 'none'
	else
		document.getElementById('divdocumentos').style.display = 'block'
}
// Script para mostrar más fotos, en las fichas de productos
function cambiar_foto() {
	for ( i=0; i<=numeroiteracciones; i++ ) {
		if (document.getElementById('fotoitem').src.indexOf(fotosinmuebles[i]) != -1) {
			j = i+1
			if(j>numeroiteraciones){
			  j=j-2;
			}
			document.getElementById('fotoitem').src = fotosinmuebles[j];
			document.getElementById('fotoitem2').href = fotosinmuebles[j];
			return true;
		}
	}	
	document.getElementById('fotoitem').src = fotosinmuebles[0];
	document.getElementById('fotoitem2').href = fotosinmuebles[0];
}

// Script para mostrar más fotos, en las fichas de productos
 var fotoAMostrar=0; 
 var contador=0;
function cambiar_foto2() {
   
   fotoAMostrar=fotoAMostrar+1;      
      
   if(fotoAMostrar>numeroIteraciones){   
      fotoAMostrar=0;      
   }    
          
  
   
   	document.getElementById('fotoitem').src = fotosinmuebles[fotoAMostrar];
	document.getElementById('fotoitem2').href = fotosinmuebles[fotoAMostrar];
	
}
// Validar formularios "Solicitar mas información"
function obligatoriossolinfo(theForm){
// Uno por campo
	theForm = document.getElementById(theForm);
	if (theForm.Nombre.value == ""){
		alert("Debe introducir su nombre.");
		theForm.Nombre.focus();
		return (false);
	}
	if (theForm.Apellidos.value == ""){
		alert("Debe introducir sus apellidos.");
		theForm.Apellidos.focus();
		return (false);
	}
	if (theForm.EMail.value == ""){
		alert("Debe introducir una direcci&oacute;n de e-mail.");
		theForm.EMail.focus();
		return (false);
	}
	if (theForm.EMail.value != ""){
		// valida el e-mail
		var checkEmail = "@.";
		var checkStr = theForm.EMail.value;
		var EmailValid = false;
		var EmailAt = false;
		var EmailPeriod = false;
		for (i = 0;  i < checkStr.length;  i++){
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkEmail.length;  j++){
				if (ch == checkEmail.charAt(j) && ch == "@")
				EmailAt = true;
				if (ch == checkEmail.charAt(j) && ch == ".")
				EmailPeriod = true;
				if (EmailAt && EmailPeriod)
				break;
				if (j == checkEmail.length)
				break;
			}
// if both the @ and . were in the string
			if (EmailAt && EmailPeriod){
				EmailValid = true
				break;
			}
		}
		if (!EmailValid){
			alert("Debe introducir una direcci&oacute;n de e-mail correcta.\n");
			theForm.EMail.focus();
			return (false);	
		}              	
	}
	if (theForm.telefono.value == ""){
		alert("Debe introducir su telefono.");
		theForm.telefono.focus();
		return (false);
	}
	document.forms[1].submit()
}

