// JavaScript Document

jQuery(document).ready(function(){
	
	site = document.location.toString();
	if(site.match('#'))
	{
		target = site.split('#')[1];
		jQuery('.opener').each(function(){
			if(jQuery(this).attr('ref') == target)
			{
				var ref = jQuery(this).attr('filler');
				jQuery('.right','.box_left').attr('filler','');
				jQuery('.right','.box_left').css('background','none');
				jQuery('.right','.box_left').css('background-image','none');
			}
		});
	}
	
	mapper();
	
});

function mapper()
{
	jQuery('.opener', '.bot_sec').each(function(){
	
		jQuery(this).click(function(){
			
			var target = jQuery(this).attr('ref');
			jQuery('.opener', '.top').each(function(){
				jQuery(this).removeClass('active');
			});
			jQuery(this).addClass('active');
			jQuery('.right','.box_left').html(jQuery('#'+target).html());
			if(jQuery('#'+target).attr('filler') != false)
			{
				jQuery('.right','.box_left').attr('style','background-image:'+jQuery('#'+target).attr('filler')+';');
			}
			if(jQuery(this).hasClass('.bottomer'))
			{
				var target = '#bar_' + jQuery(this).attr('ref');
				jQuery('#bar_idoc_intro').hide();
				jQuery('#bar_iwflow_intro').hide();
				jQuery('#bar_sigdoc_intro').hide();
				jQuery(target).show();
				jQuery('a',target).each(function(){
					jQuery(this).removeClass('active');
				});
				jQuery('.first',target).addClass('active');
			}
			if(target == 'clientes')
			{
				map_expanders()
			}
			return false;
		});
	
	});
	
	jQuery('.opener_sub', '.bot_sec').each(function(){
	
		jQuery(this).click(function(){
			
			var target = jQuery(this).attr('ref');
			jQuery('.opener_sub', '.bottom').each(function(){
				jQuery(this).removeClass('active');
			});
			jQuery(this).addClass('active');
			jQuery('.right','.box_left').html(jQuery('#'+target).html());
			if(jQuery('#'+target).attr('filler') != false)
			{
				jQuery('.right','.box_left').attr('style','background-image:'+jQuery('#'+target).attr('filler')+';');
			}
			if(target == 'clientes')
			{
				map_expanders()
			}
			return false;
		});
	
	});
	
	jQuery('#trabaja_con_nosotros').submit(function(){
		var conocido = jQuery('#tcn_conocido').val();
		var nombre = jQuery('#tcn_nombre').val();
		var apellidos = jQuery('#tcn_apellidos').val();
		var direccion = jQuery('#tcn_direccion').val();
		var ciudad = jQuery('#tcn_ciudad').val();
		var provincia = jQuery('#tcn_provincia').val();
		var cp = jQuery('#tcn_cp').val();
		var pais = jQuery('#tcn_pais').val();
		var telefono = jQuery('#tcn_telefono').val();
		var telefono_trabajo = jQuery('#tcn_telefono_trabajo').val();
		var mail = jQuery('#tcn_mail').val();
		var formacion_academica = jQuery('#tcn_formacion_academica').val();
		var idiomas = jQuery('#tcn_idiomas').val();
		var situacion = jQuery('#tcn_situacion').val();
		var puesto = jQuery('#tcn_puesto').val();
		var incorporacion = jQuery('#tcn_incorporacion').val();
		var experiencia = jQuery('#tcn_experiencia').val();
		var datos = jQuery('#tcn_datos').val();
		
		if(nombre == ''){ alert(jQuery('.name','#errores').html()); return false; }
		if(apellidos == ''){ alert(jQuery('.surname','#errores').html()); return false; }
		if(direccion == ''){ alert(jQuery('.adress','#errores').html()); return false; }
		if(ciudad == ''){ alert(jQuery('.city','#errores').html()); return false; }
		if(provincia == ''){ alert(jQuery('.state','#errores').html()); return false; }
		if(cp == ''){ alert(jQuery('.cp','#errores').html()); return false; }
		if(pais == ''){ alert(jQuery('.country','#errores').html()); return false; }
		if(formacion_academica == ''){ alert(jQuery('.education','#errores').html()); return false; }
		if(idiomas == ''){ alert(jQuery('.languages','#errores').html()); return false; }
		if(experiencia == ''){ alert(jQuery('.experience','#errores').html()); return false; }
		if(telefono == ''){ alert(jQuery('.phone','#errores').html()); return false; }
		
		jQuery.ajax({
			url: "/process_cup_info.php",
			global: false,
			type: "POST",
			data: ({conocido: conocido, nombre: nombre, apellidos: apellidos, direccion: direccion, ciudad: ciudad, provincia: provincia, cp: cp, pais: pais, telefono: telefono, telefono_trabajo: telefono_trabajo, mail: mail, formacion_academica: formacion_academica, idiomas: idiomas, situacion: situacion, puesto: puesto, incorporacion: incorporacion, experiencia: experiencia, datos: datos}),
			dataType: "json",
			success: function(data){
				if(data.status)
				{
					jQuery('.right','.box_left').html(jQuery('#wwu_wwu_response').html());
				}
				else
				{
					alert(data.msg);
				}
			}
		});
		
		return false;
	});
	
	jQuery('#contacto').submit(function(){
		var nombre = jQuery('#con_nombre').val();
		var apellidos = jQuery('#con_apellidos').val();
		var direccion = jQuery('#con_direccion').val();
		var ciudad = jQuery('#con_ciudad').val();
		var provincia = jQuery('#con_provincia').val();
		var cp = jQuery('#con_cp').val();
		var mail = jQuery('#con_mail').val();
		var consulta = jQuery('#con_consulta').val();
		
		if(nombre == ''){ alert(jQuery('.name','#errores').html()); return false; }
		if(apellidos == ''){ alert(jQuery('.surname','#errores').html()); return false; }
		if(mail == ''){ alert(jQuery('.mail','#errores').html()); return false; }
		
		jQuery.ajax({
			url: "/process_contacto.php",
			global: false,
			type: "POST",
			data: ({nombre: nombre, apellidos: apellidos, direccion: direccion, ciudad: ciudad, provincia: provincia, cp: cp, mail: mail, consulta: consulta}),
			dataType: "json",
			success: function(data){
				if(data.status)
				{
					jQuery('.right','.box_left').html(jQuery('#wwu_wwu_response').html());
				}
				else
				{
					alert(data.msg);
				}
			}
		});
		
		return false;
	});
	
	jQuery('#search_form').submit(function(){
		
		var txt = jQuery('#search_text').val();
		if(txt == '')
		{
			alert('Debe insertar un parámetro de búsqueda');
		}
		else
		{
			jQuery.ajax({
				url: "/buscador.php",
				global: false,
				type: "POST",
				data: ({palabra: txt}),
				dataType: "json",
				success: function(data){
					if(data.status)
					{
						jQuery.blockUI({ 
							message: '<div class="buscador"><p>'+ jQuery('.frase1','#buscador_contents').html() +' <b>"' + txt + '"</b> '+ jQuery('.frase2','#buscador_contents').html() +'</p><ul>'+ data.msg +'</ul><a class="cerrar" href="javascript:jQuery.unblockUI();">'+ jQuery('.close','#buscador_contents').html() +'</a></div>',
							css:{
								width: "400px",
								height:	"150px",
								border:	"1px solid black",
								padding: "15px"
							}
						}); 
					}
					else
					{
						alert('No se ha encontrado esa palabra en nuestro sitio.');
					}
				}
			});
		}
		return false;
	});
	
	jQuery('.idioma').click(function(){
		
		data = jQuery('#idioma').html();
		
		jQuery.blockUI({ 
			message: data,
			css:{
				width: "200px",
				height:	"150px",
				border:	"1px solid black",
				padding: "15px"
			}
		});
		return false;
	});
	
	jQuery('.mapa').click(function(){
		
		data = '<div class="mapa_site">'+jQuery('.mapa_site').html()+'</div>';
		
		jQuery.blockUI({ 
			message: data,
			css:{
				width: "300px",
				height:	"300px",
				border:	"1px solid black",
				padding: "15px"
			}
		});
		return false;
		
	});
	
	jQuery('.situacion').click(function(){
		
		data = '<div class="situacion_div">';
		data += jQuery('.situacion_div').html();
		data += '</div>';
		
		jQuery.blockUI({ 
			message: data,
			css:{
				width: "300px",
				height:	"140px",
				border:	"1px solid black",
				padding: "15px"
			}
		});
		return false;
		
	});
	
	jQuery('.pol_priv').click(function(){
		
		data = '<div class="privacidad_div">'+jQuery('.privacidad_div').html()+'</div>';
		
		jQuery.blockUI({ 
			message: data,
			css:{
				width: "300px",
				height:	"300px",
				border:	"1px solid black",
				padding: "15px"
			}
		});
		return false;
	});
	
	jQuery('#acceso_intranet').submit(function(){
		var user = jQuery('#aci_user').val();
		var pass = jQuery('#aci_pass').val();
		jQuery.ajax({
			url: "/intra.php",
			global: false,
			type: "POST",
			data: ({pass: pass, user: user}),
			dataType: "json",
			success: function(data){
				if(data.status)
				{
					jQuery.ajax({
						url: "/clientes/intranet/contenidos.html",
						global: false,
						dataType: "html",
						success: function(data){
							jQuery('#cont').html(data);
						}
					});
				}
				else
				{
					alert(data.msg);
				}
			}
		});
		return false;
	});
	
	jQuery('#acceso_intranet_home').submit(function(){
		var user = jQuery('#aci_user').val();
		var pass = jQuery('#aci_pass').val();
		jQuery.ajax({
			url: "/intra.php",
			global: false,
			type: "POST",
			data: ({pass: pass, user: user}),
			dataType: "json",
			success: function(data){
				if(data.status)
				{
					location.href = '/clientes/intranet/acceso.html';
				}
				else
				{
					alert(data.msg);
				}
			}
		});
		return false;
	});
	
	jQuery('.ulexpander').each(function(){
		jQuery(this).click(function(){
			var target = jQuery(this).attr('ref');
			target = '#exp_' + target;
			jQuery('.expandable').each(function(){
				jQuery(this).hide('fast');
			});
			if(jQuery(this).attr('status') == 0)
			{
				jQuery('.ulexpander').each(function(){
					jQuery(this).attr('status','0');
				});
				jQuery(target).show('fast');
				jQuery(this).attr('status','1');
			}
			else
			{
				jQuery(this).attr('status','0');
				jQuery(target).hide('fast');
			}
			
		});
	});
	jQuery('.ulexpander_full').click(function(){
		if(jQuery(this).attr('status') == 0)
		{
			jQuery('.expandable').each(function(){
				jQuery(this).show('fast');
			});
			jQuery(this).attr('status','1');
		}
		else
		{
			jQuery('.expandable').each(function(){
				jQuery(this).hide('fast');
			});
			jQuery(this).attr('status','0');
		}
	});
	
	site = document.location.toString();
	if(site.match('#'))
	{
		target = site.split('#')[1];
		jQuery('.opener').each(function(){
			if(jQuery(this).attr('ref') == target)
			{
				jQuery(this).click();
			}
		});
	}
	if(jQuery('.right','.box_left').attr('filler') != '')
	{
		 jQuery('.right','.box_left').css('background-image', 'url('+jQuery('.right','.box_left').attr('filler')+')');
	}
}

function map_expanders()
{
	jQuery('.ulexpander').each(function(){
		jQuery(this).click(function(){
			var target = jQuery(this).attr('ref');
			target = '#exp_' + target;
			jQuery('.expandable').each(function(){
				jQuery(this).hide('fast');
			});
			if(jQuery(this).attr('status') == 0)
			{
				jQuery('.ulexpander').each(function(){
					jQuery(this).attr('status','0');
				});
				jQuery(target).show('fast');
				jQuery(this).attr('status','1');
			}
			else
			{
				jQuery(this).attr('status','0');
				jQuery(target).hide('fast');
			}
			
		});
	});
	jQuery('.ulexpander_full').click(function(){
		if(jQuery(this).attr('status') == 0)
		{
			jQuery('.expandable').each(function(){
				jQuery(this).show('fast');
			});
			jQuery(this).attr('status','1');
		}
		else
		{
			jQuery('.expandable').each(function(){
				jQuery(this).hide('fast');
			});
			jQuery(this).attr('status','0');
		}
	});
}
