var $j = jQuery.noConflict();

/* userfile download link */
function goUserFileDown(loc, path, f)
{
	var data;

	if(f == null) return;
	if(f == "") return;

	path = loc + "/" + path;
//	f = encodeURIComponent(f);
	
	url = _ATLAN_USERFILE_ATT_URL + "?path="+path+"&file="+f;
	
	$j('#fm_frmDownLoad').attr('src', url);
}

/* userfile download ajax */
jQuery.download = function(url, data, method){
    // url과 data를 입력받음
    if( url && data ){
        // data 는  string 또는 array/object 를 파라미터로 받는다.
        data = typeof data == 'string' ? data : jQuery.param(data);
        // 파라미터를 form의  input으로 만든다.
        var inputs = '';
        jQuery.each(data.split('&'), function(){
            var pair = this.split('=');
            inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />';
        });
        // request를 보낸다.
        jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
        .appendTo('body').submit().remove();
    };
};

//공백인지체크
function isSpace(inChar)
{
	return (inChar == ' ' || inChar == '\t' || inChar == '\n');
}

//공백제거
function trim(tmpStr)
{
	var _tmpStr, atChar;

	if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
	while (isSpace(atChar))
	{
		tmpStr = tmpStr.substring(1, tmpStr.length);
		atChar = tmpStr.charAt(0);
	}
	if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length - 1);
	while (isSpace(atChar))
	{
		tmpStr = tmpStr.substring(0, (tmpStr.length - 1));
		atChar = tmpStr.charAt(tmpStr.length - 1);
	}
	return tmpStr;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

//numeric
function isNumber(str)
{
	var strTemp;
	for (var i=0;i<str.length;i++)
	{
		strTemp = str.charAt(i);
		if ( strTemp < "0" || strTemp > "9" )
			return(false);
	}
	if (str.length == 0)
	{
		return(false);
	}
	return(true);
}

function checkByteNextObj(obj, len,  nObj)
{
	if(obj.value.length == len)
		nObj.focus();
}

function printSWF(swf_name, w, h)
{
	var _SWF = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "
		+ " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" "
		+ " width=\""+ w +"\" height=\""+ h +"\" ><param name=\"movie\" value=\"http://img.atlan.co.kr/_www/swf/"+ swf_name +"\"> "
		+ " <param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"> "
		+ " <param name=\"allowScriptAccess\" value=\"always\"> "
		+ " <embed src=\"http://img.atlan.co.kr/_www/swf/"+ swf_name +"\" quality=\"high\" wmode=\"transparent\" "
		+ " pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" "
		+ " allowScriptAccess=\"always\" width=\""+ w +"\" height=\""+ h +"\"> "
		+ " </embed></object>";
	document.write(_SWF);
}

function printSWF_wizPC(swf_name, w, h)
{
	var _SWF = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "
		+ " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" "
		+ " width=\""+ w +"\" height=\""+ h +"\" ><param name=\"movie\" value=\"http://aumapp.atlan.co.kr/wizpc/"+ swf_name +"\"> "
		+ " <param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"> "
		+ " <param name=\"allowScriptAccess\" value=\"always\"> "
		+ " <embed src=\"http://aumapp.atlan.co.kr/wizpc/"+ swf_name +"\" quality=\"high\" wmode=\"transparent\" "
		+ " pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" "
		+ " allowScriptAccess=\"always\" width=\""+ w +"\" height=\""+ h +"\"> "
		+ " </embed></object>";
	document.write(_SWF);
}

function img_on(imgObj)
{
	var src = $j(imgObj).attr('src');
	var srcArray = src.split(".");
	var str = src.replace(srcArray[srcArray.length - 2] ,srcArray[srcArray.length - 2] + "_on" );
	$j(imgObj).attr({src:str});
}
function img_off(imgObj)
{
	var src = $j(imgObj).attr('src');
	var str = src.replace("_on." ,"." );
	$j(imgObj).attr({src:str});
}

