//var domain = "http://"+document.domain+"/";
var historyBlank = domain+"Libs/_js/blank.html?";

// ºê¶ó¿ìÁ® Á¤º¸
var browser = {};
/MSIE ([0-9]{1,})\.?/.exec(navigator.userAgent);
browser.version = RegExp.$1;
browser.kind = navigator.userAgent.match(/MSIE/) ? "IE" : "GEKO";
//#################################################################################
//pngÀÌ¹ÌÁö »ç¿ëµÇ°Ô
var setPng24 = function(el, save) {
	if(el.src=="about:blank") return;
	if(browser.kind=="GEKO" || (browser.kind=="IE" && browser.version>6)) return;
	if(save!==false) el.setAttribute('default', el.src);

	el.style.height = '1px';
	el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+el.src+')';
	el.src = "about:blank";
}

//##################################################################################
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=1 /><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 = '';				// ÄíÅ°Á¤º¸
	this.baseTop = 0;
	this.baseLeft = 0;
	this.selTop = 0;
	this.selLeft = 0;
	this.tmpHeight = 0;
	this.move_on_off = 0; //ÀÌµ¿ È°¼º ºñÈ°¼ºÈ­
	this.move_div_obj = null;//ÀÌµ¿ÇÒ DIV 
	this.move_div_obj_before = null; //ÀÌÀü¿¡ ÀÌÀüÇÑ ¾ÆÀÌµð°ª
	this.move_x_margin = 0; //X °ª
	this.move_y_margin = 0;//Y °ª
}
//## ÆË¾÷ °¡Á®¿À±â
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.nodeValue,
			left: item.getElementsByTagName("left")[0].firstChild.nodeValue,
			width: item.getElementsByTagName("width")[0].firstChild.nodeValue,
			height: item.getElementsByTagName("height")[0].firstChild.nodeValue,
			content: item.getElementsByTagName("content")[0].firstChild.nodeValue
		};
		this.view(pop);
	}

}



POPUP.prototype.view = function(pop) {
	if(!document.all) this.mode = "divpop"; // ÆÄÆø¿¡¼­´Â divpop À¸·Î °íÁ¤
	switch(this.mode) {
		case "divpop":
			// ÅÛÇÃ¸´ º¹»ç
			var content = this.template.innerHTML.replace(/{:popup_id:}/g, "divpop_id"+pop.no).replace(/{:no:}/g, pop.no);
			new Insertion.After(this.template, "<div id='divpop_id"+pop.no+"'>"+content+"</div>");
			var divpop = $('divpop_id'+pop.no);
			divpop.setStyle({
				position: 'absolute',
				top: this.selTop+'px',
				left: this.selLeft+'px',
				width: pop.width+'px',
				height: pop.height+'px',
				zIndex: 200
			});
			// ÆË¾÷ ÄÁÅÙÃ÷ ÀÔ·Â
			try {
				var pop_obj = $("popup_content"+pop.no);
				var iframe = divpop.getElementsByTagName("iframe")[0];
				iframe.contentWindow.document.write(pop.content);
				pop_obj.innerHTML = iframe.contentWindow.document.body.innerHTML;
				if(pop.width) pop_obj.style.width = pop.width;
				if(pop.height) pop_obj.style.height = pop.height;
				this.calc_popup(divpop);
			}
			catch(e) {
				//alert(e.message);
			}
			break;

		case "winpop":
			// ¹Ì±¸Çö
			break;
	}
}
// ÆË¾÷ °è»ê
POPUP.prototype.calc_popup = function(divpop) {
	var content_x = divpop.getElementsByTagName("table")[0];
	var iframe_x = divpop.getElementsByTagName("iframe")[0];
	if(content_x.offsetWidth==0) {
		var classObj = this;
		return setTimeout(function() { classObj.calc_popup(divpop) }, 0);
	}
	divpop.setStyle({ top: this.selTop, left: this.selLeft }); // 2009.03.31 fixed

	// °¡·Î »çÀÌÁî¸¦ ¿À¹öÇÒ °æ¿ì, ¼¼·Î»çÀÌÁî°¡ Å«°ªÀ¸·Î °»½Å
	this.selLeft += content_x.offsetWidth-1;
	if(this.selLeft>document.body.offsetWidth) {
		divpop.style.top = this.selTop + this.tmpHeight-1;
		divpop.style.left = this.baseLeft;
		this.selLeft = this.baseLeft + content_x.offsetWidth-1;
		this.selTop += this.tmpHeight-1;
		this.tmpHeight = content_x.offsetHeight; // °»½Å
	}
	if(content_x.offsetHeight>this.tmpHeight) this.tmpHeight = content_x.offsetHeight;
	if(browser.kind=="IE") {
		iframe_x.style.width = content_x.offsetWidth;
		iframe_x.style.height = content_x.offsetHeight;
	}
	content_x.style.visibility = 'visible';
}

//ÀÌµ¿°ª ÃÊ±âÈ­
POPUP.prototype.div_move_check = function(onoff, ev, obj) {
	if(obj != undefined) this.move_div_obj = $(obj);
	if(this.move_div_obj == null) return false;
	if(this.move_div_obj_before == null) {
		this.move_div_obj_before = this.move_div_obj;
		this.move_div_obj.setStyle({zIndex: this.move_div_obj.getStyle('z-index') + 1});
	}
	else if(this.move_div_obj_before.id !== this.move_div_obj.id) {
		var before_zindex = this.move_div_obj_before.getStyle('z-index');
		var after_zindex = this.move_div_obj.style.zIndex;
		this.move_div_obj.setStyle({zIndex: before_zindex + 1});
		this.move_div_obj_before = this.move_div_obj;
	}
	if(onoff == 0) document.onselectstart = function() { return true };
	else {
		document.onselectstart = function() { return false };
		this.move_x_margin = Event.pointerX(ev?ev:event) - this.move_div_obj.offsetLeft;
		this.move_y_margin =  Event.pointerY(ev?ev:event) - this.move_div_obj.offsetTop;
	}
	this.move_on_off = onoff;
}
//Ã¢ÀÌµ¿
POPUP.prototype.div_move = function(ev) {
	if(this.move_on_off == 1) { 
		var x_result = Event.pointerX(ev?ev:event) - this.move_x_margin; 
		var y_result = Event.pointerY(ev?ev:event) - this.move_y_margin; 
		if(x_result > 0){this.move_div_obj.style.left = x_result;} 
		if(y_result > 0){this.move_div_obj.style.top =  y_result;} 
	}
}

//## ÄíÅ°±Á±â
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.hide();
	} else if(check) this.setCookie(no,1);
}
//## ÆË¾÷ ¼³Á¤
POPUP.prototype.initialize = function(template) {
	this.template = $(template);			// ÅÛÇÃ¸´
	this.cookies = document.cookie;		// ÄíÅ°·Îµå
	this.getPopup();
	var This = this;
	document.onmouseup= function (event) {
		This.div_move_check(0, event);
	}
	document.onmousemove = this.div_move.bind(this);
}

