function StockClassInfo(product)
{
	var _class = "";
	var _text = "";
	var _product = product;
	var _newProduct = false;
	var _newInStock = false;
	var enum_productStock = { Rupture:-1, Indisponible:0, Limite:1, Stock:10 };
	
	this.GetClass = function() {
		return _class;
	};
	this.SetClass = function(class_name) {
		_class = class_name;
	};
	
	this.GetText = function() {
		return _text;
	};
	this.SetText = function(text) {
		_text = text;
	};
	this.IsNewProduct = function() {
		return _newProduct;
	};
	this.IsNewInStock = function() {
		return _newInStock;
	};
	this.IsAvailable = function() {
		switch ( Number(_product.Stock) )
		{
			case enum_productStock.Limite:
			case enum_productStock.Stock:
				return true;
		
		}
		return false;
	};
	
	GestionStock = function() {
		switch ( Number(_product.Stock) )
		{
			case enum_productStock.Rupture:
			{
				_class = "rupture";
				_text = "Rupture";
			}
			break;
			case enum_productStock.Indisponible:
			{
				_class = "indisponible";
				_text = "Indisponible";
			}
			break;
			case enum_productStock.Limite:
			{
				_class = "stock_limite";
				_text = "Stocks limités";
			}
			break;
			case enum_productStock.Stock:
			{
				_class = "stock";
				_text = "En Stock";
			}
			break;
			default:
				alert("Stock value unknown!");
		}
		return Number(_product.Stock);
	};
	
	GestionClassSpe = function() {
		var date = new Date();
		var today = date.getTime();
		var dateCreationProduct = getDate(_product.CreationDate);
		var prdCreationDate = dateCreationProduct.getTime();
		var dateModificationProduct = null;
		if ( Number(_product.MettreEnAvant) ) {
			dateModificationProduct = getDate(_product.ModificationDate);
			prdModificationDate = dateModificationProduct.getTime();
			if ( prdModificationDate > prdCreationDate ) {
				if ( prdModificationDate>=(today-(7*24*60*60*1000)) && (prdModificationDate<=today) ) {
					_newInStock = true;
					_class = 'newInStock';
					_text = 'De nouveau en Stock';
				}
			}
			return;
		}
		if ( prdCreationDate >= (today-(7*24*60*60*1000)) && (prdCreationDate<=today) ) {
			_newProduct = true; 
			_class = 'newProduct';
			_text = 'Nouveau';
		}
	};
	
	Initialize = function() {
		var ret = GestionStock();
		if ( enum_productStock.Indisponible < ret ) {
			GestionClassSpe();
		}
	};
	
	Initialize();
}

function CRange(min, max)
{
	this.min = min;
	this.max = max;
	
	this.GetMin = function() {
		return this.min;
	};
	this.SetMin = function(min) {
		this.min = min;
	};
	
	this.GetMax = function() {
		return this.max;
	};
	this.SetMax = function(max) {
		this.max = max;
	};
}

enum_pagerStyle = { none:0, top:1, bottom:2, both:3 };

function CColumnInfo(name, selected)
{
	this.enum_sort_type = { sort_undefined:-1, sort_asc:0, sort_desc:1  };
	this.name = name;
	this.selected = selected;
	this.sorted = this.enum_sort_type.sort_undefined;
}

