// JavaScript Document

// ------------------------------------------------------------------------------------------------
//                                      AJAX FUNCTION
// ------------------------------------------------------------------------------------------------
var temp = "1";

function action(action,data)
{


	$(document).ready(  function()
	{
	$.ajax( {
				type: "POST",
				url: "/inc/ajax/" + action + ".php",
  				data: data,
				dataType: "xml",
				success: afficheReponse,
				error : afficheErreurAjax
			}
		  ); 
	}
	);

	function afficheErreurAjax(xhr, ajaxOptions, thrownError){
		if(xhr.status != 200)
			alert('Une erreur de communication avec le serveur est survenu : code ' + xhr.status);
	}
	function afficheReponse(requete) {
		if(requete.responseText != ""){
			var xmlDoc = requete;
			var action = xmlDoc.getElementsByTagName('action');
			for (var iC=0 ; iC < action.length ; iC++){
				var type = action[iC].getElementsByTagName('type')[0].firstChild.nodeValue;
				
				if(type == "html" || type == "add_html"){
					var champs = action[iC].getElementsByTagName('champs')[0].firstChild.nodeValue;
				}
				
				var value = action[iC].getElementsByTagName('value')[0].firstChild.nodeValue;
				if(type == "html"){
					if($('#'+champs))
						$('#'+champs).html(value);
				}
				if(type == "add_html"){
					if($('#'+champs))
						$('#'+champs).append(value);
				}
				if(type == "remove_dom"){
					if($('#'+champs))
						$('#'+champs).remove();
				}
				else if(type == "js"){
					eval(value);
				}
				else if(type == "temp"){
					$('#temp').html(value);
				}
			}
		}
	}
}

function getTotalHeight() {
	// firefox is ok
	var height = document.documentElement.scrollHeight;
	
	// now IE 7 + Opera with "min window"
	if(document.documentElement.clientHeight > height ) {
	height  = document.documentElement.clientHeight;
	}
	// last for safari
	if(document.body.scrollHeight > height) {
	height = document.body.scrollHeight;
	}
	return height;
}
function overlay(action){
	if(action == "off")
		document.getElementById('overlay').style.display = "none";
	else{
		document.getElementById('overlay').style.height = getTotalHeight() + "px";
		document.getElementById('overlay').style.display = "block";
	}
}
iframe = "off";
function popup(action,largeur){
	if(action == "off"){
		overlay('off');
		document.getElementById('popup').style.display = 'none';
		document.getElementById('popup_content').innerHTML = '';
	}
	else{
		overlay();
		//if(document.getElementById('popup').style.display == 'none')
		document.getElementById('popup').style.display = 'block';
		document.getElementById('popup').style.width = largeur + "px";
		document.getElementById('popup').style.marginLeft = "-" + Math.round(largeur/2) + "px";
	}
}
function GetCSS(selecteur,propriete){
	$(selecteur).css(propriete);
}
function SetCSS(selecteur,propriete,valeur){
	window.action('SetCSS','selecteur=' + selecteur + '&propriete=' + propriete + '&valeur=' + valeur);
}


