/* ------------------------------------------------------------
 
* 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>"
		htmlString += "<script>"
		htmlString += " function init(){"
		htmlString += "  window.resizeBy( document.getElementById('img').width-500, document.getElementById('img').height-500 );"
		htmlString += " }"
		htmlString += "</script>"
		htmlString += "<\/head>";
		htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onload='init()'>"
		htmlString += "<a href=javascript:window.close()><img id='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,500, 500);
		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";

}


// 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.jsp"; // ½Ç½Ã°£ °Ë»ö¾î ¼øÀ§

	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 = "/beauty/"+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"
				}
			}
		}
	}
}