var formNumber;
/**
 * ログインフォーム表示
 * @return
 */
function showLoginForm(){
	$.blockUI({ message:$('#loginForm'), 
				css:{ 	backgroundColor:'#ffffff',
						color:'#565656',
						cursor:'default'}
	});

}

/**
 * ログインフォームを閉じる
 * @return
 */
function hideLoginForm(){
	$.unblockUI();
}

/**
 * ログイン処理
 * @return
 */
function userLogin(){
	UserDwr.login($("#userId").val(), $("#userPw").val(), CallbackLogin);
	
	showWait( "ログイン中..." );
	 
}

/**
 * ログイン処理　－１
 * @return
 */
function CallbackLogin( ret ){
	if ( ret == 0 ){
		$("#user").html("");
		$("#user").load("common/jsp/userLogined.html",  null, function(){loadUserInfo()});
	} else {
		//$.unblockUI();
		alertBlock("ログインに失敗しました。", "ユーザIDまたは、パスワードが間違っています。","ユーザID入力欄は、メールアドレスも可能です。",null);
	}
}

/**
 * ログイン処理　－２
 * @return
 */
function loadUserInfo( data ){
	formNumber = data;
	UserDwr.getUserInfo(callbackUserInfo);
}

/**
 * ログイン処理　－３
 * @return
 */
function callbackUserInfo(user){
	var html = "";
	//html += "";
	html += "<img id=\"kindIcon\" src=\"" + getKindIcon(user.kind) + "\">";
	html += "<span id=\"loginTitle\">&nbsp;ユーザ情報&nbsp;</span><br />";
	
	html += "<div id=\"userInfo\">";
	html += "<span id=\"userName\">ID:";
	
	if (user.userId != null){
		html += user.userId;
	} else {
		html += "未設定";
	}
	
	html += "</span><br />";
	html += "<span id=\"jnm\">";
	
	if (user.jnm != null){
		html += user.jnm;
	} else {
		html += "未設定";
	}
	
	html += "</span>";
	html += "<span id=\"userTitle\">&nbsp;";
	
	if (user.title != null){
		html += user.title;
	} else {
		html += "";
	}
	
	
	html += "</span><br />";
	html += "</div>";
	html += "<div id=\"tideBook\"></div>";
	
	$("#ul1").html(  html );
	
	html = "";
	html += "<input type=\"button\" id=\"userEdit\"   onclick=\"showEditUserPage();\"></input>";
	html += "<input type=\"button\" id=\"userLogout\" onclick=\"logout();\"></input>";
	$("#ul2").html(  html );
	
	//if ( formNumber == 10){
		UserDwr.getUserTideList( callbackUserTideList );
	//} else {
	//	$.unblockUI();
	//}
	
}

/**
 * ログイン情報　－４
 * 潮汐登録情報取得
 * @return
 */
function callbackUserTideList( data ){
	
	if (data == null || data.length == 0){
	} else {
		var html = "";
		html += "<span id=\"tideBookTitle\">潮汐</span><br />";
		html += "<ul id=\"tideBookList\">";
		for (var i=0; i<data.length; i++){
			html += "<p><a href=\"./tide?action=2001&id=" + data[i].tide.id + "\">" + data[i].tide.placeNmJp + "</a></p>";
		}
		html += "</ul>";
		$("#tideBook").html( html );
		
		
		$('#tideBookTitle').click(function(){
			$("#tideBookList").slideToggle('slow');
		});
		$('#tideBookList').css("display" , "none" );
	}
	
	$.unblockUI();
}

function callbackUserTideListNoUnblock( data ){
	
	if (data == null || data.length == 0){
	} else {
		var html = "";
		html += "<span id=\"tideBookTitle\">潮汐</span><br />";
		html += "<ul id=\"tideBookList\">";
		for (var i=0; i<data.length; i++){
			html += "<p><a href=\"./tide?action=2001&id=" + data[i].tide.id + "\">" + data[i].tide.placeNmJp + "</a></p>";
		}
		html += "</ul>";
		$("#tideBook").html( html );
		
		
		$('#tideBookTitle').click(function(){
			$("#tideBookList").slideToggle('slow');
		});
		$('#tideBookList').css("display" , "none" );
	}
	
	//$.unblockUI();
}
/**
 * ユーザ潮汐リストをリロードする
 * @param data
 * @return
 */
function reloadUserTideList( ){
	
	UserDwr.getUserTideList( callbackUserTideList );
	
}

function reloadUserTideListNoUnblock( ){
	
	UserDwr.getUserTideList( callbackUserTideListNoUnblock );
	
}

/**
 * ログアウト処理
 * @return
 */
function logout(){
	
	UserDwr.logout( CallbackLogout );
	
	showWait( 'ログアウト中...' );
	
}

function CallbackLogout(data){
	$("#user").html( "" );
	$("#user").load("common/jsp/user.html" ,  null, function(){loadUserInit()});
	
}

function loadUserInit(){
	$.unblockUI();
}