// ********************************************
// *** Librerie AJAX Lite pour VRA-Chardin	***
// *** Version: V2007020101					***
// ********************************************
var CVRSXMLHttp_Object = null;
var CVRSXMLHttp_BoxTargetName = "";
var CVRSXMLHttp_BusyInferface = false;
// ******************************************
// *** Initialiser l'objet XMLHttpRequest ***
// ******************************************
function CVRSAjaxObjectInitialisation(){
	if(window.XMLHttpRequest){
		// Firefox
		TLibXMLHttp_Object = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		// Internet Explorer
		TLibXMLHttp_Object = new ActiveXObject("Microsoft.XMLHTTP");
	}else {
		// XMLHttpRequest non supporté par le navigateur
		TLibXMLHttp_Object = null;
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest.\nCertaines fonctionnalités du site seront indisponibles!");
	}
	if (TLibXMLHttp_Object.overrideMimeType){
            TLibXMLHttp_Object.overrideMimeType('text/html;');
	}
	return TLibXMLHttp_Object;
}

CVRSXMLHttp_Object = CVRSAjaxObjectInitialisation();

function CVRSAjaxStatusQueryChange(){
	if (CVRSXMLHttp_Object.readyState==4){
		var CVRSXMLHttp_QueryResponse = CVRSXMLHttp_Object.responseText;
		alert(CVRSXMLHttp_Object.responseText);
		document.getElementById(CVRSXMLHttp_BoxTargetName).innerHTML=CVRSXMLHttp_QueryResponse;
		CVRSXMLHttp_BoxTargetName = "";
		CVRSXMLHttp_BusyInferface = false;
	}
}

// **************************
// *** Faire un Query URL ***
// **************************
function CVRSAjaxQueryURL(TLibXMLHttp_MethodQuery,TLibXMLHttp_URL,TLibXMLHttp_Variables,TLibXMLHttp_BoxTargetName){
	if (document.getElementById(TLibXMLHttp_BoxTargetName).style.display=="block"){
		CVRSXMLHttp_BusyInferface = true;
		CVRSXMLHttp_BoxTargetName = TLibXMLHttp_BoxTargetName;
		CVRSXMLHttp_Object.open("POST",TLibXMLHttp_URL, true);
		// *** Debug ***
		// document.getElementById('TTab_SheetNewResaDebug').innerHTML += 'Appel AJAX: '+TLibXMLHttp_BoxTargetName+' Display: '+document.getElementById(TLibXMLHttp_BoxTargetName).style.display+'<br>';
		CVRSXMLHttp_Object.onreadystatechange=function(){
			// *** Debug ***
			//document.getElementById('TTab_SheetNewResaDebug').innerHTML += TLibXMLHttp_BoxTargetName+' -> State: '+CVRSXMLHttp_Object.readyState+'<br>';
			if (CVRSXMLHttp_Object.readyState==4){
				var CVRSXMLHttp_QueryResponse = CVRSXMLHttp_Object.responseText;
				document.getElementById(CVRSXMLHttp_BoxTargetName).innerHTML=CVRSXMLHttp_QueryResponse;
				CVRSXMLHttp_BoxTargetName = "";
				CVRSXMLHttp_BusyInferface = false;
			}
		}
		CVRSXMLHttp_Object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		CVRSXMLHttp_Object.send(TLibXMLHttp_Variables);
	}
}

// ****************************************************************
// *** Basculer d'un TAB à l'autre, switcher aussi les TabSheet ***
// ****************************************************************
function TTabSwitchToIndex(TabIndex,TTab_TabName,TTab_TabNewColor,TTab_SheetName,TTab_SheetDisplay){
	var inc=1;
	// *** Switcher les TTab_Sheet ***
	while (document.getElementById(TTab_SheetName+inc)){
		if (TTab_SheetName+TabIndex==TTab_SheetName+inc)
			if (document.getElementById(TTab_SheetName+inc).style.display=="block")
				document.getElementById(TTab_SheetName+inc).style.display = "none";
			else
				document.getElementById(TTab_SheetName+inc).style.display = TTab_SheetDisplay;
		else
			document.getElementById(TTab_SheetName+inc).style.display = "none";
		inc++;
	}
	var inc=1;
	// *** Switcher les couleurs de TTab_Tab ***
	/*
	while (document.getElementById(TTab_TabName+inc)){
		if (TTab_TabName+TabIndex==TTab_TabName+inc){
			document.getElementById(TTab_TabName+inc).style.backgroundColor = TTab_TabNewColor;
		}else{
			document.getElementById(TTab_TabName+inc).style.backgroundColor = "#F5F5F5";
		}
		inc++;
	}
	*/
}

// **********************************
// *** Agrandir, diminuer un TBox ***
// **********************************
function TBoxExpand(TBoxIndex,TBox_Name,TBox_Display){
	var inc=1;
	// *** Agrandir, diminuer le TBox ***
	while (document.getElementById(TBox_Name+inc)){
		if (TBox_Name+TBoxIndex==TBox_Name+inc)
			if (document.getElementById(TBox_Name+inc).style.display=="block")
				document.getElementById(TBox_Name+inc).style.display = "none";
			else
				document.getElementById(TBox_Name+inc).style.display = TBox_Display;
		else
			document.getElementById(TBox_Name+inc).style.display = "none";
		inc++;
	}
}
