var N=navigator.appName;
var V=navigator.appVersion;
var version="?";
var nom=N;
var os="ALL";
var osDetected="?";
var selectedLanguage="?";
var navigatorLanguage="?";
var url;
var paramUrl = new Array();

//if (window!=top) {top.location=window.location;} //pour chargement dans la page complete et pas dans une frame

function initDefault()
{
  paramUrl = getUrlParam();
  if(paramUrl["os"] == null)
  {
    detectParamNav();
  }
  else
  {
    os = paramUrl["os"];
  }
  if(paramUrl["lang"] == null)
  {
    changeLanguage("navigator");
  }
  else
  {
    document.getElementById(paramUrl["lang"]).selected=true;
  }
}

function initTop()
{
  if(detectNet())
  {
    window.document.getElementById("CD").style.display="none";
    window.document.getElementById("WEB").style.display="block";
  }
  else
  {
    window.document.getElementById("CD").style.display="block";
    window.document.getElementById("WEB").style.display="none";
  }
}

function initArray()
{
  if(detectNet())
  {
    window.document.getElementById("update").style.display="none";
  }
}


function changeLanguage(lang)
  {
    var lien;
    var search;
    var language;
    if(lang=="navigator")
    {
      language = navigatorLanguage;
    }
    else
    {
      language=lang;
    }
    language = language.substring(0,2);
    selectedLanguage = language;
    if(language=="fr")
    {
      if(url != "default_mgt_fr.htm" && url != "DEFAULT_ MGT_FR.HTM")
      {
        lien = "explore/fra/default_mgt_fr.htm";
        search = setUrlParam(window.location.search,"lang",language);
        lien += setUrlParam(search,"os",os);
        window.location.replace(lien);
      }
      else
      {
        document.getElementById("fr").selected=true;
      }
    }
    if(language=="en")
    {
      if(url != "default_mgt.htm" && url != "DEFAULT_MGT.HTM")
      {
        lien = "../../default_mgt.htm";
        search = setUrlParam(window.location.search,"lang",language);
        lien += setUrlParam(search,"os",os);
        window.location.replace(lien);
      }
      else
      {
        document.getElementById("en").selected=true;
      }
    }
  }


function detectParamNav()
{
  if (N=="Microsoft Internet Explorer") 
	{
		navigatorLanguage=navigator.systemLanguage;
		version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf(";",V.indexOf("MSIE",0)));
		if (V.indexOf("Win",0)>0) 
		{
			if ( V.indexOf(";",V.indexOf("Win",0)) > 0 ) 
			{
				osDetected=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			} else 
			{
				osDetected=V.substring(V.indexOf("Win",0),V.indexOf(")",V.indexOf("Win",0)));
			}
		}
		if (V.indexOf("Mac",0)>0) 
		{
			osDetected="Macintosh";
			version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf("?",V.indexOf("MSIE",0)));
		}
	}
	if (N=="Opera") 
	{
		navigatorLanguage=navigator.language;
		version=V.substring(0,V.indexOf("(",0));
		osDetected=V.substring(V.indexOf("(",0)+1,V.indexOf(";",0));	
	}
	if (N=="Netscape") 
	{
		navigatorLanguage=navigator.language;
		if (navigator.vendor=="")  // Mozilla
		{
			version=(V.substring(0,V.indexOf("(",0)));
			nom="Mozilla";
			if (V.indexOf("Mac",0)>0) 
			{
				osDetected="Macintosh";
			}
			if (V.indexOf("Linux",0)>0) 
			{
				osDetected="Linux";
			}
			if (V.indexOf("Win",0)>0) 
			{
				osDetected=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			}
			if (version==5) 
			{
				version="1";
			}
			if (navigator.oscpu) 
			{
				osDetected=navigator.oscpu;
			}
		}else 	// NS 4 ou 6
		{
      version=(V.substring(0,V.indexOf("(",0)));
			if (V.indexOf("Mac",0)>0) 
			{
				osDetected="Macintosh";
			}
			if (V.indexOf("Linux",0)>0) 
			{
				osDetected="Linux";
			}
			if (V.indexOf("Win",0)>0) 
			{
				osDetected=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			}
			if (version==5) 
			{
				version="6.0";
				if (navigator.vendorSub!="")
        {
          version=navigator.vendorSub;
        }
			}
			if (navigator.oscpu) 
			{
				osDetected=navigator.oscpu;
			}
		}
	}
	V=V.toLowerCase();
  if(V.match("konqueror"))
	{
    var expression=new RegExp("linux");
    var exp=new RegExp("fr");
    if(V.match(expression))
    {
      osDetected="Linux";
    }
    if(V.match(exp))
    {
      navigatorLanguage = "fr";
    }
  }
  os = traitement(osDetected);;
}

