function search_it(){
	document.form_search.submit();
	return true;
}

function _ID(obj){
	return document.getElementById(obj)
}

function get_objectTop(obj){
	if (obj.offsetParent == document.body) return obj.offsetTop;
	else return obj.offsetTop + get_objectTop(obj.offsetParent);
}

function get_objectLeft(obj){
	if (obj.offsetParent == document.body) return obj.offsetLeft;
	else return obj.offsetLeft + get_objectLeft(obj.offsetParent);
}



function onlynumber()
{
	var e = event.keyCode;
	window.status = e;
	if (e>=48 && e<=57) return;
	if (e>=96 && e<=105) return;
	if (e>=37 && e<=40) return;
	if (e==8 || e==13 || e==46) return;
	event.returnValue = false;
}



function setDate(obj,from,to)
{
	var obj = document.getElementsByName(obj);
	obj[0].value = (from) ? from : "";
	obj[1].value = (from) ? to : "";
}

/**
 * Calendar Script
 *
 * @author	mirrh (imirrh@gmail.com)
 * @date	2006.01.22
 * @usage	<input type=text onclick="calendar()" format="%Y-%m-%d">
 */

var calObjdoc;
var calInput;

function calendar_init()
{
	var date = new Date;
	var year = date.getYear();
	var month = date.getMonth();

	var calStyle = "\
	<style>\
	body {margin:0}\
	select {font:8pt tahoma}\
	a {text-decoration:none;color:#000000}\
	.tahoma {font:8pt tahoma}\
	.white {color:#ffffff}\
	.today {font-weight:bold;color:#ff0000}\
	</style>\
	";

	var calLayout = "\
	<form name=frmCalendar style='display:inline'>\
	<table width=200 cellpadding=0 cellspacing=0><tr><td style='border:2 solid #323232'>\
	<table width=196 cellpadding=0 cellspacing=0>\
	<tr>\
		<td bgcolor=#000000 style='padding:0 9;border-bottom:2 solid #323232'>\
		<table width=100% cellpadding=0 cellspacing=0 class=tahoma>\
		<tr>\
			<td width=30><font color=#ffffff onClick='parent.calendar_move(-1)' style='cursor:pointer'>¢¸</font></td>\
			<td align=center>\
			<select name=year onChange=parent.calendar_update()></select>\
			<select name=month onChange=parent.calendar_update()></select>\
			</td>\
			<td width=30 align=right><font color=#ffffff onClick='parent.calendar_move(1)' style='cursor:pointer'>¢º</font></td>\
		</tr>\
		</table>\
		</td>\
	</tr>\
	<tr>\
		<td height=122 valign=top>\
		<table width=100% id=calInner class=tahoma>\
		<tr><th style='color:red'>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th style='color:blue'>S</th></tr>\
		<col align=center span=7>\
		</table>\
		</td>\
	</tr>\
	<tr>\
		<td bgcolor=#000000>\
		<table width=100% class=tahoma>\
		<tr>\
			<td><a href='javascript:parent.calendar_update(" + year + "," + month + ")' onfocus=blur() class=white>\
			<b>now</b> (" + year + "-" + parent.calendar_addZero(month+1) + ")\
			</a></td>\
			<td align=right><a href='javascript:parent.calendar_close()' class=white>close</a></td>\
		</tr>\
		</table>\
		</td>\
	</tr>\
	</table>\
	</td></tr></table>\
	</form>\
	";


	var ifrm = document.createElement("iframe");
	ifrm.id = "calObj";
	ifrm.frameBorder = 0;
	with (ifrm.style){
		position	= "absolute";
		left		= "-999px";
		background	= "#ffffff";
		width		= "200px";
		height		= "166px";
		//z-index	= "999";
	}
	document.body.appendChild(ifrm);

	calObjdoc = document.getElementById('calObj').contentWindow.document;
	calObjdoc.open();
	calObjdoc.write(calStyle);
	calObjdoc.write(calLayout);
	calObjdoc.close();

	calendar_setup();
}

