$(document).ready(function() {
	$("#english").hide();
	$("#francais").hide();
	$("#credits").hide()
});
function f_afficher(div) {
	if(div == "francais") {
		$("#english").slideUp("slow");
		$("#credits").slideUp("slow",function() {
			$("#francais").slideToggle("slow");
		});
	}
	if(div == "english") {
		$("#francais").slideUp("slow");
		$("#credits").slideUp("slow",function() {
			$("#english").slideToggle("slow");
		});
	}
	if(div == "credits") {
		$("#english").slideUp("slow");
		$("#francais").slideUp("slow",function() {
			$("#credits").slideToggle("slow");
		});
	}
}
function f_formulaire(mot) {
	html = "<label for=\"mot\">word :</label><input type=\"text\" name=\"mot\" value=\"";
	html += mot+"\" id=\"mot\" disabled=\"disabled\"/><br />";
	html += "<input type=\"submit\" id=\"restart\" name=\"restart\" value=\"restart\" onclick=\"f_getTweetExquisMot('";
	html += mot+"')\" />";
	html += "<input type=\"submit\" id=\"reset\" name=\"reset\" value=\"reset\" onclick=\"f_reset()\" />";
	return html;
}
function f_getTweetExquis() {
	var mot = $("#boite > #mot").val();
	var formulaire = f_formulaire(mot);
	$("#boite").html("<img src=\"attente.gif\" alt=\"loading...\"/>");
	$("#boite").css("background","white");
	$.post("tweetexquishtml.php",{q: mot},
		function(html){
			$("#phrase").html(html);
			$("#boite").html(formulaire);
		}
	);
}
function f_getTweetExquisMot(mot) {
	var formulaire = f_formulaire(mot);
	$("#boite").html("<img src=\"attente.gif\" alt=\"Chargement...\"/>");
	$("#boite").css("background","white");
	$.post("tweetexquishtml.php",{q: mot},
		function(html){
			$("#phrase").html(html);
			$("#boite").html(formulaire);
		}
	);
}
function f_reset() {
	html = "<label for=\"mot\">word :</label><input type=\"text\" name=\"mot\" value=\"\" id=\"mot\"/><br />";
	html += "<input type=\"submit\" id=\"start\" name=\"start\" value=\"start\" onclick=\"f_getTweetExquis()\"/>";
	$("#phrase").html("");
	$("#boite").html(html);
}
function f_start() {
	html = "<input type=\"submit\" id=\"restart\" name=\"restart\" value=\"restart\" onclick=\"f_getCartePostale()\"/>";
	return html;
}
function f_getCartePostale() {
	var formulaire = f_start();
	$("#boite").html("<img src=\"attente.gif\" alt=\"loading...\"/>");
	$("#boite").css("background","white");
	$.get("cartepostalehtml.php",
		function(html){
			$("#phrase").html(html);
			$("#boite").html(formulaire);
		}
	);
}
function f_getFormulaire() {
	html = "<form action=\"successful.php\" method=\"post\">";
	html += "<label for=\"login\">login</label><input type=\"text\" id=\"login\" name=\"login\"/>";
	html += "<label for=\"password\">password</label><input type=\"password\" id=\"password\" name=\"password\"/>";
	html += "<input type=\"submit\" value=\"logIn\" name=\"logIn\"/></form>";
	$("#capsule").html(html);
}
function f_logOut() {
	$.get("logOut.php",function(html) {
		$("#capsule").html(html);
	});
}
function f_checkPassword() {
	if($("#password").val() != $("#check_password").val()) {
		$("#check_password").css("background","#fcc");
		$("#signIn").attr("disabled",true);
	}
	else {
		$("#check_password").css("background","#fff");
		$("#signIn").removeAttr("disabled");
	}
}
function f_checkLogin() {
	var login = $("#boite > #login").val();
	$.post("checklogin.php",{q: login},
		function(html) {
			if(html == "false") {
				$("#check_password").css("background","#fcc");
				$("#signIn").attr("disabled",true);
			}
			else {
				$("#check_password").css("background","#fff");
				$("#signIn").removeAttr("disabled");
			}
		}
	);
}
function f_saveTweetExquis(tweet1,tweet2,mot) {
	$("#saveit").html("...");
	$.post("savetweetexquis.php",{tweet1 : tweet1, tweet2 : tweet2, mot : mot},
		function(html) {
			html = "<a href=\"http://tweetexquis.com/tweetexquis.com?id="+html+"\">fixURL</a>";
			$("#saveit").html(html);
		}
	);
}