var jQuery = $.noConflict();
var ajax = {}; // ajax ÆÐ±âÁö Á¤ÀÇ
ajax.xhr = {}; // ajaxÆÐÅ°Áö¾È¿¡ xhr ¼­ºê ÆÐÅ°Áö Á¤ÀÇ 
ajax.xhr.Request = function(url, params, callback, method) {
    this.req = null;           // XMLHttpRequest °´Ã¼ ÀúÀå¿ë 
    this.url = url;
    this.params = params;
    this.callback = callback;  // °á°ú Ã³¸® ÇÔ¼ö¸í, º¯¼ö´Â ÇÔ¼ö¸¦ ¹ÞÀ» ¼ö ÀÖÀ½
    this.method = method;      // POST, GET
    this.send();               // »ý¼ºÀÚ¿¡¼­ send() ÇÔ¼ö È£Ãâ
}
ajax.xhr.Request.prototype = {
    getXMLHttpRequest: function() {
        if (window.ActiveXObject) { // IE °Ë»ç
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) { // ±¸Çü ºê·¯¿ìÀúÀÌ¸é
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e1) { 
                    return null; 
                }
            }
        } else if (window.XMLHttpRequest) { // FirefoxÀÎÁö °Ë»ç
            return new XMLHttpRequest();
        } else {
            return null;
        }       
    },
    send: function() {
        this.req = this.getXMLHttpRequest();
        var httpMethod = this.method.toUpperCase() ? this.method : 'GET';

        if (httpMethod != 'GET' && httpMethod != 'POST') {
            httpMethod = 'POST'; // ±âº»°ª
        }

        var httpParams = (this.params == null || this.params == '') ? null : this.params;
                         
        var httpUrl = this.url;

        if (httpMethod == 'GET' && httpParams != null) {
            httpUrl = httpUrl + "?" + httpParams;
        }
        
        this.req.open(httpMethod, httpUrl, true);
        
        this.req.setRequestHeader(
            'Content-Type', 'application/x-www-form-urlencoded');
        
        var request = this;
        this.req.onreadystatechange = function() {
            request.resultProcFunc.call(request);
        }
        this.req.send(httpMethod == 'POST' ? httpParams : null);
       },
    // onStateChange ÇÔ¼ö Á¤ÀÇ
    resultProcFunc: function() {
        this.callback(this.req);
    }
}
// ajax js ³¡
//////////////////////////////////////////////////////////////////////

// Å°¿öµå, ÁÖ¼Ò°Ë»ö
function viewtab(num) {

    jQuery('#first').val('Y');
	
    if(num == 1) { //ÁÖ¼Ò °Ë»ö
    	
        jQuery('#textfieldK').val('');
        jQuery('#city').val('');
        jQuery('#district').val('');
        
        if(('#city').val == ('City/do')){
        	jQuery('#district').html('<option value="">District</option>');
        }else{
        	jQuery('#district').html('<option value="">½Ã/±º/±¸</option>');
        }

        jQuery('#dong').html('<option value="">À¾/¸é/µ¿</option>');
        jQuery('#dong').val('');

     	document.getElementById('key1').style.display='none';
     	document.getElementById('key2').style.display='';
     	
        jQuery('#searchListK').empty();
		jQuery('#searchListK').css({"display":"none"});
	
    } else if(num == 2) { //Å°¿öµå °Ë»ö
		
		jQuery('#city').val('');
        jQuery('#district').val('');
        
        jQuery('#textfieldA').val('');
        
		document.getElementById('key1').style.display='';
		document.getElementById('key2').style.display='none';	
        
		jQuery('#searchListA').empty();
		jQuery('#searchListA').css({"display":"none"});
		
	}
    
    //autoSearchAddressSearch(1,jQuery('#initCityValue').val(),jQuery('#initDistrictValue').val(),jQuery('#initDongValue').val());
    
}

