// JavaScript Document

function LockButtonStatus(name)
{
	oAnchor = $(name+"_LockAnchor");
	if(Params[name]==0)
	{

		if(oAnchor)
		{
			oAnchor.setAttribute("class", "LockDis");
			oAnchor.setAttribute("className", "LockDis");
		}
	}
	else
	{
		if(oAnchor)
		{
			oAnchor.setAttribute("class", "LockUp");
			oAnchor.setAttribute("className", "LockUp");
		}
	}
}

function LockParam(name, isGS)
{
	if(Params[name]!=0)
	{
		LockParams[name] = LockParams[name]==0?1:0;
		oAnchor = $(name+"_LockAnchor");
		if(oAnchor)
		{
			if(LockParams[name]==0)
			{
				oAnchor.setAttribute("class", "LockUp");
				oAnchor.setAttribute("className", "LockUp");
			}
			else
			{
				oAnchor.setAttribute("class", "LockDown");
				oAnchor.setAttribute("className", "LockDown");
			}
		}
		if(isGS==null)
			OnChangeFilterVal();
	}
}

function ResetParam(name)
{
	ClearLock(name);
	Params[name] = 0;
	var txt = "";
	eval("txt = "+name+"List[0].text;");
	if($(name+"_TextBox"))
		$(name+"_TextBox").innerHTML = txt;
	else if($(name+"_TxtInput"))
		$(name+"_TxtInput").value = txt;
	OnChangeFilterVal();
}

function ShowGoodsBig(num)
{
	ImgArea = $("GoodsImageArea");
	TxtArea = $("GoodsDescriptionArea");
	ImgArea.innerHTML = "<a href=\"http://www.amazon.com/gp/product/"+GoodsList[num].ASIN+"?ie=UTF8&tag=wwwcoins2com-20&linkCode=as2&camp=1789&creative=9325&creativeASIN="+GoodsList[num].ASIN+"\" target=\"_blank\"><img src=\"/getImage.php?id="+ GoodsList[num].imageId +"\" width=\"140\" height=\"140\" border=\"0\" />";
	if(GoodsList[num].title.length > 54)
		TxtArea.innerHTML = GoodsList[num].title.substr(0, 54) + "...";
	else
		TxtArea.innerHTML = GoodsList[num].title;
	$("GoodsPriceArea").innerHTML = GoodsList[num].price;
	$("HintArea").innerHTML = GoodsList[num].description;
	$("areaSelect").href = "#";
}
function AddGoodsToBasket(obj)
{
	if(GoodsList.length>0)
		obj.href = "http://www.amazon.com/gp/product/"+GoodsList[CurrentGoodsNum].ASIN+"?ie=UTF8&tag=wwwcoins2com-20&linkCode=as2&camp=1789&creative=9325&creativeASIN="+GoodsList[CurrentGoodsNum].ASIN;
	else
	{
		obj.href = "";
		return false;
	}
}
function MoveGoodsList(delta)
{
	if(GoodsList.length>1)
	{
		next = CurrentGoodsNum + delta;
		if(next<0)
		{
			//next = GoodsList.length-1;
			next = 0;
		}
		else if(next>=GoodsList.length)
		{
			//next = 0;
			next = GoodsList.length-1;
		}
		CurrentGoodsNum = next;
		ShowGoodsBig(CurrentGoodsNum);
	}
	LightDevArrows();
}

function ClearLock(name)
{
	oAnchor = $(name+"_LockAnchor");
	if(oAnchor)
	{
		oAnchor.setAttribute("class", "LockDis");
		oAnchor.setAttribute("className", "LockDis");
	}
}


function ResetAllParam()
{
	for(i=0; i<VarName.length; i++)
	{
		name = VarName[i];
		ClearLock(name);
		LockParams[name] = 0;
		Params[name] = 0;
		txt = "";
		eval("txt = "+name+"List[0].text;");
		if($(name+"_TextBox"))
			$(name+"_TextBox").innerHTML = txt;
		else if($(name+"_TxtInput"))
			$(name+"_TxtInput").value = txt;
	}
	$("GoodsImageArea").innerHTML = "";
	$("GoodsDescriptionArea").innerHTML = "";
	$("GoodsPriceArea").innerHTML = "";
	$("areaSelect").href = "#";
	GoodsList = [];
}

function ShowSelectedGoods()
{
	//
}
function ImFeelingLucky()
{
	url = '/ajax/';
	pars = 'action=ImFeelingLucky';
	new Ajax.Request(url, {method:'get', parameters: pars, onComplete:loadGoodsList });
}

function ShowGoodsDescription()
{
	if(GoodsList.length>0 && GoodsList[CurrentGoodsNum].description.length>0)
	{
		$("HintImg").style.visibility = "visible";
		$("HintTbl").style.visibility = "visible";
	}
}

function HideGoodsDescription()
{
	$("HintImg").style.visibility = "hidden";
	$("HintTbl").style.visibility = "hidden";
}

function LightDevArrows()
{
	if(GoodsList.length <= 1)
	{
		$("DevLeftArrow").setAttribute("class", "unactiveLeft");
		$("DevLeftArrow").setAttribute("className", "unactiveLeft");
		$("DevRightArrow").setAttribute("class", "unactiveRight");
		$("DevRightArrow").setAttribute("className", "unactiveRight");
	}
	else
	{
		if(CurrentGoodsNum == 0)
		{
			$("DevLeftArrow").setAttribute("class", "unactiveLeft");
			$("DevLeftArrow").setAttribute("className", "unactiveLeft");
			$("DevRightArrow").setAttribute("class", "activeRight");
			$("DevRightArrow").setAttribute("className", "activeRight");
		}
		else if(CurrentGoodsNum == GoodsList.length-1)
		{
			$("DevLeftArrow").setAttribute("class", "activeLeft");
			$("DevLeftArrow").setAttribute("className", "activeLeft");
			$("DevRightArrow").setAttribute("class", "unactiveRight");
			$("DevRightArrow").setAttribute("className", "unactiveRight");
		}
		else
		{
			$("DevLeftArrow").setAttribute("class", "activeLeft");
			$("DevLeftArrow").setAttribute("className", "activeLeft");
			$("DevRightArrow").setAttribute("class", "activeRight");
			$("DevRightArrow").setAttribute("className", "activeRight");
		}
	}
}
