//var domain = "http://"+document.domain+"/";
var historyBlank = domain+"Libs/_js/blank.html?";
//##################################################################################
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* ¸Þ´º ¸Ç ¾Æ·¡·Î ÀÌµ¿ */ 
function fnMenuMoveEnd(oMenu) { 
    var cnt = oMenu.length-1; 
    var i=0; 

    for (i=oMenu.length-1; i>=0; i--) { 
        if (Menulist_isSelected(oMenu, i)) { 
            if (i==oMenu.length-1) return; 
            var idx = i; 
            
            for (j=idx;j<cnt;j++) { 
                Menulist_downMenu(oMenu, idx); 
                idx = idx + 1; 
            } 
            cnt = cnt - 1; 
        } 
    } 
} 
/* ¸Þ´º ¸Ç À§·Î ÀÌµ¿ */ 
function fnMenuMoveStart(oMenu) { 
    var i=0; 
    var len = oMenu.length; 
    var cnt = 0; 
    for (i=0; i<oMenu.length; i++) { 
    if (Menulist_isSelected(oMenu, i)) { 
        if (i==0) return; 
        var idx = i; 

        for (j=idx;j>cnt;j--) { 
            Menulist_upMenu(oMenu, idx); 
            idx = idx - 1; 
        } 
        cnt = cnt + 1; 
        } 
    } 
} 
/* ¸Þ´º À§·Î ÀÌµ¿ */ 
function fnMenuMoveUp(oMenu) { 
    var i=0; 
    for (i=0; i<oMenu.length; i++) { 
        if (Menulist_isSelected(oMenu, i)) { 
            if (i==0) return; 
            Menulist_upMenu(oMenu, i); 
        } 
    } 
} 
/* ¸Þ´º ¾Æ·¡·Î ÀÌµ¿ */ 
function fnMenuMoveDown(oMenu) { 
    var i=0; 
    for (i=oMenu.length-1; i>=0; i--) { 
        if (Menulist_isSelected(oMenu, i)) { 
            if (i==oMenu.length-1) return; 
            Menulist_downMenu(oMenu, i); 
        } 
    } 
} 

/* °ªÀ» »èÁ¦ */
function fnMenuDelete(oMenu) {  	
	var sel_len=0;
	for(var i =0, j = oMenu.options.length;i<j;i++)
		if(oMenu.options[i].selected==true)
			sel_len++;
	if(oMenu.options.selectedIndex >= 0){
		fnMenuMoveEnd(oMenu);
		for(i=0,j=sel_len;i<j;i++)
			oMenu.options.length--;    
	}
} 

/* °ªÀ» ÀÔ·Â */
function fnMenuInsert(oMenu,val) {  
	if(val){
		oMenu.length=oMenu.length+1;
		oMenu.options[length].text=val;
		oMenu.options[length].value=val;
	}
} 


function Menulist_downMenu(oMenu, index) { 
    if (index < 0) return; 
    if (index == oMenu.length-1) { 
        return; // ´õ ÀÌ»ó ¾Æ·¡·Î ÀÌµ¿ÇÒ ¼ö ¾øÀ»¶§ 
    } 
    Menulist_moveMenu(oMenu, index, 1); 
} 

function Menulist_upMenu(oMenu, index) { 
    if (index < 0) return; 
    if (index == 0) { 
        return; // ´õ ÀÌ»ó À§·Î ÀÌµ¿ÇÒ ¼ö ¾øÀ»¶§ 
    } 
    Menulist_downMenu(oMenu, index-1); 
} 

function Menulist_isSelected(oMenu, idx) { 
    return (oMenu.options[idx].selected==true); 
} 
function Menulist_moveMenu(oMenu, index, distance) { 
    var tmpOption = new Option(oMenu.options[index].text, oMenu.options[index].value, false, 
    oMenu.options[index].selected); 
    for (var i=index; i<index+distance; i++) { 
        oMenu.options[i].text = oMenu.options[i+1].text; 
        oMenu.options[i].value = oMenu.options[i+1].value; 
        oMenu.options[i].selected = oMenu.options[i+1].selected; 
    } 
    oMenu.options[index+distance] = tmpOption; 
}  

//¼ýÀÚ ¾Æ´Ñ°ªÀ» ¼ýÀÚ·Î ¹Ù²Ù´Â ½ºÅ©¸³Æ®
function onlyDigit(el) {
		el.value = el.value.replace(/\D/g,'');
}

