// JavaScript Document
var ColorddList = {
	text:"",
	index:-1
};
var GroupddList = {
	text:"",
	index:-1
};
var ThemeddList = {
	text:"",
	index:-1
};


function selectMyRange(oTextbox, nStart, nEnd) {
    oTextbox.focus();
	if(oTextbox.setSelectionRange) { // For Mozilla
        oTextbox.setSelectionRange(nStart,nEnd);
		//alert("hook1");
    }
    else if(oTextbox.createTextRange) { // For IE
        var oTextRange = oTextbox.createTextRange();
        oTextRange.moveStart("character", nStart);
        oTextRange.moveEnd("character", nEnd-oTextbox.value.length);
        oTextRange.select();
		//alert("hook2");
    }
    else {
        oTextbox.select();
		//alert("hook3");
    }
}

function ddlUnSelectMenu(obj)
{
	obj.setAttribute("class", "NotSelected");
	obj.setAttribute("className", "NotSelected");
}

function ddlSelectMenu(obj)
{
	obj.setAttribute("class", "Selected");
	obj.setAttribute("className", "Selected");
}

function OpenDDL(name, list)
{
	objId = name + "_DropDownList";
	if(!$(objId).opened)
	{
		$(objId).style.visibility = "visible";
		MenuClick = true;
		CloseAnotherDDL(name);
		$(objId).opened = 1;
		MarkItem(objId, name, list);
	}
	else
	{
		$(objId).style.visibility = "hidden";
		$(objId).opened = 0;
	}
}

function CloseDDL(name)
{
	if(Params[name]==0)
	{
		var txt = "";
		eval("txt = "+name+"List[0].text;");
		$(name + "_TxtInput").value = txt;
	}
	objId = name + "_DropDownList";
	$(objId).style.visibility = "hidden";
	$(objId).opened = 0;
}


function selectDDLItem(name, ItemNum, list)
{
	//alert(ItemNum + " = " + list[ItemNum].id);
	oTxtBox = $(name+"_TxtInput");
	CloseDDL(name);
	oTxtBox.value = list[ItemNum].text;
	Params[name] = list[ItemNum].id;
	OnChangeFilterVal();
	LockButtonStatus(name);
}

function MarkItem(ObjId, name, list)
{
	TxtBoxId = name + "_TxtInput";
	dObj = $(ObjId);
	txt = $F(TxtBoxId).toLowerCase();
	isSel = false;
	for(i=0; i<list.length; i++)
	{
		str = list[i].text.toLowerCase();
		if(str.indexOf(txt)==0 && txt != "" && isSel==false)
		{
			oOpt = $(name+"_Option"+i);
			if(oOpt && !isSel)
			{
				dObj.scrollTop   = 19*i;
				oOpt.setAttribute("className", "Selected");
				oOpt.setAttribute("class", "Selected");
			}
			else
			{
				oOpt.setAttribute("className", "NotSelected");
				oOpt.setAttribute("class", "NotSelected");	
			}
			isSel = true;
		}
		else
		{
			oOpt = $(name+"_Option"+i);
			if(oOpt)
			{
				oOpt.setAttribute("className", "NotSelected");
				oOpt.setAttribute("class", "NotSelected");
			}
		}
	}
}
function CheckStatusDDL(name, list)
{
	if(Params[name]==0)
	{
		$(name + "_TxtInput").value = "";
	}
	OpenDDL(name, list)
}
function moveToItem(env, name, list, List)
{
	oTxtBox = $(name+"_TxtInput");
	txt = oTxtBox.value.toLowerCase();
	keyPress = env.which?env.which:env.keyCode;
	dObj = $(name+"_DropDownList");
	if(keyPress == 8)
	{
		List.text = List.text.substr(0, List.text.length-1);
		txt = List.text.toLowerCase();
		oTxtBox.value = List.text;//list[i].val.substr(0, txt.length-1);
		return;
	}
	else if(keyPress == 13)
	{
		//CloseDDL("ddlContainer");
		dObj.style.visibility = "hidden";
		dObj.opened = 0;
		selectMyRange(oTxtBox, oTxtBox.value.length, oTxtBox.value.length);
		//alert(name + " = " + Params[name]+" = "+list[List.index].id);
		Params[name] = list[List.index].id;
		OnChangeFilterVal();
		LockButtonStatus(name);
		return;
	}

	if(!dObj.opened)
	{
		dObj.style.visibility = "visible";
		dObj.opened = 1;
	}
	

	isSel = false;
	for(i=0; i < list.length; i++)
	{
		str = list[i].text.toLowerCase();
		if(str.indexOf(txt)==0 && txt != "" && isSel==false)
		{
			oOpt = $(name+"_Option"+i);
			if(oOpt && !isSel)
			{
				dObj.scrollTop   = 19*i;
				oOpt.setAttribute("className", "Selected");
				oOpt.setAttribute("class", "Selected");
				List.index = i;
			}
			else
			{
				oOpt.setAttribute("className", "NotSelected");
				oOpt.setAttribute("class", "NotSelected");	
			}
			isSel = true;
			//alert(ddList.text.length+1);
			List.text = list[i].text.substr(0, txt.length);
			oTxtBox.value = list[i].text;
			selectMyRange(oTxtBox, txt.length, str.length);
		}
		else
		{
			oOpt = $(name+"_Option"+i);
			if(oOpt)
			{
				oOpt.setAttribute("className", "NotSelected");
				oOpt.setAttribute("class", "NotSelected");
			}
		}
	}
	if(!isSel)
	{
		oTxtBox.value = List.text;
	}
	//alert(txt);
}