/*******************************************
**
**  !!!  $('obj').scrollTop = 0 // met assenseur en haut
**
**
********************************************/

/*#################################################
##  VARIABLES #####################################
#################################################*/
//<![CDATA[
/* --- gmap related --- */
var tdv_map;
var tdv_geocoder = new GClientGeocoder();
var tdv_marker_mgr;

var listePhotos = new Array();
var timer="";
var hMarkers = new Hash(); // key = programId  value : Gmarker

/*############################
## Config Vars #############*/

/* --- Default Values --- */
//var defaultVal // moved to iprospec_config.js
	
/* --- Current Values ---*/
var currentVal = {
	step:'one',
	searchDiv:"", //not used for now // rr404
	program_id:0,
	program_adrs:"",
	program_PDM:"",
	program_VDO:"",
	program_PDF:"",
	program_desc:"",
	lot_p2d:"",
	lot_m3d:"",
	lot_pdf:"",
	lot_id:0,
	lot_refPDM:'',
	lot_img:null
};

var theResults;
/* **********************************************/

/* --- Buffer Values ---*/
var current_hl_prog = '';
var current_hl_lot = '';

var step2_relevant = false;
var step3_relevant = false;

var isAccedant = 1;

var step1ListHeight = 0;
var step1ListNumRes = 0;

var step2ListHeight = 0;
var step2ListNumRes = 0;

var current_lots_list;

//var sent to flash
var current_avLots       = "";
var current_naLots       = "";
var current_reLots       = "";
var current_lots_details = ""; //used to store data sent to the PDM (novoprom...)

var lot_order_priceASC = false;
var lot_order_surfASC = true;

var popVdoURL			= "";

/*#################################################
##  FUNCTIONS #####################################
#################################################*/

/*############################
## Init Functions ##########*/

function load() {
	
	//pop div vars init
	currentVal.lot_img = new Image();
	currentVal.lot_img.onload = function(i){displayImage(this);}
	
	// ...
	if (GBrowserIsCompatible()) {
		tdv_map = new GMap2(document.getElementById("theMap"));
		load_config_tdv_map_init(tdv_map);
	}
	
	if(searchAtStart == true) searchPrograms();
}


/*############################
## Gmaps Related Functions #*/

function createMarker(aMarker){
//aMarker Structure : {lat:000,lng:000,icon:"url",program_id:"prog_0123_ID",title:"prog name",info:"info text htmlFormated"}
	//TODO -- check all cases of missing vars in aMaker
	//default to add for : lat,lng,icon,title,info
	//return null if no prog id present
	
	if(aMarker.icon == "null" || aMarker.icon == "") aMarker.icon = "../../images/v3d_sm.png";
	
	var theIcon = new GIcon();
	theIcon.image = aMarker.icon;
	theIcon.iconSize = defaultVal.iconSize;
	theIcon.iconAnchor = defaultVal.iconAnchor;
	theIcon.infoWindowAnchor = defaultVal.infoWindowAnchor;
	
	var mOpts = {icon:theIcon};
	var mPos = new GLatLng(aMarker.lat, aMarker.lng);
	
	var theMarker = new GMarker(mPos,  mOpts);
	
	theMarker.sid = aMarker.program_id;
	
	// Info binding
	 //none for now // rr404
	
	
    //mouseOver Listener => triggers highlight
	GEvent.addListener(theMarker, "mouseover", function(txt) {
			hlSelection_prog(this.sid);
		});
	
	GEvent.addListener(theMarker, "mouseout", function(txt) {
			unhlSelection_prog();
		});
	
	GEvent.addListener(theMarker, "click", function(txt) { // Might change this to dblClick // rr404
			gotoSelection(this.sid,2);
			//alert(this.sid); //for test
			//hlSelection_prog(this.sid);
			
			//goto  step 2 for this programm
		});

	return theMarker;
}

function createMarkersList(allMarkers){	
	var theMarkers = [];
	
	allMarkers.each(function(aM){
							  	var tmpM = null;
							  	if((tmpM = createMarker(aM)) != null){
								   // if geoloc is 0,0  make a geoloc research js/ajax/php
								  theMarkers.push(tmpM); // to test: assignement + test // RR404
								  hMarkers.set(tmpM.sid,tmpM);
							  	}
							  });

	return theMarkers;
}

function centerOnMarker(sId,nZoom){ //eventually add map type param? :  satelite, .../
	
	var theMarker = hMarkers.get(sId);
	
	if(theMarker != null){
		if(nZoom == undefined) tdv_map.setCenter(theMarker.getLatLng());
		else tdv_map.setCenter(theMarker.getLatLng(), nZoom)
	}
}


/*############################
## Navigation Functions ###*/

function searchPrograms(){
	isAccedant = 0;
	if($('accedant_rb')!=null){
		if($('accedant_rb').checked == true){ isAccedant = 1;}
	}
	
	//for test //$('PRGM_list').update(tdvTemplate.step1.printResult("-21-","NomProg","","Paris 15","Blabla 1 et tout ça","Ce soir on joue à GTA","Et pi voilà",10));
	step2_relevant = false; prog_2_active(false);
	step3_relevant = false; prog_3_active(false);
	
	var url = '../../scripts/php/ajaxResponder.php';
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	//build query from search fields
	//parameters : regId,deptId,villeId,typeId,nbP,sf,prix
	var v_regId,v_deptId,v_villeId,v_typeId,v_nbpMin,v_nbpMax,v_sfMin,v_sfMax,v_prixMin,v_prixMax;
	
	v_regId = searchProgramsGetValue('region_select');
	v_deptId = searchProgramsGetValue('dept_select');
	v_villeId = searchProgramsGetValue('ville_select');
	v_typeId = searchProgramsGetValue('type_select');
	v_nbpMin = searchProgramsGetValue('v_nbpMin');
	v_nbpMax = searchProgramsGetValue('v_nbpMax');
	v_sfMin = searchProgramsGetValue('v_sfMin');
	v_sfMax = searchProgramsGetValue('v_sfMax');
	v_prixMin = searchProgramsGetValue('v_prixMin');
	v_prixMax = searchProgramsGetValue('v_prixMax');
	
	// todo
		// check the consistency of data : numbers only for number fields,  min < max ... // RR404
	
	// request query
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: programsResultsProcessor,
	  parameters : {action:'searchProg',regId:v_regId,deptId:v_deptId,villeId:v_villeId,typeId:v_typeId,nbpMin:v_nbpMin,nbpMax:v_nbpMax,sfMin:v_sfMin,sfMax:v_sfMax,prixMin:v_prixMin,prixMax:v_prixMax}
	});
}

