﻿try {
    document.execCommand('BackgroundImageCache', false, true);
} catch (e) { }


var $File = {

  download: function(Url) {
    // download handler 로 연결
  //IE 6.0 한글명깨짐 때문에 encodeURIComponent 추가
//  alert(Url);
//    alert(encodeURIComponent(Url));
    location.href = "/common/handler/downloadHandler.ashx?path=" + encodeURIComponent(Url);
  }
}

/********************************************************************************************************
팝업 수동 Open 정의
변수 정의 : pop - 파일명, width - 가로사이즈, height - 세로사이즈, flag - 0:스크롤없음, 1:스크롤있음
********************************************************************************************************/
function popfix(pop,tname,width,height,flag)
{
  var url = pop;
  var wd = width;
  var he = height;
  var tn = tname;

  if ((window.navigator.userAgent.indexOf("SV1") != -1) || (window.navigator.userAgent.indexOf("MSIE 7") != -1)) {
    wd = wd + 8;
    he = he + 10;

    if (flag == "0" )    {
      winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + wd + ",height=" + he + ";");
	  winObj.focus(); 	}
    else  {
      winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + wd + ",height=" + he + ";");
	  winObj.focus();  }
  }

  else {
  if (flag == "0" )    {
    winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + wd +",height=" + he + ";");
	winObj.focus();   }
  else  {
    winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + wd +",height=" + he + ";");
	winObj.focus();   }
  }
}

function popWeb(pop,tname,width,height,flag)
{
	var url = pop;
	var wd = width;
	var he = height;
	var tn = tname;

	if (flag == "0" ) {
		winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + wd +",height=" + he + ";");
		winObj.focus();
	}
	else {
		winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + wd +",height=" + he + ";");
		winObj.focus();
	}
}

/*********** 팝업창 오픈  **********/
function uf_popOpen(url,wname) {
	var positionX = 0;
	var positionY = 0;
	winStr = window.open(url,wname,"left="+positionX+",top="+positionY+",width=100,height=100,toolbar=no,scrollbars=no" );
	winStr.focus();
}

/****** 팝업창 자동 리사이즈 **************************************************************/
function uf_popResize() {

	var Station = {
        check : function (type, checkStr, checkPoint)
        {
            var name = "ETC";
            for ( var list in checkPoint )
            {
                if (checkStr.indexOf(list) != -1)
                {
                    name = checkPoint[list];
                }
            }
            escape("this." + type + " = function () { return name }") ;
            return name;
        },
        os : function ()
        {
            var checkStr = navigator.platform.toLowerCase();
            var checkPoint =
            {
                "win" : "WINDOW", "mac" : "MAC", "unix" : "UNIX",
                "linux" : "LINUX"
            }
            return this.check("os", checkStr, checkPoint );
        },
        browser : function ()
        {
            var checkStr = navigator.userAgent.toLowerCase();
            var checkPoint =
            {
                "msie 6" : "IE6" , "msie 7" : "IE7",
                "firefox" : "FF", "navigator" : "NETSCAPE",
                "opera" : "OPERA" , "msie 8" : "IE8"
            }
            return this.check("browser", checkStr, checkPoint);

        }
    } 	/*browser Check*/

	var thisX = document.getElementById("offsetTable").offsetWidth;
	var thisY = document.getElementById("offsetTable").offsetHeight;
	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;

	if (Station.browser() == "IE7") {
		var marginY = 78;
	}
	else if (Station.browser() == "IE6") {
		var marginY = 46;
	}
	else if (Station.browser() == "FF") {
		var marginY = 88;
	}
		else if (Station.browser() == "IE8") {
		var marginY = 78;
	}
	else  {
		var marginY = 78;
	}

	if (thisX > maxThisX) {
		window.document.body.scroll = "yes";
		thisX = maxThisX;
	}
	if (thisY > maxThisY - marginY) {
		window.document.body.scroll = "yes";
		thisX += 19;
		thisY = maxThisY - marginY;
	}

	var windowX = (screen.width - (thisX+10))/2;
	var windowY = (screen.height - (thisY+marginY))/2 - 20;
	//window.moveTo(windowX,windowY);
		if (Station.browser() == "IE6") {
		window.resizeTo(thisX+18,thisY+marginY);
	}
	else {
		window.resizeTo(thisX+11,thisY+marginY);
	}


}

function menu_open(str) {
    if (str == "true") {
        document.getElementById("flash_gnb").height = "460";
    } else {
        document.getElementById("flash_gnb").height = "104";
    }
}

