// getパラメータの値を取得
function getRequest()
{
	if(location.search.length > 1) {
		var get = new Object();
		var ret = location.search.substr(1).split("&");
		for(var i = 0; i < ret.length; i++) {
			var r = ret[i].split("=");
			get[r[0]] = r[1];
		}
		return get;
	} else {
		return false;
	}
}


///////////////////////////////////////////////////////////////////////////////
// Ajaxとかで使う系
///////////////////////////////////////////////////////////////////////////////

// CreateXMLHttpRequest
// XMLHttpRequestオブジェクトを生成する
// ブラウザによる相違を吸収するためにラッパーになっている
function createXmlHttpRequest()
{
	var xmlhttp = false;

	if(window.ActiveXObject)
	{
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

// HTTPのサーバステータスをチェックする
// ブラウザごとの対応状況によっては条件を修正する必要があるかも・・・
// たいがいはこれでいいはず・・・
function HttpStatusCheck(status)
{
/* jQuery1.2.6を参考
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
return !xhr.status && location.protocol == "file:" ||
	( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 ||
	jQuery.browser.safari && xhr.status == undefined;
*/
	if(((status >= 200) && (status < 300)) ||
		(status == 304) || (status == 1223) ||
		(status == undefined) || (!status) || (location.protocol == "file:"))
	{
		return true;
	}
	return false;
}

function AjaxSend(sMethod, sURL, bAsync, xmlhttp, sParam)
{
	//var msec = (new Date()).getTime();
	//if((sParam != null) && (sParam != ""))
	//{
	//	sParam = sParam + "simpleajaxbymijyuhoge=" + msec.toString();
	//}
	//else
	//{
	//	sParam = "simpleajaxbymijyuhoge=" + msec.toString();
	//}
	xmlhttp.open(sMethod, sURL, bAsync);// true:非同期 false:同期
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(sParam);
}

// Ajaxを使用したい場合にページからコールする関数
// sMethod "GET" or "POST"
// sURL アクセス先
// sParam GETやPOSTのパラメータ文字列 (例：param1=hoge1&param2=hoge2)
// PostBackFunk ポストバック時の処理
function AjaxRequestText(sMethod, sURL, sParam, PostBackFunc)
{
	var xmlhttp = createXmlHttpRequest();
	if(!xmlhttp)
		return;

	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(HttpStatusCheck(xmlhttp.status))
				PostBackFunc(xmlhttp.responseText);
		}
	}

	AjaxSend(sMethod, sURL, true, xmlhttp, sParam);
}
function AjaxRequestXml(sMethod, sURL, sParam, PostBackFunc)
{
	var xmlhttp = createXmlHttpRequest();
	if(!xmlhttp)
		return;

	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(HttpStatusCheck(xmlhttp.status))
				PostBackFunc(xmlhttp.responseXml);
		}
	}

	AjaxSend(sMethod, sURL, true, xmlhttp, sParam);
}


///////////////////////////////////////////////////////////////////////////////
// エンコード系
///////////////////////////////////////////////////////////////////////////////

// Base64へ変換し、
// GET POST 等のパラメータ内で使用できない文字を使用できる文字に置き換える
// 入力データが文字列の場合 nMode は1を指定
function base64_encodeEx(str, nMode)
{
	str = allReplace(base64.encode(str, nMode), "+", "$");
	return allReplace(str, "/", "_");
}

// GET POST 等のパラメータ内で使用できない文字を使用できる文字に置き換えた
// Base64から変換
// 入力データが文字列の場合 nMode は1を指定
function base64_decodeEx(str, nMode)
{
	str = allReplace(str, "$", "+");
	return base64.decode(allReplace(str, "_", "/"), nMode);
}

/* /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
charset = shift_jis

+++ Base64 Encode / Decode +++


LastModified : 2006-11/08

Powered by kerry
http://202.248.69.143/~goma/

動作ブラウザ :: IE4+ , NN4.06+ , Gecko , Opera6+


* [RFC 2045] Multipurpose Internet Mail Extensions
						(MIME) Part One:
			   Format of Internet Message Bodies
ftp://ftp.isi.edu/in-notes/rfc2045.txt

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

*   Usage:

// エンコード
b64_string = base64.encode( my_data [, strMode] );

// デコード
my_data = base64.decode( b64_string [, strMode] );


strMode -> 入力データが文字列の場合 1 を

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */

