function detectBrowserType () {
  var check;
  var start;
  var pos;

  var check2;
  var start2;
  var pos2;

  var detectGecko;
  var detectNetscape;
  var detectComplete;
  
  var browser;
  var agt;

  browser = (navigator.appName);
  agt = (navigator.userAgent);
  detectComplete = "no";
  
  //Détection d'opera
  start = 0;
  pos = 0;
  if (detectComplete != "yes") {
    while ((pos < agt.length) && (pos != -1)) {
	  pos = agt.indexOf('O', start);
   	  check = agt.charAt(pos) + agt.charAt(pos+1) + agt.charAt(pos+2) + agt.charAt(pos+3) + agt.charAt(pos+4);
   
   	  if (check == "Opera") { //Opera détecté
   	    codeBrowser = "Opera";
	    pos = agt.lenght+1; //fin exécution du while
	    detectComplete = "yes";
   	  }
	  
  	  else { //Opera non-détecté
   	    start=pos+1;  
   	  }		  
    }
  } 

  //Détection de MSIE
  if (detectComplete != "yes") {  //Si Opera a déjà été détecté, ce test ne sera pas effectué.  
  	 				 		   	  //Sinon comme le test de détection d'Opera a déjà été effectué, ce test-ci sera fiable 
    if (browser == "Microsoft Internet Explorer") {
	  codeBrowser = "MSIE";
	  detectComplete = "yes";
	}
  
  } 

  //Détection de Netscape ET Mozilla
  start = 0;
  pos = 0;
  detectGecko = "no";
  detectNetscape = "no";
  if (detectComplete != "yes") {  //Si Opera a déjà été détecté, ce test ne sera pas effectué.  
  	 				 		   	  //Sinon comme le test de détection d'Opera a déjà été effectué, ce test-ci sera fiable
								  
    if (browser == "Netscape") {  //Mozilla OU Netscape détecté
	  while ((pos < agt.length) && (pos != -1)) {
	    pos = agt.indexOf('G', start);
   	  	check = agt.charAt(pos) + agt.charAt(pos+1) + agt.charAt(pos+2) + agt.charAt(pos+3) + agt.charAt(pos+4); 
        if (check == "Gecko") { //Mozilla OU Netscape 6+ détecté
		  detectGecko = "yes";
          // 2ème test requis pour faire la différence entre Mozilla et Netscape
          pos2 = pos;
		  start2 = pos;
		  while ((pos2 < agt.length) && (pos2 != -1)) {
		    pos2 = agt.indexOf('N', start2);
		  	check2 = agt.charAt(pos2) + agt.charAt(pos2+1) + agt.charAt(pos2+2) + agt.charAt(pos2+3) + agt.charAt(pos2+4) + agt.charAt(pos2+5) + agt.charAt(pos2+6) + agt.charAt(pos2+7);
		  	if (check2 == "Netscape") {
		  	  detectNetscape = "yes";
			  pos2 = agt.lenght+1; //fin exécution du while pour pos2
		  	}
		    else { //Netscape non-détecté
   	    	  start2=pos2+1;  
   	  		}		
		  }
		 pos = agt.lenght+1; //fin exécution du while pour pos	  
		}
        else { //Gecko non-détecté
   	    start=pos+1;  
   	    }	
      }
	  if ((detectGecko == "no" && detectNetscape == "no") || (detectGecko == "yes" && detectNetscape == "yes")) {
	    codeBrowser = "Netscape";
	    detectComplete = "yes";
	  }
	  if (detectGecko == "yes" && detectNetscape == "no") {
	    codeBrowser = "Mozilla";
	    detectComplete = "yes";
	  }
    }								  
  }		

  if (detectComplete =="yes") {
  return codeBrowser;
  //alert (codeBrowser);
  }
  else {
  return "Unknown";
  //alert("Unknown");
  }
			
}  //End detectBrowserType



//______________________________________________________________________________


function detectOperaVersion () {  //Only if browser Opera is yet detected
  var check;
  var start;
  var pos;
  
  var start2;
  var pos2;

  var agt =(navigator.userAgent);
  var codeVersion;
  
  start = 0;
  pos = 0;
  while ((pos < agt.length) && (pos != -1)) {
    pos = agt.indexOf('O', start);
   	check = agt.charAt(pos) + agt.charAt(pos+1) + agt.charAt(pos+2) + agt.charAt(pos+3) + agt.charAt(pos+4)+agt.charAt(pos+5);
   
   	if ((check == "Opera ") || (check == "Opera/")) { //Opera détecté
	  codeVersion = "";
   	  start2 = pos+6;
	  pos2 = agt.indexOf('.', start2+1);
	  for (var i = start2; i < pos2; i++) {
	    codeVersion = codeVersion + agt.charAt(i);
      }
	  pos = agt.length+1;  		 
   	}
	  
  	else { //Opera non-détecté
   	  start=pos+1;  
   	}		  
  }
  return codeVersion;
} // End detectOperaVersion


//______________________________________________________________________________