//»õÃ¢À» ¶ç¿ì´Â ÇÔ¼ö
function win_open(val,x,y,left,top){//»õ Ã¢À» ¶ç¿ì´Â ÇÔ¼ö
		//»õÃ¢ÀÇ Å©±â
		cw=x;
		ch=y;

		//½ºÅ©¸°ÀÇ Å©±â
		sw=screen.availWidth;
		sh=screen.availHeight;

		//¿­ Ã¢ÀÇ Æ÷Áö¼Ç
		if(!left)
			px=(sw-cw)/2;
		else
			px=Number(left)+20;
		if(!top)
			py=(sh-ch)/2;
		else
			py=Number(top)+20; 

		//Ã¢À» ¿©´ÂºÎºÐ
		window.open(val,'','left='+px+',top='+py+',width='+cw+',height='+ch+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
}

//## ÀÌ¹ÌÁö Ã¼Å© :: ie Àü¿ë ##
var checkImages = function(el, image) {
	if(document.all) {
		var imgs = el.getElementsByTagName("IMG");
		for(var i=0; i<imgs.length; i++) {
			imgs[i].onerror = function() {
				var obj = event.srcElement;
				obj.src = image ? image : domain+"images/no_thumb_goods.gif";
			}
		}
	}
}

//## flash object Ã³¸® ##
var flashDraw = function(i,s,w,h,t) {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width="+w+" height="+h+" id="+i+"><param name=wmode value="+t+" /><param name=allowScriptAccess value=sameDomain /><param name=movie value="+s+" /><param name=quality value=high /><param name=menu value=false /><param name=loop value=false /><embed src="+s+" name="+i+" quality=high wmode="+t+" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" width="+w+" height="+h+" allowScriptAccess=sameDomain loop=false menu=false></object>");
}

//## Ä«Å×°í¸® Ã³¸® ##
var changeCategory = function(from, to, val, extra1, extra2) {
	if(from.value==='') {
		to.options.length = 1;
		to.value = '';
	} else {
		var url = domain+"include/changeCategory.html?cVal="+ from.value +"&tObj="+ to.name;
		var myRequest = new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				if(!transport.responseText.match(null)) {
					var optionsData = transport.responseXML.getElementsByTagName('options')[0];
					var option = optionsData.getElementsByTagName("option");
					to.options.length = 1;
					to.value = '';
					var optgroups = to.getElementsByTagName("optgroup");
					for(var i=parseInt(optgroups.length); i>0; i--) to.removeChild(optgroups[i-1]);
					for(var i=0; i<option.length; i++) {
						if(option[i].getAttribute("optgroup")!=null) {
							var newOptgroup = document.createElement("optgroup");
							newOptgroup.style.color = "#565656";
							newOptgroup.style.backgroundColor = "#EEEEEE";
							newOptgroup.setAttribute("label", option[i].getAttribute("label"));
							to.appendChild(newOptgroup);
						} else {
							var newOption = document.createElement("option");
							newOption.setAttribute("value", option[i].getAttribute("value"));
							if(val == option[i].getAttribute("value")) newOption.setAttribute("selected", "selected");
							newOption.innerHTML = option[i].firstChild.nodeValue;
							to.appendChild(newOption);
						}
					}
				}
				myRequest = null;
			}
		});
	}
	for(var i=1; i<=2; i++) {
		var extra = eval('extra'+i);
		if(extra==null) break;
		extra.options.length = 1;
		extra.value = '';
	}
}