function CSortColumnManager() 
{
	this.columns = new Array();
	this.activeColumn = null;
	this.Types = null; // sort type : Alphanumerique, numerique, date, etc..
	
	this.Clean = function() {
		this.columns = [];
	};
	
	this.length = function() {
		return this.columns.length;
	};
	
	this.ColumnName = function(indexCol) {
		if ( this.columns.length > indexCol ) {
			return this.columns[indexCol].name;
		}
		return ""; 
	};
	
	this.SortDirection = function(indexCol) {
		if ( this.columns.length > indexCol ) {
			return this.columns[indexCol].sorted;
		}
		return undefined;
	};
	
	this.AddColumn = function(name, state) {
		if ( !this.exist(name) ) {
			var colInfo = new CColumnInfo(name, state);
			this.columns.push(colInfo);
			if ( state == true ) {
				this.SetSelected(name);
			}
		}
	};
	
	this.exist = function(name) {
		for(var i=0, imax=this.columns.length; i<imax; ++i) {
			if ( name == this.columns[i].name ) {
				return true;
			}
		}
		return false;
	};
	this.existObj = function(name) {
		for(var i=0, imax=this.columns.length; i<imax; ++i) {
			if ( name == this.columns[i].name ) {
				return this.columns[i];
			}
		}
		return null;
	};
	
	this.IsSelectedByIndex = function(indexCol) {
		if ( this.columns.length > indexCol ) {
			return this.columns[indexCol].selected;
		}
		return false;
	};
	
	this.IsSelected = function(name) {
		var o = this.existObj(name);
		if( null != o ) {
			return o.selected;
		}
		return false;
	};
	this.SetSelected = function(name) {
		var o = this.existObj(name);
		if( null != o ) 
		{
			if ( !o.selected ) {
				o.selected = true;
				o.sorted = o.enum_sort_type.sort_undefined;
			}
			
			if ( this.activeColumn ) {
				if ( this.activeColumn != o ) {
					this.activeColumn.selected = false;
				}
			}
			
			this.activeColumn = o;
			return this.activeColumn;
		}
	};
	
	this.GetSortType = function(colActive) {
		
		var type = this.Types[colActive.name];
		switch (type ) 
		{
			case 'date':
				return this.tri_date;

			case 'numerique':
				return this.tri_numerique;
			
			case 'string':
			case 'texte':
				return this.tri_string;
			
			default:
				return null;
			
		}
		return null;
	};
	
	this.toArray = function() {
		var arAssociatif = { };
		for(var i=0, imax=this.columns.length; i<imax; ++i) {
			//arAssociatif[ this.columns[i].name ] = this.columns[i].selected ;
			arAssociatif["Date"] = false;
		}
		return arAssociatif;
	};
	
}

//On suppose que la date entrée a été validée auparavant
//au format YYYY-mm-dd hh:mm:ss
function getDate(strDate)
{	  
	year = strDate.substring(0,4);
	month = strDate.substring(5,7);
	day = strDate.substring(8,10);
	hour = strDate.substring(11,13);
	min = strDate.substring(14,16);
	sec = strDate.substring(17,19);
	d = new Date();
	d.setDate(day);
	d.setMonth(month-1);
	d.setFullYear(year);
	d.setHours(hour, min, sec, 0);
	return d;  
}

CSortColumnManager.prototype = {

	tri_numerique : function(a, b) {
		return a.value-b.value;
	},
	tri_date : function(a, b) {
		d1 = getDate(a.value);
		d2 = getDate(b.value);
		//Retourne:
		//   0 si date_1=date_2
		//   1 si date_1>date_2
		//  -1 si date_1<date_2
		return (d1<d2)?1:(d1>d2)?-1:0;
	},
	tri_string : function(a, b) {
		a1 = a.value.toLowerCase(); 
		b1 = b.value.toLowerCase();
		return (a1>b1)?1:(a1<b1)?-1:0;
	}	
};

function CDisplayPageManager() 
{
	this.enum_display_mode = { display_iconized : 0, display_list:1 };
	this.enum_show_displaymode = { hide: 0, show: 1 };
	this.arProduct = new Array();
	
	this.sortColumns = new CSortColumnManager();
	this.sortAlias = null;
	this.display_mode = this.enum_display_mode.display_iconized;
	this.show_displaymode = this.enum_show_displaymode.show;
	this.resultPerPage = 0;
	this.activatePage = 1;
	this.nbPage = 0;
	this.perPage = [8, 12, 16, -1];
	
	dspmngr = this;
	this.ClassName = function () {  
		return "dspmngr";
	};
}

function CProductSortInfo(id, value, columnName)
{
	this.id = id; 
	this.value = value;
	this.columnName = columnName;
}