function searchProgramsGetValue(fieldId){
	var theVal = $(fieldId)!=null?$(fieldId).value:"";
	
	return theVal;
}

function programsResultsProcessor(answer){ // paramètre obligé a ce stade
		
	// ReInit the marker Manager
	tdv_marker_mgr = new GMarkerManager(tdv_map);
	
	// ReInit the marker hash
	hMarkers = new Hash();
	
	// Clean Map
	tdv_map.clearOverlays();
	
	theResults = eval(answer.responseText);
	//test//alert("answer");
	//empty result area:
	$('PRGM_list_container').update(""); // vidage du div
	//theResults table of this : 
		// Structure : {lat:000,lng:000,icon:"url",thumb:"url",ville:"villeName",program_id:"prog_0123_ID",title:"prog name",rl1:"bla",rl2:"blU",rl3:"bli",nLot:00}
		//aMarker Structure : {lat:000,lng:000,icon:"url",program_id:"prog_0123_ID",title:"prog name",info:"info text htmlFormated"}
		//make .info from rl1,2,3 for the marker // at the same time that what's bellow.
	
	var counter = 0;
	theResults.each(function(theR){
						
						// Print the results                                                    
						$('PRGM_list_container').insert({bottom:tdvTemplate.step1.printResult(theR.program_id,theR.title,theR.thumb,theR.ville,theR.rl1,theR.rl2,theR.rl3,theR.nLot,counter)});
												
						theR.info = "&bull;"+theR.rl1+"&bull;"+theR.rl2+"&bull;"+theR.rl3; // check taht all rl1-3 are not null before to concatenate // RR404
						counter++;
					});	
	
	var markersList = createMarkersList(theResults);
	
	var zoom = eval("defaultVal.markervisibility.step."+currentVal.step);
	
	//tdv_marker_mgr.addMarkers(markersList,  zoom.minZoom,  zoom.maxZoom);
	tdv_marker_mgr.addMarkers(markersList,0,17);
	tdv_marker_mgr.refresh();
	
	//for scrolling issue
	
	step1ListHeight = $('PRGM_list_container').getDimensions().height;// - 412; // 412 is the size of the parent div
	step1ListNumRes = $('PRGM_list_container').childElements().size();
	
	programsResultsProcessor_custom_action();
}

function listProgramLots(prog_id){
	// structure : {lots:[{lot_id:"132",nb_p:X, nom:"resumeL1", ot:0, ob:0, op:0, oc:0, oj:0 ,url_thumb:"./x.jpg",ref_pdm:"L.123",sup:"50", prix:"150000", dispo:0/1}],url_pdm:"./pdm.swf",url_vdo:"vdo.flv", date_dispo:""}	
	var url = '../../scripts/php/ajaxResponder.php';
	// notice the use of a proxy to circumvent the Same Origin Policy.

	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: lotsResultsProcessor,
	  parameters : {action:'listLots',program_id:prog_id}
	});
}

/*
** Laurent
*/

function lotsResultsProcessor(answer){
	
	current_hl_lot='';
	
	theResults = answer.responseText.evalJSON();
	//test//alert("answer");
	
	//store current prog adrs
	currentVal.program_adrs = theResults.adrs;
	
	
	//empty result area:
	$('LOT_list_container').update("");
	//{lots:[{lot_id:"132",nb_p:X, nom:"resumeL1", ot:0, ob:0, op:0, oc:0, oj:0 ,url_thumb:"./x.jpg",ref_pdm:"L.123",sup:"50", prix:"150000", dispo:0/1}],url_pdm:"./pdm.swf",url_vdo:"vdo.flv", date_dispo:"",adrs:""}
	
	//set the PDM and VDO flash from theResults.url_pdm:"./pdm.swf",url_vdo:"vdo.flv", date_dispo:"" // RR404
	
	lotsResultsProcessor_titlePanel_step2_update(theResults); //in iprospec_config.js
		
	currentVal.program_PDM  = theResults.url_pdm;
	currentVal.program_PDF  = theResults.url_pdf;
	currentVal.program_desc = theResults.descr;
	
	current_avLots = ""+theResults.avLots;
	//currentVal.avLots = ""+theResults.avLots;
	
	current_naLots = ""+theResults.naLots;
	//currentVal.naLots = ""+theResults.naLots;
	
	current_reLots = ""+theResults.reLots;
	
	

	if((theResults.url_thumb2 != "") &&  (theResults.url_thumb2 != "null"))
		$('step2_pdm').update('<img src="'+theResults.url_thumb2+'" height="145px" width="211px" border="0"/>');
	else
		$("step2_pdm").update('<img src="../../images/default_pdm_step2.jpg" />');
		
	currentVal.program_VDO = theResults.url_vdo;
	//alert(currentVal.program_VDO);
	setStep2Vdo(theResults.url_vdo);
	
	//$('dateMiseADispo').update('Livraison prévisionnelle : <strong>'+theResults.date_dispo+'</strong>');
	lotsResultsProcessor_dateMiseADispo_update(); //in iprospec_config.js
		
	current_lots_list = theResults.lots;
	
	lotsResultsProcessor_current_lots_list_print(theResults); //in iprospec_config.js
	
	setStep3Pdm(currentVal.program_PDM);
		
	step2ListHeight = $('LOT_list_container').getDimensions().height;// - 377; // 377 is the size of the parent div
	step2ListNumRes = $('LOT_list_container').childElements().size();
	
	if(currentCustomer != "cap2j") rearangeBy('prix');
}

function getLotDetails(the_lot_id){
	//get info from Ajax, undate info for lot and program plan de masse and perspectives // RR404
   
  var url = '../../scripts/php/ajaxResponder.php';
	// notice the use of a proxy to circumvent the Same Origin Policy.

	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: lotsDetailsProcessor,
	  parameters : {action:'detailsLot',lot_id:the_lot_id}
	});
	
}
var imgsuiv=0;
function goDiapo(nb){

    if(nb==(listePhotos.length-1)){
       imgsuiv=0;
    } else {
       imgsuiv=nb+1;
    }
    $("step3_thumb").update('<img src="'+listePhotos[nb]+'" border=0 width="346" height="205" style="'+setStep3Preview_step3_thumb_style_jpg+'" />');
    timer =setTimeout("goDiapo("+imgsuiv+")",4000);
}    


