﻿
//상품목록으로 이동

function goProductList(pURL, pCName1, pCName2, pCName3)
{
	//대분류명이 없으면 
	if (pCName1 == "" || pCName1 == undefined) return;
	
	var querystring = "";
	var Cat1 = "";
	var Cat2 = "";
	var Cat3 = "";
	var CDepth = 0;     //카테고리 Depth
	
	if (pCName3 == undefined) pCName3 = "";
	if (pCName2 == undefined) pCName2 = "";
	
	if (pCName2 == "") CDepth = 1;
	else if (pCName3 == "") CDepth = 2;
	else CDepth = 3;
	
	//카테고리 코드로 값이 넘어왔으면 코드값을 그대로 사용한다
	if (!isNaN(pCName1))
	{
		//숫자로 변경한 후 100보다 작으면 배열로 인식하여 myCategory에서 값을 얻는다.
		Cat1 = parseInt(pCName1);
		var cIndex = 0;
		
		if (Cat1 < 100)
		{
			cIndex = Cat1;
			Cat1 = myCategory.category[Cat1].code;
		}
		
		if (CDepth >= 2)
		{
			Cat2 = parseInt(pCName2);
			if (Cat2 < 100)
			{
				Cat2 = myCategory.category[cIndex].category2[Cat2].code;
			}
		}
		
		if (CDepth >= 3)
		{
			Cat3 = parseInt(pCName3);
			if (Cat3 < 100)
			{
				Cat3 = myCategory.category[cIndex].category3[Cat3].code;
			}
		}
		
	}
	else
	{
	
		//카테고리명으로 인식하여 카테고리코드를 구한다.
		
		for(iLoop = 0; iLoop < myCategory.category.length; iLoop++)
		{
			if (myCategory.category[iLoop].name == pCName1)
			{
				Cat1 = myCategory.category[iLoop].code;
				
				if (isCat1 == true) break;
				
				var cat2 = myCategory.category[iLoop].category2;
				for(jLoop = 0; jLoop < cat2.length; jLoop++)
				{
					if (cat2[jLoop].name == pCName2)
					{
						Cat2 = cat2[jLoop].code;					
						break;
					}
				}
			}
		}
		
	}

	if (CDepth >= 3)
	{
	    querystring = "cat3=" + Cat3;
	}
	if (CDepth >= 2)
	{
	    querystring = "cat2=" + Cat2 + "&" + querystring;
	}
	if (CDepth >= 1)
	{
	    querystring = "cat1=" + Cat1 + "&" + querystring;
	}	
	
	//alert(querystring);
	if (querystring != "")
	{
	    if(CDepth == 1)
		    location.href= pURL + "/shop/product_main.aspx?_wpoint=main_cate&" + querystring;
		else
		    location.href= pURL + "/shop/product_list.aspx?_wpoint=main_cate&" + querystring;
	}
}

//상품목록으로 이동 Product_Main2

function goProductList2(pURL, pCName1, pCName2, pCName3)
{
	//대분류명이 없으면 
	if (pCName1 == "" || pCName1 == undefined) return;
	
	var querystring = "";
	var Cat1 = "";
	var Cat2 = "";
	var Cat3 = "";
	var CDepth = 0;     //카테고리 Depth
	
	if (pCName3 == undefined) pCName3 = "";
	if (pCName2 == undefined) pCName2 = "";
	
	if (pCName2 == "") CDepth = 1;
	else if (pCName3 == "") CDepth = 2;
	else CDepth = 3;
	
	//카테고리 코드로 값이 넘어왔으면 코드값을 그대로 사용한다
	if (!isNaN(pCName1))
	{
		//숫자로 변경한 후 100보다 작으면 배열로 인식하여 myCategory에서 값을 얻는다.
		Cat1 = parseInt(pCName1);
		var cIndex = 0;
		
		if (Cat1 < 100)
		{
			cIndex = Cat1;
			Cat1 = myCategory.category[Cat1].code;
		}
		
		if (CDepth >= 2)
		{
			Cat2 = parseInt(pCName2);
			if (Cat2 < 100)
			{
				Cat2 = myCategory.category[cIndex].category2[Cat2].code;
			}
		}
		
		if (CDepth >= 3)
		{
			Cat3 = parseInt(pCName3);
			if (Cat3 < 100)
			{
				Cat3 = myCategory.category[cIndex].category3[Cat3].code;
			}
		}
		
	}
	else
	{
	
		//카테고리명으로 인식하여 카테고리코드를 구한다.
		
		for(iLoop = 0; iLoop < myCategory.category.length; iLoop++)
		{
			if (myCategory.category[iLoop].name == pCName1)
			{
				Cat1 = myCategory.category[iLoop].code;
				
				if (isCat1 == true) break;
				
				var cat2 = myCategory.category[iLoop].category2;
				for(jLoop = 0; jLoop < cat2.length; jLoop++)
				{
					if (cat2[jLoop].name == pCName2)
					{
						Cat2 = cat2[jLoop].code;					
						break;
					}
				}
			}
		}
		
	}

	if (CDepth >= 3)
	{
	    querystring = "cat3=" + Cat3;
	}
	if (CDepth >= 2)
	{
	    querystring = "cat2=" + Cat2 + "&" + querystring;
	}
	if (CDepth >= 1)
	{
	    querystring = "cat1=" + Cat1 + "&" + querystring;
	}	
	
	//alert(querystring);
	if (querystring != "")
	{
	    if(CDepth == 1)
		    location.href= pURL + "/shop/product_main2.aspx?_wpoint=main_cate&" + querystring;
		else
		    location.href= pURL + "/shop/product_list.aspx?_wpoint=main_cate&" + querystring;
	}
}


var menuX = 0;
var menuY = 0;
var tmpMenu = null;

function ShowSubCategory(pCat, pView)
{
    try{
    var obj = $("Cat_" + pCat + "");
    var e = window.event;
    
    if (tmpMenu != null)
    {
        tmpMenu.style.display = "none";
        tmpMenu = null;
    }
    
    if (obj != null)
    {
        switch(pView)
        {
            case "V":
                tmpMenu = obj;
                var scrollPos = 0;
                
                if (document.documentElement)
                {
                    scrollPos = document.documentElement.scrollTop;  
                }
                else if (top.pageYOffset)
                {
                    scrollPos = top.pageYOffset;  
                }
                
                obj.style.top = e.y-20 + scrollPos;                
                obj.style.left = e.x - 100;
                obj.style.display = "";
                break;
            case "H":
                obj.style.display = "none";
                break;
            case "M":
                obj.style.display = "";
                break;
        }
    }
    }catch(e){alert(e.message);}
}