base64 = new function()
{
	var utfLibName  = "utf";
	var b64char	 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var b64encTable = b64char.split("");
	var b64decTable = [];
	for (var i=0; i<b64char.length; i++) b64decTable[b64char.charAt(i)] = i;

	this.encode = function(_dat, _strMode)
	{
		return encoder( _strMode? unpackUTF8(_dat): unpackChar(_dat) );
	}
	
	var encoder = function(_ary)
	{
		var md  = _ary.length % 3;
		var b64 = "";
		var i, tmp = 0;
		
		if (md) for (i=3-md; i>0; i--) _ary[_ary.length] = 0;
		
		for (i=0; i<_ary.length; i+=3)
		{
			tmp = (_ary[i]<<16) | (_ary[i+1]<<8) | _ary[i+2];
			b64 +=  b64encTable[ (tmp >>>18) & 0x3f]
				+   b64encTable[ (tmp >>>12) & 0x3f]
				+   b64encTable[ (tmp >>> 6) & 0x3f]
				+   b64encTable[ tmp & 0x3f];
		}

		if (md) // 3の倍数にパディングした 0x0 分 = に置き換え
		{
			md = 3- md;
			b64 = b64.substr(0, b64.length- md);
			while (md--) b64 += "=";
		}
		
		return b64;
	}
	
	this.decode = function(_b64, _strMode)
	{
		var tmp = decoder( _b64 );
		return _strMode? packUTF8(tmp): packChar(tmp);
	}
	
	var decoder = function(_b64)
	{
		_b64	= _b64.replace(/[^A-Za-z0-9\+\/]/g, "");
		var md  = _b64.length % 4;
		var j, i, tmp;
		var dat = [];
		
		// replace 時 = も削っている。その = の代わりに 0x0 を補間
		if (md) for (i=0; i<4-md; i++) _b64 += "A";
		
		for (j=i=0; i<_b64.length; i+=4, j+=3)
		{
			tmp = (b64decTable[_b64.charAt( i )] <<18)
				| (b64decTable[_b64.charAt(i+1)] <<12)
				| (b64decTable[_b64.charAt(i+2)] << 6)
				|  b64decTable[_b64.charAt(i+3)];
			dat[ j ]	= tmp >>> 16;
			dat[j+1]	= (tmp >>> 8) & 0xff;
			dat[j+2]	= tmp & 0xff;
		}
		// 補完された 0x0 分削る
		if (md) dat.length -= [0,0,2,1][md];

		return dat;
	}
	
	var packUTF8	= function(_x){ return window[utfLibName].packUTF8(_x) };
	var unpackUTF8  = function(_x){ return window[utfLibName].unpackUTF8(_x) };
	var packChar	= function(_x){ return window[utfLibName].packChar(_x) };
	var unpackChar  = function(_x){ return window[utfLibName].unpackChar(_x) };
}

/* /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
charset = shift_jis

+++ UTF8/16 ライブラリ +++


LastModified : 2006-10/16

Powered by kerry
http://202.248.69.143/~goma/

動作ブラウザ :: IE4+ , NN4.06+ , Gecko , Opera6+



* [RFC 2279] UTF-8, a transformation format of ISO 10646
ftp://ftp.isi.edu/in-notes/rfc2279.txt

* [RFC 1738] Uniform Resource Locators (URL)
ftp://ftp.isi.edu/in-notes/rfc1738.txt

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Usage:

// 文字列を UTF16 (文字コード) へ
utf16code_array = utf.unpackUTF16( my_string );

// 文字列を UTF8 (文字コード) へ
utf8code_array = utf.unpackUTF8( my_string );

// UTF8 (文字コード) から文字列へ。 utf.unpackUTF8() したものを元に戻す
my_string = utf.packUTF8( utf8code_array );

// UTF8/16 (文字コード) を文字列へ
my_string = utf.packChar( utfCode_array );

// UTF16 (文字コード) から UTF8 (文字コード) へ
utf8code_array = utf.toUTF8( utf16code_array );

// UTF8 (文字コード) から UTF16 (文字コード) へ
utf16code_array = utf.toUTF16( utf8code_array );



// URL 文字列へエンコード
url_string = utf.URLencode( my_string );

// URL 文字列からデコード
my_string = utf.URLdecode( url_string );

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */

