$(document).ready(function() {
	
	$( "#menu ul li a.overol" ).each(
		function(){
			$( this ).bind (
			"mouseover", function(event){ 
				out( $(this) );
				}
			);
			
			$( this ).bind (
			"mouseout", function(event){ 
				inn( $(this) );
				}
			);
		}
    );
	
	$( "#menu ul li a.lamp" ).mouseover( imgSub );
	$( "#menu ul li a.lamp" ).mouseout( imgDef );
	
	$( "#facebook" ).mouseover( function(){ out($( "#facebook" )); } );
	$( "#facebook" ).mouseout( function(){ inn($( "#facebook" )); } );
	
	if( $('#enviar') ){
			$('#enviar').mouseover( function(){ $(this).animate({ left:'+=16px'}, 400); } );
			$('#enviar').mouseout( function(){ $(this).animate({ left:'-=16px'}, 400); } );
			$('#enviar').click( validate );
	}

});

function imgSub()
{
	$( "#menu ul li a.lamp img.hola" ).attr('src', 'img/menu_07_2.jpg');
}
function imgDef()
{
	$( "#menu ul li a.lamp img.hola" ).attr('src', 'img/menu_07.jpg');
}

function out(elemx){
	elemx.animate({
		opacity: 0.25,
		top: '+=20'
	}, 500);
}
function inn(elemx){
	//alert( 'a'+ gimmeTarjetero(elemx) );
	elemx.animate({
		opacity: 1, top: '-=20px'
	}, 500);
}

function validarNumero(numero)
{
	if( !/^([0-9])*$/.test(numero) ){
		return true;
	}else{
		return false;	
	}
}

function validate()
{
	var error = false;
	var msj = 'Por favor complete los siguientes campos:'
	var form = document.getElementById('form');
	var nombre = document.getElementById('nombre').value;
	var apellido = document.getElementById('apellido').value;
	var tel = document.getElementById('tel').value;
	var mail = document.getElementById('mail').value;
	var consulta = document.getElementById('consulta').value;
	
	if( nombre.length < 2 ){
		error = true;
		msj += "\n - Nombre";
	}
	if( apellido.length < 2 ){
		error = true;
		msj += "\n - Apellido";
	}
	if( validarNumero(tel) ){
		error = true;
		msj += "\n - El Telefono debe ser numerico";
	}
	if( mail.length < 6 ){
		error = true;
		msj += "\n - Email";
	}
	if( consulta.length < 6 ){
		error = true;
		msj += "\n - Consulta";
	}
	
	if( error ){
		alert(msj);
	}else{
		document.getElementById('enviar').onclick = '';
		form.submit();
	}	
}

function gimmeTarjetero(e)
{
	var targ;
	
	if(!e){
		e = window.event;
	}
	
	if(e.target){
		targ = e.target;
	}
	else if (e.srcElement){
		targ = e.srcElement;
	}
	
	if(targ.nodeType == 3){ // defeat Safari bug
		targ = targ.parentNode;
	}
	
	return targ.id;
}