function setPng24(obj) {
    obj.width = obj.height = 1;
    obj.className = obj.className.replace(/\bpng24\b/i, '');
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');"
    obj.src = '';
    return '';
}


function goSite() {
    if (document.getElementById("ulf").style.display == "none") {
        document.getElementById("ulf").style.display = "block"
    } else {
        document.getElementById("ulf").style.display = "none";
    }
}


function doSNS(btn, curl) {
	var longUrl = escape("http://lyricsbird.net/");
	var reurl = "";
	var option = "toolbar=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes";
	var shortener = "http://udanax.org/";
	var targetWin = window.open('', 'sharer', option);
	$.ajax({
	  type: 'GET',
	  url: shortener + "shorturl.jsp?mode=api&longurl=" + curl + "&jsoncallback=?",
	  dataType: 'json',
	  timeout: 6000,
	  success: function(data, status) {
	    reurl = shortener + data.shorturl;
	    if (btn == "retweet") {
	      //window.open('http://twitter.com/home?status=Visit Kia Motors corporate web site ' + reurl, 'sharer', option)
	      window.open('http://twitter.com/intent/tweet?url=' + reurl + '&text=Visit Kia Motors corporate web site', 'sharer', option);
	      targetWin.location.href = 'http://twitter.com/intent/tweet?url=' + reurl + '&text=Visit Kia Motors corporate web site';
	    } else if (btn == "share") {
	      //window.open('http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=' + reurl, 'sharer', option+',width=626,height=436');
	      window.open('http://www.facebook.com/share.php?u=' + reurl, 'sharer', option + ',width=626,height=436');
	      targetWin.location.href = 'http://www.facebook.com/share.php?u=' + reurl;
	    }
	  },
	  error: function(request, status, error) {
	    alert("Error status : " + status);
	  }
	});
}


function eventPopup(gubun,url) {
	if(gubun=="pop"){
	    window.open(url, "event", "scrollbars=yes,resizable=yes,left=0,top=0");
	}else{
		var openNewWindow = window.open("about:blank");
		openNewWindow.location.href = url
	}
}


/* 외부 JS include */
document.write(' <script type="text/javascript" src="/common/js/fakeselect.js"></script> ');


/*20110225 VR갤러리추가*/
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tabbtn")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;

			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_over.jpg", ".jpg");
				} else {
					currentmenu.className = currentmenu.className.replace(" over", "");
				}
			}
			this.targetEl.style.display = "";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".jpg", "_over.jpg");
			} else {
				this.className += " over";
			}
			this.container.current = this;

			return false;
		};

		/*if (!thismenu.container.first)
			thismenu.container.first = thismenu;*/
	}
	/*if (tabContainer.first)
		tabContainer.first.onclick();*/
}

function footerExt() {
    var obj = document.getElementById("hid_area");
    var clic = document.getElementById("ico_plus");

    if (obj.style.display == "" || obj.style.display == "none") {
        obj.style.display = "block";
        clic.className = "ico_plus on";
    } else {
        obj.style.display = "none";
        clic.className = "ico_plus";
    }
}

function viewSearchInput() {
	document.getElementById("searchBox").style.display = "block";
}

function FlashChk(){
    var UserAgent = navigator.userAgent;

    if (UserAgent.match(/iPhone|iPod/) != null || UserAgent.match(/LG|SAMSUNG|Samsung/) != null) {
        alert("플래시가 지원되지 않는 기종으로 접속하셔서 모바일 사이트로 이동됩니다.");

        var currentLocation = location.pathname;
        var tempArray = currentLocation.split("/");

        // 차량 페이지일 경우
        if (tempArray[1].toLowerCase() == "vehicles") {
            switch (tempArray[2].toLowerCase()) {
                case "morning":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KAB"; break;
                case "K5":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KDH"; break;
                case "K7":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KEF"; break;
                case "sportage-r":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KFH"; break;
                case "sorento-r":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KFG"; break;
                case "soul":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KIA"; break;
                case "forte":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KCH"; break;
                case "forte-koup":
                    location.href = "http://m.kia.co.kr/kmb/action.do?fw_txMode=N&fw_appName=MB_KUTI&fw_serviceName=MbNcarCtyFacade.selectMbNcarCtyMst&ncarVehlCd=KCI"; break;
                default:
                    location.href = "http://m.kia.co.kr/"; break;
            }
        } else {
            location.href = "http://m.kia.co.kr/";
        }
    }
}

FlashChk();

