/*****
Development by GCNMediaCorp.com
http://gcnmediacorp.com/dev
*****/
function gcn_isEmailAddress (s)
{
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	{
		return true;
	}
	return false;
}

function gcn_message_html (obj, type, txt)
{
	$(obj).show();
	$(obj).attr('class', type);
	$(obj).html(txt);
}
function gcn_message_html_ok (obj) {
	$(obj).attr('class', 'gcn_ok_mini');
	$(obj).html('Ok');
}


$(document).ready(function(){
	$("#f_send").click(function () { 
		$('#f_send').hide();
		$('#recommend_loading').show();
		setTimeout("recommend_begin()", 250);
	});
	$("#f_comment").keyup(function () {
		comment_counter();
	});
});

function recommend_begin ()
{
	if (recommend_verify())
	{
		recommend_send();
	}
	else
	{
		$('#f_send').show();
		$('#recommend_loading').hide();
	}
}

function recommend_verify ()
{
	var objId = '';
	var obj = '';
	error = 0;
		
	objId = '#f_my_name';
	objTxt = $(objId).val();
	if (objTxt.length == 0)
	{
		gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Empty my name');
		error++;
	}
	else
	{
		gcn_message_html_ok(objId+'_msg');
		$(objId+'_msg').fadeOut('slow');
	}
	
	objId = '#f_my_email';
	objTxt = $(objId).val();
	if (objTxt.length == 0)
	{
		gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Empty my email');
		error++;
	}
	else
	{
		if (!gcn_isEmailAddress(objTxt))
		{
			gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Email invalid');
			error++;
		}
		else
		{
			gcn_message_html_ok(objId+'_msg');
			$(objId+'_msg').fadeOut('slow');
		}
	}
	
	objId = '#f_friend_name';
	objTxt = $(objId).val();
	if (objTxt.length == 0)
	{
		gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Empty name friend');
		error++;
	}
	else
	{
		gcn_message_html_ok(objId+'_msg');
		$(objId+'_msg').fadeOut('slow');
	}
		
	objId = '#f_friend_email';
	objTxt = $(objId).val();
	if (objTxt.length == 0)
	{
		gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Empty email friend');
		error++;
	}
	else
	{
		if (!gcn_isEmailAddress(objTxt))
		{
			gcn_message_html(objId+'_msg', 'gcn_alert_mini', 'Email invalid');
			error++;
		}
		else
		{
			gcn_message_html_ok(objId+'_msg');
			$(objId+'_msg').fadeOut('slow');
		}
	}
	
	if (error < 1)
	{
		return true;
	}
	return false;
}

function recommend_send ()
{
	var dataString = $("#formrecommend").serialize();
	var html = $.ajax({
		type: "POST",
		url: "ajax/ajax_template_recommend.php",
		data: dataString,
		success: function (data, textStatus) {
			$('#formrecommend').html(data);
		}
	});
}

function add_comment () {
	$('#recommend_more_info').hide();
	$('#recommend_comment').slideDown('slow');
}

function comment_counter () {
	txt = $('#f_comment').val();
	
	//alert(txt);
	n_tope = 100;
	//n_tope = ('#f_comment_aux').val();
	
	n_res = n_tope - txt.length;
	//n_res = parseFloat(n_aux);
	//alert(n_res);
	/*
	if (n_res > 0) {
		alert(23);
		# llego la maximo
		//txt = txt.substr(0, tope);
		//$('#f_comment').val(txt);
	}
	*/
	txt2 = txt.substr(0, n_tope);
	$('#f_comment').val(txt2);
	$('#f_comment_aux').val(n_res);

}