///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// ajax.js
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

function oAjaxWrapper()
{
	this.tUrl = [];
	this.tUrl['Test'] = '/ajax/Test.php';
	this.tUrl['LoadVignette'] = '/beta/search/LoadThumbs';
	this.tUrl['LoadLightBoxList'] = '/lightbox/LoadLightBoxList';
	this.tUrl['CreateLightBox'] = '/lightbox/create_empty';
	this.tUrl['LoadLightBox'] = '/beta/search/LoadLightBox';
	this.tUrl['SaveLightBox'] = '/lightbox/update_media';
	this.tUrl['SaveAsLightBox'] = '/lightbox/save_as';
	this.tUrl['DeleteLightBox'] = '/lightbox/delete';
	this.tUrl['GetEditorialTypes'] = '/lightbox/editorial_select';
	this.tUrl['GetMediaInfo'] = '/media/get_info_for_player';
	this.tUrl['LoadLoginForm'] = '/beta/account/popup_login?l';
	// (DE) 15/12/2006 publication d'une story pour processing'
	this.tUrl['ProcessStory'] = '/lightbox/process_story';
	this.tResult = [];
}

function GAW_AjaxURL(commande)
{
	var tp = commande.split('?');
	tp[0] = this.tUrl[tp[0]];
	if (tp[0])
	{
		var file = tp.join('?');
		return file;
	}
	else
		return false;
}
oAjaxWrapper.prototype.AjaxURL = GAW_AjaxURL;

function GAW_AjaxPOST(commande, data)
{
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
	else
		return(false);
}
oAjaxWrapper.prototype.AjaxPOST = GAW_AjaxPOST;

function GAW_Ajax(commande, data, sync)
{
    sync = (sync)?true:false;
	var fichier = this.AjaxURL(commande);
	if (fichier)
	{
		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else
			return(false);

		if (data == null)
		{
			xhr_object.open('GET', fichier, sync);
			xhr_object.send(null);
		}
		else
		{
			xhr_object.open('POST', fichier, sync);
			xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");   
  			xhr_object.send(data);
		}
		if(xhr_object.readyState == 4)
			return(xhr_object.responseText);
		else
			return(false);
	}
	else
		alert('Erreur : Commande ' + commande + ' NON TROUVEE');
}
oAjaxWrapper.prototype.Ajax = GAW_Ajax;

function GAW_Loading(state)
{
	var o = getObj('ajaxwork');
	if (o)
	{
		var h = o.style.visibility;
		if ((state) && (h == 'none'))
			o.style.visibility = '';
		if ((!state) && (h == ''))
			o.style.visibility = 'none';
	}
}
oAjaxWrapper.prototype.Loading = GAW_Loading;


window.oAjax = new oAjaxWrapper();
