// ***********************************  
// *********************************** AJAX 
// ***********************************  

function GetAjObj(page,varparam,target,mode) {
	//http://www.xul.fr/xml-ajax.html
  // create request object
  var req = createRequest();
  // code to prevent caching
  var d = new Date();
  // set up request parameters - uses GET method
	req.open('GET', page+'?pg=adaj&tc='+d.getTime()+"&"+varparam,false);
   // submit to the server for processing
  req.send(null);
  // process returned data - error condition
  if (req.status != 200) {
    // alert('Problem with Request');
    // return "";
  } else {
	 // process returned data - OK
	//alert("retour : " + req.responseText);
	if(target !='') {
		if (mode == '') {
			document.getElementById(target).innerHTML=req.responseText; 
		}
		if (mode == 'b') {
			// add before
			document.getElementById(target).innerHTML = req.responseText + document.getElementById(target).innerHTML; 
		}
		if (mode == 'a') {
			// add after 
			document.getElementById(target).innerHTML += req.responseText; 
		}
	}
	// return req.responseText;
  }
}

function createRequest() {
  var request;
  try {
    request = new XMLHttpRequest();
  }
  catch (tryIE) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (tryOlderIE) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (failed) {
        alert("Error creating XMLHttpRequest");
      }
    }
  }
  return request;
}

// ***********************************  
// *********************************** AJAX FORM/IFRAME
// ***********************************  
// http://www.webtoolkit.info/ajax-file-upload.html

AIM = {
 
	frame : function(c) {
 
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);
 
		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}
 
		return n;
	},
 
	form : function(f, name) {
		f.setAttribute('target', name);
	},
 
	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},
 
	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}
 
		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}
 
}

// ***********************************  
// *********************************** OTHERS
// ***********************************  

function ConfirmAction(AlertText,ActionURL) {
	
	if(confirm(AlertText)) {
		document.location.replace(ActionURL);
	}
}

function DisplayWinPop(WinName,FileURL) {

	WinPop = window.open(FileURL,WinName);
	WinPop.focus();

}

function setStyle(obj,style,value){
	getRef(obj).style[style]= value;
}

function getRef(obj){
	return (typeof obj == "string") ?
		 document.getElementById(obj) : obj;
}

function goLocation(ActionURL) {
	document.location.replace(ActionURL);
}

