$(document).ready(function()
{
	$(document).mousemove(function(e)
	{
		forum_mus_x = e.pageX;
		forum_mus_y = e.pageY;
		forum_vindue_hojde = $(window).height();
		forum_vindue_bredde = $(document).width();
	});
	GorKlar();
});

function GorKlar()
{	
	$(".forum_alert_td img").hover(function()
	{
		box = $(this).next("em");
		em_hojde = box.height();
		em_style_params = {};
	
		if (forum_mus_y > forum_vindue_hojde/2) 
		{
			em_y = forum_mus_y-30-em_hojde;
			em_retning_y = "op";
		}
		else 
		{
			em_y = forum_mus_y+20;
			em_retning_y = "ned";
		}
			
		if (forum_mus_x > forum_vindue_bredde/2) 
		{
			em_x = forum_mus_x-320;
			em_retning_x = "venstre";
		}
		else 
		{
			em_x = forum_mus_x+20;
			em_retning_x = "højre";
		}
	
		em_style_params["-webkit-border-radius"] =  "10px";
			
		if (em_retning_y == "op" && em_retning_x == "venstre") em_style_params["-webkit-border-bottom-right-radius"] =  "0px";
		if (em_retning_y == "op" && em_retning_x == "højre") em_style_params["-webkit-border-bottom-left-radius"] =  "0px";
		if (em_retning_y == "ned" && em_retning_x == "venstre") em_style_params["-webkit-border-top-right-radius"] =  "0px";
		if (em_retning_y == "ned" && em_retning_x == "højre") em_style_params["-webkit-border-top-left-radius"] =  "0px";
			
		em_style_params["top"] =  em_y;
		em_style_params["left"] =  em_x;
		em_style_params["display"] =  "block";
			
		if (box.html() != "") box.css(em_style_params);
	},
	function() 
	{
		$(this).next("em").css({display:"none"});
	});
}
oprettraad_aktiv = false;
function OpretTraad()
{
	if (oprettraad_aktiv)
	{
		oprettraad_aktiv = false;
		$("#new_forum_threat_id").css({display:"none"});
		$("#oprettraad").css({"background-color":"#F3F2DD"}).hover(function()
		{
		$(this).css({"background-color":"#F3F2DD"});
		},function(){
		$(this).css({"background-color":"#FFFFFF"});
		});
	}
	else
	{
		oprettraad_aktiv = true;
		$("#new_forum_threat_id").css({display:"block"});
		$("#oprettraad").css({"background-color":"#DAD3B7"}).hover(function()
		{
		$(this).css({"background-color":"#DAD3B7"});
		},function(){
		$(this).css({"background-color":"#DAD3B7"});
		});
	}
}

opretcomment_aktiv = 0;
comment_skrevet = false;
comment_cancel = false;
function OpretComment(nr)
{	
	if (opretcomment_aktiv == nr)
	{
		if (comment_skrevet) comment_cancel = confirm("Your comment will not be saved\n\nAre you sure you want to cancel?");
		else comment_cancel = true;
		if (comment_cancel) 
		{
			$("#comment_nr").val(0);
			$("#new_comment_"+opretcomment_aktiv).css({display:"none"}).html("");
			opretcomment_aktiv = 0;
			comment_skrevet = false;
		}
	}
	else if (opretcomment_aktiv > 0)
	{
		if (comment_skrevet) comment_cancel = confirm("Your comment will not be saved\n\nAre you sure you want to cancel?");
		else comment_cancel = true;
		if (comment_cancel) 
		{
			$("#new_comment_"+opretcomment_aktiv).css({display:"none"}).html("");
			$("#new_comment_"+nr).css({display:""});
			$("#new_comment_"+nr).html($("#new_comment_indhold").html());
			$("#comment_nr").val(0);
			$("#comment_nr").val(nr);
			opretcomment_aktiv = nr;
			comment_skrevet = false;
		}
	}
	else
	{
		opretcomment_aktiv = nr;
		$("#new_comment_"+nr).css({display:""});
		$("#new_comment_"+nr).html($("#new_comment_indhold").html());
		$("#comment_nr").val(nr);
		//if (alert_default[nr]) $("#comment_tjek_alert").attr("checked","true");

	}
}

function SubmitTraad()
{
	document.new_forum_threat_form.submit();
}

function SubmitComment()
{
	$("#new_comment_form_"+opretcomment_aktiv).submit();
}

function ForumSkiftSelskab(forum_selskab_value)
{
	if (forum_selskab_value == "") donothing = true;
	else if (forum_selskab_value == "start") top.location.href = "/unlock/";
	else top.location.href = "/unlock/?"+forum_selskab_value;
}

