/* ------------------------------------------------------------
* Name      : common.js
* Desc      : PentaBreed script
* Created   : 2008/06/20 PentaBreed by BR
------------------------------------------------------------ */

//Element ID 불러쓰기
function dEI(elementID){
	return document.getElementById(elementID);
}


// roundBox Layout
function initLayout(layoutEl,childEl) {
	var layoutId = dEI(layoutEl);
	var contentsId = dEI(childEl);

	//create and build div structure
	var bodyTH = document.createElement('div');
	var bodyLV = document.createElement('div');
	var bodyRV = document.createElement('div');
	var bodyBH = document.createElement('div');
	var bodyTL = document.createElement('div');
	var bodyTR = document.createElement('div');
	var bodyBL = document.createElement('div');
	var bodyBR = document.createElement('div');
	bodyTH.className = "bodyTH";
	bodyLV.className = "bodyLV";
	bodyRV.className = "bodyRV";
	bodyBH.className = "bodyBH";
	bodyTL.className = "bodyTL";
	bodyTR.className = "bodyTR";
	bodyBL.className = "bodyBL";
	bodyBR.className = "bodyBR";
	layoutId.appendChild(bodyTH);
	bodyTH.appendChild(bodyLV);
	bodyLV.appendChild(bodyRV);
	bodyRV.appendChild(bodyBH);
	bodyBH.appendChild(bodyTL);
	bodyTL.appendChild(bodyTR);
	bodyTR.appendChild(bodyBL);
	bodyBL.appendChild(bodyBR);
	bodyBR.appendChild(contentsId);
}


//Images Btn_KSS
function BtnOn(imgEl){
	imgEl.src = imgEl.src.replace(".gif", "_on.gif");
}
function BtnOut(imgEl){
	imgEl.src = imgEl.src.replace("_on.gif", ".gif");
}

// first 예외처리 firstChild(블럭Id, 태그네임, 처리할 아이템 번호) // 아이템번호는 0번부터 반환
function firstChild(Elid, Etn, Num){
	if(Num==""){Num=0;}
	liEl = dEI(Elid).getElementsByTagName(Etn);
	if (liEl.item(Num)) {
		liEl.item(Num).className += " first-child";
	}
}

// first 예외처리 listFirst(블럭Id, 태그네임, 처리할 아이템 갯수) // 아이템번호는 0번부터 반환
function listFirst(Elid, Etn, Num){
	liEl = dEI(Elid).getElementsByTagName(Etn);
	for(i=0; liEl.length>i; i=i+Num){
		liEl.item(i).className += " first";
	}
}

// last 예외처리 lastList(블럭Id, 태그네임) // 아이템번호는 0번부터 반환
function lastList(Elid, Etn){
	liEl = dEI(Elid).getElementsByTagName(Etn);
	liEl.item(liEl.length-1).className += " last";
}

//팝업띄우기
function openPop(url,idn,intWidth,intHeight,scroll) { 
	//alert("pop_scroll");
	window.open(url, idn,"width="+intWidth+", height="+intHeight+",resizable=0,scrollbars="+scroll) ;
}

function openPop1(url,features) { 
	window.open(url, "",features) ;
}

//이미지팝업띄우기
function openPopImg(url,idn,imgWidth,imgHeight) {
	//alert("pop_scroll");

	var winHandle = window.open("", idn,"width="+imgWidth+", height="+imgHeight+",resizable=0,scrollbars=no");
	if(winHandle != null){
		var htmlString = "<html><head><title>크게보기<\/title><\/head>"
		htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
		htmlString += "<a href=javascript:window.close()><img src=" + url + " border=0 alt=창닫기><\/a>"
		htmlString += "<\/body><\/html>"
		winHandle.document.open()
		winHandle.document.write(htmlString)
		winHandle.document.close()
	}
}

//이미지 사이즈에 맞게 띄우기
function openPopAutoImg(url,idn){
	var imgElm=new Image();
	imgElm.src=url;
	imgWidth = imgElm.width;
	imgHeight = imgElm.height;

	if(url != null){
		openPopImg(url, idn,imgWidth, imgHeight);
		return false;
	}
}

// 이미지 롤오버
function imgRollover(imgBoxID){
	var MenuCounts = dEI(imgBoxID).getElementsByTagName("img");
	for (i=0;i<MenuCounts.length;i++) {
		var numImg=MenuCounts.item(i);
		var ImgCheck = numImg.src.substring(numImg.src.length-6,numImg.src.length);
		if (ImgCheck!="on.gif") {
				numImg.onmouseover = function () {
					this.src = this.src.replace(".gif", "on.gif");
				}
				numImg.onmouseout = function () {
					this.src = this.src.replace("on.gif", ".gif");
				}
			}
	}
}