//##################################################################################
//## ¹è³Ê
//##################################################################################
var BANNER = function() {
	this.name = null;
	this.roller = null;
	this.mode = null;
	this.rolling = false;					// ±×·ì¹è³ÊÀÇ ·Ñ¸µ¿©ºÎ - false ÀÌ¸é ·£´ýÀ¸·Î ÇÏ³ª¸¸ ³ëÃâ
	this.width = '';							// °¡·Î
	this.height = '';						// ¼¼·Î
	this.direction = 1;						// ¹æÇâ
	this.move_gap = 1;					// ¿òÁ÷ÀÌ´Â ÇÈ¼¿´ÜÀ§ 
	this.time_delay = 1;					// ¿òÁ÷ÀÌ´Â Å¸ÀÓµô·¹ÀÌ 
	this.time_delay_pause = 1000;	// ¹è³Ê´ç ¸ØÃâ Å¸ÀÓµô·¹ÀÌ
	this.parentClassName = '';			// ºÎ¸ð¿¡ Àû¿ëÇÒ Å¬·¡½º ÀÌ¸§
	this.childlCassName = '';			// ÀÚ½Ä¿¡ Àû¿ëÇÒ Å¬·¡½º ÀÌ¸§
	this.margin = "0 0 8 0px";			// ¿©¹é( »ó ¿ì ÇÏ ÁÂ )
	this.base_path = domain+"RAD/PEG/"; // ÀÌ¹ÌÁö ±âº»°æ·Î
	this.bindings = new Object;
	this.banners = new Array;
}
//## ¹è³Ê °¡Á®¿À±â
BANNER.prototype.getBanner = function(position) {
	var classObj = this;
	var myRequest = new Ajax.Request(domain+"rankup_module/rankup_banner/get_banner.html?mode=listing&position="+position, {
		method: 'get',
		onSuccess: function(transport) {
			if(!transport.responseText.match(null)) {
				var listData = transport.responseXML.getElementsByTagName('lists')[0];
				classObj.bindings = listData.getElementsByTagName('binding');
				classObj.formalize();
			}
			myRequest = null;
		}
	});
}
//## ¹è³Ê µî·Ï
BANNER.prototype.formalize = function() {
	var group = 1;
	for(var i=0; i<this.bindings.length; i++) {
		var banner = this.bindings[i];
		var bind = banner.getAttribute('bind');
		var items = banner.getElementsByTagName('list');
		for(var j=0; j<items.length; j++) {
			var item = items[j];
			var target = item.getElementsByTagName('target')[0].firstChild.nodeValue;
			var type = item.getElementsByTagName('type')[0].firstChild.nodeValue;
			var content = item.getElementsByTagName('content')[0].firstChild.nodeValue;
			if(type=="image") {
				var address = item.getElementsByTagName('address')[0].firstChild.nodeValue;
				var width = (this.width) ? "width='" + this.width + "'" : '';
				var height = (this.height) ? "height='" + this.height + "'" : '';
				content = "<a href='http://"+address+"' target='"+target+"'><img src='"+this.base_path+content+"' "+width+" border='0'></a>";
			}
			else if(type=='flash') {
				var width = item.getElementsByTagName('width')[0].firstChild.nodeValue;
				var height = item.getElementsByTagName('height')[0].firstChild.nodeValue;
				content = "<embed src='"+this.base_path+content+"' width='"+width+"' height='"+height+"' border='0'></embed>";
			}
			this.add(group, content, bind);
			if(bind=='no') group++;
		}
		group++;
	}
	this.view();
}
//## ¹è³Ê Ãß°¡
BANNER.prototype.add = function(group, item, bind) {
	if(this.banners.length<=group) {
		this.banners[group] = new Array;
		this.banners[group]['bind'] = bind;
		this.banners[group]['item'] = new Array;
	}
	this.banners[group]['item'].push(item);
}
//## ¹è³Ê ³ëÃâ
BANNER.prototype.view = function() {
	for(var i=1; i<this.banners.length; i++) {
		var bind = this.banners[i]['bind'];
		var item = this.banners[i]['item'];
		var newBanner = document.createElement('DIV');
		if(this.rolling==true && bind=='yes') {
			newBanner.style.height = this.height;
			newBanner.style.overflow = "hidden";
		}
		newBanner.setAttribute('id', this.name+'_id'+i);
		newBanner.style.margin = this.margin;
		newBanner.className = this.parentClassName;
		if(this.rolling==true) {
			for(var j=0; j<item.length; j++) {
				var newItem = document.createElement('SPAN');
				if(bind=='yes') {
					newItem.style.height = this.height;
					newItem.style.overflow = "hidden";
				}
				newItem.className = this.childClassName;
				newItem.innerHTML = item[j];
				newBanner.appendChild(newItem);
			}
		} else {
			var suffleItem = item.shuffle(); // ¼¯±â
			var newItem = document.createElement('SPAN');
			newItem.className = this.childClassName;
			newItem.innerHTML = suffleItem[0];
			newBanner.appendChild(newItem);
		}
		$(this.name).appendChild(newBanner);
		if(this.rolling==true && bind=='yes' && item.length>1) this.roll(this.name+'_id'+i);
	}
	if(this.rolling==true && this.mode!=null && this.banners.length>1) this.roll(this.name);
}
//## ¹è³Ê ·Ñ¸µ
BANNER.prototype.roll = function(el) {
	this.roller = new js_rolling(el); 
	this.roller.set_direction(this.direction);
	this.roller.move_gap = this.move_gap;
	this.roller.time_dealy = this.time_delay;
	this.roller.time_dealy_pause = this.time_delay_pause;
	this.roller.start();
}
//## ¹è³Ê ½ºÅ©·Ñ ¹æÇâ ¼³Á¤
BANNER.prototype.direction = function(direction) {
	this.direction = direction;
}