function getUrlParam()
{
  url = parent.location.href;
  var exp=new RegExp("[&?]+","g");
	var exp2=new RegExp("[=]+","g");
	var exp3=new RegExp("[/]+","g");
	var tabNom=url.split(exp);
  url = tabNom[0];
  url = url.split(exp3);
  url = url[url.length-1];
  var	tabParam=new Array();
	if (tabNom!=null)
  {
		for(var i=1;i<tabNom.length;i++)
   	{
      var tabTemp=tabNom[i].split(exp2);
			tabParam[tabTemp[0]]=tabTemp[1];
		}
	}
	return tabParam;
}

	

function setUrlParam(search, nameParam, valueParam)
{
  paramUrl=getUrlParam();
  if(search=="")
	{
    var param = "?";
    param += nameParam;
    param += "=";
    param += valueParam;
  }
  else
  {
    if(paramUrl[nameParam]== null)
    {
      var param = search;
      param += "&";
      param += nameParam;
      param += "=";
      param += valueParam;
    }
    else
    {
      if(paramUrl[nameParam]!= valueParam)
      {
        var param;
      	var exp=new RegExp(nameParam +"=","g");
      	var exp2=new RegExp("[&]+","g");
        var urlP = search;
        var tempParam;
        var tabParam = urlP.split(exp);
        tempParam=tabParam[1].split(exp2);
        var oldChaine = nameParam + "=" + tempParam[0];
        var newChaine = nameParam + "=" + valueParam;
        param=urlP.replace(oldChaine,newChaine);
      }
      if(paramUrl[nameParam]== valueParam)
      {
        var param = search;
      }
    }
  }
  return param;
}

function frameOut( link, target)
{
  link += parent.location.search;
  parent.open(link , target);
}

function openLink( link, target)
{
  link += setUrlParam(window.location.search,"os",os);
  window.open(link , target);
}

/**
 * Detect if the browser is the MGE OPS browser
 */	
function fnIsOurCustomBrowser()
{
	//Check to see if this is our custom
	//browser. We just see if the function 
	//IsOurCustomBrowser is available. By leaving
	//the brackets off of our function it is treated
	//as a property and thus allows us to check if
	//our method exists in the external window. If it
	//returns null then obviously this is not our custom
	//browser, so we return false.
	detectParamNav();
  if(osDetected.substring(0,3)=="Win" && nom == "Microsoft Internet Explorer")
  {
    if(window.external.mgeIsOurCustomBrowser!=null)
		{  
      return true;
	  }
    else 
		{
      return false;
    }
	}
	else 
  {
    return false;
  }
}	
	
//setup a variable to let us know if this is our
//custom browser.

function fnCallFunction()
{
	//Call c++ function that we made
	//in our custom browser
	if(fnIsOurCustomBrowser())
		parent.external.mgeCustomFunction();
}	

function fnCallFunctionWithParams(strString, nNumber)
{
	//Call c++ function that accepts parameters 
	//that we made in our custom browser
	if(fnIsOurCustomBrowser())
		parent.external.mgeCustomFunctionWithParams(strString, nNumber);
}

/**
 * Open a window of MGE OPS browser
 * @param strURL URL to open
 * @param nLeft width in pixels between the left of screen and the window 
 * @param nTop height in pixels between the top of screen and the window
 * @param nWidth width in pixels of window
 * @param nHeight height in pixels of window
 * @param nResizable window resizable or not
 */
	
function fnOpenWindow(strURL, nLeft, nTop, nWidth, nHeight, nResizable)
{
	if(fnIsOurCustomBrowser())
		parent.external.mgeOpenWindow(strURL, nLeft, nTop, nWidth, nHeight, nResizable);
}
  
/**
 * Open a modal dialog window
 * @param strURL URL to open
 * @param nLeft width in pixels between the left of screen and the window 
 * @param nTop height in pixels between the top of screen and the window
 * @param nWidth width in pixels of window
 * @param nHeight height in pixels of window
 */
	
function fnShowModalDialog(strURL, nLeft, nTop, nWidth, nHeight)
{
	if(fnIsOurCustomBrowser())
		parent.external.mgeShowModalDialog(strURL, nLeft, nTop, nWidth, nHeight);
}

