function goPage( pageNum ) {
	var season = window.document.getElementById( "season" ).value;
	window.document.forms[ "frmBoardList" ].method.value = "getList";
	window.document.forms[ "frmBoardList" ].prmPagingNum.value = pageNum;
	if( season != "" && season != 0 ) {
		window.document.forms[ "frmBoardList" ].prmSeasonCode.value = season;
	}
	window.document.forms[ "frmBoardList" ].submit();
}

function viewContent( contentNo ) {
	window.document.forms[ "frmBoardList" ].method.value = "getView";
	window.document.forms[ "frmBoardList" ].prmContentNo.value = contentNo;
	window.document.forms[ "frmBoardList" ].submit();
}

$( function() {

	$( window ).load( function(){
		var season = window.document.getElementById( "season" ).value;

		if( season != "" ) {
			if( season == "1" ) {
				
				window.document.getElementById( "liSpring" ).className = "fir";
				window.document.getElementById( "aSpring" ).className = "on";
				
			} else if( season == "2" ) {
	
				window.document.getElementById( "liSummer" ).className = "fir";
				window.document.getElementById( "aSummer" ).className = "on";
				
			} else if( season == "3" ) {
	
				window.document.getElementById( "liFall" ).className = "fir";
				window.document.getElementById( "aFall" ).className = "on";
				
			} else if( season == "4" ) {
	
				window.document.getElementById( "liWinter" ).className = "fir";
				window.document.getElementById( "aWinter" ).className = "on";
				
			} else if( season == "0" ) {
	
				window.document.getElementById( "liAll" ).className = "fir";
				window.document.getElementById( "aAll" ).className = "on";
				
			}
		}
	});
/*	
	$( "#btnAll" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getList";
		window.document.forms[ "frmBoardList" ].submit();
	});	
	
	$( "#btnSpring" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getList";
		window.document.forms[ "frmBoardList" ].prmSeasonCode.value = 1;
		window.document.forms[ "frmBoardList" ].submit();
	});	
	
	$( "#btnSummer" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getList";
		window.document.forms[ "frmBoardList" ].prmSeasonCode.value = 2;
		window.document.forms[ "frmBoardList" ].submit();
	});	
	
	$( "#btnFall" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getList";
		window.document.forms[ "frmBoardList" ].prmSeasonCode.value = 3;
		window.document.forms[ "frmBoardList" ].submit();
	});	
	
	$( "#btnWinter" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getList";
		window.document.forms[ "frmBoardList" ].prmSeasonCode.value = 4;
		window.document.forms[ "frmBoardList" ].submit();
	});	
*/	
	$( "#btnSearch" ).click( function () {
		if( window.document.getElementById( "txtSearch" ).value == "" ) {
			alert( "검색어를 입력하세요" );
		} else {
			window.document.forms[ "frmBoardList" ].method.value = "getSearch";
			window.document.forms[ "frmBoardList" ].prmKeyword.value = window.document.getElementById( "txtSearch" ).value;
			window.document.forms[ "frmBoardList" ].prmSearchKind.value = window.document.getElementById( "selSearch" ).value;
			window.document.forms[ "frmBoardList" ].prmSeasonCode.value = window.document.getElementById( "selSeason" ).value;
			window.document.forms[ "frmBoardList" ].submit();
		}
	}).css( "cursor" , "pointer" );	
	
	$( "#txtSearch" ).keydown( function( evt ) {
		var evtCode = ( window.netscape ) ? evt.which : event.keyCode;
		if( evtCode == 13 ) {
			if( window.document.getElementById( "txtSearch" ).value == "" ) {
				alert( "검색어를 입력하세요" );
			} else {
				window.document.forms[ "frmBoardList" ].method.value = "getSearch";
				window.document.forms[ "frmBoardList" ].prmKeyword.value = window.document.getElementById( "txtSearch" ).value;
				window.document.forms[ "frmBoardList" ].prmSearchKind.value = window.document.getElementById( "selSearch" ).value;
				window.document.forms[ "frmBoardList" ].prmSeasonCode.value = window.document.getElementById( "selSeason" ).value;
				window.document.forms[ "frmBoardList" ].submit();
			}			
		}
	});
	
	$( "#btnWrite" ).click( function () {
		window.location.href = "/writeTour.do";
		/*var userID = window.document.getElementById( "userID" ).value;
		if( userID != "" && userID != undefined ) {
			window.location.href = "/writeTour.do";
		}
		else {
			alert( "로그인 후에 글을 쓸 수 있습니다." );
			window.document.forms[ "logForm" ].land.value = "login";
			window.document.forms[ "logForm" ].url.value = window.location.href;
			window.document.forms[ "logForm" ].submit();
		}*/
	}).css( "cursor" , "pointer" );
	
	$( "#btnList" ).click( function () {
		window.document.location.href = "/portal0101.do";		
	}).css( "cursor" , "pointer" );
	
	$( "#btnSubmitWrite" ).click( function () {
		
		if( checkInvalid() ) {
			var size = window.document.getElementsByName( 'rdSeason' ).length;
			var season;
			for( var i=0; i<size; i++ ) {
				if ( document.getElementsByName( 'rdSeason' )[i].checked ) {
					season = document.getElementsByName( 'rdSeason' )[i].value;
				}
			}
			window.document.forms[ "frmBoardList" ].method.value = "insertContent";
			window.document.forms[ "frmBoardList" ].strSubject.value = window.document.getElementById( "txtTitle" ).value;
			window.document.forms[ "frmBoardList" ].strSeason.value = season;
			window.document.forms[ "frmBoardList" ].strWriter.value = window.document.getElementById( "txtWriter" ).value;
			//window.document.forms[ "frmBoardList" ].strComment.value = window.document.getElementById( "txtComment" ).value;
			window.document.forms[ "frmBoardList" ].submit();
		}

	}).css( "cursor", "pointer" );	
	
	$( "#btnReply" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getViewForReply";
		window.document.forms[ "frmBoardList" ].submit();
		/*var userID = window.document.getElementById( "userID" ).value;
		if( userID != "" && userID != undefined ) {
			window.document.forms[ "frmBoardList" ].method.value = "getViewForReply";
			window.document.forms[ "frmBoardList" ].submit();
		} else {
			alert( "로그인 한 회원만 답글을 쓸 수 있습니다." );
		}*/
	}).css( "cursor" , "pointer" );
	
	$( "#btnSubmitReply" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "insertReply";
		window.document.forms[ "frmBoardList" ].strSubject.value = window.document.getElementById( "txtTitle" ).value;
		window.document.forms[ "frmBoardList" ].strWriter.value = window.document.getElementById( "txtWriter" ).value;
		window.document.forms[ "frmBoardList" ].submit();
	}).css( "cursor" , "pointer" );
	
	$( "#btnComment" ).click( function () {
		var userID = window.document.getElementById( "userID" ).value;
		if( userID != "" && userID != undefined ) {
			window.document.forms[ "frmBoardList" ].method.value = "insertComment";
			window.document.forms[ "frmBoardList" ].strComment.value = window.document.getElementById( "txtComment" ).value;
			window.document.forms[ "frmBoardList" ].submit();
		} else {
			alert( "로그인 한 회원만 꼬리말을 쓸 수 있습니다." );
		}
	}).css( "cursor" , "pointer" );
	
	$( "#txtComment" ).keydown( function( evt ) {
		var evtCode = ( window.netscape ) ? evt.which : event.keyCode;
		if( evtCode == 13 ) {
			var userID = window.document.getElementById( "userID" ).value;
			if( userID != "" && userID != undefined ) {
				window.document.forms[ "frmBoardList" ].method.value = "insertComment";
				window.document.forms[ "frmBoardList" ].strComment.value = window.document.getElementById( "txtComment" ).value;
			} else {
				alert( "로그인 한 회원만 꼬리말을 쓸 수 있습니다." );
			}
		}
	});
	
	$( "#btnLogin" ).click( function () {
		window.document.forms[ "logForm" ].land.value = "login";
		window.document.forms[ "logForm" ].url.value = window.location.href;
		window.document.forms[ "logForm" ].submit();
	}).css( "cursor" , "pointer" );
	
	$( "#btnLogout" ).click( function () {
		window.document.forms[ "logForm" ].land.value = "logout";
		window.document.forms[ "logForm" ].submit();
	}).css( "cursor" , "pointer" );
	
	$( "#btnDelete" ).click( function () {
		if( confirm( "정말 삭제하시겠습니까?" ) ) {
			window.document.forms[ "frmBoardList" ].method.value = "delContent";
			window.document.forms[ "frmBoardList" ].submit();
		}
	}).css( "cursor" , "pointer" );
	
	$( "#btnModify" ).click( function () {
		window.document.forms[ "frmBoardList" ].method.value = "getViewForModify";
		window.document.forms[ "frmBoardList" ].submit();
	}).css( "cursor" , "pointer" );
	
	$( "#btnSubmitModify" ).click( function () {
		var size = window.document.getElementsByName( 'rdSeason' ).length;
		var season;
		for( var i=0; i<size; i++ ) {
			if ( document.getElementsByName( 'rdSeason' )[i].checked ) {
				season = document.getElementsByName( 'rdSeason' )[i].value;
			}
		}
		
		window.document.forms[ "frmBoardList" ].method.value = "updateModify";
		window.document.forms[ "frmBoardList" ].strSubject.value = window.document.getElementById( "txtTitle" ).value;
		window.document.forms[ "frmBoardList" ].strWriter.value = window.document.getElementById( "txtWriter" ).value;
		window.document.forms[ "frmBoardList" ].strSeason.value = season;
		window.document.forms[ "frmBoardList" ].submit();
	}).css( "cursor" , "pointer" );
	
});

