﻿var SelectionControl = new function()
{
	this.GetIndex = function(pId)
	{
		return parseInt(eval(pId + "SelectedIndex"));
	}
	
	this.FormatText = function(pText)
	{
		if (pText.indexOf("'") == 0)
		{
			return pText.substring(1);
		}
		else if (pText.indexOf("'") == (pText.length - 1))
		{
			return pText.substring(0, pText.length - 1);
		}
		else
		{
			return pText;
		}
	}
	
	this.SetFromIndex = function(pId, pIndex)
	{
		var AllValues = eval(pId + "Values").split("','");
		var AllText = eval(pId + "Text").split("','");
		
		eval(pId + "SelectedValue=''");
		eval(pId + "SelectedText=''");
		eval(pId + "SelectedIndex='" + pIndex + "'"); 
		document.getElementById(pId + "_Text").innerHTML = this.FormatText(AllText[pIndex]);
	}
	
	this.SelectPrevious = function(pId)
	{
		var Index = this.GetIndex(pId);
		if (Index > 0)
		{
			Index -= 1;
			this.SetFromIndex(pId, Index);
		}
	}
	
	this.SelectNext = function(pId)
	{
		var Index = this.GetIndex(pId);
		var Limit = eval(pId + "Values").split("','").length - 1;

		if (Index < Limit)
		{
			Index += 1;
			this.SetFromIndex(pId, Index);
		}
	}
}