﻿// JScript 파일


//#############################################################################

    //topRequest 객체 생성 - Request 충돌 오류로 인해 각각 3개의 객체를 생성해줌 
    
//#############################################################################

var topRequest1;
function createtopRequest1()
{    
    try {
        topRequest1 = new XMLHttpRequest(); //모질라 웹 브라우저
    } catch (trymicrosoft) {
        try {
            topRequest1 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (othermicrosoft){
             try {
                topRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
             }catch (failed){
                topRequest1 = null;
               }
           }
    }
    
    if (topRequest1 == null)
        alert("현 브라우저에서는 거래처를 검색할수 없습니다.");
}


var topRequest2;
function createtopRequest2()
{    
    try {
        topRequest2 = new XMLHttpRequest(); //모질라 웹 브라우저
    } catch (trymicrosoft) {
        try {
            topRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (othermicrosoft){
             try {
                topRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
             }catch (failed){
                topRequest2 = null;
               }
           }
    }
    
    if (topRequest2 == null)
        alert("현 브라우저에서는 거래처를 검색할수 없습니다.");
}



var topRequest3;
function createtopRequest3()
{    
    try {
        topRequest3 = new XMLHttpRequest(); //모질라 웹 브라우저
    } catch (trymicrosoft) {
        try {
            topRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (othermicrosoft){
             try {
                topRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
             }catch (failed){
                topRequest3 = null;
               }
           }
    }
    
    if (topRequest3 == null)
        alert("현 브라우저에서는 거래처를 검색할수 없습니다.");
}



//#############################################################################

    // 출발지역에 따른 테마메뉴 데이타 가져오기
    // num : 해당출발의 번호 
    // start : 해당출발 지역번호 ex)ICN
      
//#############################################################################

function startChange(num, start, choTheme, themeNum)
{
    createtopRequest1();
    var XmlPara="stl="+start;    
    
    topRequest1.open("post","/menu/common/ca/Top_theme.aspx",false);
    topRequest1.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    if (isIE()) {
        topRequest1.onreadystatechange = function() {startChange_Result(num, start, choTheme, themeNum)};
        topRequest1.send(XmlPara);
    }
    else 
    {
        topRequest1.send(XmlPara);
        startChange_Result(num, start, choTheme, themeNum);
    }  
}

function startChange_Result(num, start, choTheme, themeNum)
{
    var flag = false;
    var Firsttheme, FirstthemeName;
    for(i=0; i<=4; i++)
    {
        
        stl = jQuery("#stl"+i);
        
        if(num == i)
        {
            stl.removeClass("stlchangeout");
            stl.addClass("stlchangeon");
        }
        else 
        {
            stl.removeClass("stlchangeon");
            stl.addClass("stlchangeout");
        }
    }
    if (topRequest1.readyState == 4)
    {
        //alert(request.responseText);
        if(topRequest1.status == 200 || topRequest1.status == 500)
        {
            var themeList = eval("("+topRequest1.responseText+")"); 
            var themeArea = jQuery(".item_wrap .contents .sub_depth_1");
            themeArea.html("");  // 초기화
            var htmlStr = "";
            var themeNm = "";
            
            if(themeList.level != "0")
            {
                flag = true;
                //alert(themeList.label.length);
                for(i=0; i < themeList.label.length; i++)
                {
                    var label = themeList.label[i].split("//");
                    
                    themeNm = returnTheme(label[0]);
                    
                    htmlStr += "<p><a id='topSubDepth"+i+"' onclick=\"menuLink('"+label[1]+"','2','','','top');\" onmouseover='submenu1(\""+label[1]+"\",\""+label[0]+"\",\""+i+"\");'>"+label[0]+"</a>";
                    
                    if(choTheme != "")
                    {
                        if(choTheme == label[1])
                        {
                            Firsttheme = label[1];
                            FirstthemeName = label[0];
                        }
                    }
                    else 
                    {
                        if(i == 0)
                        {
                            Firsttheme = label[1];
                            FirstthemeName = label[0];
                        }
                    }
                }
            }
            themeArea.html(htmlStr);
        }
        if(flag)
        {
            document.getElementById("TopMenu").startLocation.value = start;
            document.getElementById("tcntDepth1").value = themeList.label.length    
            submenu1(Firsttheme, FirstthemeName,themeNum);
        }
        else 
        {
            var sub_depth2 = jQuery(".item_wrap .contents .sub_depth_2");
            var sub_depth3 = jQuery(".item_wrap .contents .sub_depth_3 div");
            sub_depth2.html("");  // 1차초기화
            sub_depth3.html("");  // 2차초기화
            alert("출발지역에 해당하는 테마가 없습니다");
            return false;
        }     
    }
}



//#############################################################################

    // 1차 지역 카테고리 가져오기
    // theid : 테마번호
    // themeLabel : 테마이름 
    // num     : 해당 테마의 순서
      
//#############################################################################

function submenu1(theid, themeLabel, num)
{
    var TN = returnTheme(themeLabel);
    ChangeThemeImg(TN);             //기획전 이미지변경
    changeArrow(TN, num);                 //메뉴 화살표 좌표변경
    
    Obj = document.getElementById("TopMenu");
    Obj.Theme.value = theid
    
    var stl =  Obj.startLocation.value;
    
    if (topRequest2 == null) createtopRequest2();
    var XmlPara="theid=" + theid + "&startlocation="+stl;
    //alert(XmlPara);

    topRequest2.open("post","/menu/common/ca/Top_Menu.aspx",false);
    topRequest2.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    if (isIE()) {
        topRequest2.onreadystatechange = function() {submenu1_Result(TN)};
        topRequest2.send(XmlPara);
    }
    else 
    {
        topRequest2.send(XmlPara);
        submenu1_Result();
    }
}

function submenu1_Result(TN)
{
    var theid = Obj.Theme.value;
    if (topRequest2.readyState == 4)
    {
        //alert(topRequest2.responseText);
        if(topRequest2.status == 200 || topRequest2.status == 500)
        {
            var loc1;
            var areaList = eval("("+topRequest2.responseText+")"); 
            var sub_depth2 = jQuery(".item_wrap .contents .sub_depth_2");
            var sub_depth3 = jQuery(".item_wrap .contents .sub_depth_3 div");
            sub_depth2.html("");  // 1차초기화
            sub_depth3.html("");  // 2차초기화
            var htmlStr = "";
            
            if(areaList.level != "0")
            {
                for(i=0; i < areaList.label.length; i++)
                {
                    var label = areaList.label[i].split("//");
                    htmlStr += "<p><a href='#' id='topSubDepth2"+i+"'  onclick=\"menuLink('"+theid+"','2','"+label[1]+"','"+label[1]+"','top');\" onmouseover='submenu2(\""+label[1]+"\","+i+");'>"+label[0]+"</a></p>";
                    
                    if(i == 0)
                    {
                        loc1 = label[1];
                    }
                }
            }
            sub_depth2.html(htmlStr);
            document.getElementById("tcntDepth2").value = areaList.label.length
            if(areaList.level != "0") submenu2(loc1,0);
        }
    }
}


//#############################################################################

    // 2차 지역 카테고리 가져오기
    // loc1 : 1차지역번호 
    // num  : 1차지역번호 몇번째에 해당하는지에 대한 번호(메뉴활성화를 위해 필요함)
      
//#############################################################################

function submenu2(loc1,num)
{
    Obj = document.getElementById("TopMenu");
    theid = Obj.Theme.value;
    Obj.location.value = loc1;
    var stl =  Obj.startLocation.value;
    var tcnt = document.getElementById("tcntDepth2").value;
    
    //메뉴 활성화
    subDepthActive(num,"#topSubDepth2",tcnt);
    
    if (topRequest3 == null) createtopRequest3();
    var XmlPara="theid=" + theid + "&startlocation="+stl+"&loc1="+loc1;
    
    //alert(XmlPara);

    topRequest3.open("post","/menu/common/ca/Top_Menu.aspx",false);
    topRequest3.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    if (isIE()) {
        topRequest3.onreadystatechange = function() {submenu2_Result(loc1)};
        topRequest3.send(XmlPara);
    }
    else 
    {
        topRequest3.send(XmlPara);
        submenu2_Result(loc1);
    }
}

function submenu2_Result(loc1)
{
    var loc1 = Obj.location.value;
    if (topRequest3.readyState == 4)
    {
        //alert(request.responseText);
 
        if(topRequest3.status == 200 || topRequest3.status == 500)
        {
            var areaList = eval("("+topRequest3.responseText+")"); 
            var sub_depth3 = jQuery(".item_wrap .contents .sub_depth_3 div");
            var htmlStr = "";
            
            if(areaList.level != "0")
            {
                for(i=0; i < areaList.label.length; i++)
                {
                    var label = areaList.label[i].split("//");
                    htmlStr += "<p><a href='#' onclick=\"menuLink('"+theid+"','1','"+loc1+"','"+label[1]+"','top');\">"+label[0]+"</a></p>";
                }
            }
            sub_depth3.html(htmlStr);
        }
    }
}


//#############################################################################

    // 테마 변경시 우측 기획전배너이미지 변경
    // themeLabel : 테마이름  
      
//#############################################################################

function ChangeThemeImg(themeLabel)
{
    var headTopImg = jQuery("#topTabBanner");
    var headTopImga = jQuery(".gnb .btn_go");
    switch(themeLabel)
    {
        case "패키지" :  headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_1_110928.jpg");
                        headTopImga.attr("href","/event/event_12/0117_23th/23rd.aspx?mloc=0701");
                        break;
        case "허니문"  : 
                        headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_3_110928.jpg");
                        headTopImga.attr("href","/event/event_11/0708_pac/mode.aspx?mloc=07");
                        break;
        case "자유"  :
                        headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_2_110928.jpg");
                        headTopImga.attr("href","/event/event_11/1107_m/mode.aspx?mloc=0701");
                        break;      
        case "골프"  : 
                        headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_4_110928.jpg");
                        headTopImga.attr("href","/event/event_11/0713_best/mode.aspx?mloc=0701");
                        break;
        case "JM"  : 
                        headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_5_110928.jpg");
                        headTopImga.attr("href","/event/event_11/1216_jm/mode2.aspx?mloc=0701");
                        break;
        case "크루즈"  :
                        headTopImg.attr("src","http://img.modetour.co.kr/mode2010/Onlinecp/ca/menu/bg_sub_item_6_110928.jpg");
                        headTopImga.attr("href","/event/event_10/0916_jm/mode.aspx?mloc=0701");
                        break;
    }
}


//#############################################################################

    // 메뉴 화살표 체인지, 메뉴 활성화
    // themeLabel : 테마이름  
      
//#############################################################################

function changeArrow(themeLabel , num)
{
    tcnt = document.getElementById("tcntDepth1").value;
    //var themeArea = jQuery('.gnb .sub_item .item_wrap .contents .sub_depth_1');
    switch(themeLabel){
		case "패키지" :  jQuery('.gnb .sub_item .arrow').css('left','52px'); 
		                 break;
		case "허니문" : 
		                jQuery('.gnb .sub_item .arrow').css('left','175px'); 
		                break;
		case "자유" :   jQuery('.gnb .sub_item .arrow').css('left','280px'); 
		                break;
		case "골프" : 
		                jQuery('.gnb .sub_item .arrow').css('left','385px'); 
		                break;
		case "JM" : 
		                jQuery('.gnb .sub_item .arrow').css('left','515px'); 
		                break;
		case "크루즈" : 
		                jQuery('.gnb .sub_item .arrow').css('left','650px'); 
		                break;
		//case 6 : jQuery('.gnb .sub_item .arrow').css('left','830px'); break;
		//case 7 : jQuery('.gnb .sub_item .arrow').css('left','900px'); break;
		default : break;
	}
	subDepthActive(num,"#topSubDepth",tcnt);
}

//#############################################################################

    // 해당메뉴에 활성화 표시
    //num : 해당 메뉴에 순서 
    //id : depth1, depth2 인지 구분하기 위한 id 값
    //tcnt :  depth1, depth2 의 총개수 가 틀리기 위해 for문 에 필요한 총개수 값 
      
//#############################################################################

function subDepthActive(num,id,tcnt)
{
    //alert(num);
    var theme;
    for(i=0; i < tcnt; i++)
    {
        theme = jQuery(id+i);
        if(i == num) 
        {
            
            theme.addClass("subDepthOn"); 
            theme.css({"color":"#ffffff","background-color":"#9da3af","font-weight":"bold"});

        }
        else 
        {
            theme.addClass("subDepthOut");
            theme.css({"color":"#767676","background-color":"#ffffff","font-weight":"normal"});
        }
    }
}

//#############################################################################

    // 테마이름을 가져오기 위한 함수
    // 공통적인 이름을 가져오기 위하여 배열로 선언 후 이름을 리턴(결과값으로 기획이미지나 메뉴활성화를 하기 위한 처리)
    // themeName : 테마이름
      
//#############################################################################

function returnTheme(themeName)
{
    //alert(themeName);
    var theme = "";
    var ThemeArray = new Array("패키지","허니문","자유", "골프", "JM", "크루즈" )
    for(i=0; i < ThemeArray.length; i++)
    {
        var chk = themeName.indexOf(ThemeArray[i]);
        if(chk > -1)
        {
            theme = ThemeArray[i];
            break;
        }
    }    
    return theme
}

//#############################################################################

    // top 메뉴 링크 함수
    // location : 지역1
    // location2 : 지역2
    // submain : 서브메인 있는지 없는지 여부 
    // themeName : 테마이름
      
//#############################################################################

//Top Menu
function TopLink(location, location2, submain, themeName)
{
    var Obj = document.getElementById("TopMenu");
    
    var stl = Obj.startLocation.value;
    
    if(stl != "ICN")
    {
        if(location2 == "")
        {
            location = Obj.location.value
            Obj.location.value = location + "^" + location;
            Obj.location2.value = location;
        }
        else 
        {
            location = Obj.location.value
            Obj.location.value = location + "^" + location2;
            Obj.location2.value = location;
        }
        Obj.action = "/Package/List_CA.aspx";
    }
    else 
    {
        if(submain == "1" && themeName == "패키지")
        {
            if(location != "") Obj.location.value = location; else Obj.location.value = "LOC3";
            if(location2 != "") Obj.location2.value = location2; else Obj.location2.value = "LOC3";
            Obj.action = "/Package/SubMain_CA.aspx";
        }
        else if(submain == "2")
        {
            switch(themeName)
            {
                case "패키지" : 
                    if(location != "") Obj.location.value = location; else Obj.location.value = "LOC3";
                    if(location2 != "") Obj.location2.value = location2; else Obj.location2.value = "LOC3";
                    Obj.action = "/Package/SubMain_CA.aspx";
                    break;
		        case "허니문" : 
		            if(location != "") Obj.location.value = location;
                    if(location2 != "") Obj.location2.value = location2;
		            Obj.action = "/SubMain/CA/honeymoon.aspx"; 
		                 
		            break;
		        case "자유" : 
		            if(location != "") Obj.location.value = location;
                    if(location2 != "") Obj.location2.value = location2; 
		            Obj.action = "/SubMain/CA/free.aspx";  
		            break;
		        case "골프" : 
		            if(location != "") Obj.location.value = location;
                    if(location2 != "") Obj.location2.value = location2;
		            Obj.action = "/SubMain/CA/golf.aspx"; 
		            break;
		        case "JM" : 
		            if(location != "") Obj.location.value = location;
                    if(location2 != "") Obj.location2.value = location2;
		            Obj.action = "/SubMain/CA/JMTour.aspx";  
		            break;
		        case "크루즈" : 
		            if(location != "") Obj.location.value = location;
                    if(location2 != "") Obj.location2.value = location2;
		            Obj.action = "/SubMain/CA/cruise.aspx"; 
		            break;
            }
            if(themeName != "패키지" && location2 != "")
            {
                location = Obj.location.value
                Obj.location.value = location + "^" + location2;
                Obj.location2.value = location;
		        Obj.action = "/Package/List_CA.aspx";
		    }   
        }
        else
        {
            switch(themeName)
            {
                /*
		        case "JM" : 
		            Obj.action = "/SubMain/CA/JMTour.aspx"; 
		            break;
		        case "크루즈" : 
		            Obj.action = "/SubMain/CA/cruise.aspx";
		            break;
		        */
		        default :
		             location = Obj.location.value
                    Obj.location.value = location + "^" + location2;
                    Obj.location2.value = location;
                    Obj.action = "/Package/List_CA.aspx";
		            break;
            }       
        }
    }    
    Obj.submit();
}



function myFavorite(url, favTxt) 
{ 
    window.external.AddFavorite(url, favTxt); 
} 


