/* ************************************************************************ */
/* 																	[TAB:4]	*/
/* 	JavaScript																*/
/* 																			*/
/* ************************************************************************ */
/* ************************************************************************ */
/* 	利用規約確認ダイアログ													*/
/* ************************************************************************ */
function kiyakuCheck( objFrm )
{
	with ( objFrm )
	{
		if ( ! terms_of_use.checked )
		{
			window.alert ( "利用規約に同意されない場合、お申込みをお受けできません。" );
			return false;
		}
		submit();
	}
	return true;
}

/* ************************************************************************ */
/* 	ログアウト確認ダイアログ												*/
/* ************************************************************************ */
function logoutCheck()
{
	if ( window.confirm( "ログアウトします。よろしいですか？" ) ) 
	{
		return true;
	}
	return false;
}

/* ************************************************************************ */
/* 	新規作成確認ダイアログ													*/
/* ************************************************************************ */
function AddnewCheck( val )
{
	if (! val)
	{
		val = 'データ';
	}
	
	if ( window.confirm( val + "を新規作成します。よろしいですか？" ) ) 
	{
		return true;
	}
	return false;
}
/* ************************************************************************ */
function RedirectToNewPage( url, plan, count, max, page )
{
	if ( planCheck( plan, count, max ) )
	{
		if ( window.confirm( "採用ページを新規作成します。よろしいですか？"  ) ) 
		{
			if(page == 'top'){
				return true;
			}else{
				window.location.href = url;
			}
		}
	}
	return false;
}
/* ************************************************************************ */
function RedirectToNewForm( url, plan, count, max )
{
	if ( planCheck( plan, count, max ) )
	{
		if ( window.confirm( "採用ページがまだ作成されていないようです。\n先に採用ページを作成します。よろしいですか？"  ) ) 
		{
			window.location.href = url;
		}
	}
	return false;
}
/* ************************************************************************ */
function RedirectToNewPageCa( url, plan, count, max, page )
{
	if ( planCheck( plan, count, max ) )
	{
		if ( window.confirm( "求人広告を新規作成します。よろしいですか？"  ) ) 
		{
			if(page == 'top'){
				return true;
			}else{
				window.location.href = url;
			}
		}
	}
	return false;
}
/* ************************************************************************ */
function RedirectToNewFormCa( url, plan, count, max )
{
	if ( planCheck( plan, count, max ) )
	{
		if ( window.confirm( "求人広告がまだ作成されていないようです。\n先に求人広告を作成します。よろしいですか？"  ) ) 
		{
			window.location.href = url;
		}
	}
	return false;
}
/* ************************************************************************ */
/* 	利用中のプランのチェック												*/
/* ************************************************************************ */
function planCheck( plan, count, max )
{
	if ( count >= max )
	{
		alert("ご利用中のプランでは、これ以上求人ページを作成できません。\n"
			+ "既に作成済みの求人ページを削除してから新規作成を行ってください。"
			);
		return false;
	}
	return true;
}
/* ************************************************************************ */
/* 	削除確認ダイアログ														*/
/* ************************************************************************ */
function DeleteCheck( val , addmsg )
{
	var msg;
	
	if (! val) { val = 'データ'; }
	
	msg = val + "を削除します。よろしいですか？\n\n" +
			"※　一度削除してしまうと元には戻せません。";
	
	if (addmsg) { msg = msg + "\n\n" + addmsg; }
	
	if ( window.confirm( msg ) ) 
	{
		return true;
	}
	return false;
}
/* ************************************************************************ */
/* 	コピー確認ダイアログ													*/
/* ************************************************************************ */
function CopyCheck( val , addmsg, plan, count, max  )
{
	var msg;
	
	if ( ! planCheck(plan, count, max) )
	{
		return false;
	}
	
	if (! val) { val = 'データ'; }
	
	msg = val + "をコピーします。よろしいですか？";
	
	if (addmsg) { msg = msg + "\n\n" + addmsg; }
	
	if ( window.confirm( msg ) ) 
	{
		return true;
	}
	return false;
}

/* ************************************************************************ */
/* 	チェックボックス On / Off												*/
/* ************************************************************************ */
function InputCheckbox( objFrm, value, key )
{
	with ( objFrm ) 
	{
		for ( var i = 0; i < elements.length; i++ )
		{
			if ( elements[i].type == 'checkbox' && 
				 elements[i].name == key )
			{
				elements[i].checked = value;
			}
		}
	}
}

