//------------------------------共通関数
function checkBrowser()
{
	bName = navigator.appName;
	bVer = parseInt(navigator.appVersion);
	if( bName == "Netscape" && bVer >= 5)
	{
		return true;
	}
	else if(bName.indexOf("Microsoft") >= 0 || navigator.userAgent.indexOf("MSIE")!=-1 )
	{
		if(typeof ScriptEngineMajorVersion)
		{
			var smav = ScriptEngineMajorVersion();
			var smiv = ScriptEngineMinorVersion();
			var sv   = smav + smiv/10;
			if (sv >= 5 )return true;
		}
	}
	else if(navigator.userAgent.indexOf("Safari")!=-1)
	{
		return true;
	}
	else if(window.opera)
	{
		return true;
	}
	return false;
}

function isForm( _name )
{
	var stry ='try{document.' + _name + '.action;1}catch(e){0}';
	return eval(stry)? true:false;
}

function isElemById( _id )
{
	if (checkBrowser())
	{
		var stry ='try{document.getElementById(_id).style;1}catch(e){0}';
		return eval(stry)? true:false;
	}
	else
	{
		return false;
	}
}

function getElemById( _id )
{
	if (isElemById(_id))
		return document.getElementById(_id);
	else 
		return false;
}


function getIdHTML( _id )
{
	if (isElemById(_id))
		return document.getElementById(_id).innerHTML;
	else 
		return '';
}

function setVisibilityId( _id , _val )
{
	if (isElemById(_id))
		document.getElementById(_id).style.visibility = _val;
}

function setDisplayProperty( _id , _val )
{
	if (isElemById(_id))
		document.getElementById(_id).style.display = _val;
}

function isDisplay( _id , _val )
{
	if (isElemById(_id) && document.getElementById(_id).style.display == _val)
		return true;
	else
		return false;
}

function isVisibility( _id )
{
	if( isDisplay( _id, "none" ) || (isElemById(_id) && document.getElementById(_id).style.visibility == "hidden") )
		return false;
	else
		return true;
}

function setIdHTML( _id , _html)
{
	if (isElemById(_id))
		document.getElementById(_id).innerHTML = _html;
}
// - - - - - - - - - - - - - - - - - - - - - - - -


//空チェック
function checkEmpty( _value )
{
	if (typeof(_value) == 'undefined' || _value == null || _value == '' )
		return true;
	else
		return false;
}

//------------------------------メイン

var  g_panelId = null;

//実行関数
function SwitchHtml(panelId, url )
{
	g_panelId = panelId;

	if (url.indexOf('?' != -1))
		url = url + '&tick=' + (new Date()).getTime();
	else
		url = url + '?tick=' + (new Date()).getTime();

	getHttp(url);
}

//------------------------------Ajax

//トリム関数
function Trim(str)
{
	str = str.replace(/^[ 　\t]+/,"");
	str = str.replace(/[ 　\t\n]+$/,"");
	return(str);
}

//通信開始関数
function getHttp(getFile)
{
	try
	{
		//IEの場合
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		//IE意外
		xmlhttp = new XMLHttpRequest();
	}

	if (xmlhttp)
	{
		//GETで取得し check関数をコールバック関数として動作させる(通信処理を非同期とするかどうかのフラグをtrue)
		xmlhttp.onreadystatechange = check;
		xmlhttp.open('GET', getFile, true);
		xmlhttp.send(null);
	}
}

//コールバック関数
function check()
{
	//通信が成功かチェック
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
	{
		//データが空ではないかチェック
		var res = Trim(xmlhttp.responseText);
		if(!checkEmpty(res))
		{	
			if (isElemById(g_panelId)) {
				document.getElementById(g_panelId).innerHTML = res;
			}
		}
	}
}
