/* ------------------------------------------------------------
 * Name      : common.js
 * Desc       : PentaBreed script 
 * Created   : 2008/02/01 PentaBreed by Suga
 ------------------------------------------------------------ */

//Element ID ºÒ·¯¾²±â
function dEI(elementID){
	return document.getElementById(elementID);
}

//Footer select Open
function selectOn(boxID){
	var selectBox = document.getElementById(boxID);
	
	if(selectBox.style.display!="block"){
	selectBox.style.display="block";
	selectBox.onmouseover = function(){selectBox.style.display="block";}
	selectBox.onmouseout = function(){selectBox.style.display="none";}
	}else{
		selectBox.style.display="none";
	}
}

// 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";
	}
}

//ÆË¾÷¶ç¿ì±â
function openPop(url,idn,intWidth,intHeight,scroll) { 
	window.open(url, idn,"width="+intWidth+", height="+intHeight+",resizable=no,scrollbars="+scroll) ;
}

// Tab Content
function tabCheck(dotabid , tnum){
	var inum=parseInt(tnum)-1;
	var linkTab=dEI(dotabid).getElementsByTagName("a");
	for (i=0;i<linkTab.length;i++) {
		var tabimg = linkTab.item(i).getElementsByTagName("img").item(0);
		var tabContents= dEI(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 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");
				}
			}
	}
}

//openDrop Layer
function viewInfo(list,total,num){
var size = total;// list count +1
var id = list;
	for(i=1;i<size;i++){
		var liEI = document.getElementById(id+i);
		if(i==num){
			if(liEI.className == "open"){
				liEI.className = "";
			}else{
				liEI.className = "open";
			}
		}else{
			liEI.className = "";
		}
	}
}

// scrolling layer
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;
		}

		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)
}
//scrolling layer end

function MediaObject(URL, width, height)
{ 
    document.write('<object ID="VodPlayer" name="VodPlayer" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"  standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" align="middle" width="'+width+'" height="'+height+'">'); 
    document.write('  <param name="CurrentPosition" value="1">'); 
    document.write('  <param name="SetCurrentEntry" value="1">'); 
    document.write('  <param name="ClickToPlay" value="1">'); 
    document.write('  <param name="AutoSize" value="0">'); 
    document.write('  <param name="AutoStart" value="1">'); 
    document.write('  <param name="ShowControls" value="1">'); 
    document.write('  <param name="ShowAudioControls" value="1">'); 
    document.write('  <param name="ShowDisplay" value="0">'); 
    document.write('  <param name="ShowStatusBar" value="1">'); 
    document.write('  <param name="EnableContextMenu" value="0">'); 
    document.write('  <param name="ShowPositionControls" value="0">'); 
    document.write('  <param name="DisplayBackColor" value="0">'); 
    document.write('  <param name="ShowTracker" value="1">'); 
    document.write('  <param name="ShowCaptioning" value="0">'); 
    document.write('  <param name="AutoRewind" value="0">'); 
    document.write('  <param name="EnableTracker" value="1">'); 
    document.write('  <param name="Volume" value="-1">'); 
    document.write('  <param name="stretchToFit" value="0">'); 
    document.write(' <embed src="'+URL+'" type="video/x-ms-wmv" width="'+width+'" height="'+height+'">');
  //  document.write('  <param name="Filename" value="'+URL+'">'); 
    document.write('</object>'); 
} 
function resizeImageWindow() {
alert("aa");
	imgEl = document.getElementById("photoImage");
	alert(imgEl);
	if (imgEl) {
		propotion = imgEl.offsetWidth / imgEl.offsetHeight;
		if (propotion > 1) {
			if (imgEl.offsetWidth > 500) {
				imgEl.style.width = "500px";
				imgEl.style.height = Math.floor(500 / propotion) + "px";
			}
		} else {
			if (imgEl.offsetHeight > 500) {
				imgEl.style.height = "500px";
				imgEl.style.width = Math.floor(500 * propotion) + "px";
			}
		}
	}
	document.getElementById("photoPopup").style.width = (imgEl.offsetWidth + 12) + "px";
	window.resizeTo(imgEl.offsetWidth + 52, document.getElementById("photoPopup").offsetHeight + 145);
}


function notice_setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function notice_getCookie( name )
{
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;
                        return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
        return "";
}



	// ÆË¾÷Ã¢


function getCookie(strName)
{
	var strArg = new String(strName + "=");	
	var nArgLen, nCookieLen, nEnd;
	var i = 0, j;

	nArgLen    = strArg.length;
	nCookieLen = document.cookie.length;

	if(nCookieLen > 0) 
	{
		while(i < nCookieLen) 
		{
			j = i + nArgLen;
			if(document.cookie.substring(i, j) == strArg)
			{
				nEnd = document.cookie.indexOf (";", j);
				if(nEnd == -1) nEnd = document.cookie.length;
				return unescape(document.cookie.substring(j, nEnd));
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	}
	return("");
}

function setCookie(strName, strValue, dateExpires, strPath, strDomain, isSecure)
{
	var strCookie;
	if(strName == "") return ;
	strCookie = strName + "=" + escape(strValue) + 
		    ((dateExpires) ? "; expires=" + dateExpires.toGMTString() : "")  + 
	      	    ((strPath)     ? "; path="    + strPath : "") + 
	      	    ((strDomain)   ? "; domain="  + strDomain : "") + 
		    ((isSecure)    ? "; secure" : "");
	document.cookie = strCookie; 
}


function delCookie( name )
{

	var todayDate = new Date();

	todayDate.setDate( todayDate.getDate()-1 );

	document.cookie = name+"=; domain=lg.or.kr; path=/; expires="+todayDate.toGMTString()+";";

}

function SetUrl() 
{

		setCookie("LGURL",tUrl,null,"/","lg.or.kr")			

}

function Left(str, n)
{
if (n <= 0)
  return "";
else if (n > String(str).length)
  return str;
else
  return String(str).substring(0,n);
}

function Right(str, n)
{
  if (n <= 0)
     return "";
  else if (n > String(str).length)
     return str;
  else {
     var iLen = String(str).length;
     return String(str).substring(iLen, iLen - n);
  }
}

 
