//-------------------------------------------------------------------------------------------------------------------
// AJAX PART

// URL to the script which must handle the request
//var URLBase = location.href.substr(0,location.href.lastIndexOf('/')+1);
var URLBase = "http://localhost/015--WEBEXPLO_2/";

// This function implements the instanciation of XMLhttpRequest object.
// It also attach a listener which calls the function handleHTTPObject.
function sendHTTPRequest(type,script,object,params) {

	// FF,Safari,Opera
	if (window.XMLHttpRequest) {
		try { hr = new XMLHttpRequest(); }
		catch (e) { return false; }
	} 
	// IE
	else if (window.ActiveXObject) {
		// recent Jscript version
		try { hr = new ActiveXObject("MSXML2.XMLHTTP"); }
		catch (e) {
			// old Jscript version
			try { hr = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) { return false; }
		}
	}
	// the browser implements none of the above
	else { return false }
	// Request handling
	
	hr.onreadystatechange = function(type) {
		if (hr.readyState==4) {
			if (hr.status==200) {
				//alert(hr.responseText);
				try { eval(hr.responseText); }
				catch(e) { alert(e); }
			}
		}
	};
	
	switch (type) {
		case 'HEAD' :
			hr.open("HEAD",URLBase+script,true);
			hr.send(null);
			break;
		case 'GET' :
			hr.open("GET",URLBase+script+"?"+params,true);
			hr.send(null);
			break;
		case 'POST' :
			hr.open("POST",URLBase+script,true);
			hr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			if (object=='auth') { params="async=auth&login="+document.getElementById('login').value+"&password="+document.getElementById('password').value; }
			hr.send(params);
			break;
		default :
			break;
	}
}

// END OF AJAX PART
//-------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------
// WIDGET PART
function wdg_change_tab(n,o) {
	document.getElementById(n).style.visibility = "hidden";
	document.getElementById(o).style.visibility = "visible";
}

function wsme_checkuser(exists) {
	switch (exists) {
		case 0 :
			document.getElementById('wsme_nouser').style.visibility="visible";
			document.getElementById('wsme_userform').style.visibility="hidden";
			break;
		case 1 :
			document.getElementById('wsme_nouser').style.visibility="hidden";
			document.getElementById('wsme_userform').style.visibility="visible";
			break;
		default :
			break;
	}
}

function wsme_checkgroup(exists) {
	switch (exists) {
		case 0 :
			document.getElementById('wsme_nogroup').style.visibility="visible";
			document.getElementById('wsme_groupform').style.visibility="hidden";
			break;
		case 1 :
			document.getElementById('wsme_nogroup').style.visibility="hidden";
			document.getElementById('wsme_groupform').style.visibility="visible";
			break;
		case 2 :
			document.getElementById('wsme_nogroup').innerHTML = "Le groupe a été créé avec succès.";
			document.getElementById('wsme_nogroup').style.visibility="visible";
			document.getElementById('wsme_groupform').style.visibility="hidden";
			break;
		case 3 :
			document.getElementById('wsme_nogroup').innerHTML = "Erreur lors de la création du groupe";
			document.getElementById('wsme_nogroup').style.visibility="visible";
			document.getElementById('wsme_groupform').style.visibility='hidden';
		default :
			break;
	}
}

// END OF WIDGET PART
//-------------------------------------------------------------------------------------------------------------------