function calendar_setup()
{
	var objMonth = calObjdoc.frmCalendar.month;
	for (i=0;i<12;i++) objMonth.options[i] = new Option(i+1+"¿ù",i);

	var date = new Date;
	var year = date.getYear();
	var month = date.getMonth();
	calendar_update(year,month);
}

function calendar_update(year,month)
{
	if (isNaN(year)){
		year = calObjdoc.frmCalendar.year.value;
		month = calObjdoc.frmCalendar.month.value;
	}

	year = parseInt(year);

	var objYear = calObjdoc.frmCalendar.year;
	var objMonth = calObjdoc.frmCalendar.month;

	for (i=0;i<5;i++) objYear.options[i] = new Option(year+i-2+"³â",year+i-2);
	objYear.selectedIndex = 2;
	objMonth.selectedIndex = month;

	calendar_inner(year,month);
}

function calendar_inner(year,month)
{
	var date = new Date;
	var Y = date.getYear();
	var m = date.getMonth();
	var d = date.getDate();

	var firstDay = new Date(year,month);
	firstDay = firstDay.getDay();
	var lastDay = calendar_lastDay(year,month);

	var obj = calObjdoc.getElementById('calInner');

	for (i=obj.rows.length;i>1;i--) obj.deleteRow(i-1);

	oTr = obj.insertRow();
	for (i=0;i<firstDay;i++) oTr.insertCell();
	cnt = i;

	for (i=1;i<=lastDay;i++){
		if (cnt++%7==0) oTr = obj.insertRow();
		oTd = oTr.insertCell();
		oTd.style.cursor = "pointer";
		oTd.style.backgroundColor = "#f7f7f7";
		oTd.color = "#000000";
		if (Y==year && m==month && d==i){
			oTd.color = "#ff0000";
			oTd.style.fontWeight = "bold";
		}
		oTd.innerText = i;
		oTd.style.color = oTd.color;
		oTd.onmouseover = function(){this.style.backgroundColor = "#316AC5"; this.style.color = "#ffffff"}
		oTd.onmouseout = function(){this.style.backgroundColor = "#f7f7f7"; this.style.color = this.color}
		oTd.onclick = function(){
									//alert(this.innerText);parent.calendar_print(this.innerText)
									var year	= calObjdoc.frmCalendar.year.value;
									var month	= calObjdoc.frmCalendar.month.value;
									var day		= this.innerText;
									calInput.value = calendar_format(year,month,day);
									calendar_close();
								}
	}
	//document.getElementById('calObj').height = calObjdoc.body.scrollHeight;
}

function calendar_move(idx)
{
	var year = calObjdoc.frmCalendar.year.value;
	var month = parseInt(calObjdoc.frmCalendar.month.value) + idx;

	if (month<0){ year--; month=11; }
	if (month==12){ year++; month=0; }
	calendar_update(year,month);
}

function calendar()
{
	if (!_ID('calObj')) calendar_init();

	calInput = event.srcElement;

	var xpos = calendar_get_objectLeft(calInput);
	var ypos = calendar_get_objectTop(calInput) + calInput.offsetHeight + 2;

	var calObj = document.getElementById('calObj');
	calObj.style.pixelLeft = xpos;
	calObj.style.pixelTop = ypos;
	calObj.style.display = "block";
}

function calendar_print(day)
{
	alert('aa');
	var year = calObjdoc.frmCalendar.year.value;
	var month = calObjdoc.frmCalendar.month.value;

	calInput.value = calendar_format(year,month,day);
	calendar_close();
}

function calendar_format(year,month,day)
{
	month++;
	var format = (calInput.getAttribute("format")!=null) ? calInput.format : "%Y%m%d";

	var Y = year;
	var y = year.substr(2,2);
	var m = calendar_addZero(month);
	var d = calendar_addZero(day);

	format = format.replace(/%Y/g, Y);
	format = format.replace(/%y/g, y);
	format = format.replace(/%m/g, m);
	format = format.replace(/%d/g, d);

	return format;
}