function viewtab_en(num) {
	
	jQuery('#first').val('Y');
	if(num == 1){
		jQuery('#textfieldK').val('');
		jQuery('#city').val('');
		jQuery('#district').val('');
		jQuery('#district').html('<option value="">District</option>');
		
		jQuery('#dong').html('<option value="">Dong</option>');
		jQuery('#dong').val('');
		
		document.getElementById('key1').style.display='none';
		document.getElementById('key2').style.display='';
		
        jQuery('#searchListK').empty();
		jQuery('#searchListK').css({"display":"none"});
		
        jQuery('#searchListA').empty();
        jQuery('#searchListA').css("display","none");
	}else if(num == 2){
		jQuery('#textfieldA').val('');
		document.getElementById('key1').style.display='';
		document.getElementById('key2').style.display='none';	
		
        jQuery('#searchListA').empty();
		jQuery('#searchListA').css({"display":"none"});
		
        jQuery('#searchListK').empty();
        jQuery('#searchListK').css("display","none");
	}
	//autoSearchAddressSearch(1,jQuery('#initCityValue').val(),jQuery('#initDistrictValue').val(),jQuery('#initDongValue').val());
}

//Å¬¸¯À§Ä¡ ÁÂÇ¥ ¾ò¾î¿À±â
function ClickGetXY(evtObj){ 
	alert("Å¬¸¯À§Ä¡ÁÂÇ¥(x/y) : "+evtObj.x+' / '+evtObj.y);
}
function getCenter()
{
	var centerPos = mapObj.getCenter();
	alert("Áß½ÉÁÂÇ¥(x/y) : "+centerPos.x+' / '+centerPos.y);
}
function getBound()
{
	curBound = mapObj.getBound();
	alert("°æ°è ÁÂÇ¥\n minX=" + curBound[0] + "\n minY=" + curBound[3] + "\n maxX= "+ curBound[2] + "\n maxY=" + curBound[1]);
}

/*function getZone(){	
	location.href  = "/getZone.action";
}*/


//slide
var initSliderValue = 10; // 1~~~12

function plusSlider() {
	jQuery("#levelboxJS").slider( "value" , jQuery("#levelboxJS").slider("value") + 9 );
	displayMap(Math.floor(jQuery("#levelboxJS").slider("value")/9)+1);
	
}

function minusSlider() {
	jQuery("#levelboxJS").slider( "value" , jQuery("#levelboxJS").slider("value") - 9 );
	displayMap(Math.floor(jQuery("#levelboxJS").slider("value")/9)+1);
	
	
}

// slider level ÀÌ¹ÌÁö ÀÌµ¿
function setSliderPosition(value){	
	
	jQuery("#levelboxJS").slider( "value" , (value-1)*9 );
	displayMap(Math.floor(jQuery("#levelboxJS").slider("value")/9)+1);
	if(jQuery("#levelboxJS").slider( "value") == 12){
		rlvl = 153;
	}else if(jQuery("#levelboxJS").slider( "value") == 11){
		rlvl = 306;
	}else if(jQuery("#levelboxJS").slider( "value") == 10){
		rlvl = 613;
	}else if(jQuery("#levelboxJS").slider( "value") == 9){
		rlvl = 1226
	}else if(jQuery("#levelboxJS").slider( "value") == 8){
		rlvl = 2452;
	}
	
}

function sliderChgAct(val) {
    var curlevel = Math.floor(jQuery('#levelboxJS').slider('option','value')/9);
    var sliderPercent = ((curlevel)*9);
    jQuery('#forDebugArea').html(sliderPercent);

	if(val != 0) {
		var num = Math.floor((val/9)) + 1;
		var s_num = '';
		if(num < 10) {
			s_num = '0'+ num.toString();
		} else {
			if(num > 12) {
				s_num = "12";    
			}
			s_num = num.toString();
		}
	} else {
		s_num = '01';
	}
	jQuery(jQuery('#levelboxJS a').find('img')).attr("src","../images/level_"+s_num+".gif");
}

