	function openVentana(direccion){
		window.open(direccion,"","menubar=0 , resizable=0 , scrollbars=1 , width=600 , height=400");
	}
	
	
	function stato(){
	
		//SOCIAL menu
		
		$("#social_fb").hover(
		
			function() {
				$(this).find('img').attr("src","imagenes/ico_fb_over.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos_fb.jpg");	
				}, 
				
			function() {
				$(this).find('img').attr("src","imagenes/ico_fb.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos.jpg");
			});
			
		$("#social_tw").hover(
		
			function() {
				$(this).find('img').attr("src","imagenes/ico_tw_over.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos_tw.jpg");	
				}, 
				
			function() {
				$(this).find('img').attr("src","imagenes/ico_tw.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos.jpg");
			});
			
		$("#social_fl").hover(
		
			function() {
				$(this).find('img').attr("src","imagenes/ico_fl_over.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos_fl.jpg");	
				}, 
				
			function() {
				$(this).find('img').attr("src","imagenes/ico_fl.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos.jpg");
			});
			
		$("#social_yt").hover(
		
			function() {
				$(this).find('img').attr("src","imagenes/ico_yt_over.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos_yt.jpg");	
				}, 
				
			function() {
				$(this).find('img').attr("src","imagenes/ico_yt.jpg");
				$("#txt_siguenos").attr("src","imagenes/txt_siguenos.jpg");
			});
			
		//NAV 
		
		var bt_gama = false;
		var bt_mundo = false;
	
		//CLICK....
		
		$('#nav_gama').bind('mouseover mouseout',function(event){
			
			resetButtons();
			
			if (event.type == 'mouseover') {
					
				$('#nav_gama').css({'z-index':'6'});						
				$('#nav_gama').css({'background-position':'bottom'});
												
			}
			
		});
		
		//OVERS....
		
		$('#nav_mundo').bind('mouseover mouseout',function(event){
			
			resetButtons();
			
			if (event.type == 'mouseover') {
				$('#nav_mundo').css({'z-index':'6'});
				$('#nav_mundo').css({'background-position':'bottom'});
			
			}
			
		});
		
		$('#nav_concesionario').bind('mouseover mouseout',function(event){
			
			resetButtons();
			
			if (event.type == 'mouseover') {
				
				$(this).css({'z-index':'6'});
				$(this).css({'background-position':'bottom'});
			 
			} 
						
		});
		
		$('#nav_newsletter').bind('mouseover mouseout',function(event){
			
			resetButtons();
			
			if (event.type == 'mouseover') {
				
				$(this).css({'z-index':'6'});
				$(this).css({'background-position':'bottom'});
			 
			} 
						
		});				
		
		$('#nav_contacto').bind('mouseover mouseout',function(event){
			
			resetButtons();
			
			if (event.type == 'mouseover') {
				
				$(this).css({'z-index':'6'});
				$(this).css({'background-position':'bottom'});
			 
			} 
						
		});
		
		
		
		//MOUSE OUT!!!! buscar otra solución, esto es una caspa XD
				
		$('#ova_gama').bind('mouseleave',resetButtons);
		$('#ova_mundo').bind('mouseleave',resetButtons);
		$('#models').bind('mouseleave',resetButtons);
		
				
		//SUBMENUS...
		
		$(" #navBar li.boton").hover(
								 
		function(){
		$(this).find('ul:first').slideDown(400);
		$(this).find('a:first').addClass('activo');
		
		},function(){
		
		
		$(this).find('ul:first').stop(true, true).slideUp(400);
		$(this).find('a:first').removeClass('activo');
		
		});
						
		// RESET NAVIGATOR...
		
		function resetButtons () {		
								
			$('#nav_gama').css({'background-position':'top'});	
			$('#nav_gama').css({'z-index':'5'});	
			
			$('#nav_mundo').css({'background-position':'top'});			
			$('#nav_mundo').css({'z-index':'4'});
			
			$('#nav_concesionario').css({'background-position':'top'});				
			$('#nav_concesionario').css({'z-index':'3'});
			
			$('#nav_newsletter').css({'background-position':'top'});	
			$('#nav_newsletter').css({'z-index':'2'});	
				
			$('#nav_contacto').css({'background-position':'top'});
			$('#nav_contacto').css({'z-index':'1'});
			
			if(bt_mundo) {
				
				$('#ova_mundo').stop(true,false);						
				$('#ova_mundo').animate({'top':'-120px'},400);	
				$('#modelsDesp').stop(true,false);				
				$('#modelsDesp').animate({'height':'1px'},400);	
				
				$('#ova_mundo').css({'z-index':'9'});		
					
				bt_mundo=false;
								
			}
			
			if(bt_gama) {
				
				$('#ova_gama').stop(true,false);	
				$('#ova_gama').animate({'top':'-120px'},400);	
				$('#modelsDesp').stop(true,false);
				$('#modelsDesp').animate({'height':'1px'},400);	
									
				$('#ova_gama').css({'z-index':'9'});		
											
				bt_gama=false;
				
			}	
			
		}
		
		//TOOLTIP
		

		$('.tooltipIco').live('mouseover mouseout',function(event){
			
			if (event.type == 'mouseover') {

				//alert(Math.round($(this).offset().left-523)-Math.round($('#info').offset().left-523))
				//$('.tooltip').css({'left':e.pageX});
				
				
				var cssObj = {
					'left' : Math.round($(this).offset().left)-Math.round($('#info').offset().left)-191 + 'px'
				}
				$('.tooltip').css(cssObj);
							
				
				$('.tooltip').show();
				
			} 
			if (event.type == 'mouseout') {
				$('.tooltip').hide();
	 
			} 	
		});
		
		
		//BOTON COCHES...
		
		var actual="none";
		
		$('#mini_nano_container').bind('click',function(event){
						
			mostrar("nano");
			
						
		});
		
		$('#mini_indica_container').bind('click',function(event){
			
			
			$('#contentMain').load('TATA_indica.html' + ' #contentMain');			
			mostrar("indica");
			
						
		});
		
		$('#mini_indigo_container').bind('click',function(event){
						
			$('#contentMain').load('TATA_indigo.html' + ' #contentMain');
			mostrar("indigo");
						
		});
		
		$('#mini_safari_container').bind('click',function(event){
			
			$('#contentMain').load('TATA_safari.html' + ' #contentMain');
			mostrar("safari");
			
		});
		
		$('#mini_xenon_container').bind('click',function(event){
			
			$('#contentMain').load('TATA_xenon.html' + ' #contentMain');	
			mostrar("xenon");

						
		});
		
		
		function mostrar(cual){
			
			if(actual!="none"){
			$('#mini_'+actual+'_brillo').css({'display':'none'});
			$('#mini_'+actual+' p').css({'color':'#878787'});
			$('#info #'+actual).css({'display':'none'});
				}
			actual=cual;
			$('#mini_'+cual+'_brillo').css({'display':'block'});
			$('#mini_'+cual+' p').css({'color':'#FFF'});
			
			$('#info #'+cual).css({'display':'block'});
			
		}
		
		jQuery( function () {
		  jQuery.validator.addMethod( "telefono", function( value, element, params ) {				
			  if(/^[6,9]{1}\d{8}$/.test(value) || value==''){
					return true;
			  }else{
					return false;
			  }
		  }, "El campo teléfono debe tener 9 dígitos" );
		});
		
		$('.iframe').click(function(){
		
			html = $('a',this).attr('href');
			
			if (html=='TATA_noticias.html')
				
				html = 'http://www.tatamotors.es/dev/?lang=esp&page=noticias';
					
			else
			
				html = 'http://www.tatamotors.es/dev/?lang=esp&page=eventos';
		
			$('#contentMain').html('<div id="bannerLeft" class="floatLeft"></div><iframe width="630" height="370" frameborder="0" scrolling="no" src="' + html + '"></iframe>');
								
			return false;
		
		});
		
		$('.enlace').click(function(){
		
			html = $('a',this).attr('href');
			
			$('#contentMain').load(html + ' #contentMain', function(response, status, xhr) {
				if (status == "error") {
				
					var msg = "Lo sentimos se ha producido un error y no se puede cargar la página solicitada ";
					alert (msg);
					
				}else{
				
					if (html=='TATA_formulario.html')
					{
					
						validarContacto();
						
					}
					
					if (html=='TATA_pide.html')
                    {
                    
                        validarPideCatalogo();
                        
                    }
                    
                    if (html=='TATA_newsletter.html')
                    {
                    
                        validarNewsletter();
                        
                    }
				
				}
			});						
			
			return false;
		
		});
		
	}
	
	
	
	
	function validarContacto()
	{
	
		$('#formContacto').validate({
				
			rules: {						
				telefono:"telefono"
			},					
			errorContainer: $("#mensajeError"),
			errorPlacement: function(error, element) {
				error.appendTo( $("#mensajeErrorNoVisible"));	    		    
			},
			invalidHandler: function(form, validator){			
				alert ('Debes rellenar todos los campos obligatorios\nEl teléfono debe tener 9 dígitos y empezar por 6 ó 9\nEl email debe ser un email válido');
				$('#enviar').html('<a href="javascript:;" onclick="$(\'#formContacto\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');
				return false;
			},
			submitHandler: function(form){
			    
			    $('#enviar').html('<img src="imagenes/ajax-loader.gif"/>');
			    
			    $.ajax({
                    type: 'POST',   
                    data: $('#formContacto').serialize(),
                    url: 'enviocontacto.php',
                    dataType: 'html',
                    success: function(data){                                                    
                        
                        /*if (!data.error){
                        
                            alert ('Los datos se han enviado correctamente');
                            form.reset();
                           
                        }else{
                            
                            alert ('Se ha producido un error, vuelva a intentarlo');
                            
                        }*/
                        alert (data);
                        form.reset();                                            
                        $('#enviar').html('<a href="javascript:;" onclick="$(\'#formContacto\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');
                                                                                                                
                    }
                });             
            
                return false;
			    
			}
			
		});

	}
	
	function validarPideCatalogo()
	{
	    
	    
	    $('#formPide').validate({
                
            rules: {                        
                telefono:"telefono"
            },                  
            errorContainer: $("#mensajeError"),
            errorPlacement: function(error, element) {
                error.appendTo( $("#mensajeErrorNoVisible"));                   
            },
            invalidHandler: function(form, validator){          
                alert ('Debes rellenar todos los campos obligatorios\nEl teléfono debe tener 9 dígitos y empezar por 6 ó 9\nEl email debe ser un email válido');
                $('#enviar').html('<a href="javascript:;" onclick="$(\'#formPide\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');
                return false;
            },
            submitHandler: function(form){
                
                $('#enviar').html('<img src="imagenes/ajax-loader.gif"/>');
                
                $.ajax({
                    type: 'POST',   
                    data: $('#formPide').serialize(),
                    url: 'pidecatalogo.php',
                    dataType: 'html',
                    success: function(data){                                                    
                        
                       /* if (!data.error){
                        
                            alert ('Los datos se han enviado correctamente');
                            form.reset();
                           
                        }else{
                            
                            alert ('Se ha producido un error, vuelva a intentarlo');
                            
                        }
                         */
                        alert (data);
                        form.reset();      
                        $('#enviar').html('<a href="javascript:;" onclick="$(\'#formPide\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');       
                                                                                        
                    }
                });             
            
                return false;
                
            }
            
        });
	    
	}
	
	function validarNewsletter()
    {
        
        
        $('#formNews').validate({
                                  
            errorContainer: $("#mensajeError"),
            errorPlacement: function(error, element) {
                error.appendTo( $("#mensajeErrorNoVisible"));                   
            },
            invalidHandler: function(form, validator){          
                alert ('El email debe ser un email válido\nDebes aceptar las condiciones legales');
                $('#enviar').html('<a href="javascript:;" onclick="$(\'#formNews\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');
                return false;
            },
            submitHandler: function(form){
                
                $('#enviar').html('<img src="imagenes/ajax-loader.gif"/>');
                
                $.ajax({
                    type: 'POST',   
                    data: $('#formNews').serialize(),
                    url: 'newsletter.php',
                    dataType: 'html',
                    success: function(data){                                                    
                        
                        /*if (!data.error){
                        
                            alert ('Los datos se han enviado correctamente');                            
                            form.reset();
                           
                        }else{
                            
                            alert ('Se ha producido un error, vuelva a intentarlo');
                            
                        }*/
                        alert (data);
                        form.reset();
                        $('#enviar').html('<a href="javascript:;" onclick="$(\'#formNews\').submit();"><img src="imagenes/bt_form_enviar.gif" /></a>');
                                                                                        
                    }
                });             
            
                return false;
                
            }
            
        });
        
    }
	
	function validarNumeros(oTxt, evt){
		bOk=false;

	    var key = (evt.which) ? evt.which : (evt.keyCode) ? evt.keyCode : event.keyCode;
		
	    patron =/[0-9]/;
	    te = String.fromCharCode(key);
	    if (patron.test(te)){
	    	bOk=true;
	    }
	    
		if (key==8 || key==9 || key==39 || key==37){
			bOk=true;
		}	
		return bOk;
	}
	
	function validarLetras(oTxt, evt){
		bOk=false;

	    var key = (evt.which) ? evt.which : (evt.keyCode) ? evt.keyCode : event.keyCode;
			
		if (key==32 || key==8 || key==9 || key==126 || key==39 || key==37 || key==164 || key==209 || key==241 || key==222){
			bOk=true;
		}
		patron =/[a-zA-ZáéíóúÁÉÍÓÚ]/;
	    te = String.fromCharCode(key);
	    if (patron.test(te)){
	    	bOk=true;
	    }

		return bOk;
		
		
		
	}
	
