// JavaScript Document

//--------------------------------------------------------------------------------------------//
function Comprobar()
{
	if(document.getElementById('txtnombre').value == '')
	{
		alert("Por favor, introduzca su nombre.");
		return false;
	}
	if(document.getElementById('txtmail').value == '' || !validaMail(document.getElementById('txtmail').value))
	{
		alert("Correo no valido.");
		return false;
	}
	if(document.getElementById('txttelefono').value == '' || !telefono_valido(document.getElementById('txttelefono').value))
	{
		alert("Telefono no valido.");
		return false;
	}
	if(document.getElementById('txtcomentarios').value == '')
	{
		alert("Por favor, introduzca algun comentario.");
		return false;
	}
	if(!document.getElementById('condiciones').checked)
	{
		alert("Debe aceptar las condiciones legales.");
		return false;
	}
	document.form1.submit();
}
//--------------------------------------------------------------------------------------------//
function ComprobarFormGrande()
{
	if(document.getElementById('txtnombre').value == '')
	{
		alert("Por favor, introduzca su nombre.");
		return false;
	}
	if(document.getElementById('txtapellidos').value == '')
	{
		alert("Por favor, introduzca sus apellidos.");
		return false;
	}
	if(document.getElementById('txtmail').value == '' || !validaMail(document.getElementById('txtmail').value))
	{
		alert("Correo no valido.");
		return false;
	}
	if(document.getElementById('txttelefono').value == '' || !telefono_valido(document.getElementById('txttelefono').value))
	{
		alert("Telefono no valido.");
		return false;
	}
	if(document.getElementById('txtasunto').value == '')
	{
		alert("Por favor, introduzca el asunto.");
		return false;
	}
	if(document.getElementById('txtcomentarios').value == '')
	{
		alert("Por favor, introduzca algun comentario");
		return false;
	}
	if(!document.getElementById('condiciones').checked)
	{
		alert("Debe aceptar las condiciones legales.");
		return false;
	}
	
	document.form1.submit();
}
//--------------------------------------------------------------------------------------------//
function Comprobar_trabaja_con_nosotros()
{
	if(document.getElementById('txtnombre').value == '')
	{
		alert("Por favor, introduzca su nombre.");
		return false;
	}
	if(document.getElementById('txtapellidos').value == '')
	{
		alert("Por favor, introduzca sus apellidos.");
		return false;
	}
		if(document.getElementById('txtedad').value == '')
	{
		alert("Por favor, introduzca su edad.");
		return false;
	}
	if(document.getElementById('txttelefono').value == '' || !telefono_valido(document.getElementById('txttelefono').value))
	{
		alert("Telefono no valido.");
		return false;
	}
	if(document.getElementById('txtmail').value == '' || !validaMail(document.getElementById('txtmail').value))
	{
		alert("Correo no valido.");
		return false;
	}
	if(document.getElementById('txtempleo').value == '')
	{
		alert("Por favor, introduzca el empleo que desea.");
		return false;
	}
	if(document.getElementById('txtdireccion').value == '')
	{
		alert("Por favor, introduzca su direccion.");
		return false;
	}
	if(document.getElementById('txtcomentarios').value == '')
	{
		alert("Por favor, introduzca algun comentario.");
		return false;
	}
	if(!document.getElementById('condiciones').checked)
	{
		alert("Debe aceptar las condiciones legales.");
		return false;
	}
	
	document.form1.submit();
}
//--------------------------------------------------------------------------------------------//
function Comprobar_sugerencias()
{
	if(document.getElementById('txtnombre').value == '')
	{
		alert("Por favor, introduzca su nombre.");
		return false;
	}
	if(document.getElementById('txtapellidos').value == '')
	{
		alert("Por favor, introduzca sus apellidos.");
		return false;
	}
	if(document.getElementById('txttelefono').value == '' || !telefono_valido(document.getElementById('txttelefono').value))
	{
		alert("Telefono no valido.");
		return false;
	}
	if(document.getElementById('txtmail').value == '' || !validaMail(document.getElementById('txtmail').value))
	{
		alert("Correo no valido.");
		return false;
	}
	if(document.getElementById('txtsugerencias').value == '')
	{
		alert("Por favor, introduzca alguna sugerencia.");
		return false;
	}
	if(!document.getElementById('condiciones').checked)
	{
		alert("Debe aceptar las condiciones legales.");
		return false;
	}
	
	document.form1.submit();
}
//--------------------------------------------------------------------------------------------//
function validaMail(txtmail)
{
    var mailres = true;            
    var cadena = "abcdefghijklmnnopqrstuvwxyzABCDEFGHIJKLMNNOPQRSTUVWXYZ1234567890@._-";
	var arroba = txtmail.indexOf("@",0);
	var contador = 0;

    if ((txtmail.lastIndexOf("@")) != arroba) arroba = -1;

    var punto = txtmail.lastIndexOf(".");

     for (contador = 0 ; contador < txtmail.length ; contador++)
	 {
        if (cadena.indexOf(txtmail.substr(contador, 1),0) == -1)
		{
            mailres = false;
            break;
    	}
    }

	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (txtmail.length)) && (mailres == true) && (txtmail.indexOf("..",0) == -1))
		mailres = true;
	else
		mailres = false;

	return mailres;
}
function telefono_valido(numero)
{
	var tfno= parseInt(numero);
	var error = "";
	if ( isNaN(tfno) )
		error="q";
	else
	{
		if ( !( (tfno >= 900000000) && (tfno < 1000000000) || (tfno >= 600000000) && (tfno < 700000000) ) )  
			error="q";
	}
	if(error == "")
		return true;
	return false;
}