function displayMap(num) {
	//TO DO : »ç¿ëÀÚ Á¤ÀÇ ¾×¼Ç
	//Áöµµ ·¹º§ ¼³Á¤
	//curMapLevel = mapObj.getZoomLevel();
	//mapObj.zoomIn();
	mapObj.setZoomLevel(num);
	//alert("displayMap():" + curMapLevel+"=>"+(num));
	//setSliderPositionNoNext(num);
}
function displayMapNoNext(num) {
	//TO DO : »ç¿ëÀÚ Á¤ÀÇ ¾×¼Ç
	//Áöµµ ·¹º§ ¼³Á¤
	curMapLevel = mapObj.getZoomLevel();
	//mapObj.zoomIn();
	mapObj.setZoomLevel(num);
	//alert("displayMapNoNext():" + curMapLevel+"=>"+(num));
	//(curMapLevel+"=>"+(num));
//          //console.log(value); alert(value);
	
	

	//("Áöµµ ·¹º§ : "+value);
}
// ¹Ý°æ ÀÌµ¿
function displayOnly(num) {
    var patternArray = [[], [5,4,4,4,5],[1,3,4,4,5],[1,2,3,4,5], [1,2,2,3,5],[1,2,2,2,1]];
    jQuery.each(jQuery('#area_barDiv2').find('img'),function(i,data){
        jQuery(data).attr("src","../images/bar_0" + patternArray[num][i] + '.gif');
    });

    jQuery.each(jQuery('#area_barDiv').find('a'),function(i,data){
        jQuery(data).find('img:first').attr("src",jQuery(data).find('img:first').attr("src").replace('_over',''));
        jQuery(data).addClass("rollover");
        if(i+1 == num) {
            jQuery(data).removeClass();
            var srcValue = jQuery(data).find('img:first').attr("src");
            jQuery(data).find('img:first').attr("src", srcValue.substring(0,srcValue.lastIndexOf('.')) + '_over' + srcValue.substring(srcValue.lastIndexOf('.'),srcValue.length));
            jQuery(data).find('img:last').hide();
            jQuery(data).find('img:last').removeClass();
        } else {
            jQuery(data).find('img:last').css("display","");
            jQuery(data).find('img:last').addClass("over");
        }
    });
    jQuery('#rangePng').attr("class","bar_im"+num);
}
function display(num){
	//alert(num);
    displayOnly(num);
    jQuery('#levelboxJS').slider("value",(12-(num))*9);
    mapFrame.curMapLevel=12-(num-1);
    mapFrame.setMode(3);
    mapFrame.displayMap(12-(num-1));
}
// full screen ºê¶ó¿ìÁ®º° 
function detectVersion() 
{ 
    version = parseInt(navigator.appVersion); 
    return version; 
} 
 
function detectOS() 
{ 
    if (navigator.userAgent.indexOf('Win') == -1) { 
        OS = 'Macintosh'; 
    } else { 
        OS = 'Windows'; 
    } 
    return OS; 
} 
 
function detectBrowser() 
{ 
    if (navigator.appName.indexOf('Netscape') == -1) { 
        browser = 'IE'; 
    } else { 
        browser = 'Netscape'; 
    } 
    return browser; 
} 
 
function fullScreen(url){ 
 
    var adjWidth; 
    var adjHeight; 
 
    if ((detectOS() == 'Macintosh') && (detectBrowser() == 'Netscape')) { 
        adjWidth = 20; 
        adjHeight = 35; 
    } 
    if ((detectOS() == 'Macintosh') && (detectBrowser() == 'IE')) { 
        adjWidth = 20; 
        adjHeight = 35; 
        winOptions = 'fullscreen=yes'; 
    } 
    if ((detectOS() == 'Windows') && (detectBrowser() == 'Netscape')) { 
        adjWidth = 30; 
        adjHeight = 30; 
    } 
    if (detectVersion() < 4) { 
        self.location.href = url; 
    } else { 
        var winWidth = screen.availWidth - adjWidth; 
        var winHeight = screen.availHeight - adjHeight; 
        var winSize = 'width=' + winWidth + ',height=' + winHeight; 
        var thewindow = window.open(url, 'WindowName', winSize); 
        thewindow.moveTo(0,0); 
    } 
} 
 
function openWinFullScreen(url){ 
    if ((detectOS() == 'Windows') && (detectBrowser() == 'IE')) { 
        window.open(url,'windowname','fullscreen=yes'); 
    } else { 
        onload=fullScreen(url); 
    } 
} 
// end of full screen

// ·¹º§¹Ý°æ º¯¼ö
var rlvl = 613; // ±âº»·¹º§ 10·¹º§( 0.5km)