utf = new function()
{
	this.unpackUTF16 = function(_str)
	{
		var i, utf16=[];
		for (i=0; i<_str.length; i++) utf16[i] = _str.charCodeAt(i);
		return utf16;
	}
	
	this.unpackChar = function(_str) 
	{
		var utf16 = this.unpackUTF16(_str);
		var i,n, tmp = [];
		for (n=i=0; i<utf16.length; i++) {
			if (utf16[i]<=0xff) tmp[n++] = utf16[i];
			else {
				tmp[n++] = utf16[i] >> 8;
				tmp[n++] = utf16[i] &  0xff;
			}   
		}
		return tmp;
	}
	
	this.packChar  =
	this.packUTF16 = function(_utf16)
	{
		var i, str = "";
		for (i in _utf16) str += String.fromCharCode(_utf16[i]);
		return str;
	}

	this.unpackUTF8 = function(_str)
	{
	   return this.toUTF8( this.unpackUTF16(_str) );
	}

	this.packUTF8 = function(_utf8)
	{
		return this.packUTF16( this.toUTF16(_utf8) );
	}
	
	this.toUTF8 = function(_utf16)
	{
		var utf8 = [];
		var idx = 0;
		var i, j, c;
		for (i=0; i<_utf16.length; i++)
		{
			c = _utf16[i];
			if (c <= 0x7f) utf8[idx++] = c;
			else if (c <= 0x7ff)
			{
				utf8[idx++] = 0xc0 | (c >>> 6 );
				utf8[idx++] = 0x80 | (c & 0x3f);
			}
			else if (c <= 0xffff)
			{
				utf8[idx++] = 0xe0 | (c >>> 12 );
				utf8[idx++] = 0x80 | ((c >>> 6 ) & 0x3f);
				utf8[idx++] = 0x80 | (c & 0x3f);
			}
			else
			{
				j = 4;
				while (c >> (6*j)) j++;
				utf8[idx++] = ((0xff00 >>> j) & 0xff) | (c >>> (6*--j) );
				while (j--) 
				utf8[idx++] = 0x80 | ((c >>> (6*j)) & 0x3f);
			}
		}
		return utf8;
	}
	
	this.toUTF16 = function(_utf8)
	{
		var utf16 = [];
		var idx = 0;
		var i,s;
		for (i=0; i<_utf8.length; i++, idx++)
		{
			if (_utf8[i] <= 0x7f) utf16[idx] = _utf8[i];
			else 
			{
				if ( (_utf8[i]>>5) == 0x6)
				{
					utf16[idx] = ( (_utf8[i] & 0x1f) << 6 )
								 | ( _utf8[++i] & 0x3f );
				}
				else if ( (_utf8[i]>>4) == 0xe)
				{
					utf16[idx] = ( (_utf8[i] & 0xf) << 12 )
								 | ( (_utf8[++i] & 0x3f) << 6 )
								 | ( _utf8[++i] & 0x3f );
				}
				else
				{
					s = 1;
					while (_utf8[i] & (0x20 >>> s) ) s++;
					utf16[idx] = _utf8[i] & (0x1f >>> s);
					while (s-->=0) utf16[idx] = (utf16[idx] << 6) ^ (_utf8[++i] & 0x3f);
				}
			}
		}
		return utf16;
	}
	
	this.URLencode = function(_str)
	{
		return _str.replace(/([^a-zA-Z0-9_\-\.])/g, function(_tmp, _c)
			{ 
				if (_c == "\x20") return "+";
				var tmp = utf.toUTF8( [_c.charCodeAt(0)] );
				var c = "";
				for (var i in tmp)
				{
					i = tmp[i].toString(16);
					if (i.length == 1) i = "0"+ i;
					c += "%"+ i;
				}
				return c;
			} );
	}

	this.URLdecode = function(_dat)
	{
		_dat = _dat.replace(/\+/g, "\x20");
		_dat = _dat.replace( /%([a-fA-F0-9][a-fA-F0-9])/g, 
				function(_tmp, _hex){ return String.fromCharCode( parseInt(_hex, 16) ) } );
		return this.packChar( this.toUTF16( this.unpackUTF16(_dat) ) );
	}
}


///////////////////////////////////////////////////////////////////////////////
// その他
///////////////////////////////////////////////////////////////////////////////