function lotsDetailsProcessor(answer){
	// could use the templates but wont this time as the page has only one template well fill the one that is there
	  
	//alert(answer.responseText); //for test
	
	current_hl_lot='';
	
	theResults = answer.responseText.evalJSON();
	//Structure : {dsc,p1, p2, p3, p4, p5, tb, i1, i2, i3, p2d, m3d, pdf, ref_pdm}
	
	var theOrientation = theResults.orientation;
	var oPicto = "n.gif";
	var oLabel = "Nord";
	switch(theOrientation){
		case 0:
			oPicto = "orientation_n.gif";
			oLabel = "Nord";
			break;
			
		case 1:
			oPicto = "orientation_s.gif";
			oLabel = "Sud";
			break;
		
		case 2:
			oPicto = "orientation_e.gif";
			oLabel = "Est";
			break;
			
		case 3:
			oPicto = "orientation_o.gif";
			oLabel = "Ouest";
			break;
			
		case 4:
			oPicto = "orientation_ne.gif";
			oLabel = "Nord-Est";
			break;
			
		case 5:
			oPicto = "orientation_no.gif";
			oLabel = "Nord-Ouest";
			break;
			
		case 6:
			oPicto = "orientation_se.gif";
			oLabel = "Sud-Est";
			break;
			
		case 7:
			oPicto = "orientation_so.gif";
			oLabel = "Sud-Ouest";
			break;
			
		case 8:
			oPicto = "orientation_ns.gif";
			oLabel = "Nord-Sud";
			break;
			
		case 9:
			oPicto = "orientation_eo.gif";
			oLabel = "Est-Ouest";
			break;		
	}
	/*Eli : modifi de la propriété "style" de l'image => ajout d'un margin-left pr mettre l'image a droite du texte "Orientation" */
	theOrientation = "<u>Orientation</u> : "+oLabel+" <img src='../../images/"+oPicto+"' style='vertical-align:middle; margin-left:110px' /><br /><br />";
	
	if(theResults.dsc != "") $('descrLot').update(theOrientation+"<u>Description</u> : <br />"+theResults.dsc);
	else $('descrLot').update("&nbsp;");
	
	$('titlePanel3_step3').update(theResults.lotName);
	
	lotsDetailssProcessor_les_plus_update(theResults); //in iprospec_config.js
		
	
	var thumbnail = theResults.tb;
	if(thumbnail == "" || thumbnail == "null") thumbnail = '../../images/default_step3_thumb.jpg';
	//alert(theResults.i1);
	
	if((theResults.i1=="")  &&  (theResults.i2=="") && (theResults.i3=="")) {
      //RR404 !! USE this !!
      clearTimeout(timer);
      listePhotos = new Array();
      timer = "";
      setStep3Preview(thumbnail);
  } else {
      clearTimeout(timer);
      timer = "";
      listePhotos = new Array();
      listePhotos.push(thumbnail);
      if(theResults.i1!="") {
        listePhotos.push(theResults.i1);
      }
      if(theResults.i2!="") {
         listePhotos.push(theResults.i2);
      }
      if (theResults.i3!="") {
        listePhotos.push(theResults.i3);
      }    
      goDiapo(0);
  }
	
	

	
	//RR404 OLD ! delete
	/*Eli*****modif*/ //$('step3_thumb').update('<img border=0 src="'+thumbnail+'" width="346" height="205" style="margin-bottom:2px; padding-right:2px;" />');
	
	
	
	currentVal.lot_p2d = theResults.p2d;
	if((theResults.p2d != "") && (theResults.p2d != "null")){
		$('a_p2d').writeAttribute('href',theResults.p2d);
		$('btn_p2d').show();	
	}
	else{
		$('btn_p2d').hide();
	}
	
	//show and fill / hide button Maquette3D
	currentVal.lot_m3d = theResults.m3d;
	if((theResults.m3d != "") && (theResults.m3d != "null")){
		
		/*evaluate if it's a JSON string -start-*/
		//deal with eventual JSON strings
		var jsonVar = null;
		//var prefix = "";
		//var postfix = "";
		
		try{
			jsonVar = theResults.m3d.evalJSON();	
			
		}
		catch(e){
			jsonVar = null;
		}
		
		if(jsonVar != null){
			if(jsonVar.type != null){
				if(jsonVar.type == "mvi3d"){
										
					if(jsonVar.w < 0) jsonVar.w = 640;
					if(jsonVar.h < 0) jsonVar.h = 480;
					
					if(jsonVar.url != ""){
						//prefix  = '<span onclick="OpenPopUp(\''+jsonVar.url+'\','+jsonVar.w+','+jsonVar.h+')" style="cursor:pointer;" >';
						//postfix = '</span>';
						theResults.m3d = jsonVar.url;
					}
					else{
						theResults.m3d = "null";						
					}
				}
				else{if((jsonVar.url != null) && (jsonVar.url != "")){ // for other case where we have url filled still
						theResults.m3d = jsonVar.url;
				     }
					 else{
						theResults.m3d = jsonVar.picture;	 
					 }
				}
				//{type:'no_type', picture:'http://i-prospec.com/client/indoimmo/programmes/1238657331994/1238657369338.jpg', url:'no_url', w:-1, h:-1}.
				urlVdo  = jsonVar.picture;
			}
		}
		/*evaluate if it's a JSON string -end-*/
		
		
		var anchorAttribute = 'onclick';
		var anchorPrefix = '';
		
		if(Prototype.Browser.IE == true){
			anchorAttribute = 'href';
			anchorPrefix = 'javascript:';
		}
		
		switch(theResults.m3d.slice(-4).toLowerCase()){

			case '.flv':
				$('a_m3d').writeAttribute('href','#');
				$('a_m3d').writeAttribute('target','_self');
				$('a_m3d').writeAttribute(anchorAttribute,anchorPrefix+"popVdo('"+theResults.m3d+"');");
				$('btn_m3d').show();
				break;
				
			case '.swf':
				$('a_m3d').writeAttribute('href','#');
				$('a_m3d').writeAttribute('target','_self');
				$('a_m3d').writeAttribute(anchorAttribute,anchorPrefix+"popSwf('"+theResults.m3d+"');");
				$('btn_m3d').show();
				break;
			
			case '.jpg':
				$('a_m3d').writeAttribute('href','#');
				$('a_m3d').writeAttribute('target','_self');
				$('a_m3d').writeAttribute(anchorAttribute,anchorPrefix+"popImg('"+theResults.m3d+"');");
				$('btn_m3d').show();
				break;
			
			case '.php':
			case 'html':
				$('a_m3d').writeAttribute('href','#');
				$('a_m3d').writeAttribute('target','_self'); //or window.open //OpenPopUp(\''+jsonVar.url+'\','+jsonVar.w+','+jsonVar.h+')
				$('a_m3d').writeAttribute(anchorAttribute,anchorPrefix+"OpenPopUp('"+jsonVar.url+"',"+jsonVar.w+","+jsonVar.h+")");
				//$('a_m3d').writeAttribute('onclick','popWin([...]"'+theResults.m3d+'");'); // stuff ..
				$('btn_m3d').show();
				break;
				
			default:
				$('btn_m3d').hide();
				break;
		
		}	
	}
	else{
		//eli
		$('btn_m3d').hide(); // ! HIDE NO ?? //rr404  was show()
	}
	
	//show and fill / hide PDF : residence
	if((currentVal.program_PDF != "") && (currentVal.program_PDF != "null")){
		$('a_pdf').writeAttribute('href',currentVal.program_PDF);
		$('btn_pdf').show();	
	}
	else{
		$('btn_pdf').hide();
	}
	
	//show and fill / hide PDF : details lots
	currentVal.lot_pdf = theResults.pdf; // pdf is p2d .. there have been a misunderstanding ?? // rr404
	if((theResults.pdf != "") && (theResults.pdf != "null")){
		$('a_pdf2').writeAttribute('href',theResults.pdf);
		$('btn_pdf2').show();		
	}
	else{
		$('btn_pdf2').hide();
	}
	
	
	if($('lot_adrs') != null)	$('lot_adrs').update(currentVal.program_adrs);
	
	$('step3_persp').update('');
	
	lotsDetailsProcessor_step3_persp_update(theResults); // in iprospec_config.js
	
	
	$('a_print').writeAttribute('href','./printLot_mathieu.php?lot_id='+currentVal.lot_id+'&thumb='+theResults.tb+'&lotName='+theResults.lotName);
	
	//setStep3Pdm(currentVal.program_PDM); // not needed right now as it has been done for step 2
	 
  setLotPDM(currentVal.lot_refPDM);

	
}