CDisplayPageManager.prototype = {
		
	constructor : function() {
		alert("into constructor");
	},
	
	Clean : function() {
		//this.arProduct = [];
		//this.sortColumns.Clean();
		//this.display_mode = this.enum_display_mode.display_iconized;
		this.resultPerPage = 0;
		this.activatePage = 1;
		this.nbPage = 0;
		this.pagerStyle = enum_pagerStyle.none;
		this.title = null;
	},
		
	Init : function()
	{
		if (arguments.length > 0)
		{
		    this.Clean();

		    var o = arguments[0];

		    if (o.sortColumn){
		    	for (var i=0, imax=o.sortColumn.length; i<imax; ++i){
		            this.sortColumns.AddColumn( o.sortColumn[i], (i==0 ? true : false) );
		        }
		    }
		    if (o.sortType) {
		    	this.sortColumns.Types = o.sortType;
		    }
		    if (o.sortAlias) {
		    	this.sortAlias = o.sortAlias;
		    }
		    
		    if ( o.perPage ) {
		    	if ( o.perPage.length ) {
		    		this.perPage = o.perPage;
		    	}
		    }
		    
		    if ( o.pagerStyle ) {
	    		switch ( o.pagerStyle )
	    		{
	    			case 'top' : 
		    			this.pagerStyle = enum_pagerStyle.top;
		    		break;
		    		case 'bottom' : 
		    			this.pagerStyle = enum_pagerStyle.bottom;
		    		break;
		    		case 'both' :
		    			this.pagerStyle = enum_pagerStyle.both;
		    		break;
		    	}
		    }
		    
		    if ( o.title && o.title.length ) {
		    	this.title = Remplacer(o.title, "'", "\'"); 
		    }
		    
		    if ( o.showDisplayMode ) {
		    	switch(o.showDisplayMode) {
		    		case 'hide':
		    			this.show_displaymode = this.enum_show_displaymode.hide;
		    		break;
		    		case 'show':
		    			this.show_displaymode = this.enum_show_displaymode.show;
		    		break;
		    		default:
		    			this.show_displaymode = this.enum_show_displaymode.show;
		    		break;
		    	}
		    }
		    
		    if ( o.displayMode ) {
		    	switch ( o.displayMode ) {
		    		case 'in_line' : 
		    			this.display_mode = this.enum_display_mode.display_list;
		    		break;
		    		case 'iconized':
		    			this.display_mode = this.enum_display_mode.display_iconized;
		    		break;
		    		default:
		    			this.display_mode = this.enum_display_mode.display_iconized;
		    		break;
		    	}
		    }
		}
		
		this.InitHtlmCtrl();
		this.InitSort();
		this.InitPage();
		this.InitPager();
		
		this.DrawPage();
	},
	
	GetAliasName : function(colName) {
		if ( this.sortAlias ) {
			var aliasName = this.sortAlias[colName];
			if ( aliasName ) {
				return aliasName;
			}
		}
		return colName;
	},
	
	InitHtlmCtrl : function() {
		var html = "<div id='displaybar' >";
		if ( this.title != null ) {
			html += "<div id='displaybar_title'>" + this.title + "</div>";
		}
		html += "</div>"; 
		$("#pages").append(html);
	},
	
	GetStyle : function(selected) {
		if ( selected ) {
			return "currentsort";
		}
		return "";
	},
	
	InitSort : function() {
		
		if( null != this.sortColumns.activeColumn) 
		{
			this.sortProduct(this.sortColumns.activeColumn);
		
			var html = "<div id='displaybar_header'><ul>";
			for (var i=0, imax=this.sortColumns.length(); i<imax; ++i) 
			{
				var colName = this.sortColumns.ColumnName(i);
				var selected = this.sortColumns.IsSelected(colName);
				html += "<li id='by" + colName + "' class='" + this.GetStyle(selected) + "' style='cursor:pointer;' onclick='" + this.ClassName() + ".Sort(\"" + colName + "\");'>Trier par " + this.GetAliasName(colName);
				html += "<div id='" + colName + "cont_img_sort' style='display:inline;margin-left:3px;'>";
				if ( selected ) {
					if ( colName === 'CreationDate' )  {
						html +=	"<img id='img_sort' name='img_sort' alt='' src='images/sort_desc_disabled.png' />";
					}
					else {
						html +=	"<img id='img_sort' name='img_sort' alt='' src='images/sort_asc_disabled.png' />";
					}
				}
				html += "</div></li>";
			}
			html += "</ul>";
		}
		
		if ( this.show_displaymode === this.enum_show_displaymode.show )
		{
			html += "<div id='displaymodePage' >" +
						"<img id='display_line' alt='Mode ligne' title='Affichage en ligne' class='display_mode_inactive displaybar_btn_style' src='images/display_details.gif' onclick='" + this.ClassName() + ".DisplayMode(" + this.enum_display_mode.display_list + ");' />" +
						"<img id='display_icone' alt='Mode vignette' title='Affichage en vignettes' class='display_mode_active displaybar_btn_style' src='images/display_icone.gif' onclick='" + this.ClassName() + ".DisplayMode(" + this.enum_display_mode.display_iconized + ");' />" + 
					"</div>";
		}
		
		html += "</div>";

		$("#displaybar").append(html);
	},
	
	InitPage : function() {
		$("#displaybar").append("<div id='pagePoducts'></div>");
	},	
	
	ComputePagination : function(selectedPerPage) {
		var len = this.arProduct.length;
		this.resultPerPage = parseInt(selectedPerPage);
		if ( this.resultPerPage > -1 )
		{
			var reste = (len % this.resultPerPage);
			if( reste != 0 ) {	
				this.nbPage = parseInt((len / this.resultPerPage)+1);
			}
			else {
				this.nbPage = (len / this.resultPerPage);
			}
		}
		else {
			this.resultPerPage = len;
		}
		
		if ( this.activatePage > this.nbPage ) {
			this.activatePage = 1;
		}
	},

	InitPager : function()
	{
		this.ComputePagination(this.perPage[0]);
		
		if ( this.pagerStyle == enum_pagerStyle.none ) {
			return;
		}

		if ( this.pagerStyle & enum_pagerStyle.top ) {
			var html = this.createHtmlPager(enum_pagerStyle.top);
			$("#displaybar_header").after(html);
		}
		if ( this.pagerStyle & enum_pagerStyle.bottom ) {
			var html = this.createHtmlPager(enum_pagerStyle.bottom);
			$("#displaybar").append(html);
		}
		
		this.DrawPagination();
	},
	
	createHtmlPager : function(id) {
		
		var pageNumeratorClass = "";
		if ( id & enum_pagerStyle.top ) {
			pageNumeratorClass = "top";
		}
		else if ( id & enum_pagerStyle.bottom) {
			pageNumeratorClass = "bottom";
		}
		var html = '';
		// init pager per page
		/*if ( id & enum_pagerStyle.bottom) {
			html += '<div style="clear:both;border-bottom:solid 1px gray;width:640px;" ></div>';
		}*/

		html += "<div id='pagenumerateur" + id.toString() + "' class='pagerNumerator " + pageNumeratorClass + "' >" +
					"<div style='float:left;width:190px;position:relative;'>" +
						"<div style='float:left;position:relative;'>" + 
							"<select id='productperpage" + id.toString() + "' onchange='" + this.ClassName() + ".OnChangeResultPerPage(this);'>"; 
		for (var i=0, imax=this.perPage.length ; i<imax ; ++i) {
			var value = (this.perPage[i]==-1? 'Tout' : this.perPage[i]);
			html += 				"<option value='" + this.perPage[i] +"'>" + value + "</option>";
		}
		html += 			"</select>" + 
						"</div>" +
						"<div style='float:left;padding-left:3px;position:relative;' >résultats par page</div>" +
					"</div>";
		html += 	"<div id='pagerPagination" + id.toString() + "' class='pagerPagination'></div>";
		html +=	"</div>";

		/*if ( id & enum_pagerStyle.top ) {
			html += '<div style="border-top:solid 1px gray;width:640px;" ></div>';
		}*/
		
		return html;
	},
	
	GetProduct : function() {
		return this.arProduct;
	},
	
	GetProductByIndex : function(index) {
		if (index<this.arProduct.length) {
			return this.arProduct[index];
		}
		return null;
	},
	GetIndexById : function(id){
		for (var j=0; j<this.arProduct.length; ++j) {
			if ( id == this.arProduct[j]['ID']) {
				return j;
			}
		}
		return -1;
	},
	
	SetProduct : function(arProduct) {
		this.arProduct.push(arProduct);	
	},
	
	findProduct : function(id) {
		for (var j=0; j<this.arProduct.length; ++j) {
			if ( id == this.arProduct[j]['ID']) {
				return this.arProduct[j];
			}
		}
		return null;
	},
	
	find : function(productSortInfo)
	{
		for (var j=0; j<this.arProduct.length; ++j) 
		{
			if ( productSortInfo.id == this.arProduct[j]['ID'])
			{
				var findProduct = this.arProduct[j];
				this.arProduct.splice(j, 1);
				return findProduct;
			}
		}
		return null;
	}, 
	sortProduct : function(colActive) {
		
		var arTri = new Array();
		var len = this.arProduct.length;
		for (var i=0; i<len; ++i) 
		{
			/**
			 * 
			 * Cette partie de code gère le fait qu'on met en priorité les dates de modification
			 * puis les dates de créations.
			 * Ce code est spécifique à ALCP il faudra trouver un moyen de rendre ce code plus
			 * programmation objet et donc l'enlever du displaypagemanager
			 *  
			 */
			if ( colActive.name === 'CreationDate' ) 
			{
				// seulement si on veut mettre en avant le produit
				if ( this.arProduct[i]['MettreEnAvant'] == 1 ) 
				{
					var modificationDate = this.arProduct[i]['ModificationDate'];
					if ( modificationDate != null && modificationDate.length ) {
						arTri.push(new CProductSortInfo(this.arProduct[i]['ID'], modificationDate, 'ModificationDate'));
						continue;
					}
				}
			}
			else if ( colActive.name === 'Prix' ) 
			{
				var promo = this.arProduct[i]['Promo'];
				if ( promo != null && promo.length ) {
					arTri.push(new CProductSortInfo(this.arProduct[i]['ID'], promo, 'Promo'));
					continue;
				}
			}

			arTri.push(new CProductSortInfo(this.arProduct[i]['ID'], this.arProduct[i][colActive.name], colActive.name));
		}
		
		if ( colActive.sorted == colActive.enum_sort_type.sort_undefined ) {
			var fn = this.sortColumns.GetSortType(colActive);
			if ( null != fn ) {
				arTri.sort(fn);
			}
			else {
				arTri.sort();
			}
				
			if ( colActive.name === 'CreationDate' ) {
				colActive.sorted = colActive.enum_sort_type.sort_desc;
			}
			else {
				colActive.sorted = colActive.enum_sort_type.sort_asc;
			}
		}
		else {
			arTri.reverse();
			colActive.sorted = (colActive.sorted == colActive.enum_sort_type.sort_desc ?
					colActive.enum_sort_type.sort_asc : colActive.enum_sort_type.sort_desc); 
		}

		var arTemp = new Array();
		var len = arTri.length;
		for (var i=0; i<len; ++i) {
			var  result = this.find(arTri[i]);
			if ( null != result ) {
				arTemp.push(result);
			}
		}
		this.arProduct = arTemp;
	},
	
	Sort : function(colName) {
		var previousColActive = this.sortColumns.activeColumn;
		var colActive = this.sortColumns.SetSelected(colName);
		this.sortProduct(colActive);
		
		if ( previousColActive == null || 
				colActive.name != previousColActive.name ) 
		{
			$("#by" + colActive.name).addClass("currentsort");
			$("#by" + previousColActive.name).removeClass("currentsort");
		}
		
		if ( null != previousColActive && previousColActive.name != colActive.name ) {
			$("#" + previousColActive.name + "cont_img_sort").empty();
		}

		if ( colActive.sorted == colActive.enum_sort_type.sort_asc ) {
			if ( undefined === $("#img_sort")[0] ) {
				var html =	"<img id='img_sort' name='img_sort' alt='' src='images/sort_asc_disabled.png' />";
				$("#" + colActive.name + "cont_img_sort").append(html);
			}
			else {
				$("#img_sort")[0].src = 'images/sort_asc_disabled.png';
			}
		}
		else {
			if ( undefined === $("#img_sort")[0] ) {
				var html =	"<img id='img_sort' name='img_sort' alt='' src='images/sort_desc_disabled.png' />";
				$("#" + colActive.name + "cont_img_sort").append(html);
			}
			else {
				$("#img_sort")[0].src = 'images/sort_desc_disabled.png';
			}
		}

		this.DrawPage();
	},
	
	DisplayMode : function(mode) {
		if ( this.show_displaymode === this.enum_show_displaymode.show )
		{
			if ( this.display_mode !== mode ) 
			{
				this.display_mode = mode;
				$('#display_icone').toggleClass("display_mode_active", (mode === this.enum_display_mode.display_iconized));
				$('#display_icone').toggleClass("display_mode_inactive", (mode === this.enum_display_mode.display_list));
				$('#display_line').toggleClass("display_mode_active", (mode === this.enum_display_mode.display_list));
				$('#display_line').toggleClass("display_mode_inactive", (mode === this.enum_display_mode.display_iconized));
			}
		}
		this.DrawPage();
	},
	
	OnChangeResultPerPage : function(sender) {
		
		var senderCtrl = $("#" + sender.id)[0];
		var selectedIndex = senderCtrl.selectedIndex;
		//alert("selectedIndex : " + selectedIndex);
		var resultPerPage = parseInt(senderCtrl.options[selectedIndex].value);
		this.ComputePagination(resultPerPage);
		
		var updateSelectPerPage = null;
		var top = "productperpage" + enum_pagerStyle.top.toString();
		var bottom = "productperpage" + enum_pagerStyle.bottom.toString();
		if ( sender.id == top  ) {
			if ( this.pagerStyle & enum_pagerStyle.bottom ) {
				updateSelectPerPage = "#" + bottom; 
			}
		}
		else if ( sender.id == bottom ) {
			if ( this.pagerStyle & enum_pagerStyle.top ) {
				updateSelectPerPage = "#" + top;
			}
		}

		if ( updateSelectPerPage != null ) {
			$(updateSelectPerPage)[0].options[selectedIndex].selected = "selected";
		}
		
		this.DrawPagination();
		this.DrawPage();
	},
	
	OnChangePage : function(page)	{
		this.activatePage = page;
		this.DrawPagination();
		this.DrawPage();
	},
	
	OnPrevious : function() {
		this.OnChangePage(( this.activatePage == 1 ? this.nbPage : this.activatePage-1));
	},
	
	OnNext : function() {
		this.OnChangePage(( this.activatePage == this.nbPage ? 1 : this.activatePage+1));
	},

	PageRange : function(range) {
		if ( this.resultPerPage == this.arProduct.length) {
			this.activatePage = 1;
			this.nbPage = 1;
		}
		if ( this.activatePage > this.nbPage ) {
			//this.activatePage = 0;
			this.activatePage = 1;
		}
		//var min = parseInt((this.resultPerPage*(0 == this.activatePage ? 0 : (this.activatePage-1))));
		var min = parseInt((this.resultPerPage*(this.activatePage-1)));
		range.SetMin( min );
		range.SetMax( parseInt(min+this.resultPerPage) );
	},

	DrawPagination : function() {
		
		if ( this.pagerStyle == enum_pagerStyle.none ) {
			return;
		}
		if ( this.pagerStyle & enum_pagerStyle.top ) {
			var id = "#pagerPagination" + enum_pagerStyle.top.toString();
			this.DrawPaginationSpe(id);
		}
		if ( this.pagerStyle & enum_pagerStyle.bottom ) {
			var id = "#pagerPagination" + enum_pagerStyle.bottom.toString();
			this.DrawPaginationSpe(id);
		}
	},
	
	DrawPaginationSpe : function(id) {
	
		$(id).empty();

		var html = "";
		if ( this.resultPerPage != this.arProduct.length) 
		{
			html += "<div style='float:left;width:650px;' >" +
						"<div style='float:left;margin-right:8px;' ><a class='prev_next' href='' onclick='"+ this.ClassName() + ".OnPrevious(); return false;'><<</a></div>" +
						"<ul>";
			for (var page=1; page<=this.nbPage; ++page) {
				if ( page == this.activatePage ) {
					html += "<li class='activePageNumber'>" + page + "</li>";
				}
				else {
					html += "<li class='inactivePageNumber' onclick='"+ this.ClassName() + ".OnChangePage("+page+");'>" + page + "</li>";
				}
			}
			html += 	"</ul>";
			html += 	"<div style='float:left;padding-left:5px;' ><a class='prev_next' href='' onclick='" + this.ClassName() + ".OnNext(); return false;'>>></a></div>" +
					"</div>";
		}
		
		$(id).append(html);		
	},
	
	DrawPage : function() {

		switch (this.display_mode) 
		{
		case this.enum_display_mode.display_iconized:
			this.BuildThumbnails();
			break;
		case this.enum_display_mode.display_list:
			this.BuildInLine();
			break;
		}
	},
	
	BuildInLine : function() {

		$("#pagePoducts").empty();
		var insertData = '';

		var range = new CRange();
		this.PageRange(range);
		for (var i=range.GetMin(); i<range.GetMax(); ++i) 
		{
			if ( i >= this.arProduct.length) break;
			insertData += this.DisplayInLine(i);
		}
		$("#pagePoducts").append(insertData);
	},
	
	BuildThumbnails : function() 	{
			
		$("#pagePoducts").empty();
		var line = 1;
		
		var insertData = '<ul class="in_thumbnails">';
		
		var range = new CRange();
		this.PageRange(range);
		for (var i=range.GetMin(); i<range.GetMax(); ++i) 
		{
			if ( i >= this.arProduct.length) break;
			insertData += this.DisplayThumbnails2(i); //this.arProduct[i]);
		}
		
		insertData += '</ul>';
		$("#pagePoducts").append(insertData);
	},
	
	DisplayInLine : function(index) {
		var product = this.GetProductByIndex(index);
		nom_produit = Remplacer(product['Nom'], "'", "\'");
		type_produit = Remplacer(product['Type'],  "'", "\\'");
		var prix_produit = product['Prix'];
		var prix_promo = null;
		if ( product['Promo'] != null && product['Promo'].length ) {
			prix_promo = product['Promo'];
		}
		
		var photos = product.Photo.split(";");
		
		var html = '<div id="product'+ product.ID + '" class="parure">';
		html += '		<div class="title">';
		html += '			<div class="text" >';
		html += 			nom_produit;
		html += '			</div>';

		var stock_class = new StockClassInfo(product);
		html += '			<div class="stock_class ' + stock_class.GetClass() + '" >';
		html += 			stock_class.GetText();
		html += '			</div>';
	    html += ' 			<div class="btn_achat" >';
		nom_produit = Remplacer(nom_produit, "\'", "\\'");
		product_name = nom_produit + "|" + type_produit;
		var _prix_produit = prix_produit;
		if ( prix_promo != null ) {
			_prix_produit = prix_promo;
		}		
		if ( stock_class.IsAvailable() ) {
			html += '			<img alt="" src="images/ajouter_panier.gif" onclick="javascript:AddNewProduct(\'' + product_name  + '\', \'' + _prix_produit + '\');_ShowHideDialogFX(\'panier/ajouter_produit.php?id=' + product.ID + '\');" style="cursor:pointer;" />';
		}
	    html += '			</div>';
		html += '		</div>';
		html += '		<div class="container">';
		html += '			<div class="product_info">';
		html += '				<span class="picture">';
		html += '					<img id="img' + product.ID + '" src="produits/images/174x232/'+ photos[0] +'" onclick="new CZoomProduitDlg(' + index + ');" style="cursor:pointer;" />';
		html += '			    	<span></span>';
		html += '			    </span>';
		html += '			</div>';
		html += '	        <div class="in_line_details_spe details " >';
		html += '				<div class="description" >';

		var descriptif = product.Descriptif;
		var count = descriptif.length;
		if ( count ) {
			if ( count > 200 ) {
				descriptif = descriptif.slice(0, 197);
				descriptif = descriptif.concat("...");
			}
			else {
				var len = count - 4;
				if ( len > 0 ) {
					descriptif = descriptif.slice(0, len);
					descriptif = descriptif.concat("...");
				}
				else {
					descriptif = "...";
				}
			}
		}
		html += '				    <div class="descriptif" >';
		html += '				    	'+descriptif;
		html += '				    </div>';
		html += '				    <div class="plus_info">';
		html += '						<img alt="" src="images/plusdinfo3.gif" onclick="new CZoomProduitDlg(' + index + ');" style="cursor:pointer;" />';
		html += '				    </div>';
		if ( prix_promo != null )
		{
			html += '				<div class="price">';
			html += '					<span style="color:#B00057;">Promo </span>';
//			html += '					<span style="color:#B00057;">Solde </span>';
//			html += '					<span style="color:#B00057;"><img alt="Solde" src="images/label_solde.gif" /></span>';
			html += '					<strike>' + formatNumber(prix_produit) + '</strike>€';
			html += '					<span >/</span>'; 
			html += '					<span style="color:#C4DE00;">' + formatNumber(prix_promo) + ' €</span>';
			html += '				</div>';
		}
		else {
			html += '				<div class="price">' + formatNumber(prix_produit) + ' €</div>';
		}
		html += '				</div>';
		html += '			</div>';
		html += '		</div>';
		html += '	</div>';

		return html;		
	},
	
	DisplayThumbnails2 : function(index) {
		product = this.GetProductByIndex(index);
		nom_produit = Remplacer(product['Nom'], "'", "\'");
		type_produit = Remplacer(product['Type'],  "'", "\\'");
		var prix_produit = product['Prix'];
		var prix_promo = null;
		if ( product['Promo'] != null && product['Promo'].length ) {
			prix_promo = product['Promo'];
		}
		
		var photos = product.Photo.split(";");
		var stock_class = new StockClassInfo(product);
		var stock_class_name = stock_class.GetClass();
		var stock_text = stock_class.GetText(); 

		var html = '<li>';
		html += '		<span class="title">'+ nom_produit +'</span>'; 	
		html += '		<span class="picture">';
		html += '			<img id="img' + product['ID'] + '" src="produits/images/174x232/'+ photos[0] +'" onclick="new CZoomProduitDlg(' + index + ');" style="cursor:pointer;" />';
		html += '			<span></span>';
		html += '		</span>';

		html += '		<div id="contenu" >';
		html += '			<div id="productStock" class="' + stock_class_name + '" >' + stock_text + '</div>';
		if ( prix_promo != null )
		{
			html += '		<div id="productPrice">';
			html += '			<span style="color:#B00057;">Promo </span>';
//			html += '			<span style="color:#B00057;">Solde </span>';
//			html += '			<span style="color:#B00057;"><img alt="Solde" src="images/label_solde.gif" /></span>';
			html += '			<strike>' + formatNumber(prix_produit) + '</strike>€';
			html += '			<span >/</span>'; 
			html += '			<span style="color:#C4DE00;">' + formatNumber(prix_promo) + '€</span>';
			html += '		</div>';
		}
		else {
			html += '		<div id="productPrice">' + formatNumber(prix_produit) + ' €</div>';
		}
						
		html += '			<div id="productBtn" >';
/*		html += '				<span style="padding-right:15px;">';
		html += '					<img alt="" src="images/plusdinfo.gif" onclick="javascript:_ShowHideDialog(\'produits/zoom_produit.php?id=' + product['ID'] + '\');" style="cursor:pointer;" />';
		html += '				</span>';
	*/	
		nom_produit = Remplacer(product['Nom'], "'", "\\'");
		product_name = nom_produit + "|" + type_produit;
		if ( prix_promo != null ) {
			prix_produit = prix_promo;
		}
		
		html += '				<div>';
		if ( stock_class.IsAvailable() ) {
			html += '				<img alt="" src="images/ajouter_panier.gif" onclick="javascript:AddNewProduct(\'' + product_name  + '\', \'' + prix_produit + '\', null);_ShowHideDialogFX(\'panier/ajouter_produit.php?id=' + product['ID'] + '\');" style="cursor:pointer;" />';
		}
		html += '				</div>';
		html += '			</div>';
		html += '		</div>';
		html += '	</li>';
		
		return html;
		
	}
};



