﻿//---------------------------------------------------------------------------
// ASP KanaboWeb JavaScript
//
// (C)Copyright WAC.com inc. All Rights Reserved.
//---------------------------------------------------------------------------
// kanaboweb( command, hostid, params )
//		command : on / off / toggle
//		hostid : xxxxx.xxxxx
//		params : 'kb_lv=1&kb_md=0&kb_sz=60%'
// kanaboweb('on','xxxxx.xxxxx')
// kanaboweb('on','xxxxx.xxxxx','kb_lv=3&kb_md=2')
// kanaboweb('off')
// kanaboweb('toggle','xxxxx.xxxxx')
// kanaboweb('toggle','xxxxx.xxxxx','kb_lv=3&kb_md=2')


//---------------------------------------------------------------------------
function kanaboweb( cmd, hostid, params )
{
	cmdKanaboWeb(cmd,hostid,params);
}

//---------------------------------------------------------------------------
function cmdKanaboWeb( cmd, hostid, params )
{
	switch( cmd )
	{
		case "toggle" : toggleKanaboWeb( hostid, params ); break;
		case "off" : resetKanaboWeb(); break;
		case "on" : execKanaboWeb( hostid, params ); break;
		default : execKanaboWeb( hostid, params ); break;
	}
}


//---------------------------------------------------------------------------
function execKanaboWeb( hostid, params )
{
	var asp = getASP( hostid, params );
	var url = "";
	if( isExecutedKanaboWeb() )
	{
		url = __kanaboweb.url;
	}
	else
	{
		url = location.href;
	}
	window.location.href = asp + "kb_url=" + url;
}


//---------------------------------------------------------------------------
function resetKanaboWeb()
{
	try
	{
		window.location.href = __kanaboweb.url;
	}
	catch( e )
	{
	}
}

//---------------------------------------------------------------------------
function toggleKanaboWeb( hostid, params )
{
	if( isExecutedKanaboWeb() == false )
	{
		execKanaboWeb( hostid, params );
	}
	else
	{
		resetKanaboWeb();
	}
}


//---------------------------------------------------------------------------
function isExecutedKanaboWeb()
{
	try
	{
		return __kanaboweb.translated;
	}
	catch( e )
	{
	}
	return false;
}



//---------------------------------------------------------------------------
// mapping hostid
//---------------------------------------------------------------------------

var aspURLs = new Array();
aspURLs ["pref.kyoto"] = "http://furigana.pref.kyoto.lg.jp/asp/default.ashx?";
aspURLs ["pref.kochi"] = "http://furigana.pref.kochi.lg.jp/asp/default.ashx?";
aspURLs ["pref.yamanashi"] = "http://furigana.pref.yamanashi.jp/asp/default.ashx?";

aspURLs ["test.pref.kochi"] = "http://services.pref.kochi.kanabo.com/asp/default.ashx?";
aspURLs ["test.pref.yamanashi"] = "http://services.pref.yamanashi.kanabo.com/asp/default.ashx?";

aspURLs ["auone"] = "http://furigana.junior.auone.jp/asp/default.ashx?";
aspURLs ["wac"] = "http://services.kanabo.com/kanaboweb/default.ashx?";


//---------------------------------------------------------------------------
function getASP( hostid, params )
{
	var asp = aspURLs[hostid];
	if( asp == undefined )
		alert( "undefined host ID" );

	asp = asp + "kb_id=" + hostid + "&";

	if( params != undefined )
	{
		asp = asp + params;
		asp = asp + "&";
	}

	return asp;
}

//---------------------------------------------------------------------------