function calendar_close()
{
	var calObj = document.getElementById('calObj');
	calObj.style.display = "none";
}

function calendar_addZero(str){
	return ((str < 10) ? "0" : "") + str;
}

function calendar_lastDay(year,month){
	var leap;
	var last = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (year%4==0)		leap = true;
	if (year%100==0)	leap = false;
	if (year%400==0)	leap = true;
	if (leap) last[1] = 29;
	return last[month];
}

function calendar_get_objectTop(obj){
	if (obj.offsetParent == document.body) return obj.offsetTop;
	else return obj.offsetTop + get_objectTop(obj.offsetParent);
}

function calendar_get_objectLeft(obj){
	if (obj.offsetParent == document.body) return obj.offsetLeft;
	else return obj.offsetLeft + get_objectLeft(obj.offsetParent);
}
function auto_cal(mall_no) {

	// ¹«Á¶°Ç Àú°¡ÆùÀ¸·Î ÀÎ½ÄÀ» ¿øÇÒ°æ¿ì °í°¡ ±âÁØ¾×À» 9999999999 À¸·Î
	// ½Ã°¡ÆùÀ» ¾È¾µ°æ¿ì ½Ã°¡ ±âÁØ¾×À» °í°¡ ±âÁØ¾×À¸·Î Á¤ÀÇÇØ¾ßÇÔ
	// ¹«Á¶°Ç °í°¡ÆùÀ¸·Î ÀÎ½ÄÀ» ¿øÇÒ°æ¿ì °í°¡ ±âÁØ¾×À» 0À¸·Î

	var price_net = Number(document.frm.price_net.value);		//°ø±Þ°¡°Ý
	var price_margin = Number(document.frm.price_margin.value);	//ÆÇ¸Å¸¶Áø
	
	if(document.frm.mall_no.length == undefined){
		if(document.frm.auto_price.checked == true || document.frm.all_auto_price.checked == true){
			var base_price = Number(document.frm.low_price.value); // ÃÖÀú°¡
			var low_fee = Number(document.frm.low_pro.value); // Àú°¡¼ö¼ö·á
			
			var middle_price = Number(document.frm.normal_price.value); // ½Ã°¡±âÁØ°ª
			var middle_fee = Number(document.frm.normal_pro.value); // ½Ã°¡¼ö¼ö·á

			var high_price = Number(document.frm.high_price.value); // °í°¡±âÁØ°ª
			var high_fee = Number(document.frm.high_pro.value); // °í°¡¼ö¼ö·á
			
			var high_ext = Number(document.frm.add_price.value); // Ãß°¡¼ö¼ö·á

			var price_imsi = price_net + price_margin;

			if( price_imsi >= high_price ) { //°í°¡ÆùÀ¸·Î ÀÎ½Ä
				add_total	= (price_net + price_margin + high_ext) / 100 * high_fee;
			}else {
				if(middle_price > price_imsi){//Àú°¡ÆùÀ¸·Î ÀÎ½Ä
					add_total	=	low_fee;
				}else{//½Ã°¡ÆùÀ¸·Î ÀÎ½Ä
					add_total	=	middle_fee ;
				}
			}
			total_price	= price_imsi + add_total + high_ext;

			var total_price = Math.round(total_price/1000)*1000;
			if (total_price < base_price) { 
				var total_price = base_price; 
			}
			document.frm.sell_price.value= total_price;
		}
	}else{
		if(document.frm.auto_price[mall_no].checked == true || document.frm.all_auto_price.checked == true){

			var base_price = Number(document.frm.low_price[mall_no].value); // ÃÖÀú°¡
			var low_fee = Number(document.frm.low_pro[mall_no].value); // Àú°¡¼ö¼ö·á
			
			var middle_price = Number(document.frm.normal_price[mall_no].value); // ½Ã°¡±âÁØ°ª
			var middle_fee = Number(document.frm.normal_pro[mall_no].value); // ½Ã°¡¼ö¼ö·á

			var high_price = Number(document.frm.high_price[mall_no].value); // °í°¡±âÁØ°ª
			var high_fee = Number(document.frm.high_pro[mall_no].value); // °í°¡¼ö¼ö·á
			
			var high_ext = Number(document.frm.add_price[mall_no].value); // Ãß°¡¼ö¼ö·á

			var price_imsi = price_net + price_margin;

			if( price_imsi >= high_price ) { //°í°¡ÆùÀ¸·Î ÀÎ½Ä
				add_total	= (price_net + price_margin + high_ext) / 100 * high_fee;
			}else {
				if(middle_price > price_imsi){//Àú°¡ÆùÀ¸·Î ÀÎ½Ä
					add_total	=	low_fee;
				}else{//½Ã°¡ÆùÀ¸·Î ÀÎ½Ä
					add_total	=	middle_fee ;
				}
			}
			total_price	= price_imsi + add_total + high_ext;

			var total_price = Math.round(total_price/1000)*1000;
			if (total_price < base_price) { 
				var total_price = base_price; 
			}
			document.frm.sell_price[mall_no].value= total_price;
		}
	}
}