//·¹º§¹Ý°æ ±¸ÇÏ±â
function getRlvl() {
	if(curMapLevel == 12){
		rlvl = 153;
	} else if(curMapLevel == 11){
		rlvl = 306;
	} else if(curMapLevel == 10){
		rlvl = 613;
	} else if(curMapLevel == 9){
		rlvl = 1226;
	} else if(curMapLevel == 8){
		rlvl = 2452;
	} else {
		rlvl = 613;
	}
	
	return rlvl;
}


// ajax ½ÃÀÛ -- ¸®½ºÆ® Å¬¸¯½Ã ÇØ´ç ÁÂÇ¥ÀÌµ¿
function goArea(xcode,ycode){
	var r = getRlvl();	
	var params = "xcode="+xcode+"&ycode="+ycode+"&r="+r;
	//alert(params);
	new ajax.xhr.Request("/go_area.jsp", params, getZone, 'get');

	// ¹Ý°æÀÌ ¾Æ´Ñ °æ°èÁÂÇ¥·Î °¡Á®¿À´Â API
	// http://localhost/jsonMainMap.action  ==> parameter : minX, minY, maxX, maxY
}


//ajax ½ÃÀÛ -- ¸®½ºÆ® Å¬¸¯½Ã ÇØ´ç ÁÂÇ¥ÀÌµ¿
function goAreaCount() {
	
	// ÇöÀç °æ°èÁÂÇ¥ ±¸ÇÏ±â
	curBound = mapObj.getBound();
	
	// ÇöÀç ¸Ê·¹º§ ±¸ÇÏ±â
	curMapLevel = mapObj.getZoomLevel();
	
	// °æ°èÁÂÇ¥°ª
	var minX = curBound[0];
	var minY = curBound[3];
	var maxX = curBound[2];
	var maxY = curBound[1];

	var selCity = parent.document.getElementById('city').value;
	//
	if( selCity != "" )
		var params = "selCity=" + selCity + "&currentLevel=" + curMapLevel + "&minX=" + minX + "&minY=" + minY + "&maxX=" + maxX + "&maxY=" + maxY;
	else
		var params = "currentLevel=" + curMapLevel + "&minX=" + minX + "&minY=" + minY + "&maxX=" + maxX + "&maxY=" + maxY;
    
    //alert('lang:'+ lang);

	// ÀÓ½Ã¿ë.
    if (lang == "eng") {
    	
    	new ajax.xhr.Request("/en/jsonLandMark.action", params, getZone, 'get');
    	
    } else {
    	
    	//¿©±â¼­ ¼±ÅÃµÈ µµ½Ã°ªÀ» ³Ñ°Ü¾ß ÇÔ
    	//alert( parent.document.getElementById('city').value );
    	//
    	//alert( jQuery("#city > option:selected").val() );    	
    	//alert( jQuery("#city option:selected").text() );    	 
    	//alert( jQuery('#city').val() );
    	
    	new ajax.xhr.Request("/jsonLandMark.action", params, getZone, 'get');
    
    }
    
}

// ajax ½ÃÀÛ -- ¸®½ºÆ® Å¬¸¯½Ã ÇØ´ç ÁÂÇ¥ÀÌµ¿
function goSearchAreaCount(){
	// ÇöÀç ¸í·É »óÅÂ
	curCmd = 1;
	
	// ÇöÀç ¸Ê·¹º§ ±¸ÇÏ±â
	curMapLevel = mapObj.getZoomLevel();
	
	// ÆÄ¶ó¹ÌÅÍ
    if(parent.jQuery('#key1').css("display") != 'none') {
        addParams = '&' + escape(encodeURIComponent('searchKeyWord'))+'='+escape(encodeURIComponent(parent.jQuery('#textfieldK').val()));
    } else {
    	addParams = '&' + escape(encodeURIComponent('city'))+'='+escape(encodeURIComponent(parent.document.getElementById('city').value));
    	addParams += '&' + escape(encodeURIComponent('district'))+'='+ escape(encodeURIComponent(parent.document.getElementById('district').value));
    	addParams += '&' + escape(encodeURIComponent('dong'))+'='+escape(encodeURIComponent(parent.document.getElementById('dong').value));
    	addParams += '&' + escape(encodeURIComponent('searchKeyWord'))+'='+encodeURIComponent(parent.jQuery('#textfieldA').val());
    	addParams += '&' + escape(encodeURIComponent('mopologyFlag'))+'='+encodeURIComponent(parent.jQuery('#mopologyFlag').val());
    }

	var params = 'curMapLevel=' + curMapLevel + addParams;
	//console.log(params);
	// È­¸éÁÂÃøÇÏ´Ü Á¸¸®½ºÆ®
	if (lang == "kor")
		new ajax.xhr.Request("/addressSearchList.action", params, getSearchZone, 'get');
	else
		new ajax.xhr.Request("/en/addressSearchList.action", params, getSearchZone, 'get');
}