/**
 * Open a modeless dialog window
 * @param strURL URL to open
 * @param nLeft width in pixels between the left of screen and the window 
 * @param nTop height in pixels between the top of screen and the window
 * @param nWidth width in pixels of window
 * @param nHeight height in pixels of window
 */
	
function fnShowModelessDialog(strURL, nLeft, nTop, nWidth, nHeight)
{
	if(fnIsOurCustomBrowser())
	parent.external.mgeShowModelessDialog(strURL, nLeft, nTop, nWidth, nHeight);
}
	
/**
 * to execute a file
 * @param strString Name of file to execute 
 * @param target target of window (_blank , _self ...)
 */	
	
function execute(strString , target)
{
	//Call c++ function that accepts parameters 
	//that we made in our custom browser
	var paramExe="height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,titlebar=no,dependent=yes";
  var exp=new RegExp("explore|EXPLORE","g");
	var racineUrl = parent.location.href;
  racineUrl = racineUrl.split(exp);
  var link = racineUrl[0] + strString;
  if(link.match(".exe") != null)
  {
    if(fnIsOurCustomBrowser())
    {
      parent.external.mgeExec(link);
    }
    else
	  {
	   parent.open(link, target);//, paramExe);
	  }
  }
  else
	{
		parent.open(link, target, paramExe);
	}
}
	
/**
 * to show a screen shot
 * @param strString Name of picture file to open 
 * @param target target of window (_blank , _self ...)
 * @param width width in pixels of window
 * @param height height in pixels of window
 */

function PopupImage(img)
{
  titre="Screen Shot"; // onclick='window.close()' onblur='window.close()'
  w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes'); 
  w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>"); 
  w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+35,document.images[0].height+85); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>"); 
  w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
  w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>");
  w.document.write("<TD valign='middle' align='center'><IMG src='"+img+"' border='0' onclick='window.close()'>"); 
  w.document.write("</TD></TR></TABLE>");
  w.document.write("</BODY></HTML>"); 
  w.document.close();
}
 
function show(file,txt)
{
  document.mainImage.src = file;
  //document.mainImageLink.href = "big_"+file;
}
//Les parametre vont par 2 (lien vers l'image ; text du lien) 
function PopupImageMulti()
{
  if(PopupImageMulti.arguments.length > 1)
  {
    titre="Screen Shot";
    //w=open("",'image','width=550,height=500,toolbar=no,scrollbars=no,resizable=yes'); 
    //w=open("",'image','width=800,height=600,status=yes,toolbar=yes,scrollbars=yes,resizable=yes'); 
    w=open("",'image','width=800,height=600,status=no,toolbar=no,scrollbars=no,resizable=yes'); 
    w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE>");
    w.document.write("<link rel='stylesheet' href='../../mgepage.css' type='text/css'>"); 
    w.document.write("</HEAD>"); 
    w.document.write("<SCRIPT language=javascript>function checksize() { if (document.mainImage.complete) { window.resizeTo(document.mainImage.width+30,document.mainImage.height+70); window.focus();} else { setTimeout('checksize()',250) } }");
    w.document.write("function show(file) { document.mainImage.src = file; }</"+"SCRIPT>"); 
    w.document.write("<BODY leftMargin='20' topMargin='20' marginwidth='20' marginheight='20'>");
    w.document.write("<table width='300' border='0' cellspacing='0' cellpadding='0'><tr valign='top'>");
    w.document.write("<td colspan='2' height='6'><img src='../../images/tipage_pts.gif' width='40' height='1'></td>");
    w.document.write("</tr><tr><td width='300' class='titlepage'><b>Screen Shot</b></td></tr><tr>");
    w.document.write("<td colspan='2' height='6' valign='bottom'><img src='../../images/tipage_pts.gif' width='40' height='1'></td></tr></TABLE>");
    w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'>");
    w.document.write("<TR><TD height='50' width='700'>");
    for(var i = 0; i < PopupImageMulti.arguments.length ; i = i + 2 )
    {
      w.document.write("<img src='../../images/commun/puce_orange.gif' width='8' height='10' align='absmiddle' border='0'><a class='biglink' href=\"javascript:show('" + PopupImageMulti.arguments[i] + "');\">" + PopupImageMulti.arguments[i+1] + "</a>&nbsp;&nbsp;&nbsp;&nbsp;"); 
    }
    w.document.write("</TD></TD>");
    w.document.write("<TR>");
    //w.document.write("<TD valign='top' align='center'><a href='big_"+PopupImageMulti.arguments[0]"' id='mainImageLink' name='mainImageLink' border='0' target='_blank'>");
    //w.document.write("<IMG src='"+PopupImageMulti.arguments[0]+"' border=0  id='mainImage' name='mainImage' width='700'></a><BR>"); 
    w.document.write("<TD valign='top' align='center'><BR><span class='titlelevel2'><IMG src='"+PopupImageMulti.arguments[0]+"' border=0  id='mainImage' name='mainImage' width='700'><BR></SPAN>"); 
    w.document.write("</TD>");
    w.document.write("</TR>");
    w.document.write("</TABLE>");
    w.document.write("</BODY></HTML>"); 
    w.document.close(); 
  }
}

