function goPage( pageNum ) {
	var sidoCode = window.document.getElementById( "sidoCode" ).value;
	var sigungu = window.document.getElementById( "sigungu" ).value;
	var month = window.document.getElementById( "month" ).value;
	
	var keyword = window.document.getElementById( "strKeyword" ).value;
	if( keyword != "" ) {
		window.document.forms[ "frmFestivalList" ].method.value = "getSearchList";
		window.document.forms[ "frmFestivalList" ].prmKeyword.value = keyword;		
		window.document.forms[ "frmFestivalList" ].prmSearchKind.value = window.document.getElementById( "strSearchKind" ).value;		
	} else {
		window.document.forms[ "frmFestivalList" ].method.value = "getFestivalListForSearch";
		window.document.forms[ "frmFestivalList" ].prmSidoCode.value = sidoCode;
		window.document.forms[ "frmFestivalList" ].prmSigungu.value = sigungu;
		window.document.forms[ "frmFestivalList" ].prmMonth.value = month;
	}
	
	window.document.forms[ "frmFestivalList" ].prmPagingNum.value = pageNum;
	window.document.forms[ "frmFestivalList" ].submit();
}

var viewFlag = 0;	
function viewContent( count, nSize ) {
	for( var i=1; i<=nSize; i++ ) {
		window.document.getElementById( "boardContent" + i ).style.display = "none";
	}
	
	if( viewFlag != count ) {
		window.document.getElementById( "boardContent" + count ).style.display = "block";	
		viewFlag = count;
	} else {
		window.document.getElementById( "boardContent" + count ).style.display = "none";
		viewFlag = 0;
	}
	
}

function xssReplace(a){
	var limit_char = /[~!\#$^&%*\=+|:;?"<,.>']/;
	var tmp_str="";
	for(var i=0; i<a.length; i++) {
		var data1=a.charAt(i);
		tmp_str+=data1.replace(limit_char,"");
	}
	return tmp_str;
}

$( function() {
	$( "#btnSearch" ).click( function () {
		window.document.forms[ "frmFestivalList" ].method.value = "getSearchList";
		window.document.forms[ "frmFestivalList" ].prmKeyword.value = xssReplace(window.document.getElementById( "txtSearch" ).value);
		window.document.forms[ "frmFestivalList" ].prmSearchKind.value = window.document.getElementById( "selSearch" ).value;
		window.document.forms[ "frmFestivalList" ].submit();
		
	}).css( "cursor", "pointer" );	
	
	$( "#txtSearch" ).keydown( function( evt ) {
		if( evt.keyCode == 13 ) {
			window.document.forms[ "frmFestivalList" ].method.value = "getSearchList";
			window.document.forms[ "frmFestivalList" ].prmKeyword.value = xssReplace(window.document.getElementById( "txtSearch" ).value);
			window.document.forms[ "frmFestivalList" ].prmSearchKind.value = window.document.getElementById( "selSearch" ).value;
			window.document.forms[ "frmFestivalList" ].submit();
		}
	});
	
	$( "#btnFestival" ).click( function() {
		window.document.forms[ "frmFestivalList" ].method.value = "getFestivalList";
		window.document.forms[ "frmFestivalList" ].submit();
	}).css( "cursor", "pointer" );
	
	$( "#btnMarket" ).click( function() {
		window.location.href = "/explore0302.do";
	}).css( "cursor", "pointer" );
	
	
	$( "#selSido" ).change( function() {
		var sidoCode = window.document.getElementById( "selSido" ).value;
		if( sidoCode != "" && sidoCode != undefined ) {
			var params = "method=getSigungu&prmSidoCode="+ sidoCode;
			new ajax.xhr.Request( "explore0301.do", params, setSigungu, "GET", "selSiGungu" );
		} 
	});
	
	$( "#btnSubmit" ).click( function() {
		window.document.forms[ "frmFestivalList" ].method.value = "getFestivalListForSearch";
		window.document.forms[ "frmFestivalList" ].prmSidoCode.value = window.document.getElementById( "selSido" ).value;
		window.document.forms[ "frmFestivalList" ].prmSigungu.value = window.document.getElementById( "selSiGungu" ).value;
		window.document.forms[ "frmFestivalList" ].prmMonth.value = window.document.getElementById( "selMonth" ).value;
		window.document.forms[ "frmFestivalList" ].submit();
	}).css( "cursor", "pointer" );
	
	$( document ).ready( function() {		
		for( var i=1; i<13; i++ ) {
			var node = document.createElement( "option" );
			var text = document.createTextNode( i + "월" );
			node.setAttribute( "value", i );
			node.appendChild( text );
			var result = document.getElementById( "selMonth" );
			result.appendChild( node );		
		}		
	});
});

function setSigungu( req ) {
	if ( req.readyState == 4 ) {
		if ( req.status == 200 ) {   
			xmlDoc = req.responseXML;			
			var select = xmlDoc.getElementsByTagName( "select" );
			document.getElementById( this ).length = 1;
			for( var i=0; i<select.length; i++ ) {
				var node = document.createElement( "option" );
				var text = document.createTextNode( select[i].getElementsByTagName( "text" )[0].childNodes[0].nodeValue );
				node.setAttribute( "value", select[i].getElementsByTagName( "value" )[0].childNodes[0].nodeValue );
				node.appendChild( text );
				var result = document.getElementById( this );
				result.appendChild( node );				
			}
		}
	}
}