function detectMSIEVersion () {  //Only if browser MSIE is yet detected
  var check;
  var start;
  var pos;
  
  var start2;
  var pos2;

  var version =(navigator.appVersion);
  var codeVersion;
  start = 0;
  pos = 0;
  while ((pos < version.length) && (pos != -1)) {
    pos = version.indexOf('M', start);
   	check = version.charAt(pos) + version.charAt(pos+1) + version.charAt(pos+2) + version.charAt(pos+3) + version.charAt(pos+4);
   
   	if (check == "MSIE ") { //MSIE détecté
	  codeVersion = "";
   	  start2 = pos+5;
	  pos2 = version.indexOf('.', start2+1);
	  for (var i = start2; i < pos2; i++) {
	    codeVersion = codeVersion + version.charAt(i);
      }
	  pos = version.length+1;  		 
   	}
	  
  	else { //MSIE non-détecté
   	  start=pos+1;  
   	}		  
  }
  return codeVersion;
} // End detectMSIEVersion




//______________________________________________________________________________


function detectNetscapeVersion () {  //Only if browser Netscape is yet detected
  var start;
  var pos;

  var check2;
  var start2;
  var pos2;

  var version=(navigator.appVersion);
  var agt =(navigator.userAgent);
  
  var codeVersion;
  
  start = 0;
  pos = 0;
  pos = version.indexOf('.', start);
  if ((pos > 0) && (pos != -1)) {
    codeVersion = "";
    for (var i = 0; i < pos; i++) {
      codeVersion = codeVersion + version.charAt(i)
    }  //fin for
	if (codeVersion <= 4) { //OK
  	  return codeVersion;
	  //alert(codeVersion);	
	}
	else {  //Netscape 6, 7, ...
	  codeVersion = "";
	  start2 = 0;
      pos2 = 0;
	  while ((pos2 < agt.length) && (pos2 != -1) && (check2 != "Netscape")) {
	    pos2 = agt.indexOf('N', start2);
	    check2 = agt.charAt(pos2) + agt.charAt(pos2+1) + agt.charAt(pos2+2) + agt.charAt(pos2+3) + agt.charAt(pos2+4) + agt.charAt(pos2+5) + agt.charAt(pos2+6) + agt.charAt(pos2+7);
	    if (check2 == "Netscape") { 
		  start = agt.indexOf('/', pos2)+1;
		  pos = agt.indexOf('.', start);
		  for (var i = start; i < pos; i++) {
		    codeVersion = codeVersion + agt.charAt(i);
      	  }  		 
	    } //fin if pour check 2
		else {
		pos2 = pos2+1;  
		}
	  } 
       //alert(codeVersion);
	   return codeVersion;
	  
	} //Fin test Netscape 6
	
  }  
  else {
  return "Unavailable";
  //alert ("Unavailable");
  }
}  //End detectNetscapeVersion

//______________________________________________________________________________


function detectNetscapeSubVersion (codeVersion) {  //Only if browser Netscape is yet detected and version known
  var start;
  var pos;

  var check2;
  var start2;
  var pos2;

  var version=(navigator.appVersion);
  var agt =(navigator.userAgent);
  
  var codeSubVersion;
  
  if (codeVersion <= 4) { 
    // utiliser "version"
    start = 0;
	pos = 0;
    codeSubVersion = "";  
    pos = version.indexOf('.', start)+1;
  
    while (version.charAt(pos) != " ") {
	codeSubVersion = codeSubVersion + version.charAt(pos);
	pos=pos+1;
    }
     
  
  }
  else {  //Netscape 6, 7, ...
    //utiliser "agt"
    start = 0;
	pos = 0;
    start2 = 0;
    pos2 = 0;
	  
	codeSubVersion = "";
	
	while ((pos2 < agt.length) && (pos2 != -1) && (check2 != "Netscape")) {
	  pos2 = agt.indexOf('N', start2);
	  check2 = agt.charAt(pos2) + agt.charAt(pos2+1) + agt.charAt(pos2+2) + agt.charAt(pos2+3) + agt.charAt(pos2+4) + agt.charAt(pos2+5) + agt.charAt(pos2+6) + agt.charAt(pos2+7);
	  if (check2 == "Netscape") { 
		start = agt.indexOf('.', pos2)+1;
		pos = agt.indexOf('.', start+1);
		if (pos == -1) {
		pos = agt.length;
		}
		
		for (var i = start; i < pos; i++) {
		  codeSubVersion = codeSubVersion + agt.charAt(i);
      	}  		 
	  } //fin if pour check 2
      else {
        pos2 = pos2+1;  
	  }
	} 
  }
   //alert(codeSubVersion);
   return codeSubVersion;
}  //End detectNetscapeSubVersion


//______________________________________________________________________________


function detectMozillaVersion () {  //Only if browser Mozilla is yet detected
  var check;
  var start;
  var pos;
  
  var start2;
  var pos2;

  var agt =(navigator.userAgent);
  var codeVersion;
  start = 0;
  pos = 0;
  while ((pos < agt.length) && (pos != -1)) {
    pos = agt.indexOf('r', start);
   	check = agt.charAt(pos) + agt.charAt(pos+1) + agt.charAt(pos+2);
   
   	if (check == "rv:") { //Mozilla détecté
	  codeVersion = "";
   	  start2 = pos+3;
	  pos2 = agt.indexOf('.', start2+1);
	  for (var i = start2; i < pos2; i++) {
	    codeVersion = codeVersion + agt.charAt(i);
      }
	  pos = agt.length+1;  		 
   	}
	  
  	else { //Mozilla non-détecté
   	  start=pos+1;  
   	}		  
  }
  return codeVersion;
}
