﻿$( document ).ready
(
	function()
	{
		if( navigator.appName == "Microsoft Internet Explorer" && parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] ) < 8 )
		{
			var txtAviso = "";
			switch( idioma )
			{
				case 'es':
					txtAviso = "Est&aacute; utilizando una versi&oacute;n obsoleta de Internet Explorer, de manera que algunos elementos de esta p&aacute;gina no se ver&aacute;n correctamente. Actual&iacute;cese gratu&iacute;tamente desde <a href=\"http://www.microsoft.com/spain/windows/internet-explorer/\" target=\"_blank\" style=\"color: #333\" >aqu&iacute;</a>."
				break;
				default:
					txtAviso = "Est&agrave; utilitzant una versi&oacute; obsoleta de Internet Explorer, de manera que alguns elements d'aquesta p&agrave;gina no es veuran correctament. Actualitzi gratu&iuml;tament des d'<a href=\"http://www.microsoft.com/spain/windows/internet-explorer/\" target=\"_blank\" style=\"color: #333\" >aqu&iacute;</a>."
				break;
			}
			
			$( '#avisoIE' ).html( "<img src=\"img/comunes/error.png\" > " + txtAviso );
			$( '#avisoIE' ).addClass( "avisoJS" );
		}
	}
);

function AbreN( theURL, ancho, alto )
{
    var h = ( screen.width - ancho ) / 2;
    var v = ( screen.height - alto ) / 2;
    var windowprops = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + ancho + ",height=" + alto + ",left=" + h + ",top=" + v;
    
    if( win )
    {
        win.close();
    }
    
    win = window.open( theURL, winName, windowprops );
}


function CambiaImg( idElemento, imagen )
{
    document.getElementById( idElemento ).src = imagen;
}

function EmailCmp( cual )
{
	var resp = true;
	
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	
	var arroba = cual.indexOf( "@", 0 );
	
	if( ( cual.lastIndexOf( "@" ) ) != arroba ) arroba = -1;
	
	var punto = cual.lastIndexOf( "." );
	
	for( var x = 0; x < cual.length ; x++ )
	{
		if( cadena.indexOf( cual.substr( x, 1 ), 0 ) == -1 )
		{
			resp = false;
			break;
		}
	}
	
	if( ( arroba > 1 ) && ( arroba + 1 < punto ) && ( punto + 1 < ( cual.length ) ) && ( resp == true ) && ( cual.indexOf( "..", 0 ) == -1 ) )
	{
		resp = true;
	}
	else
	{
		resp = false;
	}
	
    return resp;
}

function FormuSolicitud()
{
	//'Por favor rellena todos los campos marcados con asterisco', 'Por favor comprueba tu email'
	
	if( $( '#nombre' ).val() == '' )
	{
		alert( 'Introduce tu nombre, por favor' );
		return false;
	}
	else if( $( '#apellidos' ).val() == '' )
	{
		alert( 'Introduce tus apellidos, por favor' );
		return false;
	}
	else if( $( '#telefono' ).val() == '' )
	{
		alert( 'Introduce teléfono, por favor' );
		return false;
	}
	else if( $( '#email' ).val() == '' )
	{
		alert( 'Introduce tu e-mail, por favor' );
		return false;
	}
	else if( !EmailCmp( $( '#email' ).val() ) )
	{
		alert( 'Introduce un e-mail válido, por favor' );
		return false;
	}
	else if( $( '#comentarios' ).val() == '' )
	{
		alert( 'Introduce tu consulta, por favor' );
		return false;
	}
	
	return true;
}

//FUNCIONES DE BOTONES FLECHA//
function FlechaTrabajos( modo)
{
	if(modo=="over")
	{
		$( '#textoBtTrabajos').stop().animate({color: '#2b1c33'}, 'slow');
		$( '#btTrabajos').stop().animate({marginRight: '0px'}, 'slow');
	}
	
	if(modo=="out")
	{
		$( '#textoBtTrabajos').stop().animate({color: '#705d7a'}, 'slow');
		$( '#btTrabajos').stop().animate({marginRight: '20px'}, 'slow');
	}
}