//투명이미지 사용
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 '';
}


// 동영상 wma플레이어 제어
function PlayClick(){
	if(document.getElementById("mPlayer").style.visibility="hidden"){
		document.getElementById("mPlayer").style.visibility="visible";
	}
	mPlayer.Play();
}

function PauseClick(){
	mPlayer.Pause(); 
}

function StopClick(){
	mPlayer.Stop(); 
}

function FastForwardClick(){
	mPlayer.FastForward();
}


//메이크업영상 플레이
function playArtmovie(url, num){
	var linkTab=document.getElementById("playArtMovieLi").getElementsByTagName("a");
	var furl;

	if(document.getElementById("mPlayer").style.visibility="hidden"){
		document.getElementById("mPlayer").style.visibility="visible";
		if (navigator.appName.indexOf("Microsoft") != -1){
			window["mPlayer"].fileName=url;
		}else{
			var objSwf;
			objSwf="<object type=\"application/x-oleobject\" data="+url+" width=\"316\" height=\"238\" id=\"mPlayer\"><\/object>"
			document.getElementById("mPlayer").innerHTML=objSwf;
		}
	}

	for(i=0;i<linkTab.length;i++){
		var tabimg=linkTab.item(i).getElementsByTagName("img").item(0);
		var ImgCheck = tabimg.src.substring(tabimg.src.length-6,tabimg.src.length);

		if(i == (num-1)){
			tabimg.src=tabimg.src.replace(".gif", "on.gif");
			if(ImgCheck=="on.gif"){
				tabimg.src=tabimg.src.replace("on.gif", ".gif");
			}
		}else{
			document.getElementById("btyArtmovieCnt"+(i+1)).style.display="none";
			document.getElementById("btyArtmovieCnt"+num).style.display="block";
			tabimg.src=tabimg.src.replace("on.gif", ".gif");
		}
	}
}
//메이크업영상 플레이
function playArtmovie2(url, num){
	//var linkTab=document.getElementById("playArtMovieLi").getElementsByTagName("a");
	var furl;

	if (navigator.appName.indexOf("Microsoft") != -1){
		window["mPlayer"].fileName=url;
	}else{
		var objSwf;
		objSwf="<object type=\"application/x-oleobject\" data="+url+" width=\"720\" height=\"480\" id=\"mPlayer\"><\/object>"
		document.getElementById("mPlayer").innerHTML=objSwf;
	}
}

//탭 tab
function tabCheck(dotabid, num){
var inum=parseInt(num)-1;
var linkTab=document.getElementById(dotabid).getElementsByTagName("a");
	for (i=0;i<linkTab.length;i++) {
		var tabimg = linkTab.item(i).getElementsByTagName("img").item(0);
			var tabContents= document.getElementById(dotabid+(1+i));
			if (i==inum) {
			if(tabContents.style.display!="block"){
				tabimg.src=tabimg.src.replace(".gif", "on.gif");
				tabContents.style.display="block";
			}
	}else{
			tabimg.src=tabimg.src.replace("on.gif", ".gif");
			tabContents.style.display="none";
		}
	}
}

function tabCheck2(dotabid, num){
var inum=parseInt(num)-1;
var linkTab=document.getElementById(dotabid).getElementsByTagName("a");
	for (i=0;i<linkTab.length;i++) {
		var tabimg = linkTab.item(i).getElementsByTagName("img").item(0);
			var tabContents= document.getElementById(dotabid+(1+i));
			if (i==inum) {
			if(tabContents.style.display!="block"){
				tabimg.src=tabimg.src.replace(".jpg", "on.jpg");
				tabContents.style.display="block";
			}
	}else{
			tabimg.src=tabimg.src.replace("on.jpg", ".jpg");
			tabContents.style.display="none";
		}
	}
}
function tabCheck3(dotabid, num){
var inum=parseInt(num)-1;
var linkTab=document.getElementById(dotabid).getElementsByTagName("a");
	for (i=0;i<linkTab.length;i++) {
		var tabimg = linkTab.item(i).getElementsByTagName("img").item(0);
			var tabContents= document.getElementById(dotabid+(1+i));
			if (i==inum) {
			if(tabContents.style.display!="block"){
				tabimg.src=tabimg.src.replace(".gif", "_on.gif");
				tabContents.style.display="block";
			}
	}else{
			tabimg.src=tabimg.src.replace("_on.gif", ".gif");
			tabContents.style.display="none";
		}
	}
}

