var filter_correo=/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/;
/*$(function() { $(".lavaLamp").lavaLamp({ 
		fx: "backout", 
		speed: 700, 
		show_captions: false, 
		delay_caption: false 
	})
});*/
/*------------------------------------------------------*/

/***********************************************************/

$(document).ready(function(){		

	// $('#nvgc_menu_superior').jmenu({animation:'slide'});
	$('#nvgc_menu_superior').jmenu({animation:'slide',duration:300});

	/*-inputs-*/
	$("input.text").focus(function(e){
		value = $(this).attr("alt");
		if($(this).attr("value") == value){ $(this).val(""); }
	});
		$("input.text").blur(function(e){
			if($(this).attr("value") == ''){ $(this).attr("value", value); }
		});		 	
	/*-dropdown-*/								
  /* 	$(" #nvgc_menu_superior ul ").css({display: "none"});
	// Defino que submenus deben estar visibles cuando se pasa el mouse por encima
	$(" #nvgc_menu_superior li").hover(function(){
		$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
		},function(){
			$(this).find('ul:first').slideUp(400);
		});*/
	 /*-slide-*/
	 /*$("#pikame").PikaChoose({
		auto_play: true,
		show_prev_next: false,							 
		slide_speed: 4500,
		thumb_width: 24,
		delay_caption: false,
		thumb_height: 24						 
	 });*/
	/*-accordion-*/
	  $('#nvgc_menu_lateral ul').hide();
	  $("ul.submenu_lateral").parent().append("<span></span>");
	  $('#nvgc_menu_lateral ul:first').show();
	  $('#nvgc_menu_lateral li a').click(
		function() {
		  var checkElement = $(this).next();
		  if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
			}
		  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#nvgc_menu_lateral ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
			}
		  }
		);

	/*-suscripcion-*/
	$("#suscripcion_boton").click(function(){
		var email = $("#suscripcion").val();										   	
		if(!email.length){
			$("#suscripcion").val('Ingrese un email').select();
			return false
		}else if (!filter_correo.test(email)){
			$("#suscripcion").val('Ingrese un email').select();
		}else{
			var dataString = 'email='+email+'&tipo='+1;
			$.ajax({
				type: "POST",
				url: "ajax/enviar_suscripcion.php",
				data: dataString,
				beforeSend: function(){ $("#suscripcion").val('Enviando sucripción...');	},
				success:function(data){	
					if(data == 'ok'){
					  $("#suscripcion").val('Enviando exitosamente'); 
					  setTimeout(function (){
									$("#suscripcion").val('');
									},1540); 												
					}else{
						$("#suscripcion").val('Intente nuevamente'); 
						setTimeout(function (){
									$("#suscripcion").val('');
									},1540); 
					}	
				}
			});
		}
	});
});

