YAHOO.namespace("equatheque");

YAHOO.equatheque.loadContent = function(e, url, localisation) {
	if(window.event) e = window.event;
	if(e) YAHOO.util.Event.preventDefault(e); 

	if(!YAHOO.equatheque.contentDiv) YAHOO.equatheque.contentDiv = document.getElementById("content_Div");
	YAHOO.equatheque.contentDiv.innerHTML = "<center><img src=\"yui_2.7.0b/yui/build/assets/skins/sam/loading.gif\"/></center>";

	var target = null;
	if(e) target = YAHOO.util.Event.getTarget(e);

	if(target) {
		if(target.href) url = target.href;
	}
	if(!url) url = "yui_2.7.0b/yui/examples/container/assets/somedata.php?r=" + new Date().getTime();

	if(!localisation) {
		var node = YAHOO.equatheque.menuTreeView.getNodeByProperty('href', url);

		if(node) {
			localisation = node.label;
			var parentNode = node.parent;
			while(parentNode) {
				if(parentNode.label) localisation =  parentNode.label + " > " + localisation;
				parentNode = parentNode.parent;
			}
			node.focus();
		}
	}

	if(localisation) {
		if(!YAHOO.equatheque.localisationDiv) YAHOO.equatheque.localisationDiv = document.getElementById("localisation_Div");
		YAHOO.equatheque.localisationDiv.innerHTML = localisation;
	}

	/*
	var callback = {
		success : function(xObjResponse) {
			displayContent(xObjResponse);
		},
		failure : function(xObjResponse) {
			if( xObjResponse.responseText) YAHOO.equatheque.setContent(xObjResponse);
			else {
				YAHOO.equatheque.ajaxRequestContent(url); //POUR LE FONCTIONNEMENT EN LOCAL file:// sur Firefox
			}
		}
	}

	YAHOO.util.Connect.asyncRequest("GET", url, callback);
	*/ //NE FONCTIONNE QUE SUR SERVEUR ET PAS EN LOCAL file:// sur IE, DONC UTILISONS NOTRE PROPRE FONCTION A LA PLACE ->
	YAHOO.equatheque.ajaxRequestContent(url);

	return false;
}

YAHOO.equatheque.setContent = function (xObjResponse) {
	if(!YAHOO.equatheque.contentDiv) YAHOO.equatheque.contentDiv = document.getElementById("content_Div");
	YAHOO.equatheque.contentDiv.innerHTML = xObjResponse.responseText;
	self.scrollTo(0,0);
}

YAHOO.equatheque.ajaxRequestContent = function(url) {
		if(!YAHOO.equatheque.contentDiv.request) {
			YAHOO.equatheque.contentDiv.request = new YAHOO.equatheque.XHConn();
		}
		if(YAHOO.equatheque.contentDiv.request) {
			YAHOO.equatheque.contentDiv.request.abort();
			YAHOO.equatheque.contentDiv.request.connect(url, "GET", null, YAHOO.equatheque.setContent);
		}
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
YAHOO.equatheque.XHConn = function () {
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}

  if (!xmlhttp) return null;

  this.connect = function(sURL, sMethod, sVars, fnDone, paramDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp,paramDone);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };

  this.abort = function() /*Add by David Grima for help Aït Hagou Mouna project*/
  {
    if (!xmlhttp) return false;
    try {
      xmlhttp.abort();
    }
    catch(z) { return false; }
    return true;
  };

  return this;
}