﻿// JScript File
function MM_openBrWindow(theURL,winName,features) { //v2.0
  var Wins = window.open(theURL,winName,features);
  Wins.focus();
}
function MM_nbGroup(event, grpName) { //v6.0
    var i, img, nbArr, args = MM_nbGroup.arguments;
    if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
            img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
            if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
            nbArr[nbArr.length] = img;
            for (i = 4; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
                if (!img.MM_up) img.MM_up = img.src;
                img.src = img.MM_dn = args[i + 1];
                nbArr[nbArr.length] = img;
            } 
        }
    } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i = 1; i < args.length - 1; i += 3) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = (img.MM_dn && args[i + 2]) ? args[i + 2] : ((args[i + 1]) ? args[i + 1] : img.MM_up);
            nbArr[nbArr.length] = img;
        }
    } else if (event == "out") {
        if (document.MM_nbOver != null && document.MM_nbOver != undefined) {
            for (i = 0; i < document.MM_nbOver.length; i++) {
                img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up;
            }
        }
    } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr)
            for (i = 0; i < nbArr.length; i++) { img = nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i = 2; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = img.MM_dn = (args[i + 1]) ? args[i + 1] : img.MM_up;
            nbArr[nbArr.length] = img;
        } 
    }
}

function getObj(objID) {
    if (document.getElementById){return document.getElementById(objID);}
    else if (document.all){return document.all[objID];}
    else if (document.layers){return document.layers[objID];}
}

function Stop_Wait()
{
    var oframe = getObj("waitFrame");
    if(null != oframe) oframe.style.display = 'none';
    var odiv = getObj("waitDiv");
    if(null != odiv) odiv.style.display = 'none';
}

function Start_Wait()
{
    var oframe = getObj("waitFrame");
    if(null != oframe)
    {
        //oframe.style.top = (document.body.scrollTop) + 'px';
        oframe.style.display = 'block';
    }
    
    var odiv = getObj("waitDiv");
    if(null != odiv)
    {
        //odiv.style.top = (document.body.scrollTop + (document.body.clientHeight/2)) + 'px';
        //odiv.style.left = ((document.body.clientWidth-630)/2) + 'px';
        //alert('clientwidth:'+document.body.clientWidth);
        //alert(document.body.scrollTop + ',' + document.body.clientHeight);
        //odiv.style.top = '350px'
        odiv.style.display = 'block';
    }
}

function height_window(){ 
    if(window.innerHeight) 
        return window.innerHeight; 
    if(document.body.clientHeight) 
        return document.body.clientHeight; 
    return (null); 
} 

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
	    input.form[(getIndex(input)+1) % input.form.length].focus();
    }
}


function containsElement(arr, ele) {
	var found = false, index = 0;
    while(!found && index < arr.length) {
        if(arr[index] == ele)
            found = true; 
        else 
            index++;
	}
    return found;
}   
    
function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1) {
        if (input.form[i] == input)
			index = i;
		else
			i++;
	}
	return index;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var Wins = window.open(theURL,winName,features);
  Wins.focus();
}

