var timer;

$(function() 
{
	if ($('#FormacionTexto a#t1').hasClass('selected')) $('#FormacionT2').hide();
	else $('#FormacionT1').hide();
	$('#FormacionTexto a#t1').click(function(){
		$('#FormacionT2').hide();
		$('#FormacionT1').show();
		$('#FormacionTexto a#t1').addClass('selected');
		$('#FormacionTexto a#t2').removeClass('selected');
	});
	$('#FormacionTexto a#t2').click(function(){
		$('#FormacionT1').hide();
		$('#FormacionT2').show();
		$('#FormacionTexto a#t2').addClass('selected');
		$('#FormacionTexto a#t1').removeClass('selected');
	});
	
	$('#Serv1 a').mouseover(function(){$('#Serv1 img').attr('src','img/serv-1-a.png');}).mouseout(function(){$('#Serv1 img').attr('src','img/serv-1.png');});
	$('#Serv2 a').mouseover(function(){$('#Serv2 img').attr('src','img/serv-2-a.png');}).mouseout(function(){$('#Serv2 img').attr('src','img/serv-2.png');});
	$('#Serv3 a').mouseover(function(){$('#Serv3 img').attr('src','img/serv-3-a.png');}).mouseout(function(){$('#Serv3 img').attr('src','img/serv-3.png');});
	$('#Serv4 a').mouseover(function(){$('#Serv4 img').attr('src','img/serv-4-a.png');}).mouseout(function(){$('#Serv4 img').attr('src','img/serv-4.png');});
	$('#Serv5 a').mouseover(function(){$('#Serv5 img').attr('src','img/serv-5-a.png');}).mouseout(function(){$('#Serv5 img').attr('src','img/serv-5.png');});
	$('#Serv6 a').mouseover(function(){$('#Serv6 img').attr('src','img/serv-6-a.png');}).mouseout(function(){$('#Serv6 img').attr('src','img/serv-6.png');});
	$('#Serv7 a').mouseover(function(){$('#Serv7 img').attr('src','img/serv-7-a.png');}).mouseout(function(){$('#Serv7 img').attr('src','img/serv-7.png');});

	$('#MenuTrabajamos a').click(function () {
		$('#MenuTrabajamos a').removeClass('selected');
		$(this).addClass('selected');
		$('#TrabTituloEtapa').html($(this).html());
		$('.Etapa').removeClass('selected');
		$('.Etapa').removeClass('TextoScroll');
		var id=$(this).attr('id');
		$('#T'+id).addClass('selected');
		$('#T'+id).addClass('TextoScroll');
		CheckScroll();
	});

	$("#tabs").tabs();
	
	CheckScroll();
	
	var im1=new Image;
	im1.src='img/serv-1-a.png';
	var im2=new Image;
	im2.src='img/serv-2-a.png';
	var im3=new Image;
	im3.src='img/serv-3-a.png';
	var im4=new Image;
	im4.src='img/serv-4-a.png';
	var im5=new Image;
	im5.src='img/serv-5-a.png';
	var im6=new Image;
	im6.src='img/serv-6-a.png';
	var im7=new Image;
	im7.src='img/serv-7-a.png';
	
	setTimeout(function() {$('#texto').css('width','348px');},500);
});


function CheckScroll()
{
	var total=$('.TextoScroll').attr("scrollHeight");
	var parcial=$('.TextoScroll').attr("offsetHeight");
	if (total>parcial) 
	{
		$('.Scroll').show();
		$('.Scroll img#SCUp').mouseover(function() {
			clearInterval(timer);
			timer=setInterval(function () {
				var pos=$('.TextoScroll').attr("scrollTop");
				$('.TextoScroll').attr("scrollTop", pos-5);
			},20);
		}).
		mouseout(function(){
			clearInterval(timer);
		});
		$('.Scroll img#SCDown').mouseover(function() {
			clearInterval(timer);
			timer=setInterval(function () {
				var pos=$('.TextoScroll').attr("scrollTop");
				$('.TextoScroll').attr("scrollTop", pos+5);
			},20);
		}).
		mouseout(function(){
			clearInterval(timer);
		});
	}
	else $('.Scroll').hide();
}

function ValidarRecomienda()
{
	var f=document.getElementById('form_recom');
	valido=false;
	if (f.nombre.value=='') alert("Debes indicarnos tu nombre");
	else if (f.email2.value=='') alert('Debes indicarnos el email de tu amig@');
	else valido=true;
	return valido;	
}