function FlechaTrabajosCat( modo, cual)
{
	if(modo=="over")
	{
		$( '#textoBtTrabajos' + cual).stop().animate({color: '#2b1c33'}, 'slow');
		$( '#btTrabajos' + cual).stop().animate({marginRight: '0px'}, 'slow');
	}
	
	if(modo=="out")
	{
		$( '#textoBtTrabajos' + cual).stop().animate({color: '#705d7a'}, 'slow');
		$( '#btTrabajos' + cual).stop().animate({marginRight: '20px'}, 'slow');
	}
}

function FlechaCategorias( modo , cual)
{
	if(modo=="over")
	{
		$( '#bullet' + cual).stop().animate({marginLeft: '20px'}, 'slow');
		$( '#imagen' + cual).stop().animate({marginLeft: '-20px'}, 'slow');
	}
	
	if(modo=="out")
	{
		$( '#bullet' + cual).stop().animate({marginLeft: '10px'}, 'slow');
		$( '#imagen' + cual).stop().animate({marginLeft: '0px'}, 'slow');
	}
}


function CambiaBt(modo, cual)
{
	if(modo == 'over')
	{
		$( '#bt' + cual).stop().animate({color: '#715f7f'}, 'slow');
	}
	if(modo == 'out')
	{
		$( '#bt' + cual).stop().animate({color: '#37342e'}, 'slow');
	}
}

function CambiaFacebook (modo)
{
	if(modo == 'over')
	{
		$( '#facebook').stop().animate({marginTop: '0px'}, 'slow');
	}
	if(modo == 'out')
	{
		$( '#facebook').stop().animate({marginTop: '-10px'}, 'slow');
	}
}

function CambiaPromo( cual, modo)
{
	if(modo == 'over')
	{
		$( '#tit' + cual).stop().animate({color: '#37342e', marginLeft: '10px'}, 'slow');
	}
	if(modo == 'out')
	{
		$( '#tit' + cual).stop().animate({color: '#715f7f', marginLeft: '0px'},  'slow');
	}
}


function Maps(modo)
{
	if(modo=="over")
	{
		$( '#punteroGoogle').stop().animate({marginTop: '10px'}, 'slow');
		$( '#googleMaps').stop().animate({color: '#37342e'}, 'slow');
	}
	
	if(modo=="out")
	{
		$( '#punteroGoogle').stop().animate({marginTop: '5px'}, 'slow');
		$( '#googleMaps').stop().animate({color: '#fff'}, 'slow');
	}
}


function SacaWeb()
{
	$( '#bandaCabecera').stop().animate({height: '500px'}, 'slow', 'linear',
	function() 
		{ 
		$( '#btTrabajos').stop().animate({marginTop: '40px'}, 'slow', 'easeOutBack');
		$( '#facebook').stop().animate({marginTop: '-10px'}, 'slow', 'easeOutBack');
		}
	);
	
}

function SacaWebInterior()
{
	alto = document.getElementById('contenidoCabecera').offsetHeight;
	if(alto < 500)
	{
		alto = 500;
	}
	//$( '#indexSup').stop().animate({height: alto}, 'slow', 'linear');
	$( '#bandaCabecera').stop().animate({height: alto}, 'slow', 'linear',
	function() 
		{ 
		$( '#btTrabajos').stop().animate({marginTop: '40px'}, 'slow', 'easeOutBack');
		$( '#facebook').stop().animate({marginTop: '-10px'}, 'slow', 'easeOutBack');
		}
	);
	
}

function SacaWebInteriorVarios(cuantos)
{
	alto = document.getElementById('contenidoCabecera').offsetHeight;
	if(alto < 500)
	{
		alto = 500;
	}
	//$( '#indexSup').stop().animate({height: alto}, 'slow', 'linear');
	$( '#bandaCabecera').stop().animate({height: alto}, 'slow', 'linear',
	function() 
		{ 
			if(cuantos != 0)
			{
				for($x=0; $x<cuantos; $x++)
				{
					$( '#btTrabajos' + $x).stop().animate({marginTop: '20px'}, 'slow', 'easeOutBack');
				}
			}
		$( '#facebook').stop().animate({marginTop: '-10px'}, 'slow', 'easeOutBack');
		}
	);
	
}