function delComment( regDate, userID ) {
	
	var userIDBySession = window.document.getElementById( "userID" ).value;
	if( userIDBySession != userID ) {
		alert( "본인만 꼬리말을 삭제할 수 있습니다." );
	} else {
		if( confirm( "꼬리말을 삭제하시겠습니까?" ) ) {
			window.document.forms[ "frmBoardList" ].method.value = "delComment";
			window.document.forms[ "frmBoardList" ].strDate.value = regDate;
			window.document.forms[ "frmBoardList" ].strUserID.value = userID;
			window.document.forms[ "frmBoardList" ].submit();
		} 
	}
	
}

function checkInvalid() {
	var title = window.document.getElementById( "txtTitle" ).value;
	var season;
	var size = window.document.getElementsByName( 'rdSeason' ).length;
	var chkLength = new Number( 0 );
	
	if( title == "" ) {
		alert( "제목을 입력하세요" );
		return false;
	}
	
	if( !validateSpecialChar( title, "()<>" ) ) {
		alert( "특수문자는 입력할 수 없습니다." );
		return false;
	}
	
	for( var i=0; i<size; i++ ) {
		if ( document.getElementsByName( 'rdSeason' )[i].checked ) {
			//alert( document.getElementsByName( 'rdSeason' )[i].value );
			chkLength++;
		}
	}
	if ( chkLength == 0 ) {
		alert( "등록할 계절을 선택하세요." );
		return false;
	}
	
	return true;
}
