var $ = function(str) {return document.getElementById(str);}

function login_now()
{
	$('input_id').focus();
}

function login_cancel()
{
	$('black_overlay').style.display = 'none';
	$('login_wrap').style.display = 'none';
}

function open_sms()
{
	var win = window.open('/sms.php',"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,width=300,height=350");
}

// 2007-07-11 ¿ÀÈÄ 12:47 ÀÌÇüÃ¶
function linkboard(table_name, menu)
{
	var s = $('sels');
	if(s)
	if(s.value.length > 0)
	{
		if(confirm('¼±ÅÃµÈ ±ÛÀ» ÇØ´ç °Ô½ÃÆÇÀ¸·Î ÀÌµ¿ÇÒ±î¿ä?'))
		{
			var f = s.form;
			var to = $('moveto');
			for(var j = 0; j < to.options.length; j++)
				if(to.options[j].value == table_name) to.selectedIndex = j;
			movesel(f);
			return;
		}
		else
		{
			return;
		}
	}
	window.location.href = '/board/?menu='+menu+'&table_name='+table_name;
}

// returns the scroll left and top for the browser viewport
function getScroll() 
{
	if (document.body.scrollTop != undefined) 
	{	// IE model
		var ieBox = document.compatMode != 'CSS1Compat';
		var cont = ieBox ? document.body : document.documentElement;
		return {x : cont.scrollLeft, y : cont.scrollTop};
	}
	else {
		return {x : window.pageXOffset, y : window.pageYOffset};
	}
}
function getElementPos(e)
{
	var left = 0;
	var top  = 0;
	try
	{
		while (e.offsetParent) 
		{
			left += e.offsetLeft; 
			top += e.offsetTop; 
			e = e.offsetParent;
		}
		left += e.offsetLeft;
		top += e.offsetTop;
	}
	catch(err) {}
	return {x:left, y:top};
} 

function getElementRect(e)
{
	var left = 0;
	var top  = 0;
	var e1 = e;
	try
	{
		while (e.offsetParent)
		{
			left += e.offsetLeft; 
			top += e.offsetTop; 
			e = e.offsetParent;
		}
		left += e.offsetLeft;
		top += e.offsetTop;
	}
	catch(err) {}
	return {l: left, t: top, r: left + e1.offsetWidth, b: top + e1.offsetHeight};
}

function getMousePos(e)
{
	e = e || window.event;
	if(e.pageX || e.pageY) return {x : e.pageX, y : e.pageY};
	return {x : e.clientX + document.body.scrollLeft - document.body.clientLeft,
	y : e.clientY + document.body.scrollTop  - document.body.clientTop};
}

function showon(par,menuobj)
{
	if(typeof menuobj == 'string') menuobj = document.getElementById(menuobj);

	hideall();
	scrl = getScroll();
	
	var pos = getElementPos(par);

	// ¸¸ÀÏ client ¿µ¿ªÀÇ °æ°è¸¦ ³Ñ¾î°¡¸é ¿À¸¥ÂÊÀ¸·Î Á¤·ÄÇÑ´Ù.
	if(menuobj.offsetLeft + menuobj.offsetWidth - scrl.x > document.body.clientWidth)
		menuobj.style.posLeft = document.body.clientWidth - menuobj.offsetWidth;

	menuobj.style.left = pos.x + 'px';
	menuobj.style.top = (pos.y + parseInt(par.offsetHeight)) + 'px';
	menuobj.style.display = 'block';
} 

function hide(menuobj)
{
	if(typeof menuobj == 'string') menuobj = document.getElementById(menuobj);

	// ¸¶¿ì½º°¡ ¸Þ´º ¹ÛÀ¸·Î ºüÁ®³ª°¬À¸¸é
	var scrl = getScroll();
	if(event.clientX  + scrl.x <= menuobj.offsetLeft - 5 || 
	   event.clientX  + scrl.x >= menuobj.offsetLeft + menuobj.offsetWidth ||
	   event.clientY  + scrl.y <= menuobj.offsetTop - 5 ||
	   event.clientY  + scrl.y >= menuobj.offsetTop + menuobj.offsetHeight)
		menuobj.style.display = 'none';
} 

function hideall()
{
	for(i = 1; i < 7; i++)
	{
		var obj = $('menu' + i);
		if(!obj) break;
		obj.style.display = 'none';
	}
}

// ÆË¾÷ ÆÄÀÏÀÌ ÀÖÀ¸¸é ¶ì¿î´Ù. Á¶¿ì¼º Ãß°¡
// 2007-06-25 ÀÌÇüÃ¶ ¼öÁ¤
//ÄíÅ°°ªÀ» °¡Á®¿À´Â ÇÔ¼ö
function getCookie(name)
{
	var from_idx = document.cookie.indexOf(name+'=');
	if (from_idx != -1) {
	from_idx += name.length + 1
	to_idx = document.cookie.indexOf(';', from_idx)
	if (to_idx == -1) {
	to_idx = document.cookie.length
	}
	return unescape(document.cookie.substring(from_idx, to_idx))
	}
}

