$(document).ready(function(){
	noBigImages();
	

	$("#activar_contrasena").click(activarContrasena);	
	
	$("#botonspam").click(reportarSpam);
	$("#botonspam_no").click(reportarSpamNo);
	$("#botonspam_si").click(reportarSpamSi);
	
	prettyPrint();
});


function reportarSpam()
{
	$(this).hide();
	$("#reportar_spam").find('span').html('&iquest;Est&aacute; seguro?');
	$("#reportar_spam").find('*').show();
	$("#reportar_spam").animate({width: 'show'});
	$("#reportar_spam").css('display','inline');
	return false;
}

function reportarSpamNo()
{
	$(this).parent().hide();
	$("#botonspam").animate({width: 'show'});
	return false;
}

function reportarSpamSi()
{
	
	var topic_id = $(this).attr('topic_id');
	var btnSi = $("#botonspam_si");
	var btnNo = $("#botonspam_no");
	
	btnSi.hide();
	btnNo.hide();
	$("#reportar_spam").find('span').html('Enviando reporte...');
	$("#botonspam").hide();
	$.ajax(
	{
		type: "POST",
		data: { topic_id: topic_id },
		dataType: "html",
		url : "/reportarspam.php",
		beforeSubmit: function(xmlHTTPRequest)
		{
		},
		success: function(data, error)
		{
			
			if (data == "si")
			{
				$("#reportar_spam").find('span').html('Spam reportado. Gracias :)');
			}
			else
			{
				$("#reportar_spam").find('span').html('Oops Fallo!. Lo sentimos :(');
				$("#botonspam").show();
			}
			
		},
		complete: function()
		{
			
		}
		
	}
	)
	return false;
}


function activarContrasena()
{
	$("#activar_contrasena").hide();
	$("#cambiar_contrasena").show("fast");
	$("#cur_password").focus();
	return false;
}

function noBigImages(){
	for(a=0; a<document.images.length; a++){
		tImg = document.images[a];
		if(tImg.src.indexOf("cristalab.com/")==-1 && tImg.src.indexOf("cristalab.org/")==-1 ){
			if(tImg.width>600){
				dif = tImg.width/600;
				tImg.width = tImg.width/dif;
			}
		}
	}
}
function setEscondido ()
{
	setCookie('ver', ver, 365);
}
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie= c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length+1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1)
			{
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