//--------------------------------------------------------------------------------------------//
function cargaPagina(url,div,parametros)
{
	//new Ajax(url,{method: 'post', postBody:parametros, update:div}).request();
	
	new Request(
	{
		method: 'post',
		url: url,
		onSuccess: function(texto){
		$(div).innerHTML = texto;}
	}).send(parametros);
}
//--------------------------------------------------------------------------------------------//
var AltoPantalla = screen.Height / 2;
var AnchoPantalla = screen.Width / 2;

function AbrePopupConScroll(Ruta, Nombre, Ancho, Alto) 
{
	var AltoMostrar = AltoPantalla - (Alto / 2);
	var AnchoMostrar = AnchoPantalla - (Ancho / 2);	
	var PopUpW = window.open(Ruta, Nombre, "width=" + Ancho + ", height=" + Alto + ", top=" + AltoMostrar + ", left=" + AnchoMostrar + ", scrollbars=yes, titlebar=no, menubar=no, location=no");
	PopUpW.focus();
	return false;
}
//--------------------------------------------------------------------------------------------//
var cambioFoto;
var fotoActual = 1;
function cargaFotos()
{
	for (var i = 2; i<=5; i++)
	{
		//$('foto' + i).fade(0);
		//$('foto' + i).style.visibility = 'hidden';
	}
	cambioFoto = setTimeout("cambiaFoto()", 5000);
}
//--------------------------------------------------------------------------------------------//
function cambiaFoto()
{
	clearTimeout(cambioFoto);
	var nuevaFoto = fotoActual + 1;
	if(nuevaFoto > 5)
		nuevaFoto = 1;
	
	//var myFx1 = new Fx.Tween($('texto' + nuevaFoto), [, options]);
	//var myFx2 = new Fx.Tween($('texto' + fotoActual), [, options]);
	//myFx1.set('opacity', {duration: 2000}).start(0);
    //myFx2.set('opacity', {duration: 2000}).start(1);
	//$('foto' + nuevaFoto).style.visibility = 'visible';
	$('foto' + fotoActual).fade(0);
	$('foto' + nuevaFoto).fade(1);	
	
	fotoActual = nuevaFoto;
	cambioFoto = setTimeout("cambiaFoto()", 5000);
}
//--------------------------------------------------------------------------------------------//
function cargaMapa() {
	if (GBrowserIsCompatible()) {
	  var map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();
	//var address = $('direccion').value;
	var address = "Avenida de Europa 34 bloque B escalera derecha 1&deg; izquierda 28023 Pozuelo Madrid";
	var texto = "Grupo Caysa";
	var LatLng = new GLatLng(geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 15);
			var blueIcon = new GIcon(G_DEFAULT_ICON);
			//blueIcon.image = "http://";
			markerOptions = { icon:blueIcon }
			var marker = new GMarker(point, markerOptions);
			map.addOverlay(marker);
			//marker.openInfoWindowHtml(address);
			//var myHtml = "<center><font style='font-size: 14px;'>" + texto + "</font></center>";
			//map.openInfoWindowHtml(point, myHtml);
		  }
		}
	  )
	);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	//map.setCenter(LatLng);
	}
 }
//--------------------------------------------------------------------------------------------//
function cambiaColorMenu(id, tipo)
{
	if(tipo == 1)
		$(id).style.background = '#087dc2';
	else
		$(id).style.background = '#000000';
}
//--------------------------------------------------------------------------------------------//







