﻿    function request(str)
    {
        var rtnval = -1;
        var nowAddress = unescape(location.href);
        var parameters = (nowAddress.slice(nowAddress.indexOf('?') + 1, nowAddress.length)).split('&');

        for (var i = 0; i < parameters.length; i++)
        {
            var varName = parameters[i].split('=')[0];

            if (varName.toUpperCase() == str.toUpperCase())
            {
                  rtnval =parameters[i].split('=')[1];
                  break;
            }
          }
          return rtnval;
    }

    function setswapImage()
    {
        // Create ImageRoller Start
        if (!$.ImageRoller)
        {
            $.ImageRoller = function()
            {
                var _items = $("div.s_photo>ul>li");
                var _viewer = $("div.b_photo");
                var _index = 0;
                var _timer = null;
                var _rolling = true;

                //Handler Object
                var _handler =
                {
                    //Select Item Function
                    selectItem : function(idx)
                    {
                        if (idx >= 0 && idx < _items.length) _index = idx;
                        else return;

                        var item = _items.removeClass("on").filter(":eq("+_index+")").addClass("on");
                        var src = item.children("img:first").attr("src").replace("Thumb_", "");

                        _viewer.children("img:first-child").attr("src", src);

                        _handler.startTimer();
                    },
                    //Select Previous Item Function
                    prevItem : function()
                    {
                        var idx = _index - 1;
                        if (idx < 0) idx = _items.length - 1;

                        _handler.selectItem(idx);
                    },
                    //Select Next Item Function
                    nextItem : function()
                    {
                        var idx = _index + 1;
                        if (idx >= _items.length) idx = 0;

                        _handler.selectItem(idx);
                    },
                    //Start Rolling Timer Function
                    startTimer : function()
                    {
                        clearTimeout(_timer);
                        if (_rolling) _timer = setTimeout(_handler.nextItem, 5000);
                    },
                    //Stop Rolling Timer Function
                    stopTimer : function()
                    {
                        clearTimeout(_timer);
                    }
                };

                //Set Item Event
                _items.each(function(i) {
                    $(this).bind("click", function() {
                        _rolling = false;
                        _handler.selectItem(i);
                    });
                });

                //Set Viewer Event
                _viewer.hover(_handler.stopTimer, _handler.startTimer);

                return _handler;
            }();
        }
        //Create ImageRoller End

        //Select First Item
        $.ImageRoller.selectItem(0);

        /*
        $('div.s_photo>ul').filter(':first').children().each(function(){

            $(this).bind('click', function(event) {
                removeOnClass();
                $(this).addClass('on');
                $('div.b_photo>img').filter(':first-child').attr('src', $(this).children().filter('img:first').attr('src').replace("Thumb_", ""));

            });
        });
        */
    }

    function removeOnClass()
    {
        $('div.s_photo>ul').filter(':first').children().each(function(){
            $(this).removeClass('on');
        });

        $('#mapImg1').removeClass('on');

    }

    function AddBookMark(title)
    {
        if($.browser.msie)
        {
            window.external.AddFavorite(location.href,title);
        }
        else if($.browser.opera){ // opera
            var elem = document.createElement('a');
            elem.setAttribute('href',location.href);
            elem.setAttribute('title',title);
            elem.setAttribute('rel','sidebar');
            elem.click();
        }
        else
        {
            window.sidebar.addPanel(title,location.href, "");
        }
    }

    function getCookie( cookieName )
    {
        var search = cookieName + "=";
        var cookie = document.cookie;

        if( cookie.length > 0 )// 현재 쿠키가 존재할 경우
        {
            startIndex = cookie.indexOf( cookieName ); // 해당 쿠키명이 존재하는지 검색한 후 존재하면 위치를 리턴.
            if( startIndex != -1 )// 만약 존재한다면
            {
                startIndex += cookieName.length; // 값을 얻어내기 위해 시작 인덱스 조절
                endIndex = cookie.indexOf( ";", startIndex );// 값을 얻어내기 위해 종료 인덱스 추출
                if( endIndex == -1) endIndex = cookie.length; // 만약 종료 인덱스를 못찾게 되면 쿠키 전체길이로 설정
                return unescape( cookie.substring( startIndex + 1, endIndex ) );// 쿠키값을 추출하여 리턴
            }
            else
            {
                return false;// 쿠키 내에 해당 쿠키가 존재하지 않을 경우
            }
        }
    }


    function setCookie(nation)//(name, value, expiredays)
    {
        //var now = new Date();
        //var expires = new Date(now.getFullYear(),now.getMonth(),now.getDate()+expiredays);
        //document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + expires.toGMTString() + ";"
        document.cookie = "strLocale=" + escape( nation )+ "; path=/";
    }

    function ChangeLanguage(lan , loc)
    {
        //document.cookie='strLocale=' + escape( nation )+ "; path=/";
        //location.href= loc;

        location.href='/include/SetLocale.asp?locale=' + lan + '&url=' + escape(loc);

    }

    function Open_PopPartner(w, h)
    {
        var t = parseInt(screen.height/2, 10) - parseInt(h/2, 10);
        var l = parseInt(screen.width/2, 10) - parseInt(w/2, 10)
        var url = '/popup/' + getCookie('strLocale') + '/Gr4_Partnership.html';
        //alert(url);

        window.open(url, "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+w+"px,height="+h+"px, top=" + t +"px, left=" + l + "px").focus();

    }

    function Open_PopDesInfo(w, h)
    {
        var t = parseInt(screen.height/2, 10) - parseInt(h/2, 10);
        var l = parseInt(screen.width/2, 10) - parseInt(w/2, 10)
        var url = '/popup/' + getCookie('strLocale') + '/Gr4.2.html';
        //alert(url);

        window.open(url, "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+w+"px,height="+h+"px, top=" + t +"px, left=" + l + "px").focus();

    }


    function setSelImage()
    {
        $('div.room_sort>ul>li').each(function(index){

            $(this).bind('click', function(event) {
                removeOnSelClass();
                $(this).addClass('on');
                div_display(index);
            });
        });
    }

    function div_display(index)
    {
        $('div.room_detail').css('display','none');
        $('div.room_detail:eq(' + index + ')').css('display','block');
    }

    function removeOnSelClass()
    {
        $('div.room_sort>ul>li').each(function(){
            $(this).removeClass('on');
        });
    }

    // popup
    function PopupOpen(strUrl,strWindowName,strWidth,strHeight,scroll)
    {
        if(scroll) strWidth= strWidth+17;
        var winl = (screen.width-strWidth)/2;
        var wint = (screen.height-strHeight)/2;
        var strWindowFeatures = "width="+strWidth+",height="+strHeight+",top="+wint+",left="+winl+",scrollbars="+scroll;
        var strWindowPopup = window.open(strUrl,strWindowName,strWindowFeatures);
     }

    //숫자 체크
    function fnDown()
    {

        if (!ibNumberKeyCodeCheck(event.keyCode))
            {
                if (event.keyCode != 8 && event.keyCode != 13 && !(event.keyCode >= 35 && event.keyCode <= 40) && event.keyCode != 46)
                {
                    alert('<%=error_ment_number%>');
                    event.returnValue = false;
                }
            }
            else if (event.keyCode == 189)
            {
                alert('<%=error_ment_number%>');
                event.returnValue = false;
            }
    }

    function ibNumberKeyCodeCheck(keyCode)
    {
        return ((keyCode >= 48 && keyCode <= 57) || (keyCode == 46) || (keyCode >= 96 && keyCode <= 105) || (keyCode == 8) || (keyCode == 9) || (keyCode == 13) || (keyCode >= 35 && keyCode <= 40) || (keyCode == 189) || (keyCode == 188) || (keyCode == 109))
    }

    /**
     * 해당 년월의 마지막 일을 리턴
     *
     * @param {Number} [year]  년
     * @param {Number} [month] 월
     */
    function getLastDate(year, month)
    {
        var dt = new Date(year, month, 1)
        dt.setDate(0);
        return dt.getDate();
    }

    /**
     * 키 이벤트 검증
     *
     * @param {Object} [e] 이벤트 객체
     * @param {String} [p] 허용문자
     * @param {String} [m] 에러메세지
     */
    function validateKeyEvent(e, p, m)
    {
        var evt = window.event || e;
        var ele = evt.srcElement || evt.target;

        if (new RegExp("^["+p+"]*$").test(ele.value) == false)
        {
            //ele.value = ele.value.replace(new RegExp("[^"+p+"]", "g"), "");
            ele.value = '';
            if (m) alert(m);
        }
    }

    //셀렉트 박스 날짜 변경
    function changeDate(prefix)
    {
        prefix = "#cmb" + prefix;

        var y = $(prefix+"Year").val();
        var m = $(prefix+"Month").val();
        if (y == "" || m == "") return;

        var tmp = $(prefix+"Day>option:eq(0)").clone();
        $(prefix+"Day").empty();
        $(prefix+"Day").append(tmp);

        var d = getLastDate(y, m);
        for (var i = 1; i <= d; i++)
        {
            var val = (i >= 10) ? ""+i : "0"+i;
            $(prefix+"Day").append($("<option>").val(val).text(i));
        }
    }


	// 영문만 가능
	function checkEnglish(theValue) 
	{
		var v = theValue.replace(/(^\s*)|(\s*$)/g, "");
		var v1 = "_-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		var alphaNum = v1;

		for (var i=0; i<v.length; i++) 
		{
			if (alphaNum.indexOf(v.substring(i, i+1)) < 0) return false;
		}
		return true;
	}


	// 영문+숫자만 가능
	function checkEnglishNumber(theValue) 
	{
		theValue = theValue.replace(/(^\s*)|(\s*$)/g, "");
		var valid1 = "_-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		var valid2 = "0123456789";
		var alphaNum;
		alphaNum = valid1 + valid2;
		for (var i=0; i<theValue.length; i++) 
		{
			if (alphaNum.indexOf(theValue.substring(i, i+1)) < 0) return false;
		}
		return true;
	}

	// 숫자만
	function checkNumber(theValue) 
	{
		theValue = theValue.replace(/(^\s*)|(\s*$)/g, "");
		var valid2 = "0123456789 ";
		var alphaNum;
		alphaNum = valid2;
		for (var i=0; i<theValue.length; i++) 
		{
			if (alphaNum.indexOf(theValue.substring(i, i+1)) < 0) return false;
		}
		return true;
	}

	// 숫자만
	function checkNumber2(theValue) 
	{
		theValue = theValue.replace(/(^\s*)|(\s*$)/g, "");
		var valid2 = "0123456789";
		var alphaNum;
		alphaNum = valid2;
		for (var i=0; i<theValue.length; i++) 
		{
			if (alphaNum.indexOf(theValue.substring(i, i+1)) < 0) return false;
		}
		return true;
	}

	// 숫자만 + 기호
	function checkNumberChar(theValue) 
	{
		theValue = theValue.replace(/(^\s*)|(\s*$)/g, "");
		var valid2 = "0123456789-+ ";
		var alphaNum;
		alphaNum = valid2;
		for (var i=0; i<theValue.length; i++) 
		{
			if (alphaNum.indexOf(theValue.substring(i, i+1)) < 0) return false;
		}
		return true;
	}