function checkEmail(Texto) 
{   	
  return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Texto));      
}

function checkDate(Texto) {
	return (/^(0[1-9]|[12][0-9]|3[01])(\/|-)(0[1-9]|1[012])(\/|-)(\d{4})$/.test(Texto));
}

function ignoreSpaces(string) 
{
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
	return temp;
}

function checkCampoTexto(Texto)
{	
	return (ignoreSpaces(Texto)!="");
}

function checkMinimiumTags(string, num)
{
	string_separated_commas = string.split(',');
	total = string_separated_commas.length;
	
	if(total < num)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

function isset(variable_name) {
	
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
     
    return false;
}

function pagination_action(e)
{
	var page = this.activate_info;
	//var page = this.activate_info - 1;
	//var page_special = this.activate_info;
	var content_id = $('content_id').value;
	
			//var url = '/comentario/ver/' + content_id + '/' + page + '/' + page_special + '/';
			var url = '/comentario/ver/' + content_id + '/' + page + '/';
			//$('capa-comentarios').className = "hidden";
			var pars = {};
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars,
				onSuccess: function(transport) { 
					if(transport.responseText)
					{
						//alert(transport.responseText);	
						$('capa-comentarios').innerHTML = transport.responseText;
						load_comment_events();
					}
			}});
	Event.stop(e);
}
function load_friend_events()
{	
	Event.observe($('recomendar_amigo'), 'click', function(e) 
	{		
		if($('recomendar-amigo').className == "hidden")
		{		
			$('recomendar-amigo').className = "";	
		}
		else
		{
			$('recomendar-amigo').className = "hidden";
		}
		Event.stop(e);
		});
		
	Event.observe($('friend_form'), 'submit', function(e) 
	{
		
		check_fields = new Array ("comment_friend", "author_name_friend", "email_friend");
		name_fields = new Array ("Comentario", "Autor", "Correo electrónico");	

		ok = 1;
		
		if(!checkCampoTexto($F('comment_friend')))
		{
			ok = 0;
		}

		if(!checkCampoTexto($F('author_name_friend')))
		{
			ok = 0;
		}
		
		if(checkCampoTexto($F('email_friend')))
		{			
			if(!checkEmail($F('email_friend')))
			{
				ok = 0;
			}
		} 
		else 
		{
			ok = 0;
		}
		
		
		if(!checkCampoTexto($F('author_name_friend1')))
		{
			ok = 0;
		}
		
		if(checkCampoTexto($F('email_friend1')))
		{				
			if(!checkEmail($F('email_friend1')))
			{
				ok = 0;
			}
		}
		else
		{
			ok = 0;
		}
		
		
		
		if(ok == 1)
		{	
			$('error_friend').className = "error_friend hidden";
			var loading = document.getElementsByClassName("loading_friend hidden");
			loading[0].className = "loading_friend";
			
			var url = '/amigo/enviar';
			var pars = {comment_friend: $('comment_friend').value, 
						email_friend: $('email_friend').value, 
						author_name_friend: $('author_name_friend').value, 
						email_friend1: $('email_friend1').value, 
						url: document.location.href,
						author_name_friend1: $('author_name_friend1').value};
		
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars,
				onSuccess: function(transport) { 
					//alert(transport.responseText);	
				/*	if(transport.responseText)
					{
						alert(transport.responseText);	
					}*/
					
					loading[0].innerHTML = "Su mensaje ha sido enviado.";
					loading[0].className = "loading_friend";
					//$('recomendar-amigo').className = "hidden";
					$('friend_form').reset();
					
			}});
		}
		else
		{
			$('error_friend').innerHTML = "Error al introducir los datos";
			$('error_friend').className = "error_friend error";
		}
		
		Event.stop(e);
	});
}

load_friend_events();	