//Globale Varibale declaration

var req=null;
var resultat="";
var param=null;
var LearningObject;
var editorVar,editorsVar;

// ********************************************
// objects which represent the LO all along the
// program, for displaying and editing it.
//
// ********************************************
//In order to prevent a low speed when an instance of the xml is done with the method readXML()
//we create a methode in wich we use findTextInTag() and findAttributeInTag(). This methode
//will only be called once and executed in a single instance of readXML(). this is a way to improve the code
//but first we won't use it.

// THE LO Object.

function LO(LOname,desc,key,ti,ty,pa,req){
 this.nameLO=LOname;
 this.LOdescription=desc;
 this.LOkeywords=key;
 this.LOtitle=ti;
 this.LOtype=ty;
 this.LOpages=pa;
 this.page=new Array();
 this.pagesName=this.LOpages.split('|');
 this.pageNumber=new Array();
 //var pageNumber=findAttributeInTag("page","pageNumber",req).split('|');
 /*for(i=0;i<this.pagesName.length;i++){
   if(this.pagesName[i]){
     var end=this.pagesName[i].split("_");
     var num=end[1].split(".");
     this.pageNumber[i]=num[0];
     this.page[i]=readXML('./LO/'+LOname+'/'+this.pagesName[i],'createPage("'+ParamValeur("lo")+'","'+this.pagesName[i]+'","'+this.pageNumber[i]+'",req);');
   }
  //this.page[i]=new Page(this.pagesName[i],pageNumber[i],req,LOname);
 }*/
}

// THE Page Object.

function Page(LOname,pageNam,pageNum,req){
 this.pageName=pageNam;
 this.pageNumber=pageNum;
 this.pageDescription=findTextInTag("description",req);
 this.pageKeywords=findTextInTag("keywords",req);
 this.pageItem=new Array();
 var items=findAttributeInTag("item","type",req);
 this.item=items.split("|");
 var itemsText=findTextInTag("item",req);
 this.itemText=itemsText.split("|");
 for(i=0;i<this.item.length;i++){
   var a=this.item[i];
   var b=this.itemText[i];
   this.pageItem[i]=createItem(a,b,req);
   //this.item[i]=new Item(item[i],itemsText[i]);
 }
}

// THE Item Object.

function Item(itype,itext,req){
 this.itemType=itype;
 this.itemText=itext;
 this.itemContent=new Array();
 var items=req.responseXML.documentElement.getElementsByTagName("item");
 for(i=0;i<items.length;i++){
   if(items[i].getAttribute("type")==this.itemType){
     var contents=items[i].getElementsByTagName("content");
     for(j=0;j<contents.length;i++){
       this.itemContent[i]=new Content(contents[j].getAttribute("name"),contents[j].getAttribute("type"));
     }
   }
 }
}

// THE Content Object.

function Content(cName,cType){
 this.contentName=cName;
 this.contentType=cType
}

// ********************************************
// Récupération de paramètre d'une requête HTTP
// ou récupération des données d'un formulaire.
// ********************************************
var paramOk = true;

if (!location.search) {
  paramOk = false;
}
else {

  // Éliminer le "?"
  nReq = location.search.substring(1,location.search.length)
  // Extrait les différents paramètres avec leur valeur.
  nReq = nReq.split("&");
  param = new FaitTableau(nReq.length-1)
  for (var i=0;i<(nReq.length);i++) {
    param[i] = nReq[i]
  }
}

function FaitTableau(n) {
  // Création d'un tableau (array)
  // aux dimensions du nombre de paramètres.
  this.length = n;
  for (var i = 0; i <= n; i++) {
    this[i] = 0
  }
  return this
}

function ParamValeur(nValeur) {
  // Récupération de la valeur d'une variable
  // Pour créer la variable en Javascript.
  var nTemp = "";
  for (var i=0;i<(param.length+1);i++) {
    if (param[i].substring(0,param[i].indexOf("=")) == nValeur)
      nTemp = param[i].substring(param[i].indexOf("=")+1,param[i].length)
  }
  return Decode(nTemp)
}

