// Redimensiona los iframes
function resizeFrame() {
    document.getElementById("oFrameBusc").style.height = eval("window.frames." + "oFrameBusc"+ ".document.documentElement.scrollHeight") + "px";        
}
function resizeFrameDestacados() {
    document.getElementById("oFrameDest").style.height = eval("window.frames." + "oFrameDest"+ ".document.documentElement.scrollHeight") + "px";        
}

// Focus para inputs en IE
sfFocus = function() {
    var sfEls = document.getElementsByTagName("INPUT");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onfocus=function() {
            this.className+=" sffocus";
        }
        sfEls[i].onblur=function() {
            this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);


// Focus para textareas en IE
sfFocus = function() {
    var sfEls = document.getElementsByTagName("TEXTAREA");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onfocus=function() {
            this.className+=" sffocus";
        }
        sfEls[i].onblur=function() {
            this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);


// Focus para select en IE
sfFocus = function() {
    var sfEls = document.getElementsByTagName("SELECT");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onfocus=function() {
            this.className+=" sffocus";
        }
        sfEls[i].onblur=function() {
            this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);


// Crear links para cada idioma
function crearLinkIdioma(idioma, idiomaCompleto) {
    var idiomaActual;
    idiomaActual = document.getElementById("__Idioma").value;
    if (idiomaActual.length == 0) {  
        //Si la variable "__Idioma" esta vacia, miramos si nos han pasado alguna por parámetro 
        //(necesaria para el acceso directo al buscador con un idioma concreto)
        var URL = unescape(window.document.location);
        if (URL.indexOf("NewIdioma=") > -1) { 
            idiomaActual = URL.substring(URL.indexOf("NewIdioma=")+10, URL.lenght);
            if (idiomaActual != "es" & idiomaActual != "cat" & idiomaActual != "fr" & idiomaActual != "en"){
                //idiomaActual no es válido y pasa a ser el default (es)
                idiomaActual = "es";
            }
        } else {
            idiomaActual = "es";
        }   
        var form = document.forms[0];
        form.__Idioma.value = idiomaActual;
    }
	if (idiomaActual != idioma) {
		document.write('<a href="#" onClick="javascript:CambiarIdioma(\'' + idioma + '\')" title="' + idiomaCompleto + '"><img src="img/idioma-' + idioma + '.gif" alt="' + idiomaCompleto + '" border="0" class="langNoActivo" /></a>');
	} else {
		document.write('<img src="img/idioma-' + idioma + '.gif" alt="' + idiomaCompleto + '" border="0" />');
	}
}


//Cambiamos el idioma de la web
CambiarIdioma = function (newIdioma) {    
    var form = document.forms[0];
    form.__Idioma.value = newIdioma;
    form.submit();
}

//Vamos a la url
Goto = function (page) {
    // Si no viene ninguna página destino, nos vamos al inicio
    if (page == "") page = "Default.aspx";
    var form = document.forms[0];
    form.action = page;
    form.submit();
}

// ENVIAR E-MAIL: INICIO
var CTXT_PoblacionValido = 'La poblaci\u00F3n del inmueble ha de estar informada';
var CTXT_PrecioValido = 'El precio del inmueble ha de estar informado';
var CTXT_SuperficieValido = 'La superficie del inmueble ha de estar informada';
var CTXT_NombreValido = 'El nombre ha de estar informado';
var CTXT_EmailTelefonoValido = 'La direcci\u00F3n de correo electr\u00F3nico o alg\u00FAn tel\u00E9fono tienen que ser correctos';
var CTXT_EmailTelefonoNombreValido = 'La direcci\u00F3n de correo electr\u00F3nico o alg\u00FAn tel\u00E9fono y el nombre tienen que ser v\u00E1lidos';
var CTXT_EmailNombreValido = 'La direcci\u00F3n de correo electr\u00F3nico y el nombre tienen que ser v\u00E1lidos';
var CTXT_EmailValido = 'La direcci\u00F3n de correo electr\u00F3nico tiene que ser v\u00E1lida';

function EnviarMailContacto() {
	var okmail = true;
	var oknom = true;	
	if (typeof(document.FormContacto.uMailEMail)=="object") {
		if (document.FormContacto.uMailEMail.value.length<5) {
			okmail = false;
		}
		else {
			var arr = document.FormContacto.uMailEMail.value.indexOf('@')
			if (arr<=0||arr==document.FormContacto.uMailEMail.value.length-1) {
				okmail = false;
			}
			else if (document.FormContacto.uMailEMail.value.substr(arr,document.FormContacto.uMailEMail.value.length-1).indexOf('.')<=0) {
				okmail = false;
			}
		}
	}
	if (typeof(document.FormContacto.uMailNombre)=="object")
		if (document.FormContacto.uMailNombre.value.length==0)
			oknom = false;
	if (okmail&&oknom) {	
        var sbody = '<p><strong>Nombre: </strong>' + document.getElementById("uMailNombre").value + '</p>';
        sbody = sbody + '<p><strong>E-mail: </strong>' + document.getElementById("uMailEMail").value + '</p>';
        sbody = sbody + '<p><strong>Sugerencias: </strong>' + document.getElementById("uMailComentarios").value + '</p>';
        
        document.getElementById("bodyMail").value = sbody;
        document.getElementById("origenMail").value = "Contactar";
        document.FormContacto.submit();
	} else if(okmail) {
		alert(CTXT_NombreValido);
	} else if(oknom) {
		alert(CTXT_EmailValido);
	} else {
		alert(CTXT_EmailNombreValido);
	}
}


function EnviarMailVender() {
	var okPoblacion = true;
	var okPrecio = true;
	var okSuperficie = true;
	var okmail = true;
	var oknom = true;	
	
	if (document.FormVender.uInmueblePoblacion.value.length==0) {
		okPoblacion = false;
	}
	
	if (document.FormVender.uInmueblePrecio.value.length==0) {
		okPrecio = false;
	}
	
	if (document.FormVender.uInmuebleSuperficie.value.length==0) {
		okSuperficie = false;
	}
	
	if (typeof(document.FormVender.uMailEMail)=="object") {
		if (document.FormVender.uMailEMail.value.length<5) {
			okmail = false;
		}
		else {
			var arr = document.FormVender.uMailEMail.value.indexOf('@')
			if (arr<=0||arr==document.FormVender.uMailEMail.value.length-1) {
				okmail = false;
			}
			else if (document.FormVender.uMailEMail.value.substr(arr,document.FormVender.uMailEMail.value.length-1).indexOf('.')<=0) {
				okmail = false;
			}
		}
	}
	if (!okmail)
		if (((typeof(document.FormVender.uMailTelefono)=="object")&&(document.FormVender.uMailTelefono.value.length>=9)&&(!isNaN(document.FormVender.uMailTelefono.value)))||((typeof(document.FormVender.uMailMovil)=="object")&&(document.FormVender.uMailMovil.value.length>=9)&&(!isNaN(document.FormVender.uMailMovil.value))))
			okmail=true;
	if (typeof(document.FormVender.uMailNombre)=="object")
		if (document.FormVender.uMailNombre.value.length==0)
			oknom = false;
			
	if (okmail&&oknom&&okPoblacion&&okPrecio&&okSuperficie) {	
        var sbody = '<b><u>Informaci\u00F3n del inmueble</u></b><br /><br />';
	    if (document.getElementById("uInmuebleTipo").value.length > 0) {
	        sbody = sbody + '<p><strong>Tipo: </strong>' + document.getElementById("uInmuebleTipo").value + '</p>';
	    }
	    if (document.getElementById("uInmuebleCategoria").value.length > 0) {
	        sbody = sbody + '<p><strong>Categor\u00EDa: </strong>' + document.getElementById("uInmuebleCategoria").value + '</p>';
	    }
	    var provinciaInmueble = document.FormVender.uInmuebleProvincia.options[document.FormVender.uInmuebleProvincia.selectedIndex].value;
	    if (provinciaInmueble.length > 0) {
	        sbody = sbody + '<p><strong>Provincia: </strong>' + provinciaInmueble + '</p>';
	    }
	    if (document.getElementById("uInmueblePoblacion").value.length > 0) {
	        sbody = sbody + '<p><strong>Poblaci\u00F3n: </strong>' + document.getElementById("uInmueblePoblacion").value + '</p>';
	    }
	    if (document.getElementById("uInmuebleAnyo").value.length > 0) {
	        sbody = sbody + '<p><strong>A\u00F1o de construcci\u00F3n: </strong>' + document.getElementById("uInmuebleAnyo").value + '</p>';
	    }
	    if (document.getElementById("uInmueblePrecio").value.length > 0) {
	        sbody = sbody + '<p><strong>Precio: </strong>' + document.getElementById("uInmueblePrecio").value + '</p>';
	    }
	    if (document.getElementById("uInmuebleSuperficie").value.length > 0) {
	        sbody = sbody + '<p><strong>Superficie: </strong>' + document.getElementById("uInmuebleSuperficie").value + '</p>';
	    }
	    if (document.getElementById("uInmuebleDescripcion").value.length > 0) {
	        sbody = sbody + '<p><strong>Descripci\u00F3n: </strong>' + document.getElementById("uInmuebleDescripcion").value + '</p>';
	    sbody = sbody + '<br /><br /><br />';
	    sbody = sbody + '<b><u>Informaci\u00F3n del contacto</u></b><br /><br />';
        }
	    if (document.getElementById("uMailNombre").value.length > 0) {
	        sbody = sbody + '<p><strong>Nombre y apellidos: </strong>' + document.getElementById("uMailNombre").value + " " + document.getElementById("uMailApellido").value + '</p>';
        }
	    if (document.getElementById("uMailEMail").value.length > 0) {
	        sbody = sbody + '<p><strong>E-mail: </strong>' + document.getElementById("uMailEMail").value + '</p>';
        }
	    if (document.getElementById("uMailTelefono").value.length > 0) {
	        sbody = sbody + '<p><strong>Tel\u00E9fono: </strong>' + document.getElementById("uMailTelefono").value + '</p>';    
        }
	    if (document.getElementById("uMailMovil").value.length > 0) {
	        sbody = sbody + '<p><strong>M\u00F3vil: </strong>' + document.getElementById("uMailMovil").value + '</p>';      
        }
	    if (document.getElementById("uMailDireccion").value.length > 0) {
	        sbody = sbody + '<p><strong>Direcci\u00F3n: </strong>' + document.getElementById("uMailDireccion").value + '</p>';      
        }
	    var provinciaContacto = document.FormVender.uMailProvincia.options[document.FormVender.uMailProvincia.selectedIndex].value;
	    if (provinciaContacto.length > 0) {
	        sbody = sbody + '<p><strong>Provincia: </strong>' + provinciaContacto + '</p>';      
        }
	    if (document.getElementById("uMailPoblacion").value.length > 0) {
	        sbody = sbody + '<p><strong>Poblaci\u00F3n: </strong>' + document.getElementById("uMailPoblacion").value + '</p>';    
        }
	    if (document.getElementById("uMailComentarios").value.length > 0) {
	        sbody = sbody + '<br />'; 
            sbody = sbody + '<p><strong>Comentarios: </strong>' + document.getElementById("uMailComentarios").value + '</p>';
        }
        document.getElementById("bodyMail").value = sbody;
        document.getElementById("origenMail").value = "QuieroVender";
        document.FormVender.submit();
	} else if(!okSuperficie) {
		alert(CTXT_SuperficieValido);
	} else if(!okPoblacion) {
		alert(CTXT_PoblacionValido);
	} else if(!okPrecio) {
		alert(CTXT_PrecioValido);
	} else if(!okmail&&!oknom) {
		alert(CTXT_EmailTelefonoNombreValido);
	} else if(!oknom) {
		alert(CTXT_NombreValido);
	} else if(!okmail) {
		alert(CTXT_EmailTelefonoValido);
	} else {
		alert(CTXT_EmailTelefonoNombreValido);
	}
}
// ENVIAR E-MAIL: FIN