//beautyClass 마우스오버시 레이어 팝업
function viewPopLayer(popLayer, tPos, lPos){
	var popLayer = document.getElementById(popLayer);
	var viewClassTime = document.getElementById("btyClassCalendarBox").getElementsByTagName("a");
	for(i=0;i<viewClassTime.length;i++){
		var num = i+1;
		if(document.getElementById("btyClassPop"+(num)).style.display == "block"){
			document.getElementById("btyClassPop"+(num)).style.display = "none";
			popLayer.style.display = "none";
		}else{
			popLayer.style.display = "block";
		}
	}

	popLayer.style.top = tPos + "px";
	popLayer.style.left = lPos + "px";
}

function viewPopLayerOff(popLayer){
	var viewPopLayerBox = document.getElementById(popLayer);
	viewPopLayerBox.style.display = "none";
}

//브랜드 -모델 이미지 change
function chModel(num){
	if (num=="1"){
		document.getElementById("tab2").style.display = "block"
		document.getElementById("tab1").style.display = "none"
	}else{
		document.getElementById("tab2").style.display = "none"
		document.getElementById("tab1").style.display = "block"
	}
}


// stroe map 스크립트
function  searchStore (dep1, dep2){
	if(dep2==null){
		alert("dep1="+dep1);
	}else{
		alert("dep1="+dep1+ "\n dep2="+dep2);
	}
}


function viewPopLayerOff(popLayer){
	var viewPopLayerBox = document.getElementById(popLayer);
	viewPopLayerBox.style.display = "none";
}


//옴므스토리_브랜드 텝이미지 Change
function tabChgImg(num){
	for(i=1;i<6;i++){
		//alert(document.getElementById("tabImg").src);
		chgImg = document.getElementById("tabImg")
		chgImg.src = chgImg.src.replace("tab0"+i+".gif","tab0"+num+".gif");
	}
}
// TIP
function initToggle(tabContainer) {
	triggers = tabContainer.getElementsByTagName("a");

	for(i = 0; i < triggers.length; i++) {
		if (triggers.item(i).href.split("#")[1])
			triggers.item(i).targetEl = document.getElementById(triggers.item(i).href.split("#")[1]);

		if (!triggers.item(i).targetEl)
			continue;

		triggers.item(i).targetEl.style.display = "none";
		triggers.item(i).className="";
		triggers.item(i).onclick = function () {
			if (tabContainer.current == this) {
				this.targetEl.style.display = "none";
				this.className="";
				tabContainer.current = null;
			} else {
				if (tabContainer.current) {
					tabContainer.current.targetEl.style.display = "none";
					tabContainer.current.className="";
				}
				this.targetEl.style.display = "block";
				this.className="on";
				tabContainer.current = this;
			}
			return false;
		}
	}
}

//브랜드 -모델 이미지 change
function chModel(num){
	if (num=="1"){
		document.getElementById("tab2").style.display = "block"
		document.getElementById("tab1").style.display = "none"
	}else{
		document.getElementById("tab2").style.display = "none"
		document.getElementById("tab1").style.display = "block"
	}
}


// stroe map 스크립트
function  searchStore (dep1, dep2){
	if(dep2==null){
		alert("dep1="+dep1);
	}else{
		alert("dep1="+dep1+ "\n dep2="+dep2);
	}
}


function viewPopLayerOff(popLayer){
	var viewPopLayerBox = document.getElementById(popLayer);
	viewPopLayerBox.style.display = "none";
}



//옴므스토리_브랜드 텝이미지 Change
function tabChgImg(num){
	for(i=1;i<6;i++){
		//alert(document.getElementById("tabImg").src);
		chgImg = document.getElementById("tabImg")
		chgImg.src = chgImg.src.replace("tab0"+i+".gif","tab0"+num+".gif");
	}
}


/* 위젯 XML */
function getXML(code){
	switch (code)
	{
	case 'sort':
		return "/product_xml/prd_sorted_xml.jsp"; //선택상품 순서보기
	case 'today':
		return "/product_xml/prd_today_xml.jsp"; // 오늘 내가 본 상품목록
	case 'hot':
		return "/product_xml/prd_hot_xml.jsp"; //hot&new 상품 목록
	case 'rank':
		return "/xml/rank.xml"; // 실시간 검색어 순위
	case 'search':
		return "/product_xml/prd_search_xml.jsp"; // 상품검색 URL
	case 'select':
		return "/xml/select.xml"; // select 항목
	case 'print':
		return "/prt_uselist.jsp"; // 프린트항목
	case 'bg':
		return "/xml/bg.xml"; // 메인 배경 플래시항목
	}
}


