// JavaScript Document

// show popup window
function CloseDetail()
{

	// find target id
	var popup = document.getElementById("supplier_info_area");
	
	// close target
	if(popup.style.visibility == "visible")
	{
		popup.style.visibility = "hidden";
	}

}

// show show window
function ShowTagCtrl(e)
{
	
	// find target id
	var popup = document.getElementById(Event.element(e).id+"_target");
	
	// show target
	if(popup.style.visibility == "hidden")
	{
		popup.style.visibility = "visible";
	}
	
}

// show popup window
function CloseWindow(id)
{

	// find target id
	var popup = document.getElementById(id);
	
	// close target
	if(popup.style.visibility == "visible")
	{
		popup.style.visibility = "hidden";
	}

}


function AdjustSize(object, max_width, max_height)
{
	var img_width = object.width;
	var img_height = object.height;
	
	if(img_width>max_width || img_height>max_height)
	{
		// width of image is longer than height of it
		if(img_width > img_height)
		{
			object.width = max_width;
			object.height = img_height*max_width/img_width;
		}
		else
		{
			object.height = max_height;
			object.width = img_width*max_height/img_height;
		}
	}

	// adjust position
	object.style.marginTop = (max_height-object.height)/2+"px";
	object.style.marginLeft = (max_width-object.width)/2+"px";
	object.style.marginBottom = (max_height-object.height)/2+"px";
	object.style.marginRight = (max_width-object.width)/2+"px";
	
}

function UpdateMaterialsGraph(range, avg, you, top, target_id)
{

	if(!range)
	{
		return;
	}
	
	base_top	= -26;
	base_left	= -12;
	step = 200/range;
	avg_x = base_left+step*avg;
	top_x = base_left+step*top;
	you_x = base_left+step*you;

// find target id
	var target = document.getElementById(target_id);
	target.innerHTML = "<div class=\"bg\"><img src=\"images/base/point_avg.png\" alt='平均' style=\"top:"+base_top+"px;left:"+avg_x+"px;\" /><img src=\"images/base/point_top.png\" alt=\"トップ\" style=\"top:"+base_top+"px;left:"+top_x+"px;\" /><img src=\"images/base/point_you.png\" alt=\"あなた\" style=\"top:"+base_top+"px;left:"+you_x+"px;\" /></div>";
	
}

function UpdateRatingBar(rate, target_id)
{

	// find target id
	var target = document.getElementById(target_id);
	target.innerHTML = "<div class=\"rating_bg\"><div class=\"rating\" style=\"width:"+(20*rate)+"px;\"></div></div>"
	
}