/*function PopupImageMulti()
{
  if(PopupImageMulti.arguments.length > 1)
  {
    titre="Screen Shot";
    //w=open("",'image','width=550,height=500,toolbar=no,scrollbars=no,resizable=yes'); 
    w=open("",'image','width=800,height=600,status=yes,toolbar=yes,scrollbars=yes,resizable=yes'); 
    //w=open("",'image','width=800,height=600,status=no,toolbar=no,scrollbars=no,resizable=yes'); 
    w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE>");
    w.document.write("<link rel='stylesheet' href='../../mgepage.css' type='text/css'>"); 
    w.document.write("</HEAD>"); 
    w.document.write("<SCRIPT language=javascript>function checksize() { if (document.mainImage.complete) { window.resizeTo(document.mainImage.width+30,document.mainImage.height+70); window.focus();} else { setTimeout('checksize()',250); } }");
    w.document.write("function show(file, filebig) { document.mainImage.src = file; document.mainImageLink.href = filebig; }"); 
    w.document.write("function PopupImage(img)");
    w.document.write("{");
    w.document.write("titre=\"Screen Shot\";");
    w.document.write("w=open(\"\",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');");
    w.document.write("w.document.write(\"<HTML><HEAD><TITLE>\"+titre+\"</TITLE></HEAD>\"); ");
    w.document.write("w.document.write(\"<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+35,document.images[0].height+85); window.focus();} else { setTimeout('checksize()',250) } }</\"+\"SCRIPT>\"); ");
    w.document.write("w.document.write(\"<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>\");");
    w.document.write("w.document.write(\"<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>\");");
    w.document.write("w.document.write(\"<TD valign='middle' align='center'><IMG src='\"+img+\"' border='0' onclick='window.close()'>\"); ");
    w.document.write("w.document.write(\"</TD></TR></TABLE>\");");
    w.document.write("w.document.write(\"</BODY></HTML>\"); ");
    w.document.write("w.document.close();}</"+"SCRIPT>");
    w.document.write("<BODY leftMargin='20' topMargin='20' marginwidth='20' marginheight='20'>");
    w.document.write("<table width='300' border='0' cellspacing='0' cellpadding='0'><tr valign='top'>");
    w.document.write("<td colspan='2' height='6'><img src='../../images/tipage_pts.gif' width='40' height='1'></td>");
    w.document.write("</tr><tr><td width='300' class='titlepage'><b>Screen Shot</b></td></tr><tr>");
    w.document.write("<td colspan='2' height='6' valign='bottom'><img src='../../images/tipage_pts.gif' width='40' height='1'></td></tr></TABLE>");
    w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'>");
    w.document.write("<TR><TD height='50' width='700'>");
    for(var i = 0; i < PopupImageMulti.arguments.length ; i = i + 3 )
    {
      w.document.write("<img src='../../images/commun/puce_orange.gif' width='8' height='10' align='absmiddle' border='0'><a class='biglink' href=\"javascript:show('" + PopupImageMulti.arguments[i] + "', '" + PopupImageMulti.arguments[i+2] + "');\">" + PopupImageMulti.arguments[i+1] + "</a>&nbsp;&nbsp;&nbsp;&nbsp;"); 
    }
    w.document.write("</TD></TD>");
    w.document.write("<TR>");
    w.document.write("<TD valign='top' align='center'><a href=\"javascript:PopupImage( '"+PopupImageMulti.arguments[2]+"');\" id='mainImageLink' name='mainImageLink' border='0'>");
    w.document.write("<IMG src='"+PopupImageMulti.arguments[0]+"' border=0  id='mainImage' name='mainImage' width='700'></a><BR>"); 
    //w.document.write("<TD valign='top' align='center'><BR><span class='titlelevel2'><IMG src='"+PopupImageMulti.arguments[0]+"' border=0  id='mainImage' name='mainImage' width='700'><BR></SPAN>"); 
    w.document.write("</TD>");
    w.document.write("</TR>");
    w.document.write("</TABLE>");
    w.document.write("</BODY></HTML>"); 
    w.document.close(); 
  }
}*/