function openErrorReport(obj) {
	var url = obj.href;

	if (window.screen.height <= 800) {
		window.open(url, "winErrorReport", "left=0, top=0, toolbar=no, location=0, directories=no, status=0, menubar=no, scrollbars=no, resizable=1, titlebar=0, fullscreen=1, width=1024, height=800");
	} else {
		window.open(url, "winErrorReport", "left=0, top=0, toolbar=no, location=0, directories=no, status=0, menubar=no, scrollbars=no, resizable=1, titlebar=0, fullscreen=0, width=1024, height=820");
	}

	return false;
}

function authMustAumQuickView()
{
	var ans = confirm("원클릭 지도 업데이트를 하기 위해서는\n먼저 로그인을 하신 후 제품 인증을 하셔야 합니다.\n[확인] 버튼을 누르시면 로그인 화면으로 이동합니다.");
	if (ans)
	{
		return true;
	}else {
		return false;
	}
}

/*LOG corp javascript redirection code v1.1*/
function RedirectingSmartphone() {
           this.targetURL = "http://m.atlan.co.kr/"; /*스마트폰일 경우 이동할 URL을 입력해 주세요*/
           this.trgFrm = ( function() {
                     try {
                                if (top.document) {
                                          return top;
                                }
                     } catch (e) {
                                try {
                                          if (parent.document) {
                                                     return parent;
                                          }
                                } catch (e) {
                                          return window;
                                }
                     }
                     ;
                     return window;
           })();
           this.ref = this.trgFrm.document.referrer;
           this.QueryString = this.trgFrm.location.search.substring(1);
           this.param = [];
           this.setCookie = function(name, value) {
                     document.cookie = name + "=" + escape(value) + ";path=/;" + "domain="
                                          + document.location.host.replace("www.", ".") + ";";
           };
           this.getCookie = function(s) {
                     var C = document.cookie.split("; ");
                     for ( var i = 0; i < C.length; i++) {
                                var Cp = C[i].split("=");
                                if (s == Cp[0]) {
                                          return unescape(Cp[1]);
                                }
                     }
                     ;
                     return null;
           };
           this.init = function() {
                     if (this.getCookie("vli_kepc") == "y") {
                                return;
                     }
                     if (this.QueryString.length > 0) {
                                var arr = this.QueryString.split("&");
                                this.param = this.param.concat(arr);
                                if (this.QueryString.indexOf("vli_kepc") != -1) {
                                          this.setCookie("vli_kepc", "y");
                                          return;
                                }
                     }
 
                     if (( function() {
                                var ua = navigator.userAgent.toLowerCase();
                                var p = new RegExp(
                                                     "alcatel|audiovox|au-mic|avantgo|bolt|blackberry|blazer|cldc-|danger|dopod|epoc|ericsson|Google Wireless Transcoder|htc|huawei|iemobile|ipad|iphone|ipod|android|bada|j2me|lg|midp|mobile|mot|moto|motorola|nec-|netfront|nitro|nokia|novarra-vision|opera mini|palm|palmsource|panasonic|philips|pocketpc|portalmmm|rover|sagem|samsung|sanyo|sec|series60|sharp|sie-|smartphone|sony|symbian|t-mobile|untrusted|up.browser|up.link|vodafone/|wap1.|wap2.|windows ce");
                                return p.test(ua) ? true : false;
                     })() == false) {
                                return
                     }
                     ;
                     var goURL = (this.param.length > 0) ? this.targetURL
                                          + ((this.targetURL.indexOf("?") != -1) ? "&" : "?")
                                          + this.param.join("&") : this.targetURL;
                     if (this.ref.length > 0) {
                                goURL = (goURL.indexOf("?") != -1) ? goURL + "&OV_REFFER="
                                                     + encodeURIComponent(this.ref) : goURL + "?OV_REFFER="
                                                     + encodeURIComponent(this.ref);
                     }
                     top.location.replace(goURL);
           }
}
(new RedirectingSmartphone()).init();