/* Ergo, highlight in list functions */

function hlSelection_prog(idSelection){ // do the same for the hl in step 2 // rr404
	//we will know in which section we are and in what container div the selections (lot/program result) are.
	
	//TODO
	if(current_hl_prog != ''){
		$(current_hl_prog).style.backgroundImage = "url(../../images/fiche.jpg)";
	}
	
	if($(idSelection) != null){
		$(idSelection).style.backgroundImage = "url(../../images/fiche_hl.jpg)";
	
		if(step1ListHeight > 450){ // 450 is put there to be a bit bigger than 412 hence allow flexibility in case of an almost fitting situation
			
			$('PRGM_list').scrollTop = (step1ListHeight/(step1ListNumRes-1)) * $(idSelection).readAttribute('nplace');
		}
	}
	current_hl_prog = idSelection;
		//change selection div style (bg ...)
		//scroll to it
	//$('PRGM_list').scrollTo($('idSelection'));
}

//Eli*/******************* highlight au passage de la sourie dans la liste page 1//////////////////////////////////////
function mouseOverHl(idSelection)
{
	if(current_hl_prog != ''){
		$(current_hl_prog).style.backgroundImage = "url(../../images/fiche.jpg)";
	}
	
	if($(idSelection) != null){
		$(idSelection).style.backgroundImage = "url(../../images/fiche_hl.jpg)";
	}
	current_hl_prog = idSelection;
}
/////////////***********************************************************************************************/////////////////

function unhlSelection_prog(){ // rr404
	//we will know in which section we are and in what container div the selections (lot/program result) are.
	
	//TODO
	if(current_hl_prog != ''){
		$(current_hl_prog).style.backgroundImage = "url(../../images/fiche.jpg)";
	}
	current_hl_prog = '';
}

// current_hl_lot
function hlSelection_lot(idSelection){ // do the same for the hl in step 2 // rr404
	//we will know in which section we are and in what container div the selections (lot/program result) are.
	
	//TODO
	if(current_hl_lot == null) current_hl_lot = ''; 
	if(current_hl_lot != ''){
		try{
			$(current_hl_lot).style.backgroundImage = "url(../../images/fiche_2.jpg)";
		} catch(e){
			//
		}
	}
	
	if($(idSelection) != null){
		$(idSelection).style.backgroundImage = "url(../../images/fiche_2_hl.jpg)";
		
		if(step2ListHeight > 390){ // 390 is put there to be a bit bigger than 412 hence allow flexibility in case of an almost fitting situation
			//$('LOT_list').scrollTop = (step2ListHeight/(step2ListNumRes-1)) * ($(idSelection).readAttribute('nplace'));
			//tweak
			$('LOT_list').scrollTop = 91 * ($(idSelection).readAttribute('nplace'));
		}
	}
	current_hl_lot = idSelection;
		//change selection div style (bg ...)
		//scroll to it
	$('PRGM_list').scrollTo($('idSelection'));
}

//Eli*/******************* highlight au passage de la sourie dans la liste page 2//////////////////////////////////////
function mouseOverHl_lot(idSelection)
{
	// s33K current lot highlight
	if(current_hl_lot == null) current_hl_lot ='';

	try{
		if(current_hl_lot != ''){
			$(current_hl_lot).style.backgroundImage = "url(../../images/fiche_2.jpg)";
		}
	}
	catch(e){
		current_hl_lot = '';
	}
	
	if($(idSelection) != null){
		$(idSelection).style.backgroundImage = "url(../../images/fiche_2_hl.jpg)";
	}
	current_hl_lot = idSelection;
}
/////////////////////////////////////////////////////////////////////////////


function unhlSelection_lot(){
	//we will know in which section we are and in what container div the selections (lot/program result) are.
	
	//TODO
	if(current_hl_lot != ''){
		$(current_hl_lot).style.backgroundImage = "url(../../images/fiche_2.jpg)";
	}
	current_hl_lot = '';
}