function getSearchZone(req){
	if(req.readyState == 4){
		if(req.status==200){
			try {
				var result = eval("("+req.responseText+")");
				initSearchData(result.mapDataList);
					
			} catch(e) {
				alert(e);
			}
		}
	}

}

function getZone(req){
	
	var i = 0;
	var obj;
	var division = 0;

	// ¸¶Ä¿  ÃÊ±âÈ­
	if(curCmd == 0) {
		cMarker.init();
	}
	
	if(req.readyState == 4){
		
		if(req.status==200){
			
			try {
				
				var result = eval("("+req.responseText+")");

				for(var i=0; i < result.length ;i++){
					
					// 8·¹º§ ÀÌ»óÀÌ¸é »ó¼¼Á¤º¸ ·¹ÀÌ¾î, 8¹Ì¸¸ÀÌ¸é °³¼ö Ç¥Çö ·¹ÀÌ¾î
					if(curMapLevel > Constant.boundUpperLevel ) {
						
						obj = new cZoneInfo(result[i]);
						
						// ¸¶Ä¿ Á¤º¸¸¦ cMarker¿¡ set
						cMarker.setMarkerInfo(obj);
						
					} else {
						
						obj = new cZoneCountInfo(result[i]);

						// Á¸ °¹¼ö Á¤º¸¸¦ cMarker¿¡ set
						cMarker.setMarkerCountInfo(i, obj);
						
					}
					
					// Á¸ °¹¼ö ·¹ÀÌ¾î ³ëÃâ ½Ã¿¡´Â ¸ðÆú·ÎÁöÀÎ °ÍµéÀº ³ëÃâ ¾ÈÇÔ
					if(curMapLevel < Constant.boundUnderLevel && obj.mopology_code != Constant.normalMopology) {
						continue;
					}
					
					// ÀÏ¹Ý Á¤º¸ Ãâ·Â						
					setMark( obj );
				}

				// ¸ðÆú¸®Áö ÀÏ °æ¿ì ¸ðÆú¸®Áö¸¦ Ãâ·ÂÇÔ.(printMopology¿¡¼­ loop¸¦ µ¹±â¶§¹®¿¡ for¹Û¿¡ À§Ä¡ÇÔ)
				if(bMopologyStatus == true) {
					printMopology(curMopology);
				}					
					
			} catch(e) {
				
			}
		
		} else{
			alert("Àá½Ã ÈÄ ´Ù½Ã ½ÃµµÇØ ÁÖ¼¼¿ä.(Err : 0)");
		}
		
	} else {			

	}
	
}


function isMobileBrowser() {

    if ( DetectMobile(navigator.userAgent.toLowerCase()) ) {
        jQuery(jQuery('.area')[0]).html('¸ð¹ÙÀÏ Á¢¼Ó ÁßÀÔ´Ï´Ù');
        return true;
    }
    return false;
}

function DetectMobile(uagent) {

    var deviceWinMob = "windows ce";
    var deviceIphone = "iphone";
    var deviceIPad = "ipad";
    var deviceIpod = "ipod";
    var deviceAndroid = "android";
    var deviceS60 = "series60";
    var deviceSymbian = "symbian";
    var deviceBB = "blackberry";

    return (uagent.search(deviceWinMob) > -1) || (uagent.search(deviceIphone) > -1) ||
            (uagent.search(deviceAndroid) > -1) || (uagent.search(deviceIpod) > -1) ||
            (uagent.search(deviceS60) > -1) || (uagent.search(deviceSymbian) > -1) ||
            (uagent.search(deviceIPad) > -1) || (uagent.search(deviceBB) > -1) ;
}