function ForumSkiftGruppe(forum_gruppe_id)
{
	if (forum_gruppe_id == "other") 
	{
		$("#model_heading").css({display:"none"});
		$("#model_rulle").css({display:"none"});
		ForumSkiftModel("other");
	}
	else if (forum_gruppe_id == "") 
	{
		$("#model_heading").css({display:"none"});
		$("#model_rulle").css({display:"none"});
		$("#forum_model_andre").css({display:"none"});
	}
	else
	{
		$("#forum_model_andre").css({display:"none"});
		outprut = "<select name=\"\" onchange=\"ForumSkiftModel(this.value)\">";
		outprut += "<option value=\"\">Choose model...</option>";
		
		for (i = 0; i < modeller.length; i++)
		{
			if (modeller[i][0] == forum_gruppe_id) tremp = modeller[i][1];
		}
		
		if (tremp.length == 1) ForumSkiftModel(tremp[0][0]);
		else
		{
			for (i = 0; i < tremp.length; i++)
			{
				outprut += "<option value=\""+tremp[i][0]+"\">"+tremp[i][1]+"</option>";
			}
			
			outprut += "<option value=\"other\">Other...</option>";
	
			outprut += "</select>";
		
			$("#model_heading").css({display:""});
			$("#model_rulle").css({display:""});
			$("#model_rulle").html(outprut);
		}
	}
}

function ForumSkiftModel(forum_model_url)
{
	if (forum_model_url == "") donothing = true;
	else if (forum_model_url == "other") $("#forum_model_andre").css({display:""});
	else top.location.href = "/unlock/?"+forum_selskab_url+"="+forum_model_url;
}

function ForumRate(nr,retning)
{
	$.post("/unlock/jq.php", {nr:nr,retning:retning});
	allerede = $("#rate_"+retning+"_"+nr).html();
	$("#rate_"+retning+"_"+nr).html(eval(allerede) + 1);
	$("#rate_please_"+nr).html("<b>Thank&nbsp;you</b>");
	$("#rateimg_1_"+nr).html("<img src=\"/unlock/img/ikon/thumbs_up_used.png\" border=\"0\" alt=\"\"/>");
	$("#rateimg_2_"+nr).html("<img src=\"/unlock/img/ikon/thumbs_down_used.png\" border=\"0\" alt=\"\"/>");
}

function ForumCloseMess()
{
	$("#forum_message").css({display:"none"});
}

forum_aktiv_vis_kun = "";
function ForumVisKun(nr)
{
	if (forum_aktiv_vis_kun == nr)
	{
		$(".forum_table").css({display:""});
		$(".forum_blink").css({visibility:"visible"});
		$("#forum_vis_alle").css({visibility:"hidden"});
		forum_aktiv_vis_kun = "";

	}
	else if (nr == 0)
	{
		$(".forum_table").css({display:""});
		$(".forum_blink").css({visibility:"visible"});
		$("#forum_vis_alle").css({visibility:"hidden"});
		forum_aktiv_vis_kun = "";
	}
	else
	{
		$(".forum_table").css({display:"none"});
		$("#forum_table_"+nr).css({display:""});
		$(".forum_blink").css({visibility:"hidden"});
		$("#forum_blink_"+nr).css({visibility:"visible"});
		$("#forum_vis_alle").css({visibility:"visible"});
		forum_aktiv_vis_kun = nr;
	}
}

function VisLogin()
{
	$("#login_id").css({display:"none"});
	$("#login_tekst").css({display:"inline"});
}