function resize_img(this_s)
{
	if(!this_s.width) this_s.removeAttribute('width');
	if(!this_s.height) this_s.removeAttribute('height');
	if(this_s.width > 550)
	{
		this_s.width = 550;
		this_s.onclick = function(){
			winOpen("/board/imageview.php?path="+encodeURIComponent(this.src));
		};
		this_s.style.cursor='hand';
		this_s.className = '';
	}
}

//============================================================================ 
// ÀÌ¹ÌÁö ÀÚµ¿ ¸®»çÀÌÁî 
//============================================================================ 
function image_auto_resize(this_s,width,height){ 
 var ta_image = new Image(); 
 ta_image.src = this_s.src; 
  if(!width){this_s.removeAttribute('width'); 
  this_s.style.width='auto';} 
  else if(width < ta_image.width){ 
  this_s.width = width; 
  }else{ 
  this_s.width = ta_image.width; 
  } 
  if(!height){this_s.removeAttribute('height'); 
  this_s.style.height='auto';} 
  else if(height < ta_image.height){ 
  this_s.height = height; 
  }else{ 
  this_s.height = ta_image.height; 
  } 
} 

function image_auto_resize_inarea(this_s,width,height,view){ 
// this_s¾ÈÀÇ ¸ðµç ÀÌ¹ÌÁö´Â ÀÚµ¿ ¸®»çÀÌÁî µÈ´Ù. 
 //alert(this_s.childNodes.length); 
 if(!view){view=true;} 
 if(!this_s){return;} 
 if(this_s.nodeType!=1){return;} 
 for(var i=0,m=this_s.childNodes.length;i<m;i++){ 
  var ta = this_s.childNodes[i]; 
  
  if(ta.nodeName=='IMG'){ 
  //ta.style.border='1px solid #333333';  
  image_auto_resize(ta,width,height); 

  if(view){ 
    if(!ta.title){ta.title=ta.src;} 
    if(!ta.onclick){ 
    ta.style.cursor='pointer'; 
    ta.onclick=function(){js_image_view(this,1);} 
    } 
    if(!ta.onload) 
    ta.onload=function(){image_auto_resize(this,width,height);} 
    if(!ta.onmouseover)  
    ta.onmouseover=function(){image_auto_resize(this,width,height);} 
  } 
  } 
  if(ta.childNodes.length > 0)
  { 
  image_auto_resize_inarea(ta,width,height,view); 
  } 
 } 
 return; 

} 

//¼³Á¤ÇÑ ³¯Â¥¸¸Å­ ÄíÅ°°¡ À¯ÁöµÇ°Ô. expiredays°¡ 1 ÀÌ¸é ÇÏ·çµ¿¾È À¯Áö
function makeCookie(name, value, expiredays) {
	var expire_date = new Date();
	expire_date.setDate(expire_date.getDate() + expiredays );
	document.cookie = name + '=' + escape( value ) + '; expires=' + expire_date.toGMTString() + '; path=/';
} 
//ÄíÅ° ¼Ò¸ê ÇÔ¼ö
function clearCookie(name) {
	var expire_date = new Date();
	//¾îÁ¦ ³¯Â¥¸¦ ÄíÅ° ¼Ò¸ê ³¯Â¥·Î ¼³Á¤ÇÑ´Ù.
	expire_date.setDate(expire_date.getDate() - 1)
	document.cookie = name + '= ' + '; expires=' + expire_date.toGMTString() + '; path=/'
}
//Ã¼Å© »óÅÂ¿¡ µû¶ó ÄíÅ° »ý¼º°ú ¼Ò¸êÀ» Á¦¾îÇÏ´Â ÇÔ¼ö
function controlCookie(elemnt, id) {
	if (elemnt.checked) {
	//Ã¼Å© ¹Ú½º¸¦ ¼±ÅÃÇßÀ» °æ¿ì ÄíÅ° »ý¼º ÇÔ¼ö È£Ãâ
	makeCookie('popup'+id,'true', 1);
	self.close();
	}
	else {
	//Ã¼Å© ¹Ú½º¸¦ ÇØÁ¦ÇßÀ» °æ¿ì ÄíÅ° ¼Ò¸ê ÇÔ¼ö È£Ãâ
	clearCookie('popup'+id)
	}
}

function winOpen(imagepath,width,height){
	scrollbar = "no";
	if(width > screen.availWidth) {
		scrollbar = "yes";
		width = screen.availWidth-10;
		if(height < screen.availHeight) height = height + 16;
	}
	if(height > screen.availHeight) {
		scrollbar = "yes";
		height = screen.availHeight-30;
		if(width+10 < screen.availWidth) width = width + 16;
	}
	win = window.open(imagepath,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrollbar+",resizable=yes,width="+width+",height="+height);
	win.moveTo(0,0);
}

function addOnLoad(func)
{
	addLoadEvent(func);
}

function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
