/*
 * aic_jsonp.js
 * 
 * @author net@aic-co.jp
 * @version $Revision$
 * 
 * @see jquery.jsonp.js : http://iandeth.dyndns.org/mt/ian/archives/000654.html
 * 
 * Copyright 2006-2007, AIC CORPORATION All Rights Reserved.
 */

/*
 * AicJsonpクラスの定義
 * jquery.jsonp.js の jquery 不要バージョン
 */
if( typeof( window.AicJsonp) == "undefined")
{
	// AicJsonpオブジェクトのコンストラクタ
	var AicJsonp = function()
	{
		this.scripts = {};
		this.charset = 'utf-8';
		//this.charset = 'shift_jis';
		this.counter = 1;
		this.head = document.getElementsByTagName("head")[0];
	};
	
	// バージョン番号
	AicJsonp.VERSION = '0.01';
	
	// AicJsonpオブジェクトのプロパティ
	AicJsonp.prototype.scripts = null;
	AicJsonp.prototype.charset = null;
	AicJsonp.prototype.counter = null;
	AicJsonp.prototype.head = null;
	
	// コールバック関数名生成
	AicJsonp.prototype.name = function( callback)
	{
//		var name = '_aic_' + (new Date).getTime() + '_' + this.counter;
		var name = 'hoge';
		this.counter += 1;
		//alert(this);
		var _this = this;
		var cb = function( json)
		{
		//setTimeout("cb()", 600000);
		//alert(name);
		//alert(_this.scripts[name]);
			eval( 'delete ' + name);
			callback( json);
			if( typeof( _this.scripts[name]) != "undefined")
			{
				_this.head.removeChild( _this.scripts[name]);
				delete _this.scripts[name];
			}
		};
		eval( name + ' = cb');
		//alert(name);
		return name;
	};
	
	// JSONPローダー
	AicJsonp.prototype.load = function( url, name)
	{
		var script = document.createElement( 'script' );
		script.type    = 'text/javascript';
		script.charset = this.charset;
		script.src     = url;
//	alert('script')

	//alert(this.charset)
//	alert(this.head.appendChild)
//	alert(this.head)
//	alert(this.counter)
//	alert(script.type)
//	alert(script.charset)
//	alert(script.src)
//		setTimeout("AicJsonp()", 600000);
		this.head.appendChild( script);
//		setTimeout("AicJsonp()", 600000);
//	alert('444444')
		this.scripts[ name ] = script;
	//alert('4444444')
	};
	
	// JSONPリクエスター
	AicJsonp.prototype.getJSONP = function( url, callback)
	{
	//alert('9')
		var name = this.name( callback);
	//alert('99')
		var url = url.replace( /{callback}/, name);
//	alert('url')
//	alert(url)
//	alert('name')
//	alert(name)
		this.load( url, name);
		return this;
	};
}

/*
 * AicSystemMessageクラスの定義
 */
if( typeof( window.AicSystemMessage) == "undefined")
{
	// AicSystemMessageオブジェクトのコンストラクタ
	var AicSystemMessage = function( element_id, lang_f)
	{
	//alert(element_id)
		this.eid = element_id;
		this.langf = lang_f;
//		this.url = "http://itpack.net/test.txt?callback={callback}";
//		this.url = "http://www.mjnet.co.jp/test2.txt?callback={callback}";
		this.url = "https://www.mjnet.co.jp/site_errmsg.txt?callback={callback}";
//		this.url = "http://www.mjnet.co.jp/test.js?callback={callback}";
		this.jsonp = new AicJsonp();
		
		// onload時に setMessage() を実行
		var _this = this;
		if( window.addEventListener){ window.addEventListener('load', function(){_this.setMessage();}, false);}
		if( window.attachEvent){ window.attachEvent('onload', function(){_this.setMessage();});}
		
		return this;
	};
	
	// バージョン番号
	AicSystemMessage.VERSION = '0.01';
	
	// AicSystemMessageオブジェクトのプロパティ
	AicSystemMessage.prototype.eid = null;//
	AicSystemMessage.prototype.url = null;
	AicSystemMessage.prototype.jsonp = null;
	
	// メッセージ取得&設定
	AicSystemMessage.prototype.setMessage = function()
	{
	//alert('111')
		var _this = this;
		this.jsonp.getJSONP( this.url, function(json)
			{
				// リクエスト成功時に実行したい処理をここに定義。
				// 変数 json = サーバが返したレスポンスオブジェクト。
				if(_this.langf == 1){
					if( "" != json.message1)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						//obj.innerHTML = UnescapeSJIS(json.message1);
						obj.innerHTML = json.message1;
					}
				}else if(_this.langf == 2){
					if( "" != json.message2)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						//obj.innerHTML = UnescapeSJIS(json.message2);
						obj.innerHTML = json.message2;
					}
				}else if(_this.langf == 3){
					if( "" != json.message3)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						//obj.innerHTML = UnescapeSJIS(json.message3);
						obj.innerHTML = json.message3;
					}
				}else if(_this.langf == 4){
					if( "" != json.message4)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						//obj.innerHTML = UnescapeSJIS(json.message4);
						obj.innerHTML = json.message4;
					}
				}else if(_this.langf == 5){
					if( "" != json.message5)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						//obj.innerHTML = UnescapeSJIS(json.message5);
						obj.innerHTML = json.message5;
					}
				}else if(_this.langf == 6){
					if( "" != json.message6)
					{
						var obj = document.getElementById(_this.eid);
						obj.style.display = "";
						obj.innerHTML = json.message6;
					}
				}
			}
		);
	};
}