function ForumProfilSkift(type)
{
	$("#profil_skift_div").css({display:"inline"});
	$("#profil_skift_input").val("");
	
	if (type == "email") $("#profil_skift_h2").html("Change email-address");
	else if (type == "regemail") $("#profil_skift_h2").html("Register email-address");
	else if (type == "name") $("#profil_skift_h2").html("Change username");
	else if (type == "sletemail") $("#profil_skift_h2").html("Empty email-address! Delete login?");
	
	if (type == "email") $("#profil_skift_text").html("New email-address:");
	else if (type == "regemail") $("#profil_skift_text").html("email-address:");
	else if (type == "name") $("#profil_skift_text").html("New username:");
	else if (type == "sletemail") $("#profil_skift_text").html("The new email-address is empty...<br/><br/>Do you wanna delete your current email-address from the forum?<br/><br/>You will not be able to log in with the current profile again!<br/><br/>To proceed please enter your old email-address to verify.<br/><br/>Old email-address:");
	
	if (type == "email") $("#profil_skift_input").attr({"maxlength":"60"});
	else if (type == "regemail") $("#profil_skift_input").attr({"maxlength":"60"});
	else if (type == "name") $("#profil_skift_input").attr({"maxlength":"30"});
	else if (type == "sletemail") $("#profil_skift_input").attr({"maxlength":"60"});
	
	if (type == "email") skiftjq = "email";
	else if (type == "regemail") skiftjq = "email";
	else if (type == "name") skiftjq = "name";
	else if (type == "sletemail") skiftjq = "sletemail";
	else skiftjq = "";
	
}
function ForumProfilSubmit()
{
	skift_value = $("#profil_skift_input").val();
	
	$.post("/unlock/jq.php",{"skift":skiftjq,"ny":skift_value},
	function(data)
	{
		if (data.jq_email_slet) ForumProfilSkift("sletemail");
		else if (data.jq_status)
		{
			if (data.jq_mess) alert(data.jq_mess);
			if (data.jq_url) top.location.href = data.jq_url;
		}
		else 
		{
			if (data.jq_mess) alert(data.jq_mess);
			$("#profil_skift_input").focus();
		}
		
	},"json");
}

function ForumCloseProfilSkift()
{
	$("#profil_skift_div").css({display:"none"});
}

/*
function ForumAlert(nr,tjekked,vak)
{
	$.post("/unlock/jq.php",{"alert":nr,"ny":tjekked});
	alert_default[nr] = tjekked;
	if (vak) $("#forum_alert_vak_"+nr).hide("slow");
}


function ForumAlertCyklus(nr)
{
	$.post("/unlock/jq.php",{"cyklus":nr});
}
*/
function ForumLogOut(nr)
{
	if (nr == 4)
	{
		$("#forum_message").html("");
		$("#forum_message").css({display:"none"});
		ForumProfilSkift("regemail");
	}
	else if (nr == 5) top.location.href = "/unlock/?logout";
	else
	{
		$("#forum_message").css({display:"inline"});
		message_temp = '<table width="100%"><tr><td><h2 style="margin:0px;color:#990000">Your login will be deleted!</h2></td><td valign="top"><a href="javascript:void(0)" onclick="ForumCloseMess();return false"><img src="/unlock/img/ikon/close.png" border="0" alt="close"/></a></td></tr>';
		message_temp += '<tr><td colspan="2">You haven\'t registered your email-address.<br/>You wont be able to login to your profile another time<br/><br/>Please register your email-address, so you will be able to login to the forum again<br/><br/><br/>';
		message_temp += 'Register email?<input type="button" value="Yes, i\'ll be back" onclick="ForumLogOut(4)"/> <input type="button" value="No, get me out of here!" onclick="ForumLogOut(5)"/>';
		message_temp += '</td></tr></table>';
		$("#forum_message").html(message_temp);
		
	}
}

opret_smiley = false;
function GladSmiley()
{
	if (opret_smiley)
	{
		$("#surprised_smiley").attr("src","/unlock/img/ikon/cry.png");	
		opret_smiley = false;
	}
	else
	{
		$("#surprised_smiley").attr("src","/unlock/img/ikon/happy.png");	
		opret_smiley = true;
	}
}

function SkiftAktivitet(unix)
{
	ingenaktivitet = true;
	activity_output = new Array;
	for (i = 0; i < profilactivity.length; i++)
	{
		activity_output[profilactivity[i][0]] = 0;
	}
	
	for (i = 0; i < profilactivity.length; i++)
	{
		if (profilactivity[i][1] > unix) 
		{
			activity_output[profilactivity[i][0]]++;
			ingenaktivitet = false;
		}
	}
	
	if (ingenaktivitet) $("#forum_aktivitet_ingen").css({"display":""});
	else $("#forum_aktivitet_ingen").css({"display":"none"});
	
	
	for (var aktivitet_nr in activity_output)
	{
		if (activity_output[aktivitet_nr] > 0)
		{
			if (activity_output[aktivitet_nr] > 1) aktivitet_comment_tekst = "comments"; 
			else aktivitet_comment_tekst = "comment"; 
			
			$("#forum_aktivitet_indlag_"+aktivitet_nr).css({"display":""});
			$("#forum_aktivitet_comment_"+aktivitet_nr).html('<img src="/unlock/img/ikon/pil.png" border="0" alt=""/> '+activity_output[aktivitet_nr]+" new "+aktivitet_comment_tekst);
		}
		else
		{
			$("#forum_aktivitet_indlag_"+aktivitet_nr).css({"display":"none"});
			$("#forum_aktivitet_comment_"+aktivitet_nr).html("");
		}
	}
}