function Ucase(txt1)
{
    txt1.value = txt1.value.toUpperCase();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ObjSwf(src,width,height){
    object = '';
    object += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="param" width="'+width+'" height="'+height+'">';
    object += '<param name="movie" value="'+src+'">';
    object += '<embed src="'+src+'" quality="high" wmode="transparent" bgcolor="#ffffff" menu="false" width="'+width+'" height="'+height+'" swliveconnect="true" id="param" name="param" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
    object += '<\/object>';
    document.write(object);
}
function ObjSwfStr(src,width,height){
    object = '';
    object += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="param" width="'+width+'" height="'+height+'">';
    object += '<param name="movie" value="'+src+'">';
    object += '<embed src="'+src+'" quality="high" wmode="transparent" bgcolor="#ffffff" menu="false" width="'+width+'" height="'+height+'" swliveconnect="true" id="param" name="param" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
    object += '<\/object>';
    return object;
}

function getCookie(name) { 
  var Found = false 
  var start, end 
  var i = 0 
 
  while(i <= document.cookie.length) { 
    start = i 
    end = start + name.length 
 
    if(document.cookie.substring(start, end) == name) { 
      Found = true 
      break 
    } 
    i++ 
  } 
 
  if(Found == true) { 
    start = end + 1 
    end = document.cookie.indexOf(";", start) 
      if(end < start) 
        end = document.cookie.length 
    return document.cookie.substring(start, end) 
  } 
  return "" 
} 

function setCookie( name, value, expiredays ) 
{ 
  var todayDate = new Date(); 
  todayDate.setDate( todayDate.getDate() + expiredays ); 
  document.cookie = name + "=" + escape( value ) + "; path=/; expires=" +     todayDate.toGMTString() + ";" 
} 

function setHeightData(height)
{
    //window.clipboardData.setData("Text","height|" + height);
}

function Stop_Wait_Mini()
{
    var odiv = getObj("dv_loding");
    if(null != odiv) odiv.style.display = 'none';
}

function Start_Wait_Mini()
{
    var odiv = getObj("dv_loding");
    if(null != odiv)
    {
        odiv.style.display = 'block';
    }
}

function Start_Wait_MiniMsg(sMsg)
{
    var ospan = getObj("spLoadingMsg");
    if(null != ospan)
    {
        ospan.innerText = sMsg;
    }

    Start_Wait_Mini();
}

function callGoodHotelDetailBest(sHTLID) {
    var aid = parent.document.getElementById("aid").value;
    parent.location.href = "/booking/goodhotel_detail.aspx?HTLID=" + sHTLID + "&aid=" + aid;
}

function callGoodHotelDetailCity(sHTLID) {
    var aid = parent.parent.document.getElementById("aid").value;
    parent.parent.location.href = "/booking/goodhotel_detail.aspx?HTLID=" + sHTLID + "&aid=" + aid;
}

function viewHotelDetail(sHTLID) {
    var aid = parent.parent.document.getElementById("aid").value;
    location.href = "/booking/goodhotel_detail.aspx?HTLID=" + sHTLID + "&aid=" + aid;
}
function viewHotelDetail2(sHTLID) {
    var aid = document.getElementById("aid").value;
    location.href = "/booking/goodhotel_detail.aspx?HTLID=" + sHTLID + "&aid=" + aid;
}
//function setHeightClipboard()
//{
//    try{
//        window.clipboardData.setData("Text","height|" + document.body.scrollHeight)
//    }
//    catch(e)
//    {
//    }
//}

function setHeightClipboard(height)
{
    try{
        window.clipboardData.setData("Text","height|" + height)
    }
    catch(e)
    {
    }
}

function setHeight2Parent(height)
{
    try{
        var sParm = "if_height=" + height;
        //alert("call:" + sParm);
        var sBaseUrl = "http://www.bomultour.com/hotel/";
        //sBaseUrl = "http://cyanip.mine.nu/test/";
        //sBaseUrl = "http://www.shinhantour.co.kr/";

        var sCallPage = "set_height.asp?";
        
        document.getElementById('fraConnParent').src = sBaseUrl + sCallPage + sParm;
    }
    catch(err)
    {
        //alert("setFrameHeight call 오류");
    }
}

var timeset;
var timeset2;

function setHeight2ParentURL(sBaseUrl, height)
{
    if (sBaseUrl == "") return;

    try
    {
        var sParm = "if_height=" + height;

		var sCallPage = "set_height.asp?"; 
		if( sBaseUrl == "http://www.santatour.com/hotel/")
		    sCallPage = "set_height.php?";
		if (sBaseUrl == "http://www.verygoodtour.com/_include/outside/")
		    sCallPage = "onion_iframesize.aspx?";

        document.getElementById('fraConnParent').src = sBaseUrl + sCallPage + sParm;
        //alert("called:" + sBaseUrl + sCallPage + sParm);

        if (sBaseUrl.substring(0, 7) == "http://" && sBaseUrl.substring(0, 11) != "http://www.") {

            //BookingM modetour.bookingm call
            if (sBaseUrl.indexOf("bookingm.com") > 0) {
                if (sBaseUrl.indexOf("http://bookingm.com") == 0) {

                    sBaseUrl2 = sBaseUrl.replace("http://", "http://www.");
                    callFunc = "setHeight2ParentURL2('" + sBaseUrl2 + "'," + height + ")";
                    timeset = setTimeout(callFunc, 500);

                    sBaseUrl2 = sBaseUrl.replace("http://", "http://modetour.");
                    callFunc = "setHeight2ParentURL2('" + sBaseUrl2 + "'," + height + ")";
                    timeset2 = setTimeout(callFunc, 1000);
                }
            }
            else {

                sBaseUrl2 = sBaseUrl.replace("http://", "http://www.");

                //setHeight2ParentURL(sBaseUrl2, height);
                callFunc = "setHeight2ParentURL2('" + sBaseUrl2 + "'," + height + ")";
                timeset = setTimeout(callFunc, 1000);
                //alert("called:" + callFunc);
            }
        }
    }
    catch(err)
    {
        //alert("setFrameHeight call 오류");
    }
}
function setHeight2ParentURL2(sBaseUrl, height) {
    if (sBaseUrl == "") return;

    //alert(sBaseUrl);

    try {
        if (height == "0") {
            height = document.documentElement.scrollHeight; // ="700"; // 3930
    }

    var sParm = "if_height=" + height;

    var sCallPage = "set_height.asp?";
    if (sBaseUrl == "http://www.bieair.co.kr/home/bieair/")
        sCallPage = "set_height.php?";
    else if (sBaseUrl == "http://unitedtravel.co.kr"||sBaseUrl == "http://www.unitedtravel.co.kr"){
        sCallPage = "/08_hotel/set_height.htm?";
		}
    else if (sBaseUrl == "http://sephyrus.hosting.paran.com/")
        sCallPage = "set_height.php?";
    else if (sBaseUrl == "http://www.verygoodtour.com" || sBaseUrl == "http://www.verygoodtour.co.kr" || sBaseUrl == "http://verygoodtour.co.kr" || sBaseUrl == "http://verygoodtour.com") {
        sCallPage = "/_include/outside/onion_iframesize.aspx?";

    }

    else if (sBaseUrl == "http://www.worldairtour.com" || sBaseUrl == "http://worldairtour.com") {
        sCallPage = "/hotel/set_height.html?";
    }
    document.getElementById('fraConnParent').src = sBaseUrl + sCallPage + sParm;

        //        try{
        //            $("debug").innerText += "setHeight2ParentURL2 : call Url :" + sBaseUrl + sCallPage + sParm + "<br />";
        //        }catch(Error)
        //        { 
        //            // alert("setHeight Write Error");
        //        }
    }
    catch (err) {
        alert("2 setFrameHeight call 오류" + err);
    }
}

/*****************************************************
*       img onerror이벤트 발생시 처리 imgObj 
*       onerror = "imgOnError(this,'대체이미지 경로')"
******************************************************/
function imgOnError(imgOBJ, replaceIMG) {
    noimg = "http://www.onionhotel.co.kr/images/common/noimage.jpg";
    if (replaceIMG != '' && imgOBJ.src != replaceIMG && imgOBJ.src.indexOf(replaceIMG) < 0) {
        imgOBJ.src = replaceIMG;
    } else {
        imgOBJ.src = noimg;
    }
}

function goUrlWithParam(sURL) {
    var aid = document.getElementById("aid").value;
    var ParentBaseURL = document.getElementById("ParentBaseURL").value;
    if (ParentBaseURL.substring(0, 7) == "http://") {
        ParentBaseURL = ParentBaseURL.replace("http://", "");
    }
    var idx = sURL.indexOf("?");
    location.href = sURL + (idx>=0 ? "&" : "?") + "aid=" + aid + "&domain=" + ParentBaseURL;
}

// 이벤트 좌표 구하기
function abspos(e) {
    this.x = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    this.y = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    return this;

}

function showLoading() {
    $('#divLoading').css({ visibility: "visible" });
    $('#divSubmit').css({ visibility: "hidden" });
}

function hiddenLoading() {
    $('#divLoading').css({ visibility: "hidden" });
    $('#divSubmit').css({ visibility: "visible" });

}

//Left 기능
function Left(Str, Num) {
    if (Num <= 0)
        return "";
    else if (Num > String(Str).length)
        return Str;
    else
        return String(Str).substring(0, Num);
}


//Right 기능
function Right(Str, Num) {
    if (Num <= 0)
        return "";
    else if (Num > String(Str).length)
        return Str;
    else {
        var iLen = String(Str).length;
        return String(Str).substring(iLen, iLen - Num);
    }
}

function fncAddComma(nValue) {
    var strNo = new String(nValue);
    var pointMoney = '';
    var minus = '';
    if (strNo.indexOf('.') != -1) //소수점 공식
    {
        var nidx = fncPointReturn(strNo, strNo.length);
        pointMoney = strNo.substring(nidx);
        strNo = strNo.substring(0, nidx);
    }
    if (strNo.indexOf('-') != -1) {
        minus = '-';
        strNo = strNo.substring(1);
    }

    var nCount = strNo.length;
    var money = "";
    var y = -1;
    for (var i = nCount; i >= 0; i--) {
        var moyo = strNo.charAt(i);
        if (moyo != ",") {
            if (y % 3 == 0 && y != 0) /* 세자리 마다 컴마를 붙인다. */
            {
                money = moyo + "," + money
                y++;
            }
            else {
                money = moyo + money;
                y++;
            }
        }
    }
    return minus + money + pointMoney;
}

