var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
  browser = "Konqueror";
  OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
  browser = "Netscape Navigator"
  version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
  if (checkIt('linux')) OS = "Linux";
  else if (checkIt('x11')) OS = "Unix";
  else if (checkIt('mac')) OS = "Mac"
  else if (checkIt('win')) OS = "Windows"
  else OS = "an unknown operating system";
}

function checkIt(string)
{
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}


function show(url,height)
{
	if (browserDetect() == 2)
	{
       		var tmp="";
       		var largeur = 500;
		var options;
		if (!height)
			height = 500;
		options = "scrollbars=1";

		var top=(screen.height-height)/2;
		var left=(screen.width-largeur)/2;
		window.open(url,"","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);

	}
	else
	{
		var mywin=window.open(url,"win",'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,titlebar=no,resizable=1,width=446,height=340,modal=yes');
		mywin.focus();
	}
}

function checkCR(evt)
{
  var evt  = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;

function showUrl(url)
{

var prefixExiste = new Boolean(false);
var prefix = "";

if ( url == '')
{
	alert("Entrer l'adresse du site Web");
}
else
{
	var http = url.substring(0,7);
	var https = url.substring(0,8);
	if ( http == "http://" )
	{
      prefixExiste = true;
	}
	else
	if ( https == "https://" )
	{
      prefixExiste = true;
	}
	else 
	{
      prefix = "http://";
	}

	if (browserDetect() == 2)
	{
      var tmp="";
      var largeur = 700;
      var height = 400;
	  var options;
			
      options = "dialogHeight:" + height + "px;status=0;scroll=no;titlebar=false;resizable=1;center:yes;help:no;unadorned=no";

      var top=(screen.height-height)/2;
	  var left=(screen.width-largeur)/2;

      window.open(prefix +url,"","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);
	}
	else
	{
      parent.window.open(prefix +url,"win",'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,titlebar=no,resizable=1,width=446,height=340,modal=yes');
	}
	}
}

function showFile(url)
{
if ( url == '')
{
	alert("Entrer l'adresse du site Web");
}
else
{
	if (browserDetect() == 2)
	{
      var tmp="";
      var largeur = 800;
      var height = 600;
	  var options;
			
      options = "dialogHeight:" + height + "px,status=0,scrollbars=yes,titlebar=false,resizable=no,center=yes,help=no,unadorned=no";

      var top=(screen.height-height)/2;
	  var left=(screen.width-largeur)/2;
	
      window.open(url,"","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);
	}
	else
	{
      parent.window.open(url,"win",'toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,titlebar=no,resizable=no,width=800,height=600,modal=yes');
	}
	}
}

//********************************************
// Calcul nb de pages selon nb caractères
//********************************************

//********************************************
// Confirmation suppression
//********************************************


function confirmClose()
{
	var agree=confirm(" Vos données seront perdues, si vous n'avez pas enregistré.");
	if (agree)
	{
		document.forms[0].action = "./common.bo?cmd=close";
		document.forms[0].submit();
	}
	else
		return false ;
}

function browserDetect()
{
  if(browser=="Internet Explorer")
  {
    return 2;  // MSIE4+
  }
  if(browser=="Netscape Navigator")
  {
    return 1;  // NN4+
  }
  return 0;
}

//************************************************************************
// Fonction pour inserer une nouvelle personne dans la liste des detenteurs de 
// la parcelle
//************************************************************************


function controlForm(url,isnew)
{
		if ( isnew == "true" )
		{
			alert("Vous devez enregistrer votre fiche avant d'effectuer cette opération");
		}
		else
		{
			document.forms[0].action = "./"+url;
			document.forms[0].submit();
		}
}


// Controle si un document a été choisi

function controldocument(url)
{
 	var fileType = document.forms[0].fileType.value;
 	
 	if ( fileType.length ==0 )
 	{
 		alert("Un document doit être chargé");
 	}	
 	else
 	{

			document.forms[0].action = "./"+url;
			document.forms[0].submit();
 	}
}

// Controle si le password et sa confirmation sont identique
function controlpassword(url)
{
 	var password = document.forms[0].pwd.value;
 	var passwordrepeat = document.forms[0].pwdrepeat.value; 

 	if ( password.length ==0 )
 	{
 		alert("Mot de passe obligatoire");
 	}	
 	else
 	{
 	
 		if ( password != passwordrepeat)
	 	{
 			alert("Champ de confirmation du mot de passe différent");
 		}
 		else
		{
			document.forms[0].action = "./"+url;
			document.forms[0].submit();
		}
 	}
}


function suppression(url)
{
		var todo = confirm("Vous allez supprimer cet élément");
		
		if ( todo == true)
		{

		document.forms[0].action = "./"+url;
		document.forms[0].submit();
		
		}
}

function removeKeyword(url)
{

var checked = "";


for (var i = 0;i < document.forms[0].listKeyword.length; i++) {

if (document.forms[0].listKeyword[i].checked == true)
{
  checked = "checked";
}

}


	if ( checked == "" )
	{
		alert("Aucun mot-clé sélectionné");
	}
	else
	{
		
		var todo = confirm("Vous allez supprimer ce(s) mot(s)-clé(s)");
		
		if ( todo == true)
		{
		document.forms[0].action = "./"+url;
		document.forms[0].submit();
		}
	}
	
}

function envoieForm(url)
{
		document.forms[0].action = "./"+url;
		document.forms[0].submit();
}
function envoieFormPoleCompet(url)
{
		document.forms[0].focusForm.value="focus1";
		document.forms[0].action = "./"+url;
		document.forms[0].submit();
}

function visualize(url)
{


  var height=500;
  var largeur = 500;
  var top=(screen.height-height)/2;
  var left=(screen.width-largeur)/2;
  var options = "scrollbars=1";

  var nom = document.forms[0].nom.value;
  var beginDte = document.forms[0].beginDte.value;
  var endDte = document.forms[0].endDte.value;
  var annee = document.forms[0].annee.value;
  var go = document.forms[0].go.value;
  var version = document.forms[0].version.value;
  
  var url = url +"?nom="+nom+"&beginDte="+beginDte+"&endDte="+endDte+"&go="+go+"&annee="+annee+"&version="+version ;

  window.open(url,"","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);

}

function modif(url,incde,label)
{

	var target = url+"&inCde="+incde+"&dscKeyword="+label;
	
	if (browserDetect() == 2)
	{
		
      		var tmp="";
       		var largeur =250;
		    var options;
	
		 	height = 50;
		    options = "menubar=0,scrollbars=0";

		 var top=(screen.height-height)/2;
		 var left=(screen.width-largeur)/2;
		window.open(target,"","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);

	}
	else
	{
	
		 var mywin=window.open(target,"win",'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,titlebar=no,resizable=1,width=446,height=340,modal=yes');
		 mywin.focus();
	}

	
}

function bilan(url)
{
  var height=500;
  var largeur = 500;
  var top=(screen.height-height)/2;
  var left=(screen.width-largeur)/2;
  var options = "scrollbars=1";
  

  window.open("aap.bo?cmd=createBilan","","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);

}

function envoieRefForm(url,blocName)
{
  document.forms[0].action = "./"+url;

  document.forms[0].submit();
}

function executeForm(cmd, url)
{
  var urlTotal = url+"?cmd="+cmd;

		  document.forms[0].action =  urlTotal;
		  document.forms[0].submit();

}

function upLoadFile(cmd, url, type)
{

  var urlTotal = url+"?cmd="+cmd+"&type="+type;
  document.forms[0].action =  urlTotal;
  document.forms[0].submit();

}

function executePage(value,url)
{
  var urlTotal = url+"&inCde="+value;

  document.forms[0].action = "./"+ urlTotal;
  document.forms[0].submit();
}

function execute(value,url)
{
  var urlTotal = url+"&inCde="+value;

  document.forms[0].action = "./"+ urlTotal;
  document.forms[0].submit();
}


function executeTransform(url)
{

var todo = confirm("Vous allez transformer cette proposition en projet");
		
		if ( todo == true)
		{

		 document.forms[0].action = "./"+url;
  		 document.forms[0].submit();
		
		}
}



function executeDelete(value,url)
{

var todo = confirm("Vous allez supprimer cet élément");
		
		if ( todo == true)
		{

		 document.forms[0].action = "./"+url+"&inCde="+value;
  		 document.forms[0].submit();
		
		}
 
}



function envoie(url)
{
	window.location.href = ""+url;
}


//************************************************************************
// Fonction pour choisir les groupes opératoires 
//************************************************************************

function selection()
{
		
 popupcentree('./principal.jsp','500','300','menubar=no,scrollbars=no,statusbar=no');
		
}

//************************************************************************
// Fonction pour ouvrir une popup
//************************************************************************

function popupcentree(page,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function removeTheme(inCde)
{
  document.forms[0].action = "./groupeOp.bo?cmd=removeTheme&inCde="+inCde;
  document.forms[0].submit();
}


// -----------------------------------------
// Fonction permettant de minimiser un layer
function minimize(x,ctl){
	x.style.display="none";
	ctl.outerHTML="<div id="+ctl.id+"><img src='./image/down.gif' Onclick='maximize("+x.id+","+ctl.id+");' ></div>";
}

// -----------------------------------------
// Fonction permettant de maximiser un layer	
function maximize(x,ctl){
	x.style.display="inline";
	ctl.outerHTML="<div id="+ctl.id+"><img src='./image/up.gif' Onclick='minimize("+x.id+","+ctl.id+");' ></div>";
}

function rollIn(el){
	el.initstyle=el.style.cssText;
	el.style.cssText="background-color: #669999;FONT-WEIGHT: normal;COLOR: #FFFFFF";
}

function rollOut(el){
	el.style.cssText=el.initstyle;
}
function warning(message, url){
  var isConfirm = confirm(message);
  if(isConfirm)
    window.location.href = ""+url;
  else
    return false ;
}

function executeSoumettre(url)
{

var todo = confirm("Vous allez soumettre votre proposition, vous ne pourrez plus la modifier. Confirmez-vous ? ");
		
		if ( todo == true)
		{

		 document.forms[0].action = "./"+url;
  		 document.forms[0].submit();
		
		}
}

function executeAddGrandProjet(url)
{
		 document.forms[0].action = "./"+url;
  		 document.forms[0].submit();
}


function executeSupprimer(url)
{

var todo = confirm("Vous allez supprimer votre proposition. Confirmez-vous ? ");
		
		if ( todo == true)
		{

		 document.forms[0].action = "./"+url;
  		 document.forms[0].submit();
		
		}
}

function executeSupprimer2(url)
{

var todo = confirm("Vous allez supprimer votre partenaire. Confirmez-vous ? ");
		
		if ( todo == true)
		{

		 document.forms[0].action = "./"+url;
  		 document.forms[0].submit();
		
		}
}



function executeImprimer(url)
{

 			 if (browserDetect() == 2)
				{
			       	var largeur = 1;
			       	var height = 1;
					var options;
					options = "";

						var top=10000;
						var left=10000;
						window.open(url,"Impression","top="+top+",left="+left+",width="+largeur+",height="+height+","+options);
				}
			else
			{
				var mywin=window.open(url,"Impression",'screenX=10000,screenY=10000,toolbar=0,location=0,status=0,menubar=0,scrollbars=no,titlebar=no,resizable=no,width=1,height=1,modal=yes');
				mywin.focus();
			}
		
	
}


	function textCounter( field, maxlimit ) {
	  if ( field.value.length > maxlimit )
	  {
  	    field.value = field.value.substring( 0, maxlimit );
	    alert( 'Le texte que vous avez saisi est trop long.' );
	    return false;
	  }
	}