//ELi////////Affichage du nom du programme///////////////
/*
function getProgName(idProgramme){
	var url = '../../scripts/php/ajaxResponder.php';
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: afficherNomProg,
	  parameters : {action:'nomProg',idProg:idProgramme}
	});
}

function afficherNomProg (answer){
	theResult = answer.responseText.evalJSON();
	$('titlePanel_step2').update(theResult.nomProgramme);
}
//////////////////////////////////////////////////////////

//ELi////////Affichage du nom du lot///////////////
function getLotsName(idLots){
	var url = '../../scripts/php/ajaxResponder.php';
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: afficherNomLots,
	  parameters : {action:'nomLots',idDuLots:idLots}
	});
}

function afficherNomLots (answer){
	theResult = answer.responseText.evalJSON();
	$('titlePanel3_step3').update(theResult.nomLots);
}
*/
//////////////////////////////////////////////////////////

function gotoSelection(idSelection,headingTo,refPDM){
	//we will know if we need to aim to step 2 or 3	
	isAccedant = 0;
	if($('accedant_rb')!=null){
		if($('accedant_rb').checked == true){ isAccedant = 1;}
	}
	
	switch(headingTo){
		case 2:
			gotoSelection_case2(idSelection,headingTo,refPDM); // in iprospec_config.js				
			break;
			
		case 3:
			gotoSelection_case3(idSelection,headingTo,refPDM); // in iprospec_config.js	
			break;
		
		default:
			current_hl_lot='';
			break;
	}
}

/************************************
******* popDiv Functions
***********************************/
function popProgDesc(){
	popHtmlText('<div class="popDescContent" style="width:500px"><u>Description du programme</u> : <br /><br />'+currentVal.program_desc+'</div>');
}


function popText(descTxt){
	//_text = _text
	
	popHtmlText(descTxt);
}

function popHtmlText(descTxt){
	//flash wmode should be transparent so no need to show/hide it
	/*$('thePDM_container').hide();
	$('step2_pdm').hide();
	$('step2_vdo').hide();*/
	
	posPopDiv();
	$('popDiv').show();
	
	$("popContent").update(descTxt);
	
	posPopDiv();
}

function popImg(imgSrc){
	//flash wmode should be transparent so no need to show/hide it
	/*$('thePDM_container').hide();
	$('step2_pdm').hide();
	$('step2_vdo').hide();*/
	
	currentVal.lot_img.src = imgSrc;
	posPopDiv();
	$('popDiv').show();
}

function popVdo(vdoSrc,w,h){
	//if($("popContent")!=null)	$("popContent").update("");
	//if($("mediaContent")!=null)	$("mediaContent").update("");
	$("popContent").update('<div id="mediaContent"></div>');
	/*
	if((w == undefined) || (w < 100))
		w = 800;
		
	if((h == undefined) || (h < 100))
		h = 800;
	
	var fited = fitInWin(w,h);
	*/
	var fited = {w:640,h:480}; //Temporary, while we have some crash bug well set the size @ 500x500 // rr404
	
	/*
	$('thePDM_container').hide();
	$('step2_pdm').hide();
	$('step2_vdo').hide();*/
	try{if($('VDOStep2')) $('VDOStep2').VideopauseFromJs();}
	catch(error){};
	
	posPopDiv();
	$('popDiv').show();
	
	if(vdoSrc == "" || vdoSrc == "null"){
		$("mediaContent").update('<img src="../../images/default_vdo_step2.jpg" />');
	}
	else{
		/* // OLD WAY
		var so = new SWFObject("../../swf/page2VideoPlayer_popUP.swf", "VDOPOP", ""+fited.w, ""+fited.h, "8"); //use this later
		//so.addParam("wmode", "transparent");
		so.addVariable("urlVDO", vdoSrc);
		so.addVariable("w", fited.w);
		so.addVariable("h", fited.h);
		so.write("popContent");
		*/
		
		// swfObject 2-2 
		//Mathieu var flashvars = {urlVDO:vdoSrc, w:fited.w, h:fited.h};
		//alert(vdoSrc);
		var flashvars = {urlVDO:vdoSrc, w:fited.w, h:fited.h};
		//var params = {wmode:"transparent"};
		var params = {};
		var attributes = {id:"VDOPOP", name:"VDOPOP"};
		// MATHIEU swfobject.embedSWF("../../../Generic_lib/swf/page2VideoPlayer_popUP.swf", "mediaContent", ""+fited.w, ""+fited.h, "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("../../../Generic_lib/swf/page2VideoPlayer_popUP.swf", "mediaContent", 640, 480, "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, false, attributes);
	}
}

