	/**
	*	Fonctions pour les images
	*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function valide_recherche ()
{
	document.form_main.form_valide.value = "1";
	document.form_main.submit();
}

function rech_avancee()
{
	document.form_main.action = "recherche.jsp#rech_plus";
	document.form_main.rech_avance.value = "1";
//	document.getElementById("rech_avance").value="1";
	document.form_main.submit();
}

function resultListe()
{
	document.form_main.action="resultat.jsp";
	document.form_main.style_res.value = "2";
	document.form_main.submit();
}

function resultListeDet()
{
	document.form_main.action="resultat.jsp";
	document.form_main.style_res.value = "3";
	document.form_main.submit();
}

function resultCat()
{
	document.form_main.action="resultat.jsp";
	document.form_main.style_res.value = "1";
	document.form_main.submit();
}

function rech_genre()
{
	document.form_main.action = "recherche.jsp#ank2";
	document.form_main.submit();
}

function enable_view() 
{
	if (document.getElementById("resHaut")) document.getElementById("resHaut").style.display="block";
}


function openZoom(param,id_vo) {
	tab = param.split("_");
	
	if (tab[0]=="m") {
		var w = window.open("popup_visu.jsp?num="+tab[1]+"&id_vo="+id_vo,"TruckPlus",'width=850,height=600,scrollbars=yes');
		if (!w)
			alertAntiPopup();
	}else{
		var w = window.open("popup_visu.jsp?id_photo="+param,"TruckPlus",'width=850,height=600,scrollbars=yes');	
		if (!w)
			alertAntiPopup();	
	}
}

function changeProx()
{
	document.getElementById("distributeur").value="-1";
	document.getElementById("flag_distr_chang").value="1";
	document.form_main.submit()
}

function valideVisibilite()
{
	document.frmMain.action="do_save_visibilite.jsp";
	document.frmMain.submit();
}

function validePrix()
{
	document.frmMain.action="do_save_prix.jsp";
	document.frmMain.submit();
}

function validePrixVisible()
{
	document.frmMain.action="do_save_prix_visible.jsp";
	document.frmMain.submit();
}

function doExtractStock()
{
	if(extractStockCheckSelection())
	{
		document.frmMain.action="do_extract_stock.jsp";
		document.frmMain.submit();
	}
}
// Cr?ation objet AJAX pour le rechargement des options
var xhr = null; 
	 
function getXhr(){
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else { // XMLHttpRequest non support? par le navigateur 
	   //alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
}

// rechargement du menu d?roulant modele en fonction du genre, ou de la marque
function rech_modele(from)
{	
	getXhr(); // cr?e un objet xhr si possible	
	if(xhr != null)
	{
		// On d?fini ce qu'on va faire quand on aura la r?ponse
		xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout re?u et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				listemodelelocalisee = xhr.responseText;
				document.getElementById('sel_modele').innerHTML = listemodelelocalisee;	
			}
		}
		xhr.open("POST","ajax_listemodeles.jsp",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		idlangue = document.form_main.langue_id.value;		
		
		selgenre = document.getElementById('genre');
		// PATCH CAMION REMORQUE
		if(selgenre.value == 15) idgenre = "6";
		else idgenre = selgenre.value;
		
		selmarque = document.getElementById('marque');

		mylist="";
		for(i=0;i<selmarque.length;i++)
		{
			if (selmarque.options[i].selected)
			{
				mylist=mylist+selmarque.options[i].value+";";
			}
		}
		idmarque = mylist;
		
		param = "idLangue=" + idlangue;
		
		if ( idmarque.indexOf ( "-1", 0 ) == -1 )
			param += "&idMarque=" + idmarque;
			
		if ( idgenre.indexOf ( "-1", 0 ) == -1 )
			param += "&idGenre=" + idgenre;
			
		//param = "idMarque="+idmarque+"&idLangue="+idlangue+"&idGenre="+idgenre;
		//alert ( 'param : ' + param );
		//Window.open("ajax_listemodeles.jsp"+param);
		xhr.send(param);
	}		
}


// cherche le type en fonction du modele
function rech_type ()
{	
	if (document.getElementById('rech_avance').value=="1")
	{
		getXhr(); // cr?e un objet xhr si possible	
		if(xhr != null)
		{
			// On d?fini ce qu'on va faire quand on aura la r?ponse
			xhr.onreadystatechange = function()
			{
				// On ne fait quelque chose que si on a tout re?u et que le serveur est ok
				if(xhr.readyState == 4 && xhr.status == 200)
				{
					listetypelocalisee = xhr.responseText;
					document.getElementById('sel_type').innerHTML = listetypelocalisee;
				}
			}
			xhr.open("POST","ajax_listetype.jsp",true);
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			
			idlangue = document.form_main.langue_id.value;
			selmodele = document.getElementById('modele');
			
			mylist="";
			for(i=0;i<selmodele.length;i++)
			{
				if (selmodele.options[i].selected)
				{
					mylist=mylist+selmodele.options[i].value+";";
				}
			}
			idmodele = mylist;
			param = "idModele="+idmodele+"&idLangue="+idlangue;
			//Window.open("ajax_listetype.jsp?"+param);
			xhr.send(param);
		}
	}
}


function decoche()
{
	if (document.getElementById("vhc_promo").checked ==true)
	{
		if (document.getElementById("vhc_occasion").checked == true) 		document.getElementById("vhc_occasion").checked=false;
		if (document.getElementById("vhc_neuf").checked == true) 			document.getElementById("vhc_neuf").checked=false;
		if (document.getElementById("vhc_occasion_piece").checked == true) 	document.getElementById("vhc_occasion_piece").checked=false;
		if (document.getElementById("vhc_vendu").checked == true) 			document.getElementById("vhc_vendu").checked=false;
		if (document.getElementById("vhc_arentrer").checked == true) 		document.getElementById("vhc_arentrer").checked=false;						
	}
}

function retourRech()
{
	document.form_main.action="recherche.jsp";
	document.form_main.submit();
}
function goSelection()
{
	document.form_main.action="recherche.jsp";
	document.form_main.submit();
}

function ajoute_panier ()
{
	document.form_main.form_ajout.value = "1";
	document.form_main.submit();
}
function instr_dossier (_id_vhc)
{
//	notAvailable ();

	document.form_main.action = "demande_info.jsp";
	document.form_main.submit();
}
function acces_cotation(message)
{
	alert(message);
	return;
}

function prop_comm (_id_ddp)
{
	var action = "prop_comm.jsp";
	if (_id_ddp > 0) action += "?ddp="+_id_ddp;
	document.form_main.action = action;
	document.form_main.submit();
}

function voirFiche(_id_vhc)
{
	document.getElementById("id_vhc_on").value=_id_vhc;
	document.form_main.action="fiche.jsp";
	document.form_main.submit();
}

//********************
// Message du reseau
//********************
function voirMessage( mes_id )
{
	document.frmMain.action="message_detail.jsp?mes_id=" + mes_id;
	document.frmMain.submit();
}
function newMessage ()
{
	document.frmMain.action="message_add.jsp?Rub=17";
	document.frmMain.submit();
}

//*********
// Contacts
//*********
function voirContact( id_ctc )
{
	document.frmMain.action="contact_add.jsp?ctc_id=" + id_ctc + "&viewonly=1";
	document.frmMain.submit();
}

function newContact ()
{
	document.frmMain.action="contact_add.jsp";
	document.frmMain.submit();
}

function modifContact ( id_ctc )
{
	document.frmMain.action="contact_add.jsp?ctc_id=" + id_ctc;
	document.frmMain.submit();
}

function addContactFromDDP ( id_ddp )
{
	document.frmMain.action="contact_add.jsp?Rub=16&ddp_id=" + id_ddp + "&from=demande_prospect.jsp";
	document.frmMain.submit();
}

function changeNbRes(_nb_par_page)
{
	document.getElementById("nbparpage").value = _nb_par_page;
	document.form_main.submit();
}

function aff_panier()
{
	document.form_main.form_ajout.value = "1";
	document.form_main.action= "panier.jsp";
	document.form_main.submit();
}

function aff_panier_liste()
{
	document.form_main.form_valide.value="1";
	document.form_main.action= "panier.jsp";
	document.form_main.submit();
}


function gotoExpertise()
{
	document.getElementById("backUrl").value = "expertise.jsp";
	checkAllField();
}

function gotoGestionCamions()
{
	document.getElementById("backUrl").value = "gestion_camions.jsp" ;
	checkAllField();
}

function gotoGestionCamionsFromPneumatique()
{
	document.getElementById("backUrl").value = "gestion_camions.jsp" ;
	document.form_pneumatique.action= "do_save_pneumatique.jsp";
	document.form_pneumatique.submit ();
}

function affPrix(_prix_euro, _prix_loc, _proprio)
{
	var strStat = _proprio+' -- '+_prix_euro + " euros";
	if ( (_prix_loc!="") && (_prix_loc>0))
		strStat +="  -- "+_prix_loc;
	window.status=strStat;
}

function cachePrix()
{
	window.status="";
}


// affichage soit de la selection soit des criteres de la demande de prospect
function viewDDP(_ddp_id)
{	
	getXhr(); // cr?e un objet xhr si possible	
	if(xhr != null)
	{
		// On d?fini ce qu'on va faire quand on aura la r?ponse
		xhr.onreadystatechange = function(){
			// On ne fait quelque chose que si on a tout re?u et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200){
				var choix = xhr.responseText;
//				alert(choix);
				if (choix == 1)
					sendPanierProspect(_ddp_id);
				else
					viewCritere(_ddp_id);
			}
		}
		xhr.open("POST","ajax_dde_prospect.jsp",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		param = "ddp_id="+_ddp_id;		
//		window.open("ajax_dde_prospect.jsp?"+param);
		xhr.send(param);
	}		
}

function viewCritere(_ddp_id)
{
	document.frmMain.action="ddp_critere.jsp";
	document.getElementById("ddp").value= _ddp_id;
	document.frmMain.submit();

}
function viewRechProspect(_ddp_id)
{
	document.form_main.action="ddp_rech.jsp";
	document.getElementById("ddp").value= _ddp_id;
	document.form_main.submit();
}
function modifProspect(_ddp_id)
{
	document.frmMain.action="modif_prospect.jsp";
	document.getElementById("ddp_id").value= _ddp_id;
	document.frmMain.submit();
}
function valideModifProspect()
{
	document.form_main.submit();
}

//**************************
// Fonction pour le datagrid
//**************************

//------------------------
// Permet de naviguer dans
// une DGRID
//------------------------
function doNavigate( pstrWhere, pintTot )
{
  var strTmp;
  var intPg; 
  strTmp 	= document.frmMain.txtCurr.value;
  intPg 	= parseInt(strTmp);
  if (isNaN(intPg)) intPg = 1; 

  if ((pstrWhere == 'F' || pstrWhere == 'P') && intPg == 1)
    return;
  else if ((pstrWhere == 'N' || pstrWhere == 'L') && intPg == pintTot)
    return;

  if (pstrWhere == 'F')
    intPg = 1;
  else if (pstrWhere == 'P')
    intPg = intPg - 1;
  else if (pstrWhere == 'N')
    intPg = intPg + 1;
  else if (pstrWhere == 'L')
    intPg = pintTot; 
  else if (!isNaN(pstrWhere))
	  intPg= pstrWhere ;

  if (intPg < 1) intPg = 1;
  if (intPg > pintTot) intPg = pintTot;
  document.frmMain.txtCurr.value = intPg;
  document.frmMain.submit();
}

//-----------------------------
// Effectue un tri sur la DGRID
//-----------------------------
function doSort( _formname, pstrFld, pstrOrd )
{
	var form = eval ( "document." + _formname );

	// Si la column n'est pas pr?sente on l'ajoute
	if ( form.txtSortCol.value.indexOf( pstrFld, 0 ) == -1 )
	{
		if ( form.txtSortCol.value != "" )
			form.txtSortCol.value += ";";
		form.txtSortCol.value += pstrFld;

		if ( form.txtSortAsc.value != "" )
			form.txtSortAsc.value += ";";
		form.txtSortAsc.value += pstrOrd;
	}
	// Sinon on modifie l'ordre
	else
	{
		var tab = form.txtSortCol.value.split ( ";" );
		var num = -1;
		
		// Recherche de l'index de la columne
		for ( var i=0; i < tab.length; i++ )
		{
			if ( tab[ i ] == pstrFld )
				num = i;
		}
		
		// Parcours du tableau de l'ordre pour inverser
		// celui correspondant a la column
		var tab2 = form.txtSortAsc.value.split ( ";" );
		if ( ( num > -1 ) && ( num < tab2.length ) )
		{
			if ( tab2 [ num ] == "ASC" )
				tab2 [ num ] = "DESC";
			else
				tab2 [ num ] = "ASC";
		}
		
		// Recomposition du param
		var concat = "";
		for ( var j=0; j < tab.length; j++ )
		{
			if ( concat != "" )
				concat += ";";
			concat += tab2[ j ];
		}
		
		form.txtSortAsc.value = concat;
	}

	// Envoie du formulaire
	form.submit();
}

//----------------------
// Initialisation du tri
//----------------------
function initTri( _formname )
{
	var form = eval ( "document." + _formname );

	form.txtSortCol.value = "INIT_DGRID";
	form.txtSortAsc.value = "INIT_DGRID";
	form.submit();
}


//*****************
// Fonctions utiles
//*****************
function changeNbResList(_nb_par_page)
{
	document.getElementById("nbparpage").value = _nb_par_page;
	document.form_main.submit();
}

//******************
// Fonction de popup
//******************
function popupCotation ( _params )
{
	var params = _params;
	
	if ( ! IsVoid ( "kma" ) )
	{
		_params += "&kms_reel=" + document.getElementById ( "kma" ).value;
	}
	
	if ( ! IsVoid ( "ndo" ) )
	{
		_params += "&num_dossier=" + document.getElementById ( "ndo" ).value;
	}

	if ( ! IsVoid ( "mec" ) )
	{
		_params += "&date_mec=" + document.getElementById ( "mec" ).value;
	}
	
	var w = window.open("cotation_stock.jsp?"+ _params, "", "width=650,height=530");	
	if (!w)
		alertAntiPopup();
	
}

function openExp(_id_exp)
{
	var w = window.open("popup_exp.jsp?id_exp="+_id_exp, "", "width=665,height=600,scrollbars=yes");
	if (!w)
		alertAntiPopup();
}
function openCotVehiAsso(_id_typ,isCrossGenreCR)
{
	// PATCH PORTEUR REMORQUE
	var w = window.open("cotation_popup.jsp?id_typ="+_id_typ+"&cross_genre_cr="+(isCrossGenreCR?1:0), "", "width=500,height=600");
	//var w = window.open("cotation_popup.jsp?id_typ="+_id_typ, "", "width=500,height=600");
	if (!w)
		alertAntiPopup();
	
}
function openCotationStock(_id_vhc)
{
	var w = window.open("cotation_stock.jsp?vhc="+_id_vhc, "", "width=650,height=530");
	if (!w)
		alertAntiPopup();
}

function openFicheParebriseConfig ( vhc_id )
{
	var w = window.open("popup_parebrise_config.jsp?vhc=" + vhc_id, "", "width=540,height=580,resizable=yes,menubar=yes,scrollbars=yes");
	if (!w)
		alertAntiPopup();
}

function openCat(cg)
{
	var w = window.open("popup_cat.jsp?cg="+cg, "", "width=650,height=600");
	if (!w)
		alertAntiPopup();
}

function openPropale(ddp)
{
	var w = window.open("popup_propale.jsp?ddp="+ddp+"&height=500&width=750&keepThis=true&TB_iframe=true", "", "width=650,height=600");
	if (!w)
		alertAntiPopup();
}

function openPrintExp ()
{
	var w = window.open("popup_print_expertise.jsp", "", "width=650,height=530");
	if (!w)
		alertAntiPopup();
}

function openPreviewMailInfo ( _vhcid )
{
	var w = window.open("popup_preview_mailinfo.jsp", "TruckPlusMailInfo", "width=520,height=530");
	if ( !w )
	{
		alertAntiPopup();
	}
	else
	{
		document.form_main.target = "TruckPlusMailInfo";
		document.form_main.action = "popup_preview_mailinfo.jsp?vhc=" + _vhcid;
		document.form_main.submit();
	}
}

// Validation avec la touche "entr?e"
function enterValid ( _event, _formname )
{
	if ( ( _event ) && ( _event.keyCode == 13 ) )
	{
		var form = eval ( "document." + _formname );
		form.submit();
	}
}

// Submit d'un form ? une url
function submitTo ( _formname, _url )
{
	if (_url!="#")
	{
		var form = eval ( "document." + _formname );
		form.target = "";
		form.action = _url;
		form.submit();
	}
	else
		notAvailable();
}

// Alert redirectionnelle
function redirectAlert ( _msg, _url )
{
	myAlert ( _msg );
	window.location = _url;
}

// Alert personnalis?e
function myAlert ( _error )
{
	alert ( _error );
}

function IsInt( Data )
{
	var NumChars = "0123456789";
	var It = true;
	var c;
	for ( var x = 0; x < Data.length; x++ )
	{
		if (It)
		{
			c = Data.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}
	}
	
	return It;
}

function IsFloat( Data )
{
	var NumChars = "-.0123456789";
	var It = true;
	var c;
	var point = false;
	
	for ( var x = 0; x < Data.length; x++ )
	{
		if (It)
		{
			c = Data.charAt(x);
			It = ( NumChars.indexOf(c) != -1);

			// Patch signe : forcement au d?but
			if ( ( c == "-" ) && ( x > 0 ) )
				return false;
				
			// Patch point : un seul point
			if ( c == "." )
			{
				if ( point )
					return false;
				else
					point = true;
			}
				
		}
	}
	
	return It;
}

function IsDate( Data )
{
	var NumChars = "/0123456789";
	var It = true;
	var c;

	if ( Data.length != 10 )
	{
		return false;
	}
	
	if ( ( Data.charAt ( 2 ) != '/' ) || ( Data.charAt ( 5 ) != '/' ) )
	{
		return false;
	}
	
	for ( var x = 0; x < Data.length; x++ )
	{
		if (It)
		{
			c = Data.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}
	}
	
	return It;
}


function IsVoid ( fieldname )
{
	if ( fieldname == "" )
		return true; 

	if ( document.getElementById ( fieldname ) == null )
		return true;

	var cval = document.getElementById ( fieldname ).value;

	if ( ( cval == "") || ( cval == " " ) )
		return true; 

	return false;
}

//------------------------------
// Fonctions de check de contenu
//------------------------------

function checkContent ( fieldname, errormsg )
{
	if ( IsVoid ( fieldname ) )
	{
		myAlert( errormsg );
		document.getElementById ( fieldname ).focus();
		return false;
	}

	return true;
}

//----------------------------------------
// Fonctions de check des differents types
//----------------------------------------

// Int
function checkType_int ( fieldname, errormsg )
{
	if ( IsVoid ( fieldname ) )
		return true;

	var cval = document.getElementById ( fieldname ).value;

	if ( ( cval == null ) || ( !IsInt ( cval ) ) )
	{
		myAlert( errormsg );
		document.getElementById ( fieldname ).focus();
		return false; 
	}
	
	return true;
}

// Float
function checkType_float ( fieldname, errormsg )
{
	if ( IsVoid ( fieldname ) )
		return true;

	var cval = document.getElementById ( fieldname ).value;

	if ( ( cval == null ) || ( !IsFloat ( cval ) ) )
	{
		myAlert( errormsg );
		document.getElementById ( fieldname ).focus();
		return false; 
	}
	
	return true;
}

// Date
function checkType_date ( fieldname, errormsg )
{
	if ( IsVoid ( fieldname ) )
		return true;

	var cval = document.getElementById ( fieldname ).value;
	
	if ( ( cval == null ) || ( ! IsDate ( cval ) ) )
	{
		myAlert( errormsg );
		document.getElementById ( fieldname ).focus();
		return false; 
	}
	
	return true;
}

// Select
function checkType_select ( fieldname, errormsg )
{
	var cval = document.getElementById ( fieldname ).value;

	if ( ( cval == null ) || ( cval < 1  ) )
	{
		myAlert( errormsg );
		document.getElementById ( fieldname ).focus();
		return false; 
	}
	
	return true;
}

// Image
function checkType_image ( fieldname, errormsg, filter )
{
	if ( IsVoid ( fieldname ) )
		return true;

	var cval 		= document.getElementById ( fieldname ).value;
	
	var extension	= trim(cval.substring( cval.lastIndexOf(".") + 1 ).toLowerCase());
	
	var filters 	= filter.split( ";" );
	var valid		= false;
	var error		= errormsg;
	
	for ( var i = 0; i < filters.length; i++ )
	{
		
		filters [ i ] = filters [ i ].toLowerCase();
		
		error += "\n - " + filters [ i ];
		if ( filters[ i ] == extension )
		{
			valid = true;
		}
	}
	
	
	if ( valid == false )
	{
		myAlert( error );
		return false; 
	}
	
	return true;
}

//---------------
// Force         
//---------------

// Number
function forceType_number ( fieldname, filtre )
{
	if ( IsVoid ( fieldname ) )
		return false;

	var cval = document.getElementById ( fieldname ).value;

	if ( cval == null )
		return false;

	if ( !IsFloat ( cval ) )
	{
		//var NumChars 	= "-.0123456789";
		var cvalNew 	= "";
		var minus		= 0;
		var point		= 0;

		for ( var x = 0; x < cval.length; x++ )
		{
			c 	= cval.charAt(x);
			if ( filtre.indexOf(c) != -1)
			{
				if ( ( c == "-" ) && ( x == 0 ) )
					cvalNew += c;
				else if ( c == "." )
				{
					if ( point == 0 )
					{
						cvalNew += c;
						point = 1;
					}
				}
				else if ( c != "-" )
					cvalNew += c;
			}
		}
		document.getElementById ( fieldname ).value = cvalNew;
		
		return false; 
	}
	return true;
}

//----------------------------------
// Fonctions d'exclusivit? de champs
//----------------------------------
function unselectCheckbox ( _exludedId )
{
	if ( document.getElementById ( _exludedId ) )
	{
		if ( document.getElementById ( _exludedId ).checked )
			document.getElementById ( _exludedId ).checked = false;
	}
}

//---------------
// COMPUTE (tout)
//---------------
function custRound(x,places)
{
	return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
 }

function compute ( _operand1, _operand2, _result, _operation )
{
	if ( IsVoid ( _operand1 ) || IsVoid ( _operand2 ) )
		return;
	
	var ope1 = document.getElementById ( _operand1 ).value;
	var ope2 = document.getElementById ( _operand2 ).value;
	
	// Verification des champs
	if ( ( IsInt ( ope1 ) || IsFloat ( ope1 ) ) && ( IsInt ( ope2 ) || IsFloat ( ope2 ) ) )
	{	
		// Multiplication
		if ( _operation == 1 )
		{
			document.getElementById ( _result ).value = custRound ( ( ope1 * ope2 ), 2 );
		}
		else if ( _operation == 2 )
		{
			document.getElementById ( _result ).value = custRound ( ( ope1 / ope2 ), 2 );
		}
		else if ( _operation == 3 )
		{
			document.getElementById ( _result ).value = custRound ( ( ope1 + ope2 ), 2 );
		}
		else if ( _operation == 4 )
		{
			document.getElementById ( _result ).value = custRound ( ( ope1 - ope2 ), 2 );
		}
	}
}

//---------------------------
// Mise a jour du prix euro  
// par rapport au prix locale
//---------------------------
function updateEuroFromLocale ()
{
	var taux = document.getElementById ( "taux" ).value;

	var ctrl_input = document.getElementsByTagName ("input");
	for ( i = 0; i < ctrl_input.length; i++ )
	{
		var cur = ctrl_input [ i ];
		
		if ( ( cur.name.indexOf ( "vhc_prix" ) > -1 ) && ( cur.name.indexOf ( "euro" ) > -1 ) )
		{
			var prix_euro 	= document.getElementById ( cur.name );
			var prix_locale = document.getElementById ( cur.name.replace( "euro", "locale" ) );
			
			if ( ( prix_euro != null ) && ( prix_locale != null ) && ( prix_locale.value != "" ) )
				prix_euro.value = ( prix_locale.value / taux );
		}
	}
}

//---------------------------
//
//	FONCTIONS LAC
//
//---------------------------
// Fonction v?rifiant si la chaine est bien un nombre
function only_nb(chaine) {
	for (var i=0; i<chaine.length; i++) 
	{
		for (var j=0; j<10; j++) {
			if (chaine.charAt(i) == j.toString()) break;
		}
		if (j == 10)
		return false;
	}
	return true;
}

function testdate(date){
	// Test si le champs contient bien 10 caract?res
	if (date.value.length != 10){
		return false;
	} else {
		// Test si les barres de s?paration sont au bon endroit
		if ( date.value.charAt(2)!= "/" || date.value.charAt(5)!= "/" ) 
		{
			return false;
		} 
		else 
		{
			annee = date.value.substring(6,10);
			mois = date.value.substring(3,5);
			jour = date.value.substring(0,2);
			// Test si l'ann?e , le mois et le jour sont bien des nombres ( via la fonction only_nb )
			if ((!only_nb(annee)) || (!only_nb(mois)) || (!only_nb(jour))){
				return false;
			} else {
				annee = eval(annee);
				mois = eval(mois);
				jour = eval(jour);
				
				// Test le nombre de jour du mois de F?vrier selon l'ann?e
				if ((annee % 4 == 0) && (annee % 100 != 0) || (annee % 400 == 0)) 
				{
					tab_mois = new Array (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
				} else {
					tab_mois = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
				}
				// Test si le num?ro du mois existe
				if ((mois < 1) || (mois > 12)){
					return false;
				// Test le jour est compris entre 1 et le maximum du mois
				} 
				else 
				{
					if ((jour < 1) || (jour > tab_mois[mois-1]))
					{
						return false;
					} 
					else 
					{
					   // verifie si la date de vente n'est pas superieure a la date du jour
					   var today = new Date();
					   var strToday = today.getDate()+'/'+(today.getMonth()+1)+'/'+today.getFullYear();				   
	
					   if ( ComparerDates(strToday,date.value) > 1 )
					   { 
						  return false;
					   }
					   else
					   	return true;
					}				
				}				
			}
		}
  }
}


function DecomposeDate(LeParam1){ 
	
	// S?pare les jours, les mois et les ann?es dans une date de type "22/05/1981"
	// Renvoye le tout dans un tableau de taille 3
	
	LeRetour = new Array(3);
	LeJour="";
	LeMois="";
	LeAnnee="";
	
	// Extraction du jour
	i=0;
	while((LeParam1.charAt(i)!="/")&&(i<10)){
		LeJour+=LeParam1.charAt(i);
		i++;
	}
	if(LeJour.charAt(0)=="0"){
		LeJour=LeJour.charAt(1);
	}
	LeParam1=LeParam1.substring(i+1,LeParam1.length);
	
	// Extraction du mois
	i=0;
	while((LeParam1.charAt(i)!="/")&&(i<10)){
		LeMois+=LeParam1.charAt(i);
		i++;
	}
	if(LeMois.charAt(0)=="0"){
		LeMois=LeMois.charAt(1);
	}
	LeParam1=LeParam1.substring(i+1,LeParam1.length);
	
	
	// Extraction de l'ann?e
	LeAnnee=LeParam1;
	LeRetour[0]=LeJour;
	LeRetour[1]=LeMois;
	LeRetour[2]=LeAnnee;
	return LeRetour;
}

function DateMachine(LeParam1){
	
	// Renvoye une date sans les 0 dans les mois ou les jours "02/03/1981" -> "2/3/1981"
	
	LaDate = new Array(3);
	LaDate = DecomposeDate(LeParam1);
	LeRetour = LaDate[0]+"/"+LaDate[1]+"/"+LaDate[2];
	return LeRetour;
}



// Renvoye une date en format anglais avec le s?parateur choisi "02/03/1981" -> "1981-3-2"
// Le premier param?tre est la date a convertir, le second est le caract?re de s?paration choisi
function DateAnglaise(LeParam1,LeParam2){
	
	LaDate = new Array(3);
	LaDate = DecomposeDate(LeParam1);
	
	LeRetour = LaDate[2]+LeParam2+LaDate[1]+LeParam2+LaDate[0];
	return LeRetour;
}


function ComparerDates(LeParam1,LeParam2){

	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si ?galit?, 1 si la premi?re est sup?rieure, sinon 2
	
	var LeParam1 = DateAnglaise(LeParam1,"/");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	
	var LeParam2 = DateAnglaise(LeParam2,"/");
	LeParam1 = Date.parse(LeParam1);
	LeParam2 = Date.parse(LeParam2);
	
	if (LeParam1 == LeParam2) { 
		return 0;
	}
	
	if (LeParam1 > LeParam2){
		return 1;
	}else{
		return 2;
	}
}



function setDateVenToday(champ)
{
   var today = new Date();
   var strJour = today.getDate();
   if (parseInt(strJour) < 10) strJour = '0'+ strJour;
   
   var strMois = (today.getMonth()+1);
   if (parseInt(strMois) < 10) strMois = '0'+ strMois;

   var strToday = strJour + '/' + strMois + '/' + today.getFullYear();				   
   document.getElementById(champ).value = strToday;
}

// LAC : toutes les fct ouverture popup => top.tpl pour localisation bouton fermer

function Fermer_Patienter()
{
	window.location.replace("home.jsp");
}


//function Accepter(elemt,dis_id)
function Accepter(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
		//parametre = "id="+elemt.id+"&flag=1&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=1";
		
		new Ajax.Request(url, {asynchronous:false, method: 'get', parameters: parametre+"&trompeCache="+new Date().getTime()});  	  	

	  	if ( document.getElementById("accepter_"+elemt) ) document.getElementById("accepter_"+elemt).style.display="none";
	  	if ( document.getElementById("refuser_"+elemt) ) document.getElementById("refuser_"+elemt).style.display="none";
}

//function Refuser(elemt,dis_id)
function Refuser(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
		//parametre = "id="+elemt.id+"&flag=2&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=2";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );
		
	  	if ( document.getElementById("accepter_"+elemt) ) document.getElementById("accepter_"+elemt).style.display="none";
	  	if ( document.getElementById("refuser_"+elemt) ) document.getElementById("refuser_"+elemt).style.display="none";
}

//function Accepter_traite_demande(elemt,dis_id)
function Accepter_traite_demande(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
//		parametre = "id="+elemt.id+"&flag=3&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=3";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );
		
	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("traiter_"+elemt) ) document.getElementById("traiter_"+elemt).style.display="none";
}
//function Gagner(elemt,dis_id)
function Gagner(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
//		parametre = "id="+elemt.id+"&flag=4&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=4";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );

	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("traiter_"+elemt) ) document.getElementById("traiter_"+elemt).style.display="none";
}
//function Perdre(elemt,dis_id)
function Perdre(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
//		parametre = "id="+elemt.id+"&flag=5&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=5";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );

	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("traiter_"+elemt) ) document.getElementById("traiter_"+elemt).style.display="none";
}

//function Critere_lu(elemt,dis_id)
function Critere_lu(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
		//parametre = "id="+elemt.id+"&flag=3&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=3";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );

	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("lu_"+elemt) ) document.getElementById("lu_"+elemt).style.display="none";
}
//function Critere_gagner(elemt,dis_id)
function Critere_gagner(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
		parametre = "id="+elemt+"&flag=4";


		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );

	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("lu_"+elemt) ) document.getElementById("lu_"+elemt).style.display="none";
}

//function Critere_perdre(elemt,dis_id)
function Critere_perdre(elemt)
{
	  	var url = 'Prospect_MAJ.jsp';

		var parametre = new String();
		
//		parametre = "id="+elemt.id+"&flag=5&dis_id="+dis_id;
		parametre = "id="+elemt+"&flag=5";

		new Ajax.Request( url, {asynchronous:false,method: 'get',  parameters: parametre+"&trompeCache="+new Date().getTime()} );

	  	if ( document.getElementById("gagner_"+elemt) ) document.getElementById("gagner_"+elemt).style.display="none";
	  	if ( document.getElementById("perdre_"+elemt) ) document.getElementById("perdre_"+elemt).style.display="none";
		if ( document.getElementById("lu_"+elemt) ) document.getElementById("lu_"+elemt).style.display="none";
}

function Add_Del_num_dossier(id)
{
	if(document.getElementById(id).checked == true)
	{
		var chaine=document.getElementById('num_dossier').value;
		if(chaine !="")
		{
			chaine+=";"+id;
		}
		else
			chaine=id;
		
		document.getElementById('num_dossier').value = chaine;
		alert(chaine)
	}
	else
	{
		var temp="";
		var chaine=document.getElementById('num_dossier').value;
		var reg=new RegExp("[;]+", "g");
		var tableau=chaine.split(reg);
		for (var i=0; i<tableau.length; i++) {
			 if(tableau[i] != id)
			 {
			 	if(temp !="")
				{
					temp+=";"+tableau[i];
				}
				else
					temp=tableau[i];
			}
		}
		document.getElementById('num_dossier').value = temp;
		alert(temp)
	}
}
	
function remplieNom(type)
{
	if(document.getElementById(type+"_id_pere").value!="0")
	{
		var select=document.getElementById(type+"_id_pere");
		var nom=select.options[select.selectedIndex].innerHTML;
		document.getElementById("new_"+type).value=nom;
	}
	else
		document.getElementById("new_"+type).value='';
	
}
function valideAssoc(type)
{
	// type d'information trait?e
	// (type, mod?le)
	var name='';
	switch(type)
	{
		case 'typ' : name='type';
			break;
		case 'mod' : name='mod\350le';
			break;
		default: break;
	}
	// test si au moins un type/modele a ?t? selectionn? pour la conversion
	if(document.getElementById(type+"_id").value !="")
	{
		if(document.getElementById(type+"_id_pere").value!="" && document.getElementById(type+"_id_pere").value!="0")
		{
			//test si un nom pour le type pere a ?t? saisie
			if(document.getElementById("new_"+type).value !="")
			{
				//derni?re confirmation avant le regroupement
				if(confirm('Etes vous sur de vouloir convertir ces '+name+"s?"))
				{
					//submit du formulaire
					document.form_options.regroupe.value=1;
					document.form_options.submit();
				}
			}
			else
				alert("Veuillez saisir un nouveau nom pour le regroupement!");
		}
		else
			alert("Veuillez saisir un "+ name +" de destination!");
	}
	else
		alert("Vous devez s\351lectionner au moins un "+ name +" \340 convertir!");
}

//add thickbox to href & area elements that have a class of .thickbox
function ouvre_popup(str_close){
	var t = '';
	var a = 'popup_demande_prospect_home.jsp?height=500&amp;width=750&keepThis=true&TB_iframe=true&';
	var g = false;
	tb_show(t,a,g,str_close);
//	this.blur();
	return false;
}


function show_hide_info(id_info)
{
	if (document.getElementById("info_contact_"+id_info).style.display == "none")
	{
		document.getElementById("info_contact_"+id_info).style.display = "block";
	}
	else
	{
		document.getElementById("info_contact_"+id_info).style.display = "none";
	}
}

function extractStockSelectAll()
{
	if($('#chkExtractVoAll').attr('checked'))
		$('[id^=extractVo_]').attr('checked', true);
	else
		$('[id^=extractVo_]').attr('checked', false);
}

function extractStockSelectPriceAll()
{
	if($('#chkPriceVoAll').attr('checked'))
		$('[id^=selectPrix_]').attr('checked', true);
	else
		$('[id^=selectPrix_]').attr('checked', false);
}

function init()
{
	if ($("div#gmap").length > 0){
	    load();
	}
	
	
}

function destroy()
{
	if ($("div#gmap").length > 0){
		GUnload()
	}
}
