function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable, h)
{
	var toolbar_str		= toolbar ? 'yes' : 'no';
	var menubar_str		= menubar ? 'yes' : 'no';
	var statusbar_str	= 'yes';//statusbar ? 'yes' : 'no'
	var scrollbar_str		= scrollbar ? 'yes' : 'no';
	var resizable_str	= resizable ? 'yes' : 'no';
  
	if(h == "h") {
		left = screen.width - width - 10;
	} else if(h == "c") {
		left = screen.width / 2 - (width / 2);
		top = screen.height / 2 - (height / 2);
	} else if(h=='rightdown') {
		left = screen.width - width - 10;
		top = screen.height - height - 100;
	}

	var WIN = window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);

	if(name.substring(0,2) != 'H_') WIN.focus();

	return WIN;
}

function open_modeless(name, url, left, top, width, height, scroll, align)
{
	//dialogHeight: 360px; dialogWidth: 876px; dialogTop: 292px; dialogLeft: 841px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes

	if(align == 'left') {
		var left = 0;
	}
	else if(align == 'right') {
		var left = screen.width - width;
	}
	else(align == 'center')
	{
		var left = screen.width / 2 - (width / 2);
		var top = screen.height / 2 - (height / 2);
	}


	var style = '';
	 style += 'dialogLeft: ' + (left ? left : 0) + 'px;';
	 style += 'dialogTop: ' + (top ? top : 0) + 'px;';
	 style += 'dialogWidth: ' + width + 'px;';
	 style += 'dialogHeight: ' + height + 'px;';
	 style += 'scroll: ' + scroll + ';';
	 style +='edge:Raised; center:Yes; help:No; resizable:No; status:No;';


	return window.showModelessDialog(url, name, style);
}

function open_modal(name, url, left, top, width, height, scroll, align)
{
	//dialogHeight: 360px; dialogWidth: 876px; dialogTop: 292px; dialogLeft: 841px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes

	if(align == 'left') {
		var left = 0;
	}
	else if(align == 'right') {
		var left = screen.width - width;
	}
	else(align == 'center')
	{
		var left = screen.width / 2 - (width / 2);
		var top = screen.height / 2 - (height / 2);
	}


	var style = '';
	 style += 'dialogLeft: ' + (left ? left : 0) + 'px;';
	 style += 'dialogTop: ' + (top ? top : 0) + 'px;';
	 style += 'dialogWidth: ' + width + 'px;';
	 style += 'dialogHeight: ' + height + 'px;';
	 style += 'scroll: ' + scroll + ';';
	 style +='edge:Raised; center:Yes; help:No; resizable:No; status:No;';

	return window.showModalDialog(url, name, style);
}

function check_all(T,form,target)//Ã¼Å©¹Ú½º ¿ÃÃ¼Å©
{
	if(form.substring(0,2) == 'ID') {
		var E = document.all(target);
	} else {
		var F = eval("document."+form);
		var E = F.elements[target];
	}
	if(E)
	{
		if(E.length>=2)
		{
			if(T)
			{
				for (var i=0 ; i < E.length ; i++)
				{
					if(E[i].disabled==false) E[i].checked=T.checked;
				}
			}
			else
			{
				if(E[0].checked==true)		var chk = false;
				else									var chk = true;

				for (var i=0 ; i < E.length ; i++)
				{
					E[i].checked = chk;
				}
			}		
		}
		else
		{
			if(T)
			{
				var chk = T.checked;
			}
			else
			{
				if(E.checked==true)	var chk = false;
				else							var chk = true;
			}
			E.checked = chk;
		}
	}
}

function number_format(num) 
{
	if(num)
	{
		var num
		tmp = "";
		retStr = "";
		argStr = String(num);
	
		for(var i = 0 ; i < argStr.length ; i++) 
		{
			if(argStr.charAt(i) == '.')	return argStr;
			if(i % 3 == 0)				tmp += ',';
			
			tmp += argStr.charAt(argStr.length - i - 1);
		}
				  
		for(i= 0; i < tmp.length - 1; i++) 
		{
			retStr += tmp.charAt(tmp.length - i - 1);
		}
				
		argStr = retStr;
		return argStr;
	}
	else
	{
		return '';
	}
}

function Comma_replace(Str)
{
	if(Str) {
		while(Str.search(',') > 0) {
			Str = Str.replace(',','');
		}
		return parseInt(Str);
	} else {
		return 0;
	}
}

function go(URL)
{
	alert(URL);
	location = URL;
}

function File_download(user_code, query)
{
//	alert('현재 작업중이므로 다운로드 할 수 없습니다. 관리자에게 문의하세요');
	layer_iframe(0, 0, 'http://www.toolnshop.co.kr/download.php?user_num='+user_code+'&'+query, 'center');
	document.getElementById('SP_layer').removeNode(true);
}