// 文字列中の指定文字列を、指定文字列で置き換える
function allReplace(text, sText, rText)
{
	while (true)
	{
		dummy = text;
		text = dummy.replace(sText, rText);
		if (text == dummy)
		{
			break;
		}
	}
	return text;
}

// 文字列のバイト数を返す
function getByte(text)
{
	count = 0;
	for(i=0; i<text.length; i++)
	{
		n = escape(text.charAt(i));
		if(n.length < 4)
			count++;
		else
			count+=2;
	}
	return count;
}

function GetClientHeight()
{
	if(document.all && document.getElementById && (document.compatMode == "CSS1Compat"))
		return document.documentElement.clientHeight;
	else
		//return innerHeight;
		return document.body.clientHeight;
}

function GetClientWidth()
{
	if(document.all && document.getElementById && (document.compatMode == "CSS1Compat"))
		return document.documentElement.clientWidth;
	else
		//return innerWidth;
		return document.body.clientHeight;
}

function getScreenSize()
{
	var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
	var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
	var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
	if (isOpera) isIE = false;
	var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);
	var obj = new Object();
	if (!isSafari && !isOpera)
	{
		//obj.x = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
		//obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
		obj.mx = parseInt(document.body.clientWidth);
		obj.my = parseInt(document.body.clientHeight);
		return obj;
	}
	else
	{ 
		obj.x = window.innerWidth;
		obj.y = window.innerHeight;
	} 
	obj.mx = parseInt((obj.x)/2);
	obj.my = parseInt((obj.y)/2);
	return obj;
}

function getScrollPosition()
{
	var obj = new Object();
	obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	obj.y = document.documentElement.scrollTop || document.body.scrollTop;
	//obj.x = document.body.scrollLeft;
	//obj.y = document.body.scrollTop;
	return obj;
}

// 数値チェック
function IsDigit(sVal){
	if(sVal.search(/[^0-9]/)>=0){
		return false;
	}
	return true;
}

// 0～9と-のみＯＫ
// 郵便番号や電話番号に使うかな・・・？
function IsTelOrPost(sVal){
	if(sVal.search(/[^0-9-]/)>=0){
		return false;
	}
	return true;
}

// 英文字チェック
function IsAlpha(str){ 
	if(sVal.search(/[^a-zA-Z]/)>=0){
		return false;
	}
	return true;
}

function IsDigitAlpha(str)
{
	if(str.search(/[^0-9a-zA-Z]/)>=0){
		return false;
	}
	return true;
}

// 半角チェック
function IsHalfChar(str){ 
	for (var i = 0; i < str.length; i++) { 
		var c = str.charCodeAt(i); 
		// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
		// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
		if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
			continue;
		}
		else
			return false;
	}
	return true;
}

function IsTime(sVal)
{
	var t = sVal.split(":");
	if(t.length != 2)
		return false;
	if(IsDigitRange(t[0], 0, 23) != true)
		return false;
	if(IsDigitRange(t[1], 0, 59) != true)
		return false;
	return true;
}

function IsMonthDate(sVal)
{
	var dt = sVal.split("/");
	if(dt.length != 2)
		return false;
	if(IsDigitRange(dt[0], 1, 12) != true)
		return false;
	if(IsDigitRange(dt[1], 1, 31) != true)
		return false;

	switch(parseInt(dt[0]))
	{
		case 2:
			if(parseInt(dt[1]) > 29)
				return false;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if(parseInt(dt[1]) > 30)
				return false;
			break;
		default:
			if(parseInt(dt[1]) > 31)
				return false;
			break;
	}
	return true;
}

// 数値チェック
// chkVal：許可する文字列
function IsDigitEx(sVal, chkVal){
	if(sVal.search(/[^0-9]/)>=0 || sVal.search(/[chkVal]/) >=0){
		return true;
	}
	return false;
}

function IsZenkakuKatakana(sVal){
	if(sVal.search(/[^アイウエオヴァィゥェォカキクケコガギグゲゴサシスセソザジズゼゾタチツテトダヂヅデドナニヌネノハヒフヘホバビブベボパピプペポマミムメモヤユヨャュョラリルレロワヲンー]/)>=0){
		return false;
	}
	return true;
}

