// JavaScript Document
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}$/;
$(document).ready(function(){
	// Borra los textos de todos los inputs text
$("#ctndr_nv_sbmn ul").css({display: "none"});
	$("#ctndr_nv_sbmn li").hover(
	function(){
		$(this).find('ul:first:hidden').css({visibility:"visible", display:"none"}).slideDown(400);
		$(this).addClass('std_2');
	},
	function(){
		$(this).find('ul:first').slideUp(400);
		$(this).removeClass('std_2');
	});

	$("#despliegue_noticias").cycle({
		fx:     'scrollDown', 
		speed:   300, 
		timeout: 9000, 
		pause:   1 																		
	});
});

function set_idioma(tipo){
$.ajax({
	type:"POST",
	url: "ajax/set_idioma.php",
	data: 'tipo='+tipo,
	success:function(data){
		data = jQuery.trim(data);
		if(data == 'ok'){
			top.location = 'index.php';
		}
	}
})
}

function snd_nfrm(){
	$("#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 email	= $("#txtemail").val();
	var asunto	= $("#txtasunto").val();
	var mensaje = $("#txtmensaje").val();
	var para = $("#txtcorreocategoria").val();
	var data	= '';
	
	var var1	= 0;
	var var2 	= 0;
	var var3	= 0;
	var var4	= 0;
	var var5    = 0;
	var pr		= '';
	var nmb		= '';
	var ml		= '';
	var snt		= '';
	var msnj	= '';	
	
	if(!para){ 
			var5 = 1; 
		if( tipo== 1){	var pr = '<li>Para no valido</li>'; }
		else{	var pr = '<li>For not valid</li>';  }		
		$("#txtcorreocategoria").select();
	}
	else{ var5 = 0; }
	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((var1 == 0)&&(var2 == 0)&&(var3 == 0)&&(var4 == 0)&&(var5 == 0)){
		data = 'nombre='+nombre+'&email='+email+'&asunto='+asunto+'&mensaje='+mensaje+'&tipo='+tipo+'&para='+para;
		$.ajax({
			type: "POST",
			url: "ajax/send_email.php",
			data: data,
			beforeSend: function(){
				if( tipo== 1){
					var rps = '<br/><strong>Procesando solicitud...</strong> <img style="margin:0px; padding:0px; border:none;" src="images/loadinfo.gif" alt="loader" /><br /><br /><div class="ln_sprn">&nbsp;</div><br />';					
				}else{	
					var rps = '<br/>Processing... <img style="margin:0px; padding:0px; border:none;" src="images/loadinfo.gif" alt="loader" /><br /><br /><div class="ln_sprn">&nbsp;</div><br />';									
				}						
				
				$("#ctnd_rrs").html(rps).fadeIn();
			},
			success:function(data){
				data = jQuery.trim(data);
				$("#ctnd_rrs").html('').fadeOut();
				if(data == 'ok'){
					if( tipo== 1){
						var rps = '<br/><strong>Informaci&oacute;n enviada exitosamente</strong><br /><div class="ln_sprn">&nbsp;</div><br />';						
					}else{	
						var rps = '<br/><strong>Information sent successfully</strong><br /><div class="ln_sprn">&nbsp;</div><br />';								
					}						
						
					$("#txtcorreocategoria").val('').focus();
					$("#txtnombre").val('');
					$("#txtemail").val('');
					$("#txtasunto").val('');
					$("#txtmensaje").val('');					
				}else if(data == 'error'){	
					if( tipo== 1){	
						var rps = '<br/>Error al intentar enviar el correo, intente m&aacute;s tarde<br /><div class="ln_sprn">&nbsp;</div><br />';					
					}else{	
						var rps = '<br/>Error attempting to send mail, try later<br /><div class="ln_sprn">&nbsp;</div><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 /><strong>Por favor, revisar antes de enviar:</strong><br/><ul>'+nmb+ml+snt+msnj+'</ul><br /><div class="ln_sprn">&nbsp;</div><br />';					
		}else{	
			var rps = '<br /><strong>Please check before sending:</strong><br/><ul>'+nmb+ml+snt+msnj+'</ul><br /><div class="ln_sprn">&nbsp;</div><br />';								
		}			
		
		$("#ctnd_rrs").html(rps).fadeIn(100).fadeOut().fadeIn(100).fadeOut().fadeIn('slow');
		setTimeout(function(){ $("#ctnd_rrs").fadeOut(); },9500);		
	}
		
}
function getbusqueda(){
	var bsqd = $("#search").val();
	
	if(!bsqd.length ){ return false; }	
	
	if($("#tipo").val() == 1){ var direccion = '41-busqueda'; }
	else{ var direccion = '42-serach'; }
	
	top.location="contenido.php?ctg="+direccion+"&key="+bsqd;
}