/*-valida correo-*/
function snd_nfrm(){
	if(!$("#enviar").val()){ return 0; }else{
		$("#ctnd_rrs").hide().html('');
		var filter_correo=/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/;		
		var tipo	= $("#tipo").val();
		var nombre	= $("#txtnombre").val();
		var telefono= $("#txttelefono").val();
		var email	= $("#txtemail").val();
		var asunto	= $("#txtasunto").val();
		var mensaje = $("#txtmensaje").val();	
		var captcha = $("#captcha").val();	
		var enviar 	= $("#enviar").val();
		var data	= '';
		
		var var1	= 0;
		var var2 	= 0;
		var var3	= 0;
		var var4	= 0;
		var var5	= 0;
		
		var nmb		= '';
		var ml		= '';
		var snt		= '';
		var msnj	= '';	
	
		if(!nombre.length){ 
				var1 = 1; 
			if( tipo== 1){	var nmb = '<li>Nombre no valido</li>'; }
			else{	var nmb = '<li>Name not valid</li>';  }		
			$("#txtnombre").select();
		}
		else{ var1 = 0; }
		if(!email.length){ 
				var2 = 1; 
				if( tipo== 1){	var ml = '<li>Email no valido</li>';  }
				else{	var ml = '<li>Invalid Email</li>';   }						
				$("#txtemail").select(); 
		}
		else if (filter_correo.test(email)){ var2 = 0; }
		else{ 
			var2 = 1; 
			if( tipo== 1){	var ml = '<li>Email no valido</li>';  }
			else{	var ml = '<li>Invalid Email</li>';   }					
			$("#txtemail").select(); 
		}	
		if(!asunto.length){ 
			var3 = 1; 
			if( tipo== 1){	var snt = '<li>Asunto no valido</li>';   }
			else{	var snt = '<li>Invalid Subject</li>';   }			
			$("#txtasunto").select();
		}
		else{ var3 = 0; }	
		
		if(!mensaje.length){ 
			var4 = 1; 
			if( tipo== 1){	var msnj = '<li>Mensaje no valido</li>';    }
			else{	var msnj = '<li>Invalid Message</li>';    }					
			$("#txtmensaje").select(); 
		}
		else{ var4 = 0; }	
	
		if(!captcha.length){ 
			var5 = 1; 
			if( tipo== 1){	var msjCpt = '<li>Codigo no valido</li>';    }
			else{	var msjCpt = '<li>Invalid Code</li>';    }					
			$("#captcha").select(); 
		}
		else{ va5 = 0; }	
		
		if((var1 == 0)&&(var2 == 0)&&(var3 == 0)&&(var4 == 0)&&(var5 == 0)){
			data = 'nombre='+nombre+'&email='+email+'&asunto='+asunto+'&mensaje='+mensaje+'&tipo='+tipo+'&telefono='+telefono+'&captcha='+captcha+'&enviar='+enviar;
			$.ajax({
				type: "POST",
				url: "ajax/send_email.php",
				data: data,
				beforeSend: function(){
					if( tipo== 1){
						var rps = '<br/><h3>Procesando solicitud... <img style="margin:0px; padding:0px; border:none;" src="images/loadinfo.gif" alt="loader" /></h3><br />';					
					}else{	
						var rps = '<br/><h3>Processing... <img style="margin:0px; padding:0px; border:none;" src="images/loadinfo.gif" alt="loader" /></h3><br />';									
					}						
					
					$("#ctnd_rrs").html(rps).fadeIn();
				},
				success:function(data){
					data = jQuery.trim(data);
					$("#ctnd_rrs").html('').fadeOut();
					if(data == 'captcha'){
						if( tipo== 1){
							var rps = '<br/><h2>C&oacute;digo de validaci&oacute;n, no es igual</h2>';						
						}else{	
							var rps = '<br/><h2>Validation code is not equal</h2>';								
						}					
						$("#captcha").val('').focus();
						
						}
						
					if(data == 'ok'){
						if( tipo== 1){
							var rps = '<br/><h2>Informaci&oacute;n enviada exitosamente</h2><br/>';						
						}else{	
							var rps = '<br/><h2>Information sent successfully</h2><br/>';								
						}						
										
						$("#txtnombre").val('').focus();
						$("#txtemail").val('');
						$("#txtasunto").val('');
						$("#txtmensaje").val('');
						$("#txttelefono").val('');
						$("#captcha").val('');
						
						setTimeout(function(){ reloader(); },9500);	
					}else if(data == 'error'){	
						if( tipo== 1){	
							var rps = '<br/><h3>Error al intentar enviar el correo, intente m&aacute;s tarde</h3><br/>';					
						}else{	
							var rps = '<br/><h3>Error attempting to send mail, try later</h3><br/>';								
						}						
						
					}
					$("#ctnd_rrs").html('');
					$("#ctnd_rrs").html(rps).fadeIn(100).fadeOut().fadeIn(100).fadeOut().fadeIn('slow');
					setTimeout(function(){ $("#ctnd_rrs").fadeOut(); },9500);				
				}
			});		
		}else{
			if( tipo== 1){	
				var rps = '<br /><h2>Por favor, revisar antes de enviar:</h2><ul>'+nmb+ml+snt+msnj+msjCpt+'</ul>';					
			}else{	
				var rps = '<br /><h2>Please check before sending:</h2><ul>'+nmb+ml+snt+msnj+msjCpt+'</ul>';								
			}			
			
			$("#ctnd_rrs").html(rps).fadeIn(100).fadeOut().fadeIn(100).fadeOut().fadeIn('slow');
			setTimeout(function(){ $("#ctnd_rrs").fadeOut(); },9500);		
		}
	}
}


/*
jQuery menu

Example:
$(document).ready(function()
{
    $('#jmenu').jmenu({animation:'fade',duration:100});
});

(c) 2010 Sawanna Team (http://sawanna.org)
*/

var jmenu={
    effect: 'fade',           /* default animation effect */
    duration: 400,         /* default duration */
    set: function (settings)
    {
       try
        {
            if (settings.animation == 'show') { this.effect='show'; }
            if (settings.animation == 'slide') { this.effect='slide'; }
            if (settings.animation == 'fade') { this.effect='fade'; }
        } catch (e) {}
        
        try
        {
            this.duration=settings.duration;
        } catch (e) {} 
    },
    fix_pos:function(elem)
    {
        if ($(elem).parent('ul').parent('li').length)
        {
            $(elem).children('ul').eq(0).css({marginTop:-$(elem).height(),marginLeft:$(elem).width()});
        } else
        {
/*            $(elem).children('ul').eq(0).css({'top':$(elem).offset().top+$(elem).height(),'left':$(elem).offset().left});*/        $(elem).children('ul').eq(0).css({'top':$(elem).height(),'left':$(elem).offset().left});
        }
    },
    show:function(elem)
    {
        if (this.effect=='fade') { $(elem).children('ul').eq(0).stop(1,1).fadeIn(this.duration); }
        else if (this.effect=='slide') {$(elem).children('ul').eq(0).stop(1,1).slideDown(this.duration); }
        else if (this.effect=='show') { $(elem).children('ul').eq(0).stop(1,1).show(this.duration); }
    },
    hide: function(elem)
    {
        $(elem).children('ul').eq(0).stop(1,1).fadeOut(100);
    }
}

jQuery.fn.jmenu=function(settings)
{
    jmenu.set(settings);
    
    $(this).find('li').each(function()
    {
            $(this).hover(
                function()
                {
                    jmenu.fix_pos(this);
                    jmenu.show(this);
                },
                function()
                {
                    jmenu.hide(this);
                }
            );
    });
}