//위젯 인쇄
function printURL(url){
	document.getElementById("printFrame").src=url;
	document.printFrame.focus();
}

function largeViewProductDetail(url) //확대보기
{
	//alert("largeViewProductDetail :" + url);
	document.getElementById("prdViewBig").style.display = "block";
	document.getElementById("prdViewBigImg").src = url;
}

function closePrdViewBig(){
	document.getElementById('prdViewBig').style.display='none';  //확대창닫기
}

function tag(tag){
	ProductList.obj().searchTag(tag);
}


//향장 페이지 넘기기 (paging이 위아래2개가 있을경우)
function zinePage(zinName,num){
	var linkTab=document.getElementById("zinPage1").getElementsByTagName("a");
	var linkTab2=document.getElementById("zinPage2").getElementsByTagName("a");

	for(i=0;i<linkTab.length;i++){
		var tabimg=linkTab.item(i).getElementsByTagName("img").item(0);
		var tabimg2=linkTab2.item(i).getElementsByTagName("img").item(0);

		if(i == (num-1)){
			if(document.getElementById(zinName+num).style.display=="none"){
				tabimg.src=tabimg.src.replace(".gif", "_on.gif");
				tabimg2.src=tabimg2.src.replace(".gif", "_on.gif");
				document.getElementById(zinName+num).style.display="block";
			}
		}else{
			document.getElementById(zinName+(i+1)).style.display="none";
			tabimg.src=tabimg.src.replace("_on.gif", ".gif");
			tabimg2.src=tabimg2.src.replace("_on.gif", ".gif");
		}
	}
}

//homme-향장 페이지 넘기기 (paging이 하나만있을경우)
function zinePage2(zinName,num){
	var linkTab=document.getElementById("zinPage").getElementsByTagName("a");

	if(num==1){
		document.getElementById("hmmZineTitImg").style.display="block";
	}else{
		document.getElementById("hmmZineTitImg").style.display="none";
	}
	for(i=0;i<linkTab.length;i++){
		var tabimg=linkTab.item(i).getElementsByTagName("img").item(0);

		if(i == (num-1)){
			if(document.getElementById(zinName+num).style.display=="none"){
				tabimg.src=tabimg.src.replace(".gif", "_on.gif");
				document.getElementById(zinName+num).style.display="block";
			}
		}else{
			document.getElementById(zinName+(i+1)).style.display="none";
			tabimg.src=tabimg.src.replace("_on.gif", ".gif");
		}
	}
}


//
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}

//레이어팝업
function lyrPop(eid,mode){
	if (mode=="on"){
		document.getElementById(eid).style.display = "block"
	}else{
		document.getElementById(eid).style.display = "none"
	}
}

//시즌 메이크업 룩
function seasonList(season){
	//alert(season);
	self.location.href = "/product/"+season;
}

//시즌 메이크업 룩 - 리스트 selectBox check
function seasonCh(){
	var fullUrl = document.URL;

	var fn=fullUrl.replace("http://", "");
	fn = fn.match(/\/([a-z0-9_-]+\.\w+)/i);
//	return (fn == null) ? "": fn[1];

	var thisSeason=document.seasonSelect.select;

	for(i=0; i<thisSeason.options.length; i++){
		if(thisSeason.options[i].value==fn[1]){
			thisSeason.options[i].selected=true;
		}
	}
}

//시즌 메이크업 룩 - 서브메뉴(시즌별공통)
function seasonSubMenu(){
	if (window.addEventListener){
		window.addEventListener("load", createcssmenu2, false);
	}
	else if (window.attachEvent){
		window.attachEvent("onload", createcssmenu2);
	}
	
	function createcssmenu2(){
	var cssmenuids=["seasonMenu"]; //Enter id(s) of CSS Horizontal UL menus, separated by commas
	var csssubmenuoffset=-1; //Offset of submenus from main menu. Default is 0 pixels.

		for (var i=0; i<cssmenuids.length; i++){
		var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul");

			for (var t=0; t<ultags.length; t++){
				ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px";
				var spanref=document.createElement("span");
				ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref);
				ultags[t].parentNode.onmouseover=function(){
					this.getElementsByTagName("ul")[0].style.visibility="visible"
				}
				ultags[t].parentNode.onmouseout=function(){
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
				}
			}
		}
	}
}