// Extraction des paramètres de la requête HTTP
// et initialise la variable "paramOk" à false
// s'il n'y a aucun paramètre.
// Décoder la requête HTTP
// manuellement pour le signe (+)
function Decode(tChaine) {
  while (true) {
    var i = tChaine.indexOf('+');
    if (i < 0) break;
    tChaine = tChaine.substring(0,i) + '%20' + tChaine.substring(i + 1, tChaine.length);
  }
  return unescape(tChaine)
}

// ********************************************
// FUNCTION which create the different object
// which compose the LO object.
//
// ********************************************

function createLO(LOname,req){
  var desc=findTextInTag("description",req);
  var key=findTextInTag("description",req);
  var ti=req.responseXML.documentElement.getAttribute("title");
  var ty=req.responseXML.documentElement.getAttribute("type");
  var pa=findAttributeInTag("page","name",req);
  myLO=new LO(LOname,desc,key,ti,ty,pa,req);
  alert(myLO);
  alert(typeof(myLO));
  return myLO;
}
function createPage(LOname,pageName,pageNumber,req){
  return myPage=new Page(LOname,pageName,pageNumber,req);
}
function createItem(itemType,itemText,req){
  return myItem=new Item(itemType,itemText,req);
}

// ********************************************
// usual FUNCTION to improve the interface
// utilization
//
// ********************************************

//Function which transform a span in a input
function textInput(el){
  inputField=document.createElement("input");
  inputField.setAttribute("type","text");
  inputField.setAttribute("size","15");
  inputField.setAttribute("id","LOtitle");
  inputField.setAttribute("name","input");
  inputField.setAttribute("value",el.firstChild.nodeValue);

  el.replaceChild(inputField, el.firstChild);
  getObjectById("LOtitle").setAttribute("onBlur","Alink(this)");
}
function Alink(el){
  inputField=document.createElement("a");
  inputField.setAttribute("href","#");
  inputField.setAttribute("onClick","textInput(this);return false;");
  inputField.appendChild(document.createTextNode(el.getAttribute("value")));
  el.replaceChild(inputField, el.firstChild);
  alert(this);
}
function toggle(image,win){
  var titleA=document.getElementById(win).getElementsByTagName("a");
  for(n in titleA){
    if(titleA[n].nodeName=="A"){
      if(titleA[n].getAttribute("class")=="titleImage"){
        titleA[n].getElementsByTagName("img")[0].setAttribute("src",image);
      }
    }
  }
}
//Functions which close or open the different windows
function showhide(obj)
{
	if (!getObjectStyle)
	return;
	if ( !show)
	return;
	if ( !hide)
	return;
	var txt=" ";
	var result="";
	for(i in obj){
          if(obj[i]!="c"){
            result+=obj[i];
          }else{
            break;
          }
        }
	if (theObj = getObjectStyle(obj))
	{
		if (theObj.display == 'none')
                {
                        toggle("images/open.png",result);

			show(obj);
		}
                else
                {
                        toggle("images/closed.png",result);
			hide(obj);
		}

	}
}
function hide(obj)
{
	if (!getObjectStyle)
		return;
			
	if (theObj = getObjectStyle(obj))
		theObj.display = 'none';
}

function show(obj) 
{
	if (!getObjectStyle)
		return;
					
	if (theObj = getObjectStyle(obj))
		theObj.display = 'block';
}

//function wich display a visual informatin when the user clic on a page in the LOW
function active(on,off){
  var li=getObjectById('pages').getElementsByTagName("li");
  for(i in li){
    //alert(li[i].nodeName);
   if(li[i].nodeName=="LI"){
    li[i].onclick = function(){

      for(j in li){
        if(li[j].nodeName=="LI"){
          li[j].style.backgroundColor=off;
        }
      }
      this.style.backgroundColor = (this.style.backgroundColor==off)?on:off;
    }
   }
  }
}

//POPUP function
var pop=null;
function popup(url,largeur,hauteur,option) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  if (pop && !pop.closed) {
    pop.location = url;
    pop.focus();
  }
  else pop = window.open(url,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+option);
  return !pop;
}