//##################################################################################
//## ÆË¾÷
//##################################################################################
var POPUP = function() {
	this.mode = "divpop";		// ÆË¾÷¸ðµå{ divpop | winpop }
	this.items = new Object;
	this.popups = new Array;	// ÆË¾÷µ¥ÀÌÅÍ
	this.template = '';				// ÅÛÇÃ¸´
	this.cookies = '';				// ÄíÅ°Á¤º¸
}
//## ÆË¾÷ °¡Á®¿À±â
POPUP.prototype.getPopup = function() {
	var classObj = this;
	var myRequest = new Ajax.Request(domain+"rankup_module/rankup_popup/get_popup.html", {
		method: 'get',
		onSuccess: function(transport) {
			if(!transport.responseText.match(null)) {
				var popupData = transport.responseXML.getElementsByTagName('popupData')[0];
				classObj.items = popupData.getElementsByTagName('item');
				classObj.formalize();
			}
			myRequest = null;
		}
	});
}
//## ÆË¾÷ µî·Ï
POPUP.prototype.formalize = function() {
	for(var i=0; i<this.items.length; i++) {
		var item = this.items[i];
		var pNo = item.getAttribute("no");
		if(this.cookies.indexOf("popup_id"+pNo+"=checked")!=-1) continue;
		var pop = {
			no: item.getAttribute("no"),
			top: item.getElementsByTagName("top")[0].firstChild.data,
			left: item.getElementsByTagName("left")[0].firstChild.data,
			width: item.getElementsByTagName("width")[0].firstChild.data,
			height: item.getElementsByTagName("height")[0].firstChild.data,
			content: item.getElementsByTagName("content")[0].firstChild.data
		};
		this.popups.push(pop);
	}
	this.view();
}
//## ÆË¾÷ ³ëÃâ
POPUP.prototype.view = function() {
	if(!document.all) this.mode = "divpop"; // ÆÄÆø¿¡¼­´Â divpop À¸·Î °íÁ¤
	for(var i=0; i<this.popups.length; i++) {
		var pop = this.popups[i];
		switch(this.mode) {
			case "divpop":
				var divpop = document.createElement("DIV");
				divpop.setAttribute("id", "divpop_id"+pop.no);
				divpop.style.width = pop.width+"px";
				divpop.style.position = "absolute";
				divpop.style.top = pop.top+"px";
				divpop.style.left = pop.left+"px";
				divpop.style.zIndex = 200;
				divpop.style.display = "block";
				divpop.innerHTML = this.template.innerHTML;
				document.body.appendChild(divpop);
				var curPop = $("divpop_id"+pop.no);
				curPop.innerHTML = curPop.innerHTML.replace(/{:no:}/g, pop.no);
				var iframe = curPop.getElementsByTagName("iframe")[0];
				iframe.style.width = pop.width+"px";
				iframe.style.height = pop.height+"px";
				eval(iframe.name).document.write("<html>\n<head>\n<title>divPop</title>\n<link rel='stylesheet' type='text/css' href='../Libs/_style/rankup_style.css'>\n</head>\n<body>\n"+pop.content+"\n</body>\n</html>");
				break;
			case "winpop": // ÆÄÆø¿¡¼­´Â ¾ÈµÊ
				var content = this.template.innerHTML.replace(/{:no:}/g, pop.no);
				content = content.replace(/javascript:popup./, "javascript:");
				content = "<html>\n<head>\n<title>winPop</title>\n<link rel='stylesheet' type='text/css' href='../Libs/_style/rankup_style.css'>\n<script type='text/javascript'>var popup = opener.popup;var closeWin = function(no) { popup.closeWin(no , document.getElementsByTagName('input')[0].checked); window.close(); }</script>\n</head>\n<body style='margin:0px'>\n"+content+"\n</body>\n</html>";
				var winpop = window.open("about:blank", "winpop_id"+pop.no, "width="+(parseInt(pop.width)+8)+",height="+(parseInt(pop.height)+38)+",left="+pop.left+",top="+pop.top);
				winpop.document.write(content);
				winpop.document.getElementsByTagName("iframe")[0].parentNode.innerHTML = pop.content;
				break;
		}
	}
}
//## ÄíÅ°±Á±â
POPUP.prototype.setCookie = function(no, expiredays) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate()+expiredays);
	document.cookie = "popup_id"+no+"=checked; path=/; expires="+todayDate.toGMTString()+";"
}
//## ÆË¾÷Ã¢´Ý±â
POPUP.prototype.closeWin = function(no, check) {
	if(this.mode=="divpop") {
		var divPop = $("divpop_id"+no);
		if(divPop.getElementsByTagName("input")[0].checked) this.setCookie(no,1);
		divPop.style.visibility = "hidden";
	} else if(check) this.setCookie(no,1);
}
//## ÆË¾÷ ¼³Á¤
POPUP.prototype.initialize = function(template) {
	this.template = $(template);			// ÅÛÇÃ¸´
	this.cookies = document.cookie;		// ÄíÅ°·Îµå
	this.getPopup();
}
