//============================================================================
//                          COSCAページ共用
//============================================================================
//----------------------------------------------
//                オンロード
//----------------------------------------------
function FUNC_Onload()
{
	if( typeof PAGEFUNC_Onload != "undefined" ){
		PAGEFUNC_Onload();
	}
}

//----------------------------------------------
//                ログインボタン
//----------------------------------------------
function FUNC_LoginButton()
{
	location.href=GBL_HTTP+"/login/top/";
}

//----------------------------------------------
//               ログアウトボタン
//----------------------------------------------
function FUNC_LogoutButton()
{
	location.href=GBL_HTTP+"/command/login/logout/logout.php";
}

//----------------------------------------------
//         現在時刻文字列取得(URI付加用)
//----------------------------------------------
function FUNC_GetCurrentTimeURI()
{
	var tmp;
	var tm;

	tm = new Date();

	tmp = "tm=" + tm.getYear();
	tmp = tmp + (tm.getMonth() + 1);
	tmp = tmp + tm.getDate();
	tmp = tmp + tm.getHours();
	tmp = tmp + tm.getMinutes();
	tmp = tmp + tm.getSeconds();
	tmp = tmp + Math.random();

	return(tmp);
}

//-----------------------------------------------------------------
//            指定IMG内の画像を立て横比固定で拡縮
//-----------------------------------------------------------------
function FUNC_AdjustImg( id ,w ,h ,visible)
{
	var tmp;
	var img;

	img = document.images[id];

	if( img == null )return;

	img.hspace = 0;
	img.vspace = 0;

//alert("W:" + w + " H:" + h + "IW:" + img.width + " IH:" + img.height);
	if( img.width > img.height ){
		// 横基準
		tmp = img.height * w / img.width;
		img.width  = w;
		img.height = tmp;
		img.vspace = (h - img.height) / 2;	// 真ん中に寄せる
	}else {
		// 縦基準
		tmp = img.width * h / img.height;
		img.height = h;
		img.width  = tmp;
		img.hspace = (w - img.width)  / 2;	// 真ん中に寄せる
	}

	if( visible == true ){
		img.style.visibility = "visible";
	}else{
		img.style.visibility = "hidden";
	}
}

//-----------------------------------------------------------------
//                       英数半角チェック
//-----------------------------------------------------------------
function FUNC_CheckAZaz09(in_str ,minsize ,maxsize)
{
	var result = in_str.match(/[0-9a-zA-Z]*/);	// 英数半角チェック

	if( in_str == result ){
		// 英数半角
		if( minsize > 0 ){
			if( FUNC_StrLength(in_str) < minsize )return(false);
		}
		if( maxsize > 0 ){
			if( FUNC_StrLength(in_str) > maxsize )return(false);
		}
		return(true);
	}

	return(false);
}

//-----------------------------------------------------------------
//                     英数半角スペースチェック
//-----------------------------------------------------------------
function FUNC_CheckAZaz09SP(in_str ,minsize ,maxsize)
{
	var result = in_str.match(/[0-9a-zA-Z\ ]*/);	// 英数半角チェック

	if( in_str == result ){
		// 英数半角
		if( minsize > 0 ){
			if( FUNC_StrLength(in_str) < minsize )return(false);
		}
		if( maxsize > 0 ){
			if( FUNC_StrLength(in_str) > maxsize )return(false);
		}
		return(true);
	}

	return(false);
}

//-----------------------------------------------------------------
//                       数字チェック
//-----------------------------------------------------------------
function FUNC_Check09(in_str ,minsize ,maxsize)
{
	var result = in_str.match(/[0-9 ]*/);	// 数字チェック

	if( in_str == result ){
		if( minsize > 0 ){
			if( FUNC_StrLength(in_str) < minsize )return(false);
		}
		if( maxsize > 0 ){
			if( FUNC_StrLength(in_str) > maxsize )return(false);
		}
		return(true);
	}

	return(false);
}

//-----------------------------------------------------------------
//                       ペンＩＤ
//-----------------------------------------------------------------
function FUNC_CheckPenID(in_str)
{
	var result = in_str.match(/[0-9A-Za-z\., ]*/);

	if( in_str == result ){
		if( FUNC_StrLength(in_str) != 10 )return(false);
		return(true);
	}

	return(false);
}

//-----------------------------------------------------------------
//                       英半角チェック
//-----------------------------------------------------------------
function FUNC_CheckAZaz(in_str ,minsize ,maxsize)
{
	var result = in_str.match(/[a-zA-Z ]*/);	// 英半角チェック

	if( in_str == result ){
		// 英半角
		if( minsize > 0 ){
			if( FUNC_StrLength(in_str) < minsize )return(false);
		}
		if( maxsize > 0 ){
			if( FUNC_StrLength(in_str) > maxsize )return(false);
		}
		return(true);
	}

	return(false);
}

//-----------------------------------------------------------------
//                       EMAILチェック
//-----------------------------------------------------------------
function FUNC_CheckEmail(in_str ,minsize ,maxsize)
{
	var result = in_str.match(/^[^@]+@[^.]+\..+/);

	if( in_str != result ){
		return(false);
	}

	if( (FUNC_StrLength(in_str) < minsize) || (FUNC_StrLength(in_str) > maxsize) ){
		return(false);
	}

	return(true);
}

//-----------------------------------------------------------------
//                    バーコードチェック
//-----------------------------------------------------------------
function FUNC_CheckBARCODE(in_str)
{
	var tmp;

	// 文字種と文字数
	if( FUNC_Check09(in_str ,8 ,13) == false )return(false);
	if( (FUNC_StrLength(in_str) != 8) && (FUNC_StrLength(in_str) != 13) )return(false);

	// チェックサム
	tmp = in_str.substr(0 ,FUNC_StrLength(in_str)-1);
	tmp = FUNC_MakeBarcode(tmp);

	// チェックサムは正しいか？
	if( tmp != in_str ){
		return(false);
	}

	return(true);
}

//-----------------------------------------------------------------
//                    コスカコードチェック
//-----------------------------------------------------------------
function FUNC_CheckCOSCACODE(in_str)
{
	var tmp;

	// 文字種と文字数
	if( FUNC_Check09(in_str ,15 ,15) == false )return(false);

	// チェックサム
	tmp = in_str.substr(0 ,FUNC_StrLength(in_str)-1);
	tmp = FUNC_MakeBarcode(tmp);

	// チェックサムは正しいか？
	if( tmp != in_str ){
		return(false);
	}

	return(true);
}

//-----------------------------------------------------------------
// バーコードパリティを計算
//-----------------------------------------------------------------
function FUNC_MakeBarcode( i )
{
	var j;
	var s=260;

	for(j=0;j!=i.length;++j){
		if(i.length==14&&j<3)continue;
		if(i.length==7)s-=parseInt(i.charAt(j))*(j%2?1:3);
		else           s-=parseInt(i.charAt(j))*(j%2?3:1);
	}
	if(i.length==13)s=s*7;
	s%=10;
	return( i+s.toString(10) );
}

//-----------------------------------------------------------------
//            文字列の文字数(半角1 全角2)を計算
//-----------------------------------------------------------------
function FUNC_StrLength( in_str )
{
	var tmp;
	var len;
	var slen;

	len  = 0;
	slen = in_str.length;
	for(i = 0; i < slen; i++){
		tmp = in_str.charAt(i);
		tmp = escape(tmp);
		if( tmp.charAt(0) == '%' ){
			if( tmp.charAt(1) == 'u' ){
				// 全角
				len ++;
			}
		}
		len ++;
	}

	return(len);
}

