/*drop downs functuons*/
function CopyElements(list, toObject)
{
	for (var j=0; j< list.length; j++)
	{	
		var oOption = document.createElement("OPTION");
		oOption.text = list[j].text;
		oOption.value = list[j].value;
		toObject.add(oOption);
	}
}

function RemElements(listObject, onlySelected)
{
	for (var j=0; j< listObject.options.length; j++)
	{
		if (onlySelected && listObject[j].selected)
		{
			listObject.remove(j);
			j--;
		}
		else
		{
			if (!onlySelected)
			{
				listObject.remove(j);
				j--;
			}
		}
	}
}
			
function FromNotInTo(fromOptions, toOptions)
{
	var results = new Array();
	for (var j=0; j< fromOptions.length; j++)
	{
		var existInTo = false;
		for (i=0; i< toOptions.length; i++)
		{
			if (fromOptions[j].value == toOptions[i].value)
			{
				existInTo = true;
				break;
			}
		}
		if (!existInTo) results.push(fromOptions[j]);
	}
	return results;
}

function GetSelected(options)
{
	var results = new Array();
	for (var j=0; j< options.length; j++)
	{
		if (options[j].selected) results.push(options[j]);
	}
	return results;
}
/*drop downs functuons*/

/*Product Object*/
var products = new Array();
function MarketProd(id, objId, colorId)
{
	this.id = id;
	this.name = "prod_" + id.split("-").join("_");
	this.inputText = document.getElementById(objId);
	if (this.inputText) this.inputText.value= "0";
	this.colorObj = document.getElementById(colorId);
	this.color = "";
	this.quantity = 0;
	
	this.ChangeColor = _prodChangeColor;
	this.Add = _prodAdd;
	this.Min = _prodMin;
	this.ToString = _prodToString;
	var func = this.name + ".ChangeColor();";
	if (this.colorObj)
	{
		this.colorObj.onchange = new Function("eval('"+ func +"')");
	}
	products.push(this);
}

function _prodChangeColor()
{
	this.color = this.colorObj.options[this.colorObj.selectedIndex].value;
}

function _prodAdd()
{
	this.quantity ++;
	if (this.colorObj && this.colorObj.options.length > 0)
	{
		this.color = this.colorObj.options[this.colorObj.selectedIndex].value;
	}
	this.inputText.value = this.quantity;
}
function _prodMin()
{
	if (this.quantity > 0) this.quantity --;
	this.inputText.value = this.quantity;
}

function _prodToString()
{
	return (this.quantity == 0) ? "" : this.id + ":" + this.color + ":" + this.quantity;
}