// 数値チェックおよび桁数チェック
// nLen：許可する桁数
function IsDigitLen(sVal, nLen){
	if ((!IsDigit(sVal)) || sVal.length > nLen || sVal==""){
		return false;
	}
	return false;
}

// 数値範囲チェック
function IsDigitRange(sVal, nMin, nMax){
	if(!IsDigit(sVal)){
		return false;
	}
	if(parseInt(sVal) < nMin || parseInt(sVal) > nMax){
		return false;
	}
	return true;
}

// Trim
function Trim(sVal){
	return sVal.replace(/^\s+|\s+$/g, "");
}

// NULLチェック
function IsNull(sVal){
	if(Trim(sVal) == "")
		return true;
	else
		return false;
}

// HEXチェック
function IsHex(sVal){	
	if(sVal.search(/[^0-9a-fA-F]/)>=0)
		return false;
	else
		return true;
}

// IP文字チェック
function IsIpChar(sVal){
	if(sVal.search(/[^0-9.]/)>=0)
		return false;
	else
		return true;
}

// IPアドレスチェック
function IsIpaddress(sVal){
	if (!IsIpChar(sVal)){
		//alert(1);
		return false;
	}

	var sip = sVal.split("\.");
	if (sip.length < 4 && sip.length > 4 || sVal.lastIndexOf(" ") != -1){
		//alert(2);
		return false;
	}
	for(i=0; i<4; i++){
		if (!IsDigitRange(sip[i], 0, 255)){
			//alert(3);
			return false;
		}
	}
	return true;
}

function MailAddrCheck(sVal)
{
	var sAddr = sVal.split("@");
	if(sAddr.length != 2)
		return false;
	
	var sUser = sAddr[0];
	var sDomain = sAddr[1];
	
	if((sDomain.length - 1) == sDomain.lastIndexOf("\."))
		return false;
	if(sDomain.lastIndexOf("\.") < 0)
		return false;
	if(sDomain.lastIndexOf("\.\.") >= 0)
		return false;
	if(sDomain.lastIndexOf(" ") != -1)
		return false;
	if(sDomain.lastIndexOf("　") != -1)
		return false;
	
	if(IsHalfChar(sUser) != true)
		return false;
	if(sUser.lastIndexOf(" ") != -1)
		return false;
	return true;
}

// 日付チェック
//nYear:年 nMonth:月 nDay:日
function IsDate(nYear, nMonth, nDay){
	var dtCal = new Date;
	var strDate;
	var nMonthCount = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	//年度のチェック （ここでは4桁チェック)
//	if ((nYear < 1970) || (nYear > 12)){
//		return false;
//	}
	//月のチェック
	if ((nMonth < 1) || (nMonth > 12)){
		return false;
	}

	dtCal.setYear(nYear);
	dtCal.setMonth(nMonth-1);
	var nDayCount = nMonthCount[nMonth-1];
	if ((nMonth == 2)&&(((nYear%4 == 0)&&(nYear%100 != 0))||(nYear%400 == 0))){
		nDayCount = 29;
	}

	//日付チェック
	if ((nDay < 1) || (nDay > nDayCount)){
		return false;
	}
	return true;
}

// 指定月の最終の日にちを取得する
function GetLastDayOfMonth(nYear, nMonth)
{
	if (IsDate(nYear, nMonth, 1) == false){
		return -1;
	}

	var nMonthCount = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if ((nMonth == 2)&&(((nYear%4 == 0)&&(nYear%100 != 0))||(nYear%400 == 0))){
		nMonthCount[nMonth-1] = 29;
	}
	return nMonthCount[nMonth-1];
}
// 指定日付の曜日を取得
// 0:日曜日
function GetDay(nYear, nMonth, nDay)
{
	if (IsDate(nYear, nMonth, nDay) == false){
		return -1;
	}

	var d = new Date(nYear, nMonth, nDay);
	return d.getDay();
}

// FlashPlayerのバージョン取得
function getFlashPlayerVersion()
{
	var vsn = '';
	if( navigator.plugins && navigator.mimeTypes.length )
	{// not IE
		var tmp = navigator.plugins["Shockwave Flash"].description.match(/([0-9]+)/);
		vsn = tmp[0];
	}
	else
	{// IE
		var tmp = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/);
		vsn = tmp[0];
	}
	return parseFloat(vsn);
}