var lang;
function go_eng(){
	location.replace("/en/index.action");
	lang = "eng";
}

function go_kor(){
	location.replace("/index.action");
	lang = "kor";
}

/**
 * ºê¶ó¿ìÀú Á¾·ù ¹× ¹öÀü ±¸ºÐ
 * @return
 */

function getUserAgent()
{
 var retAgent="UW";   // 
 var abbr="";
 
 // FireFox
 if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
  var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  abbr = "FF";
  if (ffversion>=3)
  retAgent = "FF03";
  else if (ffversion>=2)
  retAgent = "FF02";
  else if (ffversion>=1)
  retAgent = "FF01";
  else 
  retAgent = "FF00";  
 }
 
 // InternetExplorer
 else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
  var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  abbr = "IE";
  if (ieversion>=8)
  retAgent = "IE08";
  else if (ieversion>=7)
  retAgent = "IE07";
  else if (ieversion>=6)
  retAgent = "IE06";
  else if (ieversion>=5)
  retAgent = "IE04";
  else
  retAgent = "IE00";
 }
 
 //Opera
 else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
  var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  abbr = "OP";
  if (oprversion>=10)
  retAgent = "OP10";
  else if (oprversion>=9)
  retAgent = "OP09";
  else if (oprversion>=8)
  retAgent = "OP08";
  else if (oprversion>=7)
  retAgent = "OP07";
  else
  retAgent = "OP00";
 }
 
 //Safari
 else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Safari/x.x or Safari x.x (ignoring remaining decimal places);
  var sfrversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  abbr = "SF";
  if (sfrversion>=5)
  retAgent = "SF05";
  else if (sfrversion>=4)
  retAgent = "SF04";
  else if (sfrversion>=3)
  retAgent = "SF03";
  else if (sfrversion>=2)
  retAgent = "SF02";
  else
  retAgent = "SF00";
 }
 
 return retAgent + ',' + abbr;

}

/*
function userAgent() {
	var browserType = "";
	if (navigator.userAgent.indexOf("MSIE") !=-1) { // If user's browser is MSIE, return value is 70.
		browser = "IE";
		return browserType;
	}
	 
	if (navigator.userAgent.indexOf("Firefox") !=-1) {
		browser = "FF";
		return browserType;
	}
	 
	if (navigator.userAgent.indexOf("Mozilla") !=-1) {
		browser = "MZ";
		return browserType;
	}
	 
	if (navigator.userAgent.indexOf("Opera") !=-1) {
		browser = "OP";
		return browserType;
	}
	 
	if (navigator.userAgent.indexOf("Safari") !=-1) {
		browser = "SF";
		return browserType;
	}
	 
	if (navigator.userAgent.indexOf("Mac") !=-1) {
		browser = "MC";
		return browserType;
	}
	 
	browserType = "NG"; // Not Supported Browser
	return browserType;
}
*/

function getCutStr(str, max) {
	var p, len = 0;
	var retStr = '';
	for(p=0; p<str.length; p++) {
		(str.charCodeAt(p) > 255) ? len+=2 : len++;
		retStr += str.substr(p, 1);
		if (len >= max) {
			retStr += ' ...';
			break;
		}
	}
	return retStr;
}

function getStrByte(str) {
	var p, len = 0;
	for(p=0; p<str.length; p++) {
		(str.charCodeAt(p) > 255) ? len+=2 : len++;
	}
	return len;
}

function getStrSearchHangulComplete(str) {
	var retStr='', p, len = 0;
	if (str.charCodeAt(str.length - 1) > 255)
		retStr = str.substr(0, str.length-1);
	else retStr = str;
	//alert('retStr:' + retStr);
	return retStr;
}