function SelectBox_Search(T, name)
{
	if(document.getElementById('SelectBox_Layer')) {
		return false;
	}

	var _Layer = Create_layer('SelectBox_Layer');
	_Layer.style.top = 20;
	_Layer.style.left = 0;
	document.getElementById('SBL_'+name).appendChild(_Layer);
	_Layer.innerHTML = "<div style='position:absolute;left:0;top:0;'><iframe id='SBL_iframe' name='SBL_iframe' width='200' height='21' src='/blank.php' frameborder='0' scrolling='no'></iframe></div>";
	SBL_iframe.document.write("<body style='margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;'><input type='text' name='SBL_keyword' size='5' onkeyup=\"return parent.SelectBox_Search2(this.value, '"+name+"')\" style='font-size:9pt;width:200;height:20;background:#FFCCCC;color:blue;border-style:solid;border-width:1;border-color:red;'><div id='SBL_SearchLayer'></div></body>");

	SBL_iframe.document.getElementById('SBL_keyword').focus();
}
function SelectBox_Search2(keyword, name)
{
	if(SBL_iframe.event.keyCode == 38)
	{
		var Table = SBL_iframe.document.getElementById('SBL_SearchTable');
		var i = parseInt(Table.i) - 1;

		if(i >= 0) {
			if(i > 0) {
			Table.rows[i].cells[0].style.borderColor = '#FF3300';
			Table.rows[i].cells[0].style.background = '#FFD8B0';
			}
	
			Table.rows[i-1].cells[0].style.borderColor = '#0000FF';
			Table.rows[i-1].cells[0].style.background = '#FFFFCC';

			Table.i = i;
			Table.index = Table.rows[i-1].index;
		}
	}
	else if(SBL_iframe.event.keyCode == 40)
	{
		var Table = SBL_iframe.document.getElementById('SBL_SearchTable');
		var i = parseInt(Table.i) + 1;

		if(Table.rows.length >= i) {
			if(Table.i >= 1) {
			Table.rows[i-2].cells[0].style.borderColor = '#FF3300';
			Table.rows[i-2].cells[0].style.background = '#FFD8B0';
			}
	
			Table.rows[i-1].cells[0].style.borderColor = '#0000FF';
			Table.rows[i-1].cells[0].style.background = '#FFFFCC';

			Table.i = i;
			Table.index = Table.rows[i-1].index;
		}
	}
	else if(SBL_iframe.event.keyCode != 13)
	{
		if(keyword) {
			var Sel = document.getElementById(name);
			keyword = keyword.toLowerCase();
			var keyword2 = keyword.toUpperCase();

			var Arr = Array();
			var ii = 0;
			for(var i = 0 ; Sel.length > i ; i++) {
				if(Sel.options[i].text.match(keyword) || Sel.options[i].text.match(keyword2)) {
					Arr[ii] = i+'|'+Sel.options[i].text;
					ii++;
				}
			}

			var Table = "<table id='SBL_SearchTable' i='0' index='0' style='font-family:Tahoma;font-size:9pt;border-style:solid;border-width:1;border-color:#FF00FF;' width='100%' border='0' cellpadding='1' cellspacing='1'>"
			var sp;
			var i = 0;
			while(Arr.length > i) {
				sp = Arr[i].split('|');

				Table += "<tr height='21' index='"+sp[0]+"'><td onclick=\"alert(this.index);\" style='border-style:solid;border-width:1;border-color:#FF3300;background:#FFD8B0;cursor:hand;'>";
				Table += '&nbsp;'+sp[1];
				Table += "</td></tr>";

				i++;
			}
			Table += "</table>";
			document.getElementById('SBL_iframe').height = (Arr.length+1) * 22 + 3;
			SBL_iframe.document.getElementById('SBL_SearchLayer').innerHTML = Table;
		}
	}
	else
	{
		var Table = SBL_iframe.document.getElementById('SBL_SearchTable');
		var Sel = document.getElementById(name);
		var index = Table.index>0 ? Table.index : Table.rows[0].index;
		Sel.selectedIndex = index;
		if(Sel.onchange) Sel.onchange();
		SelectBox_None();
	}
	return false;
}
function SelectBox_None()
{
	if(document.getElementById('SelectBox_Layer')) {
		document.getElementById('SelectBox_Layer').removeNode(true);
	}
}


//쿠키 관련 함수
function Cookie_Set(Name, Value, Expire)
{ 
/*
	60000 = 1분
	3600000 = 1시간
*/
	var C = Name + '=' + escape(Value) + '; path=/;';

	if(Expire > 0) {
		var todayDate = new Date();
		todayDate.setTime(todayDate.getTime() + Expire);
		C += 'expires=' + todayDate.toGMTString() + ';';
	}

	document.cookie = C;
} 

// 쿠키 버리기 
function Cookie_Del(Name)
{ 
	if(document.cookie != '') { 

		var cookie_arr = document.cookie.split("; ");
		var expireDate = new Date();
		expireDate.setDate(expireDate.getDate()-1);

		var cookie_name='';
		for (var i=0  ; i < cookie_arr.length ; i++) {
			cookie_name = cookie_arr[i].split('=');
			if(cookie_name[0] == Name) {
				document.cookie = Name + '=; path=/; expires=' + expireDate.toGMTString();
			}
		}
	}
} 

function Login(user_num, guest)
{
	if(parseInt(user_num) > 0) {
		return 'Success';
	} else {
		var Re = open_modal('Login', '/Etc/Login/?guest='+(guest?guest:''), 100, 100, 690, 344, 0);
	
		if(Re=='join')
			location = '/User/User_join/';
		else if(Re=='search')
			location = '/User/SearchIDPW/';
	
		return Re;
	}
}

function Go_Banner(code)
{
	var Url = HTTP_SEND('/Etc/go/banner/', 'code='+code, 'TEXT');
	location = Url;
}

function Str_byte(msg)
{
	var byte = 0;
	var str = '';

	for(var i=0 ; i<msg.length ; i++) {
		str = msg.charAt(i);
		if(escape(str).length > 4)
			byte = byte + 2;
		else
			byte = byte + 1;
	}

	return byte;
}

function Cursor_move(input, i)
{
	try
	{
		var input = F.elements[input];
		if(event.keyCode==40)			input[i+1].focus();
		else if(event.keyCode==38) 	input[i-1].focus();
	}
	catch (e)
	{
	}
}

function js_sleep(sec)
{
	// 1초 = 1000
	var now = new Date();
	var exitTime = now.getTime() + sec;
	
	while (true) {
		now = new Date();
		//alert(now.getTime() +'>'+ exitTime);
		if(now.getTime() > exitTime) return;
	}
}