/* ************************************************************************ */
/* 	項目の表示・非表示														*/
/* ************************************************************************ */
function block_disp ( baseid, count, disp )
{
	if (! document.getElementById ) return;
	
	var last_count = ( parseInt( count )  - 1 );

	// 各種項目表示
	document.getElementById( baseid + '_' + count ).style.display = disp;
	
	if ( disp == "none" )
	{
		// 項目の非表示
		document.getElementById( baseid + '_' + count + '_id').value = "";
		
		// 追加ボタンの表示
		document.getElementById( baseid + '_' + last_count + '_add' ).style.display = "block";
	}
	else if ( disp == "block" )
	{
		// 項目の表示
		document.getElementById( baseid + '_' + count + '_id').value = count;
		
		// 追加ボタンの非表示
		document.getElementById( baseid + '_' + last_count + '_add' ).style.display = "none";
	}
}

/* ************************************************************************ */
/* Tab On / Off 															*/
/* ************************************************************************ */
// hpref = tab header prefix
// bpref = tab body prefix
// id_max
// selected
function selTab( hpref, bpref, id_max, selected, className ) 
{
	if ( ! document.getElementById ) return;
	
	for ( var i = 1; i <= id_max; i++ ) 
	{
		if ( ! document.getElementById( bpref + "_" + i ) ) continue;
		if ( ! document.getElementById( hpref + "_" + i ) ) continue;
		
		var tab_body 	= document.getElementById( bpref + "_" + i );
		var tab_header 	= document.getElementById( hpref + "_" + i );
		
		if ( i == selected ) 
		{
			tab_body.style.visibility = "visible";
			tab_body.style.display = "block";
//			tab_body.style.position = "";
			tab_header.className = className + "_open";
			
		} 
		else 
		{
			tab_body.style.visibility = "hidden";
			tab_body.style.display = "none";
//			tab_body.style.position = "absolute";
			tab_header.className = className +  "_close";
		}
		
		if ( document.getElementById( hpref + "_" + i + "_L" ) )
		{
			var tab_header_L = document.getElementById( hpref + "_" + i + "_L" );
			if ( i == selected ) 
			{
				tab_header_L.className = className + "_open_L";
			}
			else
			{
				tab_header_L.className = className + "_close_L";
			}
		}
		
		if ( document.getElementById( hpref + "_" + i + "_C" ) )
		{
			var tab_header_C = document.getElementById( hpref + "_" + i + "_C" );
			if ( i == selected ) 
			{
				tab_header_C.className = className + "_open_C";
			}
			else
			{
				if ( i + 1 == selected)
				{
					tab_header_C.className = className + "_close_C";
				}
				else
				{
					tab_header_C.className = className + "_close_C_2";
				}
			}
		}
		
		if ( document.getElementById( hpref + "_" + i + "_R" ) )
		{
			var tab_header_R = document.getElementById( hpref + "_" + i + "_R" );
			if ( i == selected ) 
			{
				tab_header_R.className = className + "_open_R";
			}
			else
			{
				tab_header_R.className = className + "_close_R";
			}
		}
	}
}

/* ************************************************************************ */
function showBlock( id, value )
{
	if ( ! document.getElementById ) return;
	if ( ! document.getElementById( id ) ) return;
	var el = document.getElementById( id );
	
//	debug.print( 'id : '    + id    );
//	debug.print( 'value : ' + value );
	
//	debug.print( '1:el.style.visibility : ' + el.style.visibility );
//	debug.print( '1:el.style.display    : ' + el.style.display    );
//	debug.print( '1:el.style.position   : ' + el.style.position   );
	
	if ( value == 'on' ) 
	{
		el.style.visibility = "visible";
		el.style.display = "block";
		el.style.position = "";
	//	document.getElementById( id ).style.display = "block";
	} 
	else 
	{
		el.style.visibility = "hidden";
		el.style.display = "none";
		el.style.position = "absolute";
	//	document.getElementById( id ).style.display = "none";
	}
	
//	debug.print( '2:el.style.visibility : ' + el.style.visibility );
//	debug.print( '2:el.style.display    : ' + el.style.display    );
//	debug.print( '2:el.style.position   : ' + el.style.position   );
}

/* ************************************************************************ */
function BackButton( objFrm , mode , act ) 
{
	with ( objFrm )
	{
		var prev_action = action;
		var prev_rm     = rm.value;
		
		if ( act ) { action = act; }
		rm.value = mode;
		submit();
		
		action   = prev_action;
		rm.value = prev_rm;
	}
}

/* ************************************************************************ */
function PreView( objFrm , mode , param ) 
{
	with ( objFrm )
	{
		var prev_action = action;
		var prev_target = target;
		var prev_rm     = rm.value;
		var perv_pv;
		if ( param ) { perv_pv = pv.value; }
		
		action = "preview";
		target = "preview";
		rm.value = mode;
		if ( param ) { pv.value = param; }
		submit();
		
		action   = prev_action;
		target   = prev_target;
		rm.value = prev_rm;
		if ( param ) { pv.value = perv_pv; }
	}
}

