/*---------------------------------------------------------------------------
**	
**	プログラム名：【GJ!】Javascrpitインターフェイス ver2
**	rev		 	 :2.00
**	製作者		：HEX68
**	Website		：http://hmlab.info/minor/
**	Date		：2008/03/27
**
**---------------------------------------------------------------------------*/

//【GJ!】PHPスクリプトへのURL
URL = "http://torauma.arrow.jp/gj/gj.php";

//拍手数を表す画像へのURL
img_1  ="http://torauma.arrow.jp/gj/img/mark1.gif";//１の位（小画像）
img_10 ="http://torauma.arrow.jp/gj/img/mark10.gif";//１０の位（中画像）
img_100="http://torauma.arrow.jp/gj/img/mark100.gif";//１００の位（大画像）


/*---------------------------------------------------------------------------
**	
**	ウェブ【GJ!】PHPへのリクエストメソッド
**
**---------------------------------------------------------------------------*/
function goodjob(cpageurl,cpagename)
{
	param = "pageurl=" + cpageurl + "&pagename=" + cpagename + "&cache=" + (new Date()).getTime();
	
	mess_id = cpageurl + "_gj_message";
	new Ajax.Request(URL,{
			method:'get',
			parameters:param+"&mode=gj" + "&gj_message=" + $(mess_id).value,
			onComplete:function(e)
			{
				$(mess_id).value = "";
				$(mess_id).style.visibility = "visible";
				
				showbutton(cpageurl,cpagename,1);
			},
			onException:function(e)
			{

			}
		}
	);
	
}

/*---------------------------------------------------------------------------
**	
**	ウェブ【GJ!】PHPへの拍手数の取得,描画
**
**---------------------------------------------------------------------------*/

function getgjcount(cpageurl)
{
	param = "pageurl=" + cpageurl + "&mode=xml"+ "&cache=" + (new Date()).getTime();
	
	new Ajax.Request(URL,{
			method:'get',
			parameters:param,
			onComplete:function(e)
			{
				result = e.responseXML;
				var count = result.getElementsByTagName("count")[0].childNodes[0].nodeValue;
				$(cpageurl+'_gj_mark').innerHTML = "";
				
				num100 = Math.floor(count / 100);
				for(var i=0;i<num100;i++)
				{
					$(cpageurl+'_gj_mark').innerHTML += "<img src='" + img_100 + "'>";
				}
				
				num10 = Math.floor(Math.floor(count-num100*100) / 10);
				for(var i=0; i<num10; i++)
				{
					$(cpageurl+'_gj_mark').innerHTML += "<img src='" + img_10 + "'>";
				}

				num = (count%10);
				for(var i = 0; i < num ;i++)
				{
					$(cpageurl+'_gj_mark').innerHTML += "<img src='" + img_1 + "'>";
				}

			}

		}
	);
	
}
/*---------------------------------------------------------------------------
**	
**	拍手ボタンの描画メソッド
**
**---------------------------------------------------------------------------*/
function showbutton(cpageurl, cpagename, cbutton)
{
	var buttong = "http://***.com/gj/img/gjbutton3.gif";
	var gj_st = "0";//0はボタン上に拍手数表示、１は拍手数のアイコン表示
	
	if(gj_st == "0")
	{
		address = URL + "?pageurl=" + cpageurl + "&pagename=" + cpagename + "&button=" + cbutton + "&mode=button" +"&cache=" + (new Date()).getTime();
		$(cpageurl).src = address;
	}
	if(gj_st == "1")
	{
	
		$(cpageurl).src = buttong;
		getgjcount(cpageurl);
	}
}