function popSwf(src){
	/*$('thePDM_container').hide();
	$('step2_pdm').hide();
	$('step2_vdo').hide();*/
	
	posPopDiv();
	$('popDiv').show();
	
	if(src == "" || src == "null"){
		$("popContent").update('<img src="../../images/default_vdo_step2.jpg" />')
	}
	else{
		/* // OLD WAY
		var so = new SWFObject(src, "SWFPOP", "100%", "100%", "8");
		so.addParam("wmode", "transparent");
		so.write("popContent");
		*/
		
		// swfObject 2-2 
		var flashvars = {};
		var params = {wmode:"transparent"};
		var attributes = {id:"SWFPOP", name:"SWFPOP"};
		swfobject.embedSWF(src, "popContent", "100%", "100%", "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);
	}
}

function posPopDiv(){
	$('popDiv').setStyle({top:document.viewport.getScrollOffsets()[1]});
}
function closePop(){
	
	try{ $('VDOStep2').VideoplayFromJs();}
	catch(error){};
	
	$('popDiv').hide();
	$('popContent').update('<img src="../../images/wait.gif" alt="wait" style="border:0px" />');

	
	/*$('thePDM_container').show();
	$('step2_pdm').show();
	$('step2_vdo').show();*/
}

function displayImage(img){
	var width = "";
	var w = ($('popDiv').getWidth()-50);
	
	var height = "";
	var h = img.height;
	
	// Width ---------------------------
	if(img.width > w ){
		h = (w*img.height/img.width);
		width = "width:"+w+"px;";		
	}
	else{
		w = (img.width);
		width = "width:"+w+"px;";			
	}
	// HEIGHT -----------------------
	if(h > ($('popDiv').getHeight() - 50) ){
		h = ($('popDiv').getHeight() - 50);
		w = (h*img.width/img.height);
		height = "height:"+h+"px;";		
	}
	else{
		h = (img.height)+"px";
		height = "height:"+h+"px;";			
	}
	
	$('popClick').writeAttribute('width',w+'px')
	/* *modif* style de l'image */
	displayImage_popContent_update(img,width,height) // in iprospec_config.js
	
}

function fitInWin(_w,_h){
	var width = "";
	var w = ($('popDiv').getWidth()-50);
	
	var height = "";
	var h = _h;
	
	// Width ---------------------------
	if(_w > w ){
		h = (w*_h/_w);
		width = "width:"+w+"px;";		
	}
	else{
		w = (_w);
		width = "width:"+w+"px;";			
	}
	// HEIGHT -----------------------
	if(h > ($('popDiv').getHeight() - 50) ){
		h = ($('popDiv').getHeight() - 50);
		w = (h*_w/_h);
		height = "height:"+h+"px;";		
	}
	else{
		h = (_h)+"px";
		height = "height:"+h+"px;";			
	}
	
	return {w:_w,h:_h};
}

function fitInCustom(_w,_h,areaW,areaH){
	
	var newW,newH;
	
	newW = areaW;
	newH = newW*_h/_w;
	
	if(newH > areaH){
		newH = areaH;
		newW = newH*_w/_h;
	}
	
	return {w:newW,h:newH};
}

function fitStr(str,length,truncation){
	truncation = truncation==undefined? "...":truncation;
	var trunc = str.length>length?str.slice(0,length)+truncation:str;
	
	if(trunc != str){
		for(i = trunc.length - 12;i<trunc.length;i++){
			if(trunc.charAt(i) == "&"){
				trunc = trunc.slice(0,i-1)+truncation;	
			}
		}
	}
	
	return trunc;
}

/*************************************
**************************************/
function updateDepts(){
	new Ajax.Updater('dept_list', '../../scripts/php/ajaxResponder.php', {
  		parameters: { action:'listDepts',id_region:$('region_select').value }
	});	
}

function updateVilles(){	
	new Ajax.Updater('ville_list', '../../scripts/php/ajaxResponder.php', {
  		parameters: { action:'listVilles',id_region:$('region_select').value,id_dept:$('dept_select').value }
	});	
}


/* step2: change swf for 'plan de masse' */
/* //RR404, not used anymore
function setStep2Pdm(urlSwf){
	if(urlSwf == "" || urlSwf == "null"){
		$("thePDM_container").update('<img src="../../images/default_pdm_step2.jpg" />');
	}
	else{
		var so = new SWFObject(urlSwf, "PlanDeMasseEnFlash", "211", "145", "8");
		so.addVariable("reserve", current_reLots);
		so.addVariable("vendu", current_naLots);
		so.addVariable("avaible", current_avLots);
		so.write("thePDM_container");	
	}
}
*/

function setStep3Pdm(urlSwf){ // setStep3Pdm: need to change the size of the swf and make sure in main.php that it is centered verticaly
	/* setStep3Pdm_w & h from iprospec_config.js */
	$("thePDM_container").update('<div id="PDMFlashContainer"></div>');
	
	if(urlSwf == "" || urlSwf == "null"){
		//$("PDMFlashContainer").update('<img width="'+setStep3Pdm_w_ifNull+'" height="'+setStep3Pdm_h_ifNull+'" src="../../images/default_pdm_step2.jpg" />')
		$("PDMFlashContainer").update('<img width="'+setStep3Pdm_w_ifNull+'" height="'+setStep3Pdm_h_ifNull+'" src="../../images/default_pdm_step2_large.jpg" />');
	}
	else{
		//alert("urlSwf end with JPG ? " + urlSwf.endsWith(".jpg"));
		/* // OLD WAY
		var so = new SWFObject(urlSwf, "PlanDeMasseEnFlashST3", setStep3Pdm_w, setStep3Pdm_h, "8");
		so.addParam("wmode", "transparent");
		so.addVariable("reserve", current_reLots); //not used for now //rr404
		so.addVariable("vendu", current_naLots);
		so.addVariable("avaible", current_avLots);
		so.addVariable("_info",current_lots_details);
		so.write("thePDM_container");	
		*/
		// swfObject 2-2 
		//var flashvars = {reserve:current_reLots,vendu:current_naLots,avaible:current_avLots,_info:current_lots_details};
		var flashvars = {_info:current_lots_details};
		var params = {wmode:"transparent"};
		var attributes = {id:"PlanDeMasseEnFlashST3", name:"PlanDeMasseEnFlashST3"};
		//var attributes = {};
		//FAKE TEST !!!
		//swfobject.embedSWF("../../programmes/1214235667953/plan_masse_page3.swf", "PDMFlashContainer", ""+setStep3Pdm_w, ""+setStep3Pdm_h, "9.0.0","../../swf/expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF(urlSwf, "PDMFlashContainer", ""+setStep3Pdm_w, ""+setStep3Pdm_h, "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);
	}
}


function setStep2Vdo(urlVdo){
	
	//deal with eventual JSON strings
	var jsonVar = null;
	var prefix = "";
	var postfix = "";
	
	try{
		jsonVar = urlVdo.evalJSON();	
	}
	catch(e){
		jsonVar = null;
	}
	
	if(jsonVar != null){
		if(jsonVar.type != null){
			if(jsonVar.type == "mvi3d"){
				urlVdo  = jsonVar.picture;
				
				if(jsonVar.w < 0) jsonVar.w = 640;
				if(jsonVar.h < 0) jsonVar.h = 480;
				
				if(jsonVar.url != ""){
					prefix  = '<span onclick="OpenPopUp(\''+jsonVar.url+'\','+jsonVar.w+','+jsonVar.h+')" style="cursor:pointer;" >';
					postfix = '</span>';
				}
			}
			else{
				if(jsonVar.picture != null)
				urlVdo = jsonVar.picture;
			}
		}
		else{
			if((jsonVar.picture != "") && (jsonVar.picture != null))
				urlVdo = jsonVar.picture;
		}
	}
	else{
		//nothing
	}

	popVdoURL=urlVdo;
	
	if(urlVdo == "" || urlVdo == "null"){
		$("step2_vdo").update('<img src="../../images/default_vdo_step2.jpg" alt="Image" />');
	}
	else{		
		if(urlVdo.endsWith(".jpg"))	{
			$("step2_vdo").update('<img src="'+urlVdo+'" alt="Image" width="211" height="145"/>');
		}
		else{
			$("step2_vdo").update('<div id="step2_vdo_container">');

			if(urlVdo.endsWith(".swf")){
				/* // OLD WAY
				var so = new SWFObject(urlVdo, "VDOStep2", "211", "145", "8");
				so.addParam("wmode", "transparent");
				so.write("step2_vdo");
				*/
				// swfObject 2-2 
				
				var flashvars = {};
				var params = {wmode:"transparent"};
				var attributes = {id:"VDOStep2", name:"VDOStep2"};
				swfobject.embedSWF(urlVdo, "step2_vdo_container", "211", "145", "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);
				
			}
			else{ // --> FLV
				/* // OLD WAY 
				var so = new SWFObject("../../swf/page2VideoPlayer.swf", "VDOStep2", "211", "145", "8");
				so.addParam("wmode", "transparent");
				so.addVariable("urlVDO",urlVdo);
				so.write("step2_vdo");
				*/

				var flashvars = {urlVDO:urlVdo};
				var params = {wmode:"transparent"};
				var attributes = {id:"VDOStep2", name:"VDOStep2"};
				swfobject.embedSWF("../../../Generic_lib/swf/page2VideoPlayer.swf", "step2_vdo_container", "211", "145", "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);
			}
		}
	}
	
	if(prefix!="") $("step2_vdo").update(prefix+$("step2_vdo").innerHTML+postfix);
}

function setStep3Preview(urlFile){
	//setStep3Preview_step3_thumb_style from iprospec_config.js
	if(urlFile == "" || urlFile == "null"){
		$("step3_thumb").update('<img src="../../images/default_vdo_step2.jpg" border=0 width="346" height="205" style="'+setStep3Preview_step3_thumb_style_null+'" />');
	}
	else{
		if(urlFile.endsWith(".jpg")){
			$("step3_thumb").update('<img src="'+urlFile+'" border=0 width="346" height="205" style="'+setStep3Preview_step3_thumb_style_jpg+'" />');
		  
    }else if(urlFile.endsWith(".flv")){		
			
//		var obj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="211" height="144">'
//				  +'<param name="movie" value="../../swf/page2VideoPlayer.swf" />'
//  				  +'<param name="quality" value="high" />'
//                  +'<param name="FlashVars" value="'+urlVdo+'" />'
//                  +'<embed src="../../swf/page2VideoPlayer.swf" width="211" height="144" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" flashvars="'+urlVdo+'"></embed>'
//				  +'</object>';
			
			/* // OLD WAY
			var so = new SWFObject("../../swf/page2VideoPlayer.swf", "PlanDeMasseEnFlashST3", "346", "205", "8");
			so.addParam("wmode", "transparent");
			so.addVariable("urlVDO", urlFile);
			so.write("step3_thumb");
			*/
			// swfObject 2-2 
			var flashvars = {urlVDO:urlFile};
			var params = {wmode:"transparent"};
			var attributes = {id:"PlanDeMasseEnFlashST3", name:"PlanDeMasseEnFlashST3"};
			swfobject.embedSWF("../../../Generic_lib/swf/page2VideoPlayer.swf", "step3_thumb", "346", "205", "9.0.0","../../../Generic_lib/swf/expressInstall.swf", flashvars, params, attributes);

		}else{
			$("step3_thumb").update('<img src="../../images/default_vdo_step2.jpg" border=0 width="346" height="205" style="'+setStep3Preview_step3_thumb_style_default+'" />');
		}
	}
}

// DO THE SAME FOR THE VIDEO in STEP 2 and the PDM, visite, perspectives IN STEP 3  // RR404 !

/*############################
## MISC Functions ##########*/
/* navigation function from progression bar */

/**************Eli ***** Ajout de fonctions pour le rollover des boutons progression****************/
//Boutons highlightés suite click
function highLightButtons()
{
	if($('bouton1')!=null) $('bouton1').update(currentButton1);
	if($('bouton2')!=null) $('bouton2').update(currentButton2);
	if($('bouton3')!=null) $('bouton3').update(currentButton3);
}

/********************************************************************************************************/

// ***** Eli ***** fonction modifier pour le rollover des bontons progression *****/
function gotoSection1(){ 

	currentVal.step = "one";
	
	/*Eli*****modif*/
	currentButton1 = button1_on;
	currentButton2 = button2_off;
	currentButton3 = button3_off;
	highLightButtons();
	/*////////////////////*/
	
	gotoSection1_div_actions(); // in  iprospec_config.js //eventually move the whole function to config
}

// ***** Eli ***** fonction modifier pour le rollover des bontons progression *****/
function gotoSection2(){
	if(step2_relevant){
		currentVal.step = "two";

		/*Eli*****modif*/
		currentButton1 = button1_off;
		currentButton2 = button2_on;
		currentButton3 = button3_off;
		highLightButtons();
		/*//////////////////////*/
		
		gotoSection2_div_actions(); //in  iprospec_config.js
	}
}

// ***** Eli ***** fonction modifier pour le rollover des bontons progression *****/
function gotoSection3(){
	if(step3_relevant){
		currentVal.step = "three";
		
		
		currentButton1 = button1_off;
		currentButton2 = button2_off;
		currentButton3 = button3_on;
		highLightButtons();
		
		
		 gotoSection3_div_actions(); //in  iprospec_config.js
	}
}

function prog_2_active(setTo){
	if($('progArea2') != null){
		if(setTo == true) $('progArea2').setStyle({cursor:'pointer'});
		else $('progArea2').setStyle({cursor:'default'});
	}
}

function prog_3_active(setTo){
	if($('progArea3') != null){
		if(setTo == true) $('progArea3').setStyle({cursor:'pointer'});
		else $('progArea3').setStyle({cursor:'default'});
	}	
}

function openForm(){
	var params = "./form.php?idPrg="+currentVal.program_id+"&idLot="+currentVal.lot_id+"&a="+isAccedant;
	OpenPopUp(params,390,465);
}

/* Scroll related function: init */  //not used for now
function init_dw_Scroll() {
	var wndo = new dw_scrollObj('PRGM_list', 'PRGM_list_container');
	wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
	//wndo.setUpScrollControls('scrollbar', true, 'v');
	//wndo.setUpLoadLinks('scroll_controls');
	//wndo.setUpScrollControls('scroll_controls');
}



/************************
**
**  FONCTIONS CALLED BY FLASH       // Sort if in proper categories later // RR404
**
***********************************************/
//function setupPDM(fake){  // Not used for now... flashvars implemented
//	/* reserve, vendu, published */
//	if((current_naLots == undefined) || (current_naLots == null))
//				current_naLots = "";
//				
//	if((current_avLots == undefined) || (current_avLots == null))
//		current_avLots = "";
//				
//	if(($('PlanDeMasseEnFlashST3') != null) && (currentVal.step == "three")){
//		$('PlanDeMasseEnFlashST3').echo("",current_naLots,current_avLots);
//	}
//	
//	if(($('PlanDeMasseEnFlash') != null) && (currentVal.step == "two")){
//		$('PlanDeMasseEnFlash').echo("",current_naLots,current_avLots);
//	}
//}

function setLotPDM(numLot){
	if(($('PlanDeMasseEnFlashST3') != null) && ($('PlanDeMasseEnFlashST3').currentPlace != null)){
		$('PlanDeMasseEnFlashST3').currentPlace(numLot);
	}
	else{
		//do something ??  	
	}
}

function DisplayLot(str) {
	//alert("lot : " + str);
	//if(currentVal.step == "two")s
	gotoSelection($(String(str)).readAttribute('sid'),3,str);
}

function RollOverFunction(str){
	if(currentVal.step == "two"){
		hlSelection_lot(str);
	}
}

function RollOutFunction(){
	if(currentVal.step == "two"){
		unhlSelection_lot();
	}
}

function videoClick(w,h){
	//mathieu alert(currentVal.program_VDO);
	//popVdo(currentVal.program_VDO,w,h); OLD WAY
	popVdo(popVdoURL,w,h);
}

function videoClose(){
		closePop();
}
/******END OF SECTION***********/


function rearangeBy(str){
	// Rearangement du tablea de résultat et changement de l'image up_arrow.jpg en down_arrow.jpg
	//on the way
	//$('LOT_list_container').childElements().sortBy(function(e){return (-1)*e.readAttribute('nsurf');}).each(function(e){$('LOT_list_container').insert({bottom:e.innerHTML})})
	
	//var lot_order_priceASC = true;
	//var lot_order_surfASC = true;
	$('LOT_list_container').update('');
	
	switch(str){
		
		case "description":
			//alert("descr");
			break;
			
/*Eli***** Modification des images**********/
		case "prix":
			/*Eli*****modif* a vérifier*/$('surfaceOrderImg').writeAttribute('src',"../../images/up_arrow_on.gif");
			var tempRealPricedLots = new Array();
			var tempNCPricedLots = new Array();
			
			//alert(current_lots_list.length);
			for(i=0;i<current_lots_list.length;i++){
				if(current_lots_list[i].prix ==0) tempNCPricedLots.push(current_lots_list[i]);
				else tempRealPricedLots.push(current_lots_list[i]);
			}
			
			if(lot_order_priceASC){				
				/*Eli*****modif* a vérifier*/$('priceOrderImg').writeAttribute('src',"../../images/downred_arrow.gif");	
				//current_lots_list = current_lots_list.sortBy(function(l){return (-1)*l.prix});
				current_lots_list = tempRealPricedLots.sortBy(function(l){return (-1)*l.prix}).concat(tempNCPricedLots);
				lot_order_priceASC = false; 
			}
			else{
				/*Eli*****modif* a vérifier*/$('priceOrderImg').writeAttribute('src',"../../images/up_arrow_on.gif");
				//current_lots_list = current_lots_list.sortBy(function(l){return l.prix});
				current_lots_list = tempRealPricedLots.sortBy(function(l){return l.prix}).concat(tempNCPricedLots);
				lot_order_priceASC = true;
			}
			break;
		case "surface":
			/*Eli*****modif* a vérifier*/$('priceOrderImg').writeAttribute('src',"../../images/up_arrow_off.gif");
			
			var tempRealPricedLots = new Array();
			var tempNCPricedLots = new Array();
			
			//alert(current_lots_list.length);
			for(i=0;i<current_lots_list.length;i++){
				if(current_lots_list[i].prix ==0) tempNCPricedLots.push(current_lots_list[i]);
				else tempRealPricedLots.push(current_lots_list[i]);
			}
			
			if(lot_order_surfASC){				
				/*Eli*****modif* a vérifier*/$('surfaceOrderImg').writeAttribute('src',"../../images/downred_arrow.gif");				
				//current_lots_list = current_lots_list.sortBy(function(l){return (-1)*l.sup});
				current_lots_list = tempRealPricedLots.sortBy(function(l){return (-1)*l.sup}).concat(tempNCPricedLots);
				lot_order_surfASC =false;
			}
			else{
				/*Eli*****modif* a vérifier*/$('surfaceOrderImg').writeAttribute('src',"../../images/up_arrow_off.gif");
				//current_lots_list = current_lots_list.sortBy(function(l){return l.sup}).concat(tempNCPricedLots);
				current_lots_list = tempRealPricedLots.sortBy(function(l){return l.sup}).concat(tempNCPricedLots);
				lot_order_surfASC = true;
			}
			break;
		default:
			break;
	}
	
	var nplace = 0;
	current_lots_list.each(function(theR){
						
						// Print the results // printResult:function(sId,nb_p,nom,ot,ob,op,oc,oj,url_thumb,ref_pdm,superf,prix,dispo)
						$('LOT_list_container').insert({bottom:tdvTemplate.step2.printResult(theR.lot_id,theR.nb_p,theR.nom,theR.ot,theR.ob,theR.op,theR.oc,theR.oj,theR.url_thumb,theR.ref_pdm,theR.sup,theR.prix,theR.dispo,nplace)});	
						nplace++;
					});	
}

function OpenPopUp(trgt,_width,_height){
	popup = window.open(trgt,'info','width='+ _width+', height='+_height+',menubar=no, status=no, scrollbars=no');
	if(setFocusOnPop == true)popup.focus();
}

function PopHtml(trgt){ //...craaade ? not from rr404
	popup = window.open(trgt,'info','width=1024, height=768');
	if(setFocusOnPop == true)popup.focus();
}

function reglette(str){
	alert(str);
	$('reglette').value = str;
}

/***********************************************
** Misc Functions *****************************/

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_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_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];}
}
//]]>
