﻿

var CURRENCY = "$";
var CONVERSION = 1;
var DECIMAL_PLACES = 2;

if (IsUK > 0 && ResellerID == 3)
{
	CURRENCY = "&pound;";
	CONVERSION = 0.61;
	DECIMAL_PLACES = 0;
}

var PriceType = new Object();
PriceType.Money = 0;
PriceType.Percent = 1;

function Price(val, t)
{
	


	if (val == undefined)
	{
		val = 0;
	}
	if (t == undefined)
	{
		t = PriceType.Money;	
	}
	
    
    this.type = t;
    this.value = val;
    return this;

}

Price.prototype.gt = function(price)
{
	if (isNaN(price))
	{
		return this.value > price.value;
	}

	return this.value > price;

}
Price.prototype.gte = function(price)
{
	if (isNaN(price))
	{
		return this.value >= price.value;
	}
	return this.value >= price;
}
Price.prototype.lt = function(price)
{
	if (isNaN(price))
	{
		return this.value < price.value;
	}
	return this.value < price;
}
Price.prototype.lte = function(price)
{
	if (isNaN(price))
	{
		return this.value <= price.value;
	}
	return this.value <= price;
}	

Price.prototype.equal = function(price)
{
	if (isNaN(price))
	{
		return this.value == price.value;
	}
	return this.value == price;
}

Price.prototype.add = function(price)
{
	if (isNaN(price))
	{
		this.value += price.value;
		
	}
	else 
	{
		this.value += price;
	}	
	return this;
}

Price.prototype.sub = function(price)
{
	
	if (isNaN(price))
	{
		this.value -= price.value;
		
	}
	else 
	{
		this.value -= price;
	}
	return this;
}

Price.prototype.mult = function(price)
{
	if (isNaN(price))
	{
		this.value *= price.value;
	}
	else 
	{
		this.value *= price;
	}
	
	return this;
}

Price.prototype.div = function(price)
{
	if (isNaN(price))
	{
		this.value /= price.value;
	}
	else 
	{
		this.value /= price;
	}
	
	return this;
}	

Price.prototype.getSign = function()
{
	
	if (this.value < 0)
	{
		return "-";
	}
	return "";
}

Price.prototype.getValue = function()
{


	var theval = this.value;
	if (theval < 0)
	{
		theval = (-1)*this.value;
	}
	/*
	if (CONVERSION < 1)
	{
		return Math.ceil(theval*CONVERSION);
	}
	*/

	return theval;
}

Price.prototype.getSignedValue = function()
{

	/*
	if (CONVERSION < 1)
	{
		return Math.ceil(this.value*CONVERSION);
	}
	else 
	{
		return this.value;
	}
	*/

	return this.value;

}	

Price.prototype.convert = function()
{
	if (CONVERSION < 1)
	{
		return new Price(Math.ceil(this.value*CONVERSION));
	}
	else 
	{
		return new Price(this.value);
	}
}

Price.prototype.unconvert = function()
{
	return new Price(Math.floor(this.value/CONVERSION));
}

Price.prototype.valueString = function()
{
	return this.getSignedValue().toFixed(DECIMAL_PLACES);
}

Price.prototype.toString = function(useSign)
{
	var s = "";
	if (useSign != undefined && useSign)
	{
		if (this.value < 0)
		{
			s = "-";
		}
	}
    
    if (this.type == PriceType.Percent)
    {
        return s+this.getValue().toFixed(DECIMAL_PLACES)+"%";
    }
    else
    {
        
        return s+CURRENCY+(this.getValue()).toFixed(DECIMAL_PLACES);
    
    }
    
}

Price.prototype.copy = function()
{
	return new Price(this.value, this.type);
}




