function goPage( pageNum ) {
	var sido = window.document.getElementById( "strSido" ).value;
	
	window.document.forms[ "frmSpecialProductList" ].method.value = "getSpecialProductList";
	window.document.forms[ "frmSpecialProductList" ].prmPagingNum.value = pageNum;
	window.document.forms[ "frmSpecialProductList" ].prmSido.value = sido;
	window.document.forms[ "frmSpecialProductList" ].prmSigungu.value = window.document.getElementById( "selSiGungu" ).value;
	window.document.forms[ "frmSpecialProductList" ].submit();
}

$( function() {
	$( "#btnSubmit" ).click( function () {
		window.document.forms[ "frmSpecialProductList" ].method.value = "getSpecialProductList";
		window.document.forms[ "frmSpecialProductList" ].prmSido.value = window.document.getElementById( "selSido" ).value;
		window.document.forms[ "frmSpecialProductList" ].prmSigungu.value = window.document.getElementById( "selSiGungu" ).value;
		window.document.forms[ "frmSpecialProductList" ].submit();
		
	}).css( "cursor", "pointer" );
	
	$( "#selSido" ).change( function () {
		var sido = window.document.getElementById( "selSido" ).value;
		window.document.getElementById( "txtAddress" ).innerHTML = sido + "의 특산물";
		if( sido != "" && sido != undefined ) {
			var params = "method=getSigungu&prmSido="+ encodeURIComponent( sido );
			new ajax.xhr.Request( "explore0401.do", params, setSigungu, "GET", "selSiGungu" );
		} 
	});	
	
	$( "#selSiGungu" ).change( function () {
		var sido = window.document.getElementById( "selSido" ).value;
		var sigungu = window.document.getElementById( "selSiGungu" ).value;
		window.document.getElementById( "txtAddress" ).innerHTML = sido + " " + sigungu + "의 특산물";
		if( sigungu != "" && sigungu != undefined ) {
			var params = "method=getProduct&prmSido="+ encodeURIComponent( sido ) +"&prmSigungu="+ encodeURIComponent( sigungu );
			new ajax.xhr.Request( "explore0401.do", params, setProduct, "GET", "txtProduct" );
		} 
	});	
});

function setProduct( req ) {
	if ( req.readyState == 4 ) {
		if ( req.status == 200 ) {   
			var result = req.responseText;
			window.document.getElementById( "txtProduct" ).innerHTML = result;
		}
	}
}

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 );				
			}
		}
	}
}