function rebuildEvent(e)
{
	var ua = getUserAgent(); // return str : '{userAgent},{abbr}'
	var theEvent = e ? e : window.event;

	var event = new Object();
	// Get the right event object
	if (!e)
	{
		e = window.event;
	}
	
	// Store the event object
	event.event = e;
	
	// Store the type of the event
	event.type = e.type;
	
	// Store the target of the event
	if (e.target) 
	{
		event.target = e.target;
	}
	else if (e.srcElement)
	{
		event.target = e.srcElement;
	}
	if (event.target.nodeType == 3) // defeat Safari bug
	{
		event.target = event.target.parentNode;	
	}

	// Store the keycode of the event (if applicable)
	// Note that this might store the mouse button on a mouse event instead of being blank.
	if ('number' == typeof e.which)
	{
		event.keyCode = e.keyCode;
		event.charCode = e.which;
	}
	else if (e.keyCode)
	{
		event.keyCode = 0;
		event.charCode = e.keyCode;
	}
	if (event.charCode)
	{
		event.character = String.fromCharCode(event.charCode);
	}
	else
	{
		event.character = null;
	}
	
	// Store if any of alt, ctrl, shift or meta were pressed
	event.altKey = e.altKey;
	event.ctrlKey = e.ctrlKey;
	event.shiftKey = e.shiftKey;
	event.metaKey = e.metaKey || false;
	
	return event;
}

var maxStr = 22; // °Ë»ö¾î ÀÚµ¿¿Ï¼º½Ã ¸ñ·Ï¿¡ ³ªÅ¸³¯ ÇÑ±Û ÃÖ´ë±ÛÀÚ¼ö(ÃÖ´ëÆø)
function autocompletionK(e,searchType) {
	//var ua = getUserAgent(); // return str : '{userAgent},{abbr}'
	if (!e)
	{
		e = window.event;
	}
	// return e?e.which:e.keyCode;
	if ( (e?e.keyCode:e.which) == 13 )
		return true;
	jQuery(function(){
    	var cnt = getStrByte(jQuery('#textfieldK').val());
    	if ( cnt >= 4) {
    		if(searchType == "en") {
    			maxStr = 18;
    		}
            var html = '';
            var url = '/autoComplete.action';
            //jQuery.post(url,{'searchKeyword':encodeURIComponent( getStrSearchHangulComplete(jQuery('#textfieldK').val()) )},function(resultList){
            jQuery.post(url,{'searchKeyword':encodeURIComponent( jQuery('#textfieldK').val() ),'searchType':searchType},function(resultList){
            	//alert('rslt:'+resultList);
            	var keywords = resultList.split('@@');
            	var idx = 0;
            	for (idx in keywords) {
                    //html += '<li><span id="keywordsK' + idx + '" onclick="setSearchKeywordK(' + idx + ');">'+keywords[idx]+'</span></li>';
                    //html += '<li><span id="keywordsK' + idx + '" onclick="setSearchKeywordK(' + idx + ',""' +keywords[idx]+ '"");">'+keywords[idx]+'</span></li>';
                    //html += '<li><a href="" id="keywordsK0" onclick="setSearchKeywordK(0,\"¸í¤§\");return false;">¸í¤§</a></li>';
                    //html += '<li><a href="" id="keywordsK0" onclick="setSearchKeywordK(0,\'¸í¤§\');return false;">¸í¤§</a></li>';
                    html += '<li><a id="keywordsK' + idx + '" onclick="setSearchKeywordK(' + idx + ',\'' +keywords[idx]+ '\');return false;">' + getCutStr(keywords[idx], maxStr)+'</a></li>';
            	}
                jQuery('#searchListK').empty();
            	if (keywords.length == 1 && keywords[0] == '') {
            		jQuery('#searchListK').css({"display":"none"});
            	} else {
                    jQuery('#searchListK').css({"height":""+(14*keywords.length)+"px"});
//                    jQuery('#searchListK').css({'font':'12px µ¸¿ò, dotum, arial, serif, sans-serif', 'color':'#000000','line-height':'16px'});
                    jQuery('#searchListK').css({"display":"block"});
                    html = "<ul>"+html+"</ul>";                    
                    jQuery('#searchListK').html(html);
            	}
            });
    	} else { // ÀÚµ¿¿Ï¼º Á¶°ÇÀÌ ¾Æ´Ï¸é ³»¿ëÀ» »èÁ¦ÇÏ°í style:none Ã³¸®ÇÑ´Ù.
            jQuery('#searchListK').empty();
    		jQuery('#searchListK').css({"display":"none"});
    	}
    });
    return true;
}
function setSearchKeywordK(idx, str) { // ÀÏ¹Ý°Ë»ö¿ë
	//jQuery('#textfieldK').val(jQuery('#keywordsK'+idx).html());
	jQuery('#textfieldK').val(str);
    jQuery('#searchListK').css({"display":"none"});
    jQuery('#key1SearchBt').click();
	//document.getElementById('textfieldK').nodeValue = jQuery('#keywords'+idx).val();
}