function showScreenShot(strString , target, width , height)
{
	var paramSh="height=600,width=800,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,titlebar=no,dependent=yes";
  /*if(fnIsOurCustomBrowser())
	{
		/*var exp=new RegExp("images|IMAGES","g");
    temp = strString.split(exp);
    var link = "images" + temp[1];*/
    //fnShowModelessDialog(strString,0,0,width,height);
	//}else{
		show_screenShot(strString);
    //parent.open(strString,target,paramSh);
	//}
}
	
/**
 * to show a popup
 * @param strString Name of file to open 
 * @param target target of window (_blank , _self ...)
 */

function showPopUp(strString , target)
{
	var paramPopUp="height=200,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,titlebar=no,dependent=yes";
  if(fnIsOurCustomBrowser())
	{
		fnShowModelessDialog(strString,200,250,300,200);
	}else{
		parent.open(strString,target,paramPopUp);
	}
}
	
/**
 * to show licence
 * @param strString Name of licence file to open 
 * @param target target of window (_blank , _self ...)
 */
	
function showLicence(strString , target, file, OS)
{
	var param="height=600,width=600,status=no,toolbar=no,menubar=no,resizable=yes,location=no,scrollbars=yes,titlebar=no,dependent=yes";
	search=parent.location.search;
  search = setUrlParam(search,"file",file);
  search = setUrlParam(search,"os",traitement(osDetected));
  strString += setUrlParam(search,"typeOs",OS);
  if(fnIsOurCustomBrowser())
	{
    fnShowModelessDialog(strString,0,0,600,600);
		//fnOpenWindow(reconstructionLien(strString),0,0,800,600);
	}
  else
  {
		parent.open(strString,target,param);
	}
}

/**
 * to show licence
 * @param strString Name of licence file to open 
 * @param target target of window (_blank , _self ...)
 */
	
function showUnix(strString , target, file)
{
	var param="height=600,width=800,status=no,toolbar=no,menubar=no,resizable=yes,location=no,scrollbars=yes,titlebar=no,dependent=yes";
	search=parent.location.search;
  strString += setUrlParam("","file",file);
  if(fnIsOurCustomBrowser())
	{
    fnShowModelessDialog(strString,0,0,800,600);
	}
  else
  {
		parent.open(strString,target,param);
	}
}
	
/**
 * to show a documentation
 * @param strString Name of documentation file to open 
 * @param target target of window (_blank , _self ...)
 */
	 
function showDoc (strString , target)
{
  var param="status=no,toolbar=no,menubar=yes,resizable=yes,location=no,scrollbars=yes,titlebar=no,dependent=yes";
  if(fnIsOurCustomBrowser())
	{
    fnOpenWindow(strString,0,0,800,600);
	}else{
		parent.open(strString,target,param);
	}
}
	
/**
 * open a dependent window
 * @param strString Name of file to open 
 * @param target target of window (_blank , _self ...)
 */
	 
function openWindow(strString , target)
{
	var param="height=600,width=800,resizable=yes,status=no,menubar=no,location=no,toolbar=no,scrollbars=yes,dependent=yes,titlebar=no";  
  parent.open(strString,target,param); 
}

function openWindowTxt(strString , target)
{
	var param="height=600,width=800,resizable=yes,status=no,menubar=yes,location=no,toolbar=no,scrollbars=yes,dependent=yes,titlebar=no";  
  parent.open(strString,target,param); 
}
	
/**
 * Close a dependent window
 */
	 
function closeWindow()
{
	if(fnIsOurCustomBrowser())
	{
		parent.external.mgeClose();
	}else{
		parent.close();
	}
}
function detectNet()
{
  if(parent.location.href.match(".com") || parent.location.href.match("http://"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

function traitement(osSelected)
{
  if(osSelected.substring(0,3)=="Win")
  {
    osSelected="WIN";
  }
  if(osSelected.substring(0,3)=="Lin")
  {
    osSelected="LINUX";
  }
  if(osSelected.substring(0,3)=="Mac" || osSelected.substring(0,3)=="PPC")
  {
    osSelected="MAC";
  }
  if(osSelected.substring(0,2)=="HP")
  {
    osSelected="HPUX";
  }
  return osSelected;
}