//Function wich adapt the browser and improve compatibility for the DOM object.
navHover = function() {
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);
function checkBrowser()
{	
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55=((this.ver.indexOf("MSIE 5.5")>-1 || this.ie6) && this.dom)?1:0;
	this.ie5=((this.ver.indexOf("MSIE 5")>-1 || this.ie5 || this.ie6) && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.ie4plus=(this.ie6 || this.ie5 || this.ie4);
	this.ie5plus=(this.ie6 || this.ie5)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this;
}

bw = new checkBrowser();
			
if (!document.getElementById) 
{
document.getElementById = getObjectById;
}
			
function getObjectById(ID) 
{
	var obj;
	if (bw.dom)
		return document.getElementById(ID);
	else if (bw.ie4)
		return document.all(ID);
	else if (bw.ns4)
		return eval('document.' + ID);
}
			
function getObjectByIdParent(ID) 
{
	var obj;
	if (bw.dom)
		return parent.document.getElementById(ID);
	else if (bw.ie4)
		return parent.document.all(ID);
	else if (bw.ns4)
		return eval('parent.document.' + ID);
}

function cancelBubble(netEvent) 
{
    if (document.all) 
    {
        window.event.cancelBubble = true;
    } 
    else 
    {
        netEvent.cancelBubble = true;
    }
}
function getObjectStyle(obj)
{
         if (!getObjectById)
         return;
         if (theObj = getObjectById(obj))
	 return theObj.style;
}

// ********************************************
// AJAX FUNCTION to acces the XML Files
//
//
// ********************************************

// ********************************************
// FUNCTION which search into the xml file
// the appropriate information following
// the DOM statement
// ********************************************

function findTextInTag(tagName,req){
  var result=new Array();
  var el=req.documentElement.getElementsByTagName(tagName);
  for(i=0;i<el.length;i++){
     result[i]=el[i].firstChild.nodeValue;
  }
  return result;
}

function findAttributeInTag(tagName,attrName,req){
  var result=new Array();
  var el="";
  if(!req){
    alert("ERROR findAttributeInTag : req is not define!");
  }else{
    if(!tagName){
      alert("ERROR findAttributeInTag : tagName is not define!");
    }else{
      if(!attrName){
        alert("ERROR findAttributeInTag : attrName is not define!");
      }else{
        if(tagName=="documentElement"){
          el=req.documentElement;
          result=el.getAttribute("title");
        }else{
          el=req.documentElement.getElementsByTagName(tagName);
          for(i=0;i<el.length;i++){
            result[i]=el[i].getAttribute(attrName);
            //alert(el[i]);
          }
        }
      }
    }
  }
  return result;
}
// ********************************************
// FUNCTION for processing the data
// display it into the interface
// the DOM statement
// ********************************************

// ******************************
// MetaData Display
// ******************************

function displayMetadata(response){
  var bpw=document.getElementById("area");
  var content="";
  content+='<h4>Title</h4><input type="text" id="lotitle" value="'+response.documentElement.getAttribute("title")+'"/>';
  content+='<h4>Keywords</h4><textarea cols="26" id="keywords" name="kwd" class="text" rows="5">'+response.getElementsByTagName("keywords")[0].firstChild.nodeValue+'</textarea>';
  content+='<h4>LO Description</h4><textarea cols="26" id="description" name="desc" class="text" rows="15">'+response.getElementsByTagName("description")[0].firstChild.nodeValue+'</textarea>';
  bpw.innerHTML=content;
}
function saveMetadata(){
  document.formPage.submit();
  
  ajax_request("GET", 'process.php', "verb=LOmodifydesc&loname="+ParamValeur("lo")+'&description='+document.getElementById('description').firstChild.nodeValue+'&keywords='+document.getElementById('keywords').firstChild.nodeValue, "responseText", "alert(http_request.responseText)");
}
// ******************************
// LOW & LPW DISPLAY
// ******************************

//Make the index following the index.xml file of the LO.
function LOindex(response){
   ul=document.getElementById("pages");
   ulLPW=document.getElementById("pagesLPW");
   /*var kwds=response.getElementsByTagName("keywords")[0].firstChild.nodeValue;
   var keywords=new Array();
   keywords=kwds.split(" ");
   var desc=response.getElementsByTagName("description")[0].firstChild.nodeValue;
   var descriptions=new Array();
   descriptions=desc.split(" ");*/
   ul.innerHTML+="<a href='#' onClick=\"ajax_request(\'GET\', './LO/'+ParamValeur(\'lo\')+'/index.xml', false, \'responseXML\', \'displayMetadata\');return false;\">"+findAttributeInTag("documentElement","title",response)+"</a>";
   ulLPW.innerHTML+=response.documentElement.getAttribute("type");
   var pages=response.getElementsByTagName("page");
   for(i=0;i<pages.length;i++){
     for(j=0;j<pages.length;j++){
       if(pages[j].getAttribute("pageNumber")==i+1){
         ul.innerHTML+='<div id="top"><div id="LITopMiddle"><div id="LITopRight"><img src="images/Interface/LITopLeft.jpg"/></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><li id="'+pages[j].getAttribute("name")+'" >';
         ulLPW.innerHTML+='<div id="top"><div id="LITopMiddle"><div id="LITopRight"><img src="images/Interface/LITopLeft.jpg"/></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><li id="'+pages[j].getAttribute("name")+'LPW">';
       }
     }
   }
  //set the active function to the list element after having creating them.
  //Change the color of the ACTIVE and DISABLED page by changing the respective argument of the function.
  //active("rgb(255, 255, 147)","rgb(255, 255, 187)");
}

//Complete the index of the LOW window
function pageIndex(){
  var el=document.getElementById("pages").getElementsByTagName("li");
  for(node in el){
    if(el[node].nodeType=="1"){
      var id=el[node].getAttribute("id");
      ajax_request("GET", './LO/'+ParamValeur("lo")+'/'+id, false, "responseXML", "createPageIndex");
    }
  }

}

//fill in the LOW index with each pages.
function createPageIndex(response){
 var pageName=response.documentElement.getAttribute('name');
 var pageNameLPW=response.documentElement.getAttribute('name')+"LPW";
 var page=document.getElementById(pageName);
 var pageLPW=document.getElementById(pageNameLPW);
 var pageItems=response.getElementsByTagName("item");
 var result="";
 var resultLPW="";
 result+='<a href="#" onClick="displayBPW(\''+pageName+'\');setTimeout(\'editor()\',0);">'+findAttributeInTag("documentElement","title",response)+'</a><ul class="pageContent">';

 resultLPW+=response.documentElement.getAttribute("type")+'<ul class="pageContent">';
 for(i=0;i<pageItems.length;i++){
   //if(pageItems[i].getAttribute("type")=="example"||pageItems[i].getAttribute("type")=="text"){
     result+='<li><a href="#" onClick=\'javascript:displayBPW(\"'+pageName+'\");TASSinfo(\"'+pageItems[i].getAttribute("type")+'\",\"'+pageName+'\");setTimeout(\"editor()\",0);popup("uploadFile.php?lo='+ParamValeur("lo")+'&page='+pageName+'&item='+pageItems[i].getAttribute("type")+'",250,250,"menubar=no,scrollbars=yes,statusbar=no");return false;\'>'+pageItems[i].getAttribute("type")+'</a><ul class="mediaList">';
   /*}else{
     result+='<li>'+pageItems[i].getAttribute("type")+'<ul class="mediaList">';
   }*/
   resultLPW+='<li>'+pageItems[i].getAttribute("type")+'</li>';
   var content=pageItems[i].getElementsByTagName('content');
   for (n in content){

     if(content[n].nodeName=="content"){
       result+="<li><a href='#' onclick='popup(\"deleteComponent.php?file="+content[n].getAttribute("name")+"\",250,250,\"menubar=no,scrollbars=yes,statusbar=no\");'>"+content[n].getAttribute("name")+"</a></li>";
     }

   }
   result+='</ul></li>';
 }
 resultLPW+='</ul></li><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div>';
 result+='</ul></li><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div>';
 page.innerHTML+=result;
 pageLPW.innerHTML+=resultLPW;
}
//Fonction which display a prompt message for the user in the tass window when adding a media
function TASSinfo(area,page){
  ajax_request("GET", './LO/'+ParamValeur("lo")+'/'+page, false, "responseXML", "TASScontent(http_request.responseXML,\""+area+"\")");
}
function TASScontent(response,area){
  show("TASScontent");
  var tass=document.getElementById("TASScontent");
  var content="";
  var page=response.documentElement.getAttribute("name");
  content+='<div id="top"><div id="LITopMiddle"><div id="LITopRight"><div id="LITopLeft"><p>Would you like to assign an alternative resource to this resource?</p></div></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div>';
  var media=response.getElementsByTagName("item");
  //alert(media[0].nodeValue);
  //alert(media[0].nodeType);
  for(n in media){
    if(media[n].nodeName=="item"){
    if(media[n].getAttribute("type")==area){
      var file=media[n].getElementsByTagName("content");
        for(m in file){
          if(file[m].nodeName=="content"){
            var mediaFile=file[m].getAttribute("typeMIME");
            if(mediaFile.split("/")[0]=="video"||mediaFile.split("/")[0]=="text"||mediaFile.split("/")[0]=="image"){
              content+='<div class="equivalent"><div id="top"><div id="LITopMiddle"><div id="LITopRight"><div id="LITopLeft"><a class="equivalent"  href"#" onclick=\'popup("uploadFile.php?lo='+ParamValeur("lo")+'&page='+response.documentElement.getAttribute("name")+'&item='+area+'",250,250,"menubar=no,scrollbars=yes,statusbar=no");\'><p class="equivalent" style="display:inline">Visual equivalent<img src="images/ticked.gif" style="display:inline"/></p></a></div></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div></div>';
            }else{
              content+='<div class="equivalent"><div id="top"><div id="LITopMiddle"><div id="LITopRight"><div id="LITopLeft"><a class="equivalent" href"#" onclick=\'popup("uploadFile.php?lo='+ParamValeur("lo")+'&page='+response.documentElement.getAttribute("name")+'&item='+area+'",250,250,"menubar=no,scrollbars=yes,statusbar=no");\'><p style="display:inline">Visual equivalent</p></a></div></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div></div>';
            }
            if(mediaFile.split("/")[0]=="audio"){
              content+='<div class="equivalent"><div id="top"><div id="LITopMiddle"><div id="LITopRight"><div id="LITopLeft"><a class="equivalent"  href"#" onclick=\'popup("uploadFile.php?lo='+ParamValeur("lo")+'&page='+response.documentElement.getAttribute("name")+'&item='+area+'",250,250,"menubar=no,scrollbars=yes,statusbar=no");\'><p class="equivalent" style="display:inline">Audio equivalent<img src="images/ticked.gif" style="display:inline"/></p></a></div></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div></div>';
            }else{
              content+='<div class="equivalent"><div id="top"><div id="LITopMiddle"><div id="LITopRight"><div id="LITopLeft"><a class="equivalent"  href"#" onclick=\'popup("uploadFile.php?lo='+ParamValeur("lo")+'&page='+response.documentElement.getAttribute("name")+'&item='+area+'",250,250,"menubar=no,scrollbars=yes,statusbar=no");\'><p class="equivalent" style="display:inline">Audio equivalent</p></a></div></div></div></div><div id="LIMiddleLeft"><div id="LIMiddleRight"><div id="Bottom"><div id="LIBottomMiddle"><div id="LIBottomRight"><img src="images/Interface/LIBottomLeft.jpg"/></div></div></div></div></div></div>';
            }
          }
        }
      }
    }
  }
  tass.innerHTML=content;
}
// ******************************
// BPW DISPLAY
// ******************************

function displayBPW(page){
  ajax_request("GET", './LO/'+ParamValeur("lo")+'/'+page, false, "responseXML", "createBPW");
}
function createBPW(response){
  /*el=document.getElementById("area").childNodes;
  for(n in el){
    document.getElementById("area").removeChild(el[n]);
  }*/
  var items=response.getElementsByTagName("item");
  var titleOK=false;
  var exampleOK=false;
  var BPWcontent="";
  while(!titleOK){
   for(n in items){
    if(items[n].nodeType==1){
    switch(items[n].getAttribute("type"))
    {
      case("title"):
        titleOK=true;
        BPWcontent+='<input type="text" class="title" name="title" size="74" maxlength="40" value="'+items[n].firstChild.nodeValue+'"/>';
        break;
      case("example"):
        if(titleOK){
          BPWcontent+='<div id="BPWarea" ><div class="textArea"><h4>Example Area</h4><div id="exampleDIV">'+insertMedia(items[n],response)+'</div></div>';
          break;
        }
      case("text"):
        if(titleOK){
          BPWcontent+='<div class="textArea"><h4>Text Area</h4><textarea cols="26" id="text" name="text" class="text" rows="15">'+items[n].firstChild.nodeValue+'</textarea></div>';
          break;
        }
     }
    }
   }
  }
  BPWcontent+='</div><div id="menu"><UL><LI><A href="#"><img src="images/interface/start.jpg"/></A></LI><LI><A href="#"><img src="images/interface/back.jpg"/></A></LI><LI><A href="#"><img src="images/interface/next.jpg"/></A></LI><LI><A href="#"><img src="images/interface/end.jpg"/></A></LI></UL></div>';
  document.getElementById("area").innerHTML=BPWcontent;
}

//This function apply the text editor to the related field.
function editor(){

  var editorArgs = {
    items: ["bold", "italic", "underline", "strikethrough",'createlink','insertorderedlist', 'insertunorderedlist','forecolor', 'hilitecolor', 'justifyleft', 'justifycenter', 'justifyright','fontFace', 'formatBlock']
  };

  if(getObjectById("text")!=null){
    editorVar = dojo.widget.fromScript("Editor", editorArgs,dojo.byId("text"));
    /*editorsVar = dojo.widget.fromScript("Editor", editorArgs,dojo.byId("2"));*/
  }
}

function BPWfooter(item){
  var content=item.getElementsByTagName('content');
   for (n in content){
     if(content[n].nodeName=="content"){
       result+="<li>"+content[n].getAttribute("name")+"</li>";
     }

   }
}
//Function which insert the media with the appropriate tag.
function insertMedia(obj,response){
  var content=obj.getElementsByTagName("content")[0];
  var typeMIME=content.getAttribute("typeMIME");
  var file=content.getAttribute("name");
  /*if(typeMIME.split("/")[0]=="image"){
    return "<object height=\"100%\" width=\"100p%\" data=\"./content/"+file+"\" type=\""+typeMIME+"\">Your Browser cannot render \""+file+"\", no plug-in for \""+typeMIME+"\" MIME type.";//
  }else{
    return "<object height=\"200px\" width=\"200px\" data=\"./content/"+file+"\" type=\""+typeMIME+"\">Your Browser cannot render \""+file+"\", no plug-in for \""+typeMIME+"\" MIME type.";/
  }*/
  switch(typeMIME.split("/")[0]){
      case("audio"):
        if(typeMIME.split("/")[1]=="x-pn-realaudio-plugin"||typeMIME.split("/")[1]=="x-pn-realaudio"){
          return '<object id="video" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="320" height="240"><param name="SRC" value="./content/'+file+'"/><param name="CONTROLS" value="ImageWindow"/><param name="CONSOLE" value="one"/><param name="AUTOSTART" value="false"/><embed src="./content/'+file+'" width="320" height="240" nojava="true" controls="ImageWindow" console="one" autostart="false">Your Browser cannot render \"'+file+'\", no plug-in for \"'+typeMIME+'\" MIME type.</embed></object>';
        }else{
          return "<object height=\"200px\" width=\"200px\" data=\"./content/"+file+"\" type=\""+typeMIME+"\"><EMBED src=\"./content/"+file+"\" autostart=\"true\" loop=\"true volume=\"0\" height=\"45\" width=\"300\"controls=\"smallconsole\"  >Your Browser cannot render \""+file+"\", no plug-in for \""+typeMIME+"\" MIME type.</embed></object>";
        }
        break;
      case("image"):
        return '<img src="./content/'+file+'" width="100%" heigth="100%"/>'
        break;
      case("video"):
        return '<EMBED TYPE="'+typeMIME+'" SRC="./content/'+file+'" CONTROLS="imagewindow" CONSOLE="video" AUTOPLAY="true" CONTROLLER="false" WIDTH="320" HEIGHT="240" AUTOSTART="1" SHOWCONTROLS="0">Your Browser cannot render \"'+file+'\", no plug-in for \"'+typeMIME+'\" MIME type.</EMBED>'
       break;
      case("text"):
        break;
      case("application"):
        if(typeMIME.split("/")[1]=="x-shockwave-flash"){
          return '<object type="application/x-shockwave-flash" data="'+file+'" width="550" height="400" id="clip"><param name="movie" value="'+file+'" /><param name="quality" value="high" />Your Browser cannot render \"'+file+'\", no plug-in for \"'+typeMIME+'\" MIME type.</object>';
        }else{
          return
        }
        break;
      default:
        return "The "+mimeType+" MIME Type specied is not a valid MIME Type for "+file+".";
        break;
  }
}
function chooseMedia(mimeType,file){
  var type=mimeType.split('/');
  var result="";
    switch(type[0]){
      case("audio"):
        break;
      case("image"):
        result+='<img src="./content/'+file+'" width="100%" heigth="100%"/>'
        break;
      case("video"):
        break;
      case("text"):
        break;
      case("application"):
        break;
      case(pnp):
        break;
      default:
        result="The "+mimeType+" MIME Type specied is not a valid MIME Type for "+file+".";
    }
}
// ********************************************
// FUNCTION which write into the xml file
// and give back a feeddback concerning
// the result of the process
// ********************************************



/********************************************************************************
**
*                                  ajax_request                                     *
********************************************************************************
*****
* methode : methode de la requette          ex :--> "POST" ou "GET"                 *
* url : url du fichier asynchrone           ex :--> "fichier1.php"                  *
* arguments : arguments de la requette      ex :--> "vara1=test1&vara2=vara2"       *
* type : type de resultat                   ex :--> "responseText" ou "responseXML" *
* fonction : de traitement de la requette   ex :--> "traitement1"                   *
& #092;***************************************************************************
********/
function ajax_request(methode, url, arguments,type, fonction) {
         var http_request = false;
         var data=null;
         var taille=0;

         //traitement de la methode souhaité
         if(methode != "GET") {
                  if(methode != "POST") {
                          alert("Requete Ajax : methode incorrecte --> " + methode);
                          return false;
                  }
         }

         //traitement des arguments
         if(!arguments) {
                 arguments='';
         }

         //traitement du type de réponse
         if(type != "responseText") {
                 if(type != "responseXML") {
                          alert("Requete Ajax : type incorrecte --> " + type);
                          return false;
                 }
         }

         //traitement du fichier asynchrone
         if(!url) {
                 alert("Requete Ajax : url incorrecte");
                 return false;
         }

         //traitement de la fonction de traitement du resultat
         if(!fonction) {
                 alert("Requete Ajax : fonction incorrecte");
                 return false;
         }else{
            if(fonction.split("(")[0]=="TASScontent"||fonction.split("(")[0]=="alert"){
            }else{
                 fonction=fonction+"(http_request."+type+")";
            }
         }

         //traitement des arguments
         if(methode == "GET") {
                 url+="?"+arguments;
         } else {
                 data=arguments;
                 taille=data.length;
         }


         if (window.XMLHttpRequest) { // Mozilla, Safari,...
             http_request = new XMLHttpRequest();
             if (http_request.overrideMimeType) {
                 http_request.overrideMimeType('text/xml');
             }
         } else {
             if (window.ActiveXObject) { // IE
                 try {
                     http_request = new ActiveXObject("Msxml2.XMLHTTP");
                 } catch (e) {
                     try {
                          http_request = new ActiveXObject("Microsoft.XMLHTTP");
                     } catch (e) {}
                 }
             }
         }

         if (!http_request) {
              alert('Cannot create an XMLHTTP instance');
              return false;
         } else {
             http_request.onreadystatechange = function() {
                 if (http_request.readyState == 4) {
                      if (http_request.status == 200) {
                               eval(fonction);
                               return true;
                      } else {
                               alert(url);
                               alert("Error no."+http_request.status+"\nAn error occur while receiving data");
                               return false;
                      }
                 }

             }
             http_request.open(methode, url ,true);
             http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
             http_request.setRequestHeader("Content-length", taille);
             http_request.setRequestHeader("Cache-Control", "no-cache");
             http_request.setRequestHeader("Connection", "close");
             http_request.send(data);
         }
}