function ValidarCurriculum()
{
	var f=document.getElementById('form_recom');
	var valido=true;
	mensaje=true;
	if (f.curriculum.value!='')
	{
		var texto=f.curriculum.value;
		texto=texto.toLowerCase();
		var textosalida = texto.replace(/(\u00E1|\u00E9|\u00ED|\u00F3|\u00FA|\u00F1|\u00E4|\u00EB|\u00ED|\u00F6|\u00FC)/gi,'');
		if (texto!=textosalida)
		{
			alert('El nombre del fichero a enviar no es v\u00E1lido. Debes eliminar acentos y e\u00F1es en el nombre del fichero antes de enviarlo.');
			return false;
		}
	}
	$('#form_recom input.required').each(function (){
	 	if (valido) 
	 	{
			if ($(this).attr('value')=='') 
			{
				alert('El campo '+$(this).parent().find('label').html()+'  debe contener algun valor.');
				valido=false;
			}
		}
	});
	if (valido)
	{
		$('#form_recom select.required').each(function (){
			if (valido)
			{
				if ($(this).val()=='')
				{
					alert('No has rellenado el campo '+$(this).parent().find('label').html());
					valido=false;
				}
			}
		});	
	}
	if (valido)
	{
		if ($('#titulacion').val()!='N') {
			if (f.educacion_infantil.value==''  && f.enfermeria.value=='' && f.psicopedagogia.value=='' && f.psicologia.value=='' && f.auxiliar_tecnica.value=='' && f.otra_titulacion.value=='') 
			{
				valido=false;
				alert('Debes indicar que titulacion posees.');	
			}
		}
	}
	if (valido)
	{
		if (f.canguro.checked=='' && f.ninera.checked=='' && f.cuidadora.checked=='' && f.doula.checked=='')
		{
			valido=false;
			alert('Debes indicar que tipo de trabajo deseas.');
		}
	}	
		
	if (valido)
	{	
		if (f.interna.checked=='' && f.externa.checked=='')
		{
			valido=false;
			alert('Debes indicar si quieres trabajar interna o externa.');
		}
	}
	if (valido)
	{	
		if (f.sueldo_desde_hora.value=='' && f.sueldo_desde_hora.value=='' && f.sueldo_desde_mes.value=='' && f.sueldo_desde_mes.value=='')
		{
			valido=false;
			alert('Debes indicar al menos una opcion de sueldo (por horas o por mes).');

		}
	}
	
	if (valido)
	{	
		if (f.madrid.checked=='' && f.noroeste.checked=='' && f.sierra_norte.checked=='' && f.henares.checked=='' && f.sur.checked=='' && f.sureste.checked=='' && f.alberche_guadarrama.checked=='' && f.tajo_tajuna.checked=='') 
		{
			valido=false;
			alert('Debes indicar al menos una zona en la que quieres trabajar.');
		}
	}
	
	if (valido)
	{	
		if (f.media_jornada.value=='' && f.jornada_completa.value=='' && f.horas_sueltas.value=='')
		{
			valido=false;
			alert('Debes indicar al menos un tipo de jornada laboral.');
		}

	}
	if (valido && !f.pdatos.checked) 
	{
		alert('Debes aceptar la clausula de proteccion de datos.');
		valido=false;
	}
	if (valido && !f.decalogo.checked) 
	{
		alert('Debes aceptar el decalogo antes de enviar el formulario.');
		valido=false;
	}
	return valido;
}

function ValidarCurriculumkk()
{
	var f=document.getElementById('form_recom');
	valido=true;
	mensaje=true;
	if (f.curriculum.value!='')
	{
		var texto=f.curriculum.value;
		texto=texto.toLowerCase();
		var textosalida = texto.replace(/(\u00E1|\u00E9|\u00ED|\u00F3|\u00FA|\u00F1|\u00E4|\u00EB|\u00ED|\u00F6|\u00FC)/gi,'');
		if (texto!=textosalida)
		{
			alert('El nombre del fichero a enviar no es v\u00E1lido. Debes eliminar acentos y e\u00F1es en el nombre del fichero antes de enviarlo.');
			return false;
		}
	}
	//alert (f.pdatos.checked);
	if (f.nombre.value=='' || 
		f.direccion.value=='' ||
		f.poblacion.value=='' ||
		f.provincia.value=='' ||
		f.nacionalidad.value=='' ||
		f.nif.value=='' ||
		(f.movil.value=='') ||
		f.email.value=='') valido=false;
		
	if ((f.canguro.checked=='' && f.ninera.checked=='' && f.cuidadora.checked=='' && f.doula.checked=='') ||
		(f.interna.checked=='' && f.externa.checked=='') ||
		(f.sueldo_desde_hora.value=='' && f.sueldo_desde_hora.value=='' && f.sueldo_desde_mes.value=='' && f.sueldo_desde_mes.value=='') ||
		(f.madrid.checked=='' && f.noroeste.checked=='' && f.sierra_norte.checked=='' && f.henares.checked=='' && f.sur.checked=='' && f.sureste.checked=='' && f.alberche_guadarrama.checked=='' && f.tajo_tajuna.checked=='') ||
		(f.media_jornada.value=='' && f.jornada_completa.value=='' && f.horas_sueltas.value=='') ||
		f.fecha_nacimiento.value=='' ||
		f.experiencia.value=='') valido=false;

	if (f.bebes.value=='N' || 
		f.menores_1.value=='N' ||
		f.entre_1_y_3.value=='N' ||
		f.entre_3_y_6.value=='N' ||
		f.mayores_6.value=='N' ||
		f.necesidades_especiales.value=='N' ||
		f.mellizos_trillizos.value=='N') valido=false;

	if (f.madre.value=='' ||
		f.carnet.value=='' ||
		f.vehiculo.value=='' ||
		f.referencias.value=='' ||
		f.titulacion.value=='') valido=false;
		
	if (f.titulacion.value=='S' && f.educacion_infantil.value==''  && f.enfermeria.value=='' && f.psicopedagogia.value=='' && f.psicologia.value=='' && f.auxiliar_tecnica.value=='' && f.otra_titulacion.value=='') 
	{
		valido=false;
		mensaje=true;
		alert('Debes indicar que titulacion posees.')	
	}
	if (f.ayudar_en_deberes.value=='' ||
		f.estimulacion.value=='' ||
		f.labores_hogar.value=='' ||
		f.cocinar.value=='' ||
		f.animales.value=='' ||
		f.fumador.value=='' ||
		f.viajar.value=='') valido=false;
	
	if (!valido) alert('Todos los campos marcados con un * deben contener algun valor.');
	if (valido && !f.pdatos.checked) 
	{
		alert('Debes aceptar la clausula de proteccion de datos');
		valido=false;
	}
	return valido;	
}
