﻿function UpdateStats(cara) {
	var xhr;
	if(window.XMLHttpRequest || window.ActiveXObject) {
		if(window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		}
		else {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return;
	}
	if(xhr && xhr.readyState != 0) {
		xhr.abort();
	}
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			
		}
	}
	xhr.open("GET", "inc/updatestats.php?cara="+ cara, true);
	xhr.send(null);
}

function AfficheStats(cara){
	var points = parseInt(document.getElementById("pointscara").innerHTML);
	var carac = parseInt(document.getElementById(cara).innerHTML);

	if (points > 0){
		points = parseInt(points) - 1;
		carac = parseInt(carac) + 1;
		document.getElementById(cara).innerHTML = carac;
		document.getElementById("pointscara").innerHTML = points;
	}
}

function UpdateAll(cara) {
	var xhr;
	if(window.XMLHttpRequest || window.ActiveXObject) {
		if(window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		}
		else {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return;
	}
	if(xhr && xhr.readyState != 0) {
		xhr.abort();
	}
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
		
		}
	}
	xhr.open("GET", "inc/updatestats.php?all="+ cara, true);
	xhr.send(null);
}


function AfficheStatsAll(cara){
	var points = parseInt(document.getElementById("pointscara").innerHTML);
	var carac = parseInt(document.getElementById(cara).innerHTML);

	if (points > 0){
		carac = parseInt(carac) + parseInt(points);
		document.getElementById(cara).innerHTML = carac;
		document.getElementById("pointscara").innerHTML = 0;
	}
}

function verifrequest(url,action,div){
	if (confirm("Etes vous sur de vouloir "+action+" cet objet ?"))
		request(url,div);
}

function request(url,div){
	$("#"+div).load(url);
}

function augmentcom(id_comp) {
	$("#total"+id_comp).load("inc/competences.php?comp="+ id_comp +"");
	
	vospo = document.getElementById("vospo").value;
	points = document.getElementById("total"+id_comp).innerHTML;
		if (isNaN(points)){
			alert("Vous n'avez pas les prérequis !");
		}
		else{
			if(points < 200){
				if(points > 0){
					if(vospo > 4999){
						vospo = vospo - 5000;
						document.getElementById("vospo").value = vospo;
					}
					else
						alert('Plus assez d\'argent !');
				}
			}
			else{
				alert("Impossible d'augmenter votre compétence à plus de 200 points !");
			}
		}
}

function GetId(id){
	return document.getElementById(id);
}

//~ $(window).load(function(){
	//~ size = GetId("cadre_centre").scrollHeight;
	//~ if(size < 750){
		//~ size=750;
	//~ }
//~ });

function cache_div(){
	GetId('div_error').style.display = "none";
}

function send_mail(pseudo){
	request('send_mail.php?pseudo='+pseudo,'receive_mail');
}

var display_tuto = function(){
	request("inc/tuto.inc.php","question_tuto");
	$("#question_tuto").fadeIn("slow");
	$("#div_black").css("display","block");
}

var hide_event = function(){
	$("#event").fadeOut("slow");
	$("#div_black").fadeOut("slow");
}

$(document).ready(function(){
// Fermeture des fenetres info/erreurs
	if($("#close")){
		$("#close").click(function(){
			if($("#error")){
				$("#error").fadeOut("slow");
			}
			
			if($("#info")){
				$("#info").fadeOut("slow");
			}
		});
	}
	
	if($("#tuto")){
		$("#event").click(function(){hide_event();});
		$("#div_black").click(function(){hide_event();});
	}
});