function setSearchKeywordA(idx, str) {	// ÁÖ¼Ò°Ë»ö¿ë
	//jQuery('#textfieldA').val(jQuery('#keywordsA'+idx).html());
	jQuery('#textfieldA').val(str);	
    jQuery('#searchListA').css({"display":"none"});
    jQuery('#key2SearchBt').click();
	//document.getElementById('textfieldK').nodeValue = jQuery('#keywords'+idx).val();
}

function autocompletionA(e,searchType) {
	//var ua = getUserAgent(); // return str : '{userAgent},{abbr}'
	if (!e)
	{
		e = window.event;
	}
	// return e?e.which:e.keyCode;
	if ( (e?e.keyCode:e.which) == 13 )
		return true;

	jQuery(function(){
    	var cnt = getStrByte(jQuery('#textfieldA').val());
    	if ( cnt >= 4) {
    		if(searchType == "en") {
    			maxStr = 18;
    		}    		
            var html = '';
            var url = '/autoComplete.action';
            //jQuery.post(url,{'searchKeyword':encodeURIComponent( getStrSearchHangulComplete(jQuery('#textfieldA').val()) )},function(resultList){
            jQuery.post(url,{'searchKeyword':encodeURIComponent( jQuery('#textfieldA').val() ),'searchType':searchType},function(resultList){
            	//alert('rslt:'+resultList);
            	var keywords = resultList.split('@@');
            	for (idx in keywords) {
                    //html += '<li><span id="keywordsA' + idx + '" onclick="setSearchKeywordA(' + idx + ');">'+keywords[idx]+'</span></li>';
                    html += '<li><a id="keywordsA' + idx + '" onclick="setSearchKeywordA(' + idx + ',\'' +keywords[idx]+ '\');return false;">' + getCutStr(keywords[idx], maxStr)+'</a></li>';
            	}
                jQuery('#searchListA').empty();
            	if (keywords.length == 1 && keywords[0] == '') {
            		jQuery('#searchListA').css({"display":"none"});
            	} else {
                    jQuery('#searchListA').css({"height":""+(14*keywords.length)+"px"});
//                    jQuery('#searchListA').css({'font':'12px µ¸¿ò, dotum, arial, serif, sans-serif', 'color':'#000000','line-height':'16px'});
                    jQuery('#searchListA').css({"display":"block"});
                    html = "<ul>"+html+"</ul>";
                    jQuery('#searchListA').html(html);
            	}
            });
    	} else { // ÀÚµ¿¿Ï¼º Á¶°ÇÀÌ ¾Æ´Ï¸é ³»¿ëÀ» »èÁ¦ÇÏ°í style:none Ã³¸®ÇÑ´Ù.
            jQuery('#searchListA').empty();
    		jQuery('#searchListA').css({"display":"none"});
    	}
    });
    return true;
}

/* firefox hangul key-event trick 
var db = "";

function $(p) {
    return document.getElementById(p);
}

function sss() {
    $("bbb").innerHTML = $("bbb").innerHTML + "!";   
}



function trick() {

    if (db != $("aaa").value) {
        sss();
        db = $("aaa").value;
    } else {
    }
    setTimeout("trick()", 10);
}

<div id="bbb" style="border:1px solid red"></div>
<input type="text" id="aaa" name="aaa" onkeypress="trick()" />
*/
//}
// ¿À¸¥ÂÊ ¸¶¿ì½º ºñÈ°¼ºÈ­(IE)
document.oncontextmenu=new Function("return false"); 
document.onselectstart=new Function("return false");
document.ondragstart=new Function("return false");