/* ************************************************************************ */
function PreViewMap( objFrm , mode , param , server ) 
{
	with ( objFrm )
	{
		var prev_action = action;
		var prev_target = target;
		var prev_rm     = rm.value;
		var perv_pv;
		if ( param ) { perv_pv = pv.value; }
		
		action = "http://" + server + "/do/users/map";
		//action = "../users/map";
		target = "preview";
		rm.value = mode;
		if ( param ) { pv.value = param; }
		submit();
		
		action   = prev_action;
		target   = prev_target;
		rm.value = prev_rm;
		if ( param ) { pv.value = perv_pv; }
	}
}

/* ************************************************************************ */
function MakePDF( objFrm , mode , param ) 
{
	with ( objFrm )
	{
		var prev_target = target;
		var prev_rm     = rm.value;
		var perv_entry_id;
		if ( param ) { perv_entry_id = entry_id.value; }
		
		target = "pdf";
		rm.value = mode;
		if ( param ) { entry_id.value = param; }
		submit();
		
		target   = prev_target;
		rm.value = prev_rm;
		if ( param ) { entry_id.value = perv_entry_id; }
	}
}

/* ************************************************************************ */
/* 	デザインモードの画面配置設定											*/
/* ************************************************************************ */
function select_align(obj_id, align)
{
	document.getElementById(obj_id).align = align;
}

/* ************************************************************************ */
/* 住所のコピー																*/
/* ************************************************************************ */
function copyAddress( from, to )
{
	copyAddress_sub( from, to, 'zip_1' );
	copyAddress_sub( from, to, 'zip_2' );
	copyAddress_sub( from, to, 'prefecture' );
	copyAddress_sub( from, to, 'address_1' );
	copyAddress_sub( from, to, 'address_2' );
	copyAddress_sub( from, to, 'tel_1' );
	copyAddress_sub( from, to, 'tel_2' );
	copyAddress_sub( from, to, 'tel_3' );
	copyAddress_sub( from, to, 'fax_1' );
	copyAddress_sub( from, to, 'fax_2' );
	copyAddress_sub( from, to, 'fax_3' );
	copyAddress_sub( from, to, 'email' );
	copyAddress_sub( from, to, 'email_2' );
	copyAddress_sub( from, to, 'mobile_tel_1' );
	copyAddress_sub( from, to, 'mobile_tel_2' );
	copyAddress_sub( from, to, 'mobile_tel_3' );
	copyAddress_sub( from, to, 'mobile_email' );
	copyAddress_sub( from, to, 'mobile_email_2' );
}
function copyAddress_sub( from, to, target)
{
	if ( !document.getElementById( to   + '_' + target) ) return;
	if ( !document.getElementById( from + '_' + target) ) return;
	document.getElementById( to + '_' + target).value = document.getElementById( from + '_' + target).value;
}

/* ************************************************************************ */
/*	満年齢計算																*/
/* ************************************************************************ */
/* http://www.accessclub.jp/actips/tips_98.htm								*/
/* http://www.nagasaki-gaigo.ac.jp/media_c/2002_johoen/function/datedif.htm	*/
/* ************************************************************************ */
function setAge( year, month, day, age )
{
	if ( !document.getElementById( age   ) ) return;
	var el_age   = document.getElementById( age );
	el_age.innerHTML = '';
	
	if ( !document.getElementById( year  ) ) return;
	var el_year  = document.getElementById( year );
	if ( !el_year.value ) return;
	
	if ( !document.getElementById( month ) ) return;
	var el_month = document.getElementById( month );
	if ( !el_month.value ) return;
	
	if ( !document.getElementById( day   ) ) return;
	var el_day   = document.getElementById( day );
	if ( !el_day.value ) return;
	
	var age = 0;
	var dtNow = new Date();		// 今日の日付
	var dtAge = new Date();		// 誕生日
	dtAge.setFullYear( el_year.value );
	dtAge.setMonth( el_month.value - 1 );
	dtAge.setDate( el_day.value );
	
	// "年"を計算します。
	age = dtNow.getFullYear() - dtAge.getFullYear();
	
	// 今年の誕生日を求めます
	var dtNowBirthday = new Date();
	dtNowBirthday.setFullYear( dtNow.getFullYear() );
	dtNowBirthday.setMonth( el_month.value - 1 );
	dtNowBirthday.setDate( el_day.value );
	
	// もし、今年の誕生日が過ぎていれば求めた 満年齢 から１歳引きます。
	if (dtNowBirthday > dtNow)
	{
		age = age - 1;
	}
	
	el_age.innerHTML = '満 ' + age + ' 歳';
	
}
/* ************************************************************************ */
/* [EOF]																	*/
/* ************************************************************************ */
