
function terk_updateWithSize(size){
	//alert(gTerk_objPrices.getPriceAt(size));
	window.gTerk_objPrices.updateWithSize(size);
	return true;
}
// --------------------
//
// --------------------
function terk_updateWithQuantity(quantity){
	window.gTerk_objPrices.updateWithQuantity(quantity);
	return true;
}

// --------------------
//
// --------------------

function PriceManager(objPricesList, remise, sizeInit){

	this.pre_total_field = document.getElementById('pre_total');
	this.total_field = document.getElementById('total');
	
	this.hidden_total_field = document.getElementById('fi_hidden_prix');
	this.hidden_pre_total_field = document.getElementById('fi_hidden_old_price');

	this.hidden_size_field = document.getElementById('fi_hidden_taille');
	
	
	this.current_quantity = 1;

	this.remise = remise;
	this.objPrices = objPricesList; //  {"1191":136.00, "1192":138.00, ...}
	
	this.current_size = sizeInit;

}


// --------------------
//
// --------------------
PriceManager.prototype.getPriceAt = function(index){
	if (this.objPrices.indexOf(index) !== -1){return 0;}
	return this.objPrices[index];
}
// --------------------
//
// --------------------


PriceManager.prototype.displayPrices = function(){

	var lePrix = (this.current_quantity * this.getPriceAt(this.current_size)).toFixed(2);
		
	if (this.pre_total_field){
		this.pre_total_field.innerHTML = lePrix.toString().replace('.', ',');
		this.hidden_pre_total_field.value = lePrix.toString();
	}
	if (this.remise > 0){
	lePrix = (lePrix - ((lePrix/100) * this.remise)).toFixed(2);

	}
	this.total_field.innerHTML = lePrix.toString().replace('.', ',');
	this.hidden_total_field.value = lePrix.toString();
	this.hidden_size_field.value = this.current_size;
	
}
// --------------------
//
// --------------------
PriceManager.prototype.updateWithSize=function(what){
	this.setSize(what);
	this.displayPrices();
}
// --------------------
//
// --------------------
PriceManager.prototype.updateWithQuantity=function(qte){
	this.setQuantity(qte);
	this.displayPrices();
}
// --------------------
//
// --------------------
PriceManager.prototype.setQuantity = function(n){
	this.current_quantity = n;
}	
// --------------------
//
// --------------------
PriceManager.prototype.setSize = function(n){
	this.current_size = n;
}	
// --------------------
//
// --------------------
Object.prototype.indexOf = function(val){
var n = 0;
 for(var prop in this){
  if (this[prop] == val ){
     return n;
     }
   n++;
  }
return -1;
}
// --------------------
//
// --------------------


