$( function() {	
	$( "#selDistirct" ).click( function() {
		var tourKind = window.document.getElementById( "selTourKind" ).value;
		var district = window.document.getElementById( "selDistirct" ).value;
		if( tourKind != "" && tourKind != undefined ) {
			var params = "method=getTourList&prmDistrict="+ district +"&prmTourKind=" + tourKind;
			new ajax.xhr.Request( "explore0501.do", params, setTourList, "GET", "selTourList" );
		} 
	});
	
	$( "#selTourKind" ).click( function() {
		var district = window.document.getElementById( "selDistirct" ).value;
		var tourKind = window.document.getElementById( "selTourKind" ).value;
		if( district != "" && district != undefined ) {			
			var params = "method=getTourList&prmDistrict="+ district +"&prmTourKind=" + tourKind;
			new ajax.xhr.Request( "explore0501.do", params, setTourList, "GET", "selTourList" );
		} 
	});
	
	$( "#imgSearch" ).click( function() {
		var tourNo = window.document.getElementById( "selTourList" ).value;
		if( tourNo != "" ) {
			var selText = window.document.getElementById( "selTourList" ).options[window.document.getElementById( "selTourList" ).selectedIndex].text;
			window.document.getElementById( "subTitle" ).style.visibility = "visible";
			window.document.getElementById( "subTitle" ).innerHTML = selText;
			
			window.document.forms[ "frmLocalTripList" ].method.value = "getTravelInfo";
			window.document.forms[ "frmLocalTripList" ].prmTourNo.value = tourNo;
			window.document.forms[ "frmLocalTripList" ].submit();	
			
			window.document.getElementById( "divBefore" ).style.display = "none";
			window.document.getElementById( "imgBefore" ).src = "";
		} else {
			alert( "답사지를 선택하세요" );
		}
	});
	
	$( "#goWebGIS" ).click( function() {
		
		var x = window.document.getElementById( "coordX" ).value;
		var y = window.document.getElementById( "coordY" ).value;
		var title = window.document.getElementById( "title" ).value;
		var width = window.screen.availWidth;
		var height = window.screen.availHeight;
		
		var str = "http://www.zaolsoft.com/land/webGIS.do?menu=viewTourInfo";
		popGIS = window.open( 'about:blank' ,'webGIS','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=no,width=' + width + ',height=' + height + ',left=0,top=0');
		if(popGIS != null){ 
			window.document.forms[ "gisForm" ].target = 'webGIS';
			window.document.forms[ "gisForm" ].x.value = x;
			window.document.forms[ "gisForm" ].y.value = y;
			window.document.forms[ "gisForm" ].title.value = title;
			window.document.forms[ "gisForm" ].action = str; 
			window.document.forms[ "gisForm" ].submit();
		}
	}).css( "cursor" , "pointer" );
	
});
/*
var popGIS;
function viewTourInfo( x, y, title ) {
	popGIS.viewTourInfo( x, y, title );	
}
*/
function setTourList( req ) {
	if ( req.readyState == 4 ) {
		if ( req.status == 200 ) {   
			xmlDoc = req.responseXML;			
			var select = xmlDoc.getElementsByTagName( "select" );
			document.getElementById( this ).length = 0;
			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 );				
			}
		}
	}
}
