//공통 사용 JS 파일

/* 게시판 쪽 IE7 에서 스크립트 오류 발생해서 일단 주석 - Hoya 080516
//커서위치 잡아주기위해 한번 Blur 해줌
window.addEventListener("load", BodyInit, false);
function BodyInit() {
	//var i = $("search_txt");
	//i.style = "border: 10px solid #c17c81;"
}
*/

//Main에서 사용하는 단축키 shortcut.js 가 include 되어야함.
//커서이동->로그인창
//shortcut.add("Alt+L",function() {
//	$("openid_identifier").focus();
//});

//커서이동 -> 검색창
//shortcut.add("Alt+S",function() {
//	$("search_txt").focus();
//});

//클립보드로 내용 복사
function setClipBoard(meintext)
{
	
	if (window.clipboardData)
	{
		// the IE-manier
		window.clipboardData.setData("Text", meintext);

		// waarschijnlijk niet de beste manier om Moz/NS te detecteren;
		// het is mij echter onbekend vanaf welke versie dit precies werkt:
	}
	else if (window.netscape) 
	{ 
		// dit is belangrijk maar staat nergens duidelijk vermeld:
		// you have to sign the code to enable this, or see notes below 
	
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		// maak een interface naar het clipboard

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// maak een transferable

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specificeer wat voor soort data we op willen halen; text in dit geval

		trans.addDataFlavor('text/unicode');


		// om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig om het in op te slaan

		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*2);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);

	}
	window.alert('클립보드에 저장되었습니다. \nCtrl+V 하시면 붙여넣기가 됩니다.');
	return false;
}

// 공백 제거 함수
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}

function oldHAJAjoin()
{
	location.href='http://2008.haja.net/member/mem_regist.asp?flag=in';
}

//메인으로 이동하는 함수
//메시지가 있을경우 메시지를 Alert 창에 띄우고
//없을경우 그냥 이동한다.
function goMain(Msg)
{
	if (Msg)
	{
		alert(Msg);
	}
	location.href = "http://haja.net";
	return;
}

//Flash Loader JS
//이함수를 써야만 IE 에서 점선이 생기지 않는다
function swf(src,width,height)
{
	object = '';
	object += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="param" width="'+width+'" height="'+height+'">';
	object += '<param name="movie" value="'+src+'">';
	object += '<param name="quality" value="high" >';

	object += '<embed src="'+src+'" quality="high" wmode="transparent" bgcolor="#ffffff" menu="false" ';
	object += 'width="'+width+'" height="'+height+'" swliveconnect="true" id="param" name="param" ';
	object += ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed>';
	object += '</object>';

	document.write(object);
}

//// 상태 표시 Layer 생성 함수
function showStatLayer(msg, delay, type)
{
	if(this.interval==null)
	{
		// delay 값을 설정하지 않을 경우 700ms으로 설정함
		if(delay==null) { delay = 30000; }

		// statlayer 가 존재하는 경우 삭제함
		if($('statLayer')) { clearMsg(); }

		var x = document.documentElement.clientWidth;
		var y = document.documentElement.clientHeight;

		// statlayer 삭제 함수
		var clearMsg = function()
		{
			if(this.blink)
			{
				clearInterval(this.blink); 
			}

			if($('statLayer'))
			{
				document.body.removeChild($('statLayer'));
			}
		}

		/*
		// statlayer 보임/숨김 함수
		var displayMsg = function()
		{	
			displayOnOff($('statLayer'))

		}
		*/

		// statlayer 중앙 고정함수
		var setLayerPos = function() 
		{
			var yOffSet = document.documentElement.scrollTop;
			var xOffSet = document.documentElement.scrollLeft;
			
			if($('statLayer'))
			{
				$('statLayer').style.left = ( (x / 2) - 100 ) + xOffSet + "px";
				$('statLayer').style.top = ( (y / 2) - 40 ) + yOffSet + "px"; 
			}
		}

		// Layer 생성 함수
		var createMsg = function()
		{
			var yOffSet = document.documentElement.scrollTop;
			var xOffSet = document.documentElement.scrollLeft;

			var layer = document.createElement("div");
			layer.id = "statLayer";
			layer.style.zIndex = "100";
			layer.style.position = "absolute";
			layer.style.height = "80px";
			layer.style.width = "200px";
			layer.style.backgroundColor = "#F9F9F9";
			layer.style.borderStyle = "solid"
			layer.style.borderWidth = "1px"
			layer.style.borderColor = "#DDDDDD"
			layer.style.color = "#000000";
			layer.style.fontWeight = "bold";
			layer.style.textAlign = "center";
			layer.style.display = "block";
			layer.style.left = ( (x / 2) - 100 ) + xOffSet + "px";
			layer.style.top = ( (y / 2) - 40 ) + yOffSet + "px";

			var cell1 = document.createElement("div");

			var cell2 = document.createElement("div");


			var loadImg = document.createElement("img");
			if(type=="0")
			{
				loadImg.src = "/tpl/img/icons/ajax-loader.gif";
			}
			else
			{
				loadImg.src = "/tpl/img/icons/ajax-complete.gif";
			}
			loadImg.style.marginTop = "12px";
			loadImg.style.marginBottom = "10px";

			var optText = document.createTextNode(msg);

			cell1.appendChild(loadImg);
			cell2.appendChild(optText);
			layer.appendChild(cell1);
			layer.appendChild(cell2);
			//layer.appendChild(loadImg);
			//layer.appendChild(optText);
			document.body.appendChild(layer);
		}
		
		createMsg();

		window.onscroll=setLayerPos;

		setTimeout(clearMsg, delay);
	}
}

//// object 보이기/숨기기 함수
function objShowHide(obj)
{
	if($(obj).style.display=="none")
	{ 
		if (navigator.userAgent.indexOf("MSIE") > 0) { $(obj).style.display = "inline-block" }
		else { $(obj).style.display = "table-row"; }
	}
	else
	{ $(obj).style.display="none" }
}

// 쿠키 생성 함수
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = 
		name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// 쿠키 가져오는 함수
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie(check_name)
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}

		a_temp_cookie = null;
		cookie_name = '';
	}

	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// 태그 혹은 클래스를 배열로 변환해주는 함수
function getElementsByClass(tag, searchClass, node)
{
	var classElements = new Array();
	if( node == null ) { node = document.body; }
	if( tag == null ) { tag = '*'; }
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	for (i = 0, j = 0; i < elsLen; i++)
	{
		if(searchClass!=null)
		{
			if(els[i].className == searchClass)
			{
				classElements[j] = els[i];
				j++;
			}
		}
		else
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// object 보이기
function showObj(obj)
{
	$(obj).style.display="block";
}

// object 숨기기
function hideObj(obj)
{
	$(obj).style.display="none";
}

