// Cookieの保存期間（日数）を変更してください。
// ex) 3日
var holddays = 3;

/**
 * Cookie登録
 *
 * setCookie
 *
 * @param	pKey		キー
 * @param	pVal		値
 * @param	pExpire		有効期限日数
 * @return	void		なし
 */
function setCookie( pKey, pVal, pExpire ){
	oExp = new Date();
	oExp.setTime( oExp.getTime() + ( pExpire * 24 * 60 * 60 * 1000 ) );
	sItem = "@" + pKey + "=" + escape( pVal ) + ";";
	sExpires = "expires=" + oExp.toGMTString();
	document.cookie =  sItem + sExpires;
}

/**
 * Cookie取得
 *
 * setCookie
 *
 * @param	pKey		キー
 * @return	string		値　null:該当なし
 */
function getCookie( pKey ){
	var sCookie = "@" + pKey + "=";
   	var sValue = null;
   	var sStr = document.cookie + ";";
	oOffset = sStr.indexOf( pKey );
	if ( oOffset != -1 ){
		iStart = ( oOffset + sCookie.length ) - 1;
		iEnd   = sStr.indexOf(";" , iStart);
		sValue = unescape( sStr.substring( iStart, iEnd ) );
	}
	
	if( ( '@' + pKey + ';' ) == sValue ){
		sValue = '';
	}
	return sValue;
}


/**
 * ページ読込み時のCookie取得
 * 
 * @access	public
 * @param	void	なし
 * @return	void	なし
 */
function loadCookies(){
	var chkSave = document.getElementById("chkSave");
	var oId		= document.getElementById("txt_kpp1");
	var ids		= getCookie( 'ids' );
	if( ids != null && ids != '' ){
		// IDをセット
		oId.value = ids;
		// チェックon
		chkSave.checked = true;
	}
}

/**
 * Cookieの登録・解除
 * 
 * @access	public
 * @param	void	なし
 * @return	void	なし
 */
function setCookies(){
	var chkSave = document.getElementById("chkSave");
	var oId		= document.getElementById("txt_kpp1");
	if( chkSave.checked == true ){
		// Cookie登録
		setCookie( 'ids', oId.value, holddays );
		
	} else {
		// Cookieクリア
		setCookie( 'ids', null, -1 );
		
	}
}
