function approve(widarco, comment) {
	var rand=Math.floor(Math.random()*10001);
	$(".item > .attempt").fadeOut("slow", function(){
		$("#comment-"+comment+"").load("/js/approve.php?widarco="+widarco+"&comment="+comment+"", function(){
			$("#comment-"+comment+"").fadeIn("fast");
		});
	});
}

function disapprove(widarco, comment) {
	var rand=Math.floor(Math.random()*10001);
	$("#comment-"+comment+"").fadeOut("slow", function(){
		$("#comment-"+comment+"").load("/js/disapprove.php?widarco="+widarco+"&comment="+comment+"", function(){
			$("#comment-"+comment+"").fadeIn("fast");
		});
	});
}

function showHide(layer) {	
	if(layer == "register") {
		$("#login").animate({ height: "0px" }, "fast");
		$("#login").fadeOut("fast");
		
		if($("#register").is(":hidden")) {
			$("#register").fadeIn("fast", function(){
				$("#register").animate({ height: "150px" }, "sloth");
			});
		}else{
			$("#register").animate({ height: "0px" }, "fast");
			$("#register").fadeOut("fast");
		}
	}
	
	if(layer == "login") {
		$("#register").animate({ height: "0px" }, "fast");
		$("#register").fadeOut("fast");
		
		if($("#login").is(":hidden")) {
			$("#login").fadeIn("fast", function(){
				$("#login").animate({ height: "150px" }, "slow");
			});
		}else{
			$("#login").animate({ height: "0px" }, "fast");
			$("#login").fadeOut("fast");
		}
	}
}

function showPosted() {
	if($("#posted").is(":hidden"))
		$("#won").hide("fast", function(){
			$("#posted").show("fast");
		});
	else {
		$("#posted").hide("fast");
	}
}

function showWon() {
	if($("#won").is(":hidden"))
		$("#posted").hide("fast", function(){
			$("#won").show("fast");
		});
	else {
		$("#won").hide("fast");
	}
}

function profile() {
	var rand=Math.floor(Math.random()*10001);
	if($("#myWids").is(':visible')) {
		$("#myWids").fadeOut("fast", function(){
			$("#profile").load("/js/profile.php?rand="+rand+"",function(){
				$("#profile").fadeIn("fast");
			});
		});
	}
	
	if($("#wonWids").is(':visible')) {
		$("#wonWids").fadeOut("fast", function(){
			$("#profile").load("/js/profile.php?rand="+rand+"",function(){
				$("#profile").fadeIn("fast");
			});
		});
	}
	
	if($("#addWid").is(':visible')) {
		$("#addWid").fadeOut("fast", function(){
			$("#profile").load("/js/profile.php?rand="+rand+"",function(){
				$("#profile").fadeIn("fast");
			});
		});
	}
}

function addWid() {
	if($("#myWids").is(':visible')) {
		$("#myWids").fadeOut("fast", function(){
			$("#addWid").fadeIn("fast");
		});
	}
	
	if($("#wonWids").is(':visible')) {
		$("#wonWids").fadeOut("fast", function(){
			$("#addWid").fadeIn("fast");
		});
	}
	
	if($("#profile").is(':visible')) {
		$("#profile").fadeOut("fast", function(){
			$("#addWid").fadeIn("fast");
		});
	}
}

function myWids() {
	var rand=Math.floor(Math.random()*10001);
	if($("#addWid").is(':visible')) {
		$("#addWid").fadeOut("fast", function(){
			$("#myWids").load("/js/myWids.php?rand="+rand+"", function(){
				$("#myWids").fadeIn("fast");
			})
		});
	}
	
	if($("#wonWids").is(':visible')) {
		$("#wonWids").fadeOut("fast", function(){
			$("#myWids").load("/js/myWids.php?rand="+rand+"", function(){
				$("#myWids").fadeIn("fast");
			})
		});
	}
	
	if($("#profile").is(':visible')) {
		$("#profile").fadeOut("fast", function(){
			$("#myWids").load("/js/myWids.php?rand="+rand+"", function(){
				$("#myWids").fadeIn("fast");
			})
		});
	}
}

function wonWids() {
	var rand=Math.floor(Math.random()*10001);
	if($("#addWid").is(':visible')) {
		$("#addWid").fadeOut("fast", function(){
			$("#wonWids").load("/js/wonWids.php?rand="+rand+"", function(){
				$("#wonWids").fadeIn("fast");
			})
		});
	}
	
	if($("#myWids").is(':visible')) {
		$("#myWids").fadeOut("fast", function(){
			$("#wonWids").load("/js/wonWids.php?rand="+rand+"", function(){
				$("#wonWids").fadeIn("fast");
			})
		});
	}

	if($("#profile").is(':visible')) {
		$("#profile").fadeOut("fast", function(){
			$("#wonWids").load("/js/wonWids.php?rand="+rand+"", function(){
				$("#wonWids").fadeIn("fast");
			})
		});
	}
}

function limitChars(textid, limit, infodiv) {
	var text = $('#'+textid).val();
	var textlength = text.length;
	if(textlength > limit) {
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else {
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}