
// FUNCIONES JavaScript ePALCO

function ok_search(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  if (tecla==13) search_now();
}

function validar_recom(i,id){
	
	var para = $('#para').val();
	var de = $('#de').val();
	var err=0;

	if (i=='es') {
		msg='Recomendación enviada. Gracias.';
		msg_e='Hubo algún problema técnico. Inténtelo de nuevo. Gracias.';
	}
	if (i=='en') {
		msg='Recomendation sent. Thank you.';
		msg_e='Technical problems. Try again. Thank you.';
	}
	if (i=='va') {
		msg='Recomanació enviada. Gracies.';
		msg_e='Hi va haver algun problema tècnic. Torneu a provar-ho. Gràcies.';
	}

	$('#para').css("border","1px solid  #646567");
	$('#de').css("border","1px solid  #646567");	
	if(allTrim(para)=='' || isEmailAddress(para)){
		$('#para').css("border","1px solid #F00");
		err = 1;
	}
	if(allTrim(de)==''){
		$('#de').css("border","1px solid #F00");
		err = 1;
	}

	if(err==0){ 
		 var params = "de=" + de + "&para=" + para + "&lang=" + i+ "&id=" + id;
		 $.ajax({
		  type: "POST",
		  url: "php/send_rec.php",
		  data: params,
		   success: function(html){
			   html=html.replace(/\r/,'');
				if (html=='\n1') {
					$('#para').val('');
					$('#de').val('');
					pageTracker._trackEvent('ePalco', 'Recomendaciones', 'id_noticia '+id);
					alert(msg);
				} else {
					alert(msg_e);
				}
		   } 
		 });
	}
}

function validar_addcom(i,id){
	
	var nombre = $('#nombre').val();
	var email = $('#email').val();
	var sexo = $('#sexo').val();
	var comentario = $('#comentario').val();
	
	var err=0;

	if (i=='es') {
		msg='Comentario enviado. Gracias.';
		msg_e='Hubo algún problema técnico. Inténtelo de nuevo. Gracias.';
	}
	if (i=='en') {
		msg='Comment sent. Thank you.';
		msg_e='Technical problems. Try again. Thank you.';
	}
	if (i=='va') {
		msg='Comentari enviat. Gracies.';
		msg_e='Hi va haver algun problema tècnic. Torneu a provar-ho. Gràcies.';
	}

	$('#nombre').css("border","1px solid  #646567");
	$('#email').css("border","1px solid  #646567");
	$('#sexo').css("border","1px solid  #646567");
	$('#comentario').css("border","1px solid  #646567");
	
	if(allTrim(email)=='' || isEmailAddress(email)){
		$('#email').css("border","1px solid #F00");
		err = 1;
	}
	if(allTrim(nombre)==''){
		$('#nombre').css("border","1px solid #F00");
		err = 1;
	}

	if(allTrim(sexo)=='0'){
		$('#sexo').css("border","1px solid #F00");
		err = 1;
	}
	
	if(allTrim(comentario)==''){
		$('#comentario').css("border","1px solid #F00");
		err = 1;
	}

	if(err==0){ 
		 var params = "nombre=" + nombre + "&email=" + email +"&comentario=" + comentario +"&sexo=" + sexo + "&lang=" + i+ "&id=" + id;
		 $.ajax({
		  type: "POST",
		  url: "php/send_com.php",
		  data: params,
		   success: function(html){
				//if (allTrim(html)=='1') {
					$('#nombre').val('');
					$('#sexo').val('');
					$('#email').val('');
					$('#comentario').val('');
					alert(msg);
			//	} else {
			//		alert(msg_e);
			//	}
		   } 
		 });
	}
}



function lTrim(sStr){
	while (sStr.charAt(0) == " "){
		sStr = sStr.substr(1, sStr.length - 1);
	}
	return sStr;
}
function rTrim(sStr){
	while (sStr.charAt(sStr.length - 1) == " "){
		sStr = sStr.substr(0, sStr.length - 1);
	}
	return sStr;
}
function allTrim(sStr){
	return rTrim(lTrim(sStr));
}

function isEmailAddress(e)
{
var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (filter.test(e))
return 0;
else
return 1;
}


function ajusta_columnas() {
	var alto = $("#body").height();
	//alto=alto-(156+30+17);  /* cabecera, footer, y padding bottom del wrapcontent */
	alto=alto-100;
	$("#rightbar").height(alto);
}

function cambia_idioma(j) {
	$.ajax({
	   type: "GET",
	   url: "php/update_lang.php",
	   data: "l="+j,
	   success: function(html){
			location.href="index.php";
	   } 
	 });
};

function vermas(i) {
	location.href="?r=1&id="+i;
}


$(document).ready(function() {
	if ($(".pics").length>0) {refresh_gal();  } 
	ajusta_columnas();					   	
	$("#archivo").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	});
		
	
	$("#eng").hover(function(){
		$(this).animate({width:'75px'},{queue:false,duration:200});
	}, function(){
		$(this).animate({width:'25px'},{queue:false,duration:200});
	});
		
	$("#val").hover(function(){
			$(this).animate({width:'75px'},{queue:false,duration:200});
		}, function(){
			$(this).animate({width:'25px'},{queue:false,duration:200});
		});
		
	$("#esp").hover(function(){
			$(this).animate({width:'75px'},{queue:false,duration:200});
		}, function(){
			$(this).animate({width:'25px'},{queue:false,duration:200});
		});
	
	// control de navegador para automatismo de columnas
	var ejecutar=1;
	if ($.browser.msie) {
		   var version = parseInt($.browser.version,10);
			if (version<7) 
				{ 
					ejecutar = 0;
					return false; 
				} 
	}
	
	if (ejecutar==1) {
		$(window).bind("resize", ajusta_columnas);
		$(window).bind("load", ajusta_columnas);
	}


});// FIN DOCUMENT.READY	

function search_now(){
	location.href="?search="+$("#search").val();
}