function all_check(){
	form = document.frm;
	ch_length	= document.frm.mall_no.length;

	if(ch_length == undefined){
		if(form.elements['mall_number'].checked == true){
			document.frm.auto_price0.checked = true;
			auto_cal(0);
		}
	}else{
		for(i = 0; i < ch_length; i++) {
			if(form.elements['mall_number'][i].checked == true){
				form.elements['auto_price'+i].checked = true;
				auto_cal(i);
			}
		}
	}
}


function auto_cal_1(mall_no,this_name){
	if(document.getElementById(this_name).checked == true){
		auto_cal(mall_no);
	}
}

function all_check_color(){
	form = document.frm;
	ch_length	= document.frm.mall_no.length;

	if(ch_length == undefined){
		if(form.elements['mall_number'].checked == true){
			document.frm.color.value = document.frm.t_color.value;
		}
	}else{
		for(i = 0; i < ch_length; i++) {
			if(form.elements['mall_number'][i].checked == true){
				form.elements['color'][i].value = document.frm.t_color.value;
			}
		}
	}
}

function all_check_tgcode(){
	/*
	form = document.frm;
	ch_length	= document.frm.mall_no.length;

	if(ch_length == undefined){
		if(form.elements['mall_number'].checked == true){
			document.frm.tg_code.value = document.frm.t_tg_code.value;
		}
	}else{
		for(i = 0; i < ch_length; i++) {
			if(form.elements['mall_number'][i].checked == true){
				form.elements['tg_code'][i].value = document.frm.t_tg_code.value;
			}
		}
	}
	*/
	var group_no_value = document.frm.tg_sort.value;

	for(z=0;z<document.frm.elements.length;z++){
		var group_no_nm = 'tg_code_id'+group_no_value;
		if(document.frm.elements[z].id == group_no_nm){
			document.frm.elements[z].value= document.frm.t_tg_code.value;
		}
	}
}

function all_mall(ch_name){
	form = document.frm;
	var ch_length = form.elements['mall_number'].length;
	if(document.getElementById(ch_name).checked == true){
		val = true;
	}else{
		val = false;
	}

	if(ch_length == undefined){
		form.elements['mall_number'].checked = val;
	}else{
		for(i = 0; i < ch_length; i++) {
			form.elements['mall_number'][i].checked = val;
		}
	}
}
function progress_edit(){
	form = document.frm;
	var ch_length = form.elements['mall_number'].length;

	ch_val	= document.frm.t_progress.value;

	if(ch_length == undefined){
		if(form.elements['mall_number'].checked == true){
			form.elements['progress'].value = ch_val;
		}
	}else{
		for(i = 0; i < ch_length; i++) {
			if(form.elements['mall_number'][i].checked == true){
				form.elements['progress'][i].value = ch_val;
			}
		}
	}

}


