var isMSIE = false;
var nVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf("¸¶ÀÌÅ©·Î¼ÒÇÁÆ®") >= 0) ||
	(navigator.appName.indexOf("Microsoft") >= 0)){
	isMSIE  = true;
	if (navigator.userAgent.indexOf("MSIE 5") != -1) nVersion = 5;
	else if (navigator.userAgent.indexOf("MSIE 6") != -1) nVersion = 6;
}

function wmv_player(no,title) {
	if(no=="Error1") alert('ÆÄÀÏÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù...');
	else window.open("http://home.dailystudy.com/dailyPlayer/Player_Auth.php?no="+no+"&title="+title,"player","width=480, height=611, status=no, help=no;");
}

function NewWindow(surl, stitle, bmenu, btool, bloc, bdir, bresize, bscroll, bstatus, width, height){
   var x = 0;
   var y = 0;
   var x = (screen.width/2) - (width / 2);
   var y = (screen.height/2) - (height / 2);
   var features = "menubar=" + bmenu + ",toolbar=" + btool + ",location=" + bloc + ",directories=" + bdir + ",resizable=" + bresize+ ",scrollbars=" + bscroll + ",status=" + bstatus + ",";
   if ( isMSIE ) features = features + "width=" + width + ",height=" + height + ",left=" + x + ",top=" +y;
   else features = features + "width=" + width + ",height=" + height + ",screenX=" + x + ",screenY=" + y;
   var newwin = window.open(surl, stitle ,features);
}
function SetPopupWindowWidth(strWinID,nWidth)
{
	$(strWinID).style.setAttribute("width",nWidth);
}
function NewPopupWindow(strURL,strParams)
{
	OpenPopupWindow();
	var myAjax = new Ajax.Request(
		strURL, 
		{
			method: 'POST', 
			parameters: strParams,
			onComplete: function (originalRequest) {

				$("PopupWindowContents").innerHTML = originalRequest.responseText;
				GetOpenPopupWindowLeft();
			}
		}
	);
}
function ClosePopupWindow()
{
	$("PopupWindow").style.setAttribute("display","none");
}

function OpenPopupWindow()
{
	var y = document.body.scrollTop + 30;
	$("PopupWindow").style.setAttribute("display","block");
	$("PopupWindow").style.setAttribute("top",y);
}

function GetOpenPopupWindowLeft()
{
	var x = (document.body.clientWidth - $("PopupWindow").offsetWidth) / 2;
	$("PopupWindow").style.setAttribute("top",120);
	$("PopupWindow").style.setAttribute("left",x);
}
function getRealOffsetTop(o)
{
	return o ? o.offsetTop + getRealOffsetTop(o.offsetParent) : 0;
}

function getRealOffsetLeft(o)
{
	return o ? o.offsetLeft + getRealOffsetLeft(o.offsetParent) : 0;
}

function HiddenElement(strID,bTextClear)
{
	try
	{
		if($(strID).innerHTML)
		{
			if(bTextClear == true)
			{
				$(strID).innerHTML = "";
			}
		}
		$(strID).style.setAttribute("display","none");
	}
	catch(e)
	{

	}
}

function ShowElement(strID)
{
	$(strID).style.display = "block";
}

function SetElementPosition(StandardOBJ,TargetOBJ)
{
	TargetOBJ.style.setAttribute("top",getRealOffsetTop(StandardOBJ) + StandardOBJ.offsetHeight + 1);
	TargetOBJ.style.setAttribute("left",getRealOffsetLeft(StandardOBJ) -1);
}

function exchange_item(frm, slist, tlist){
	for ( var i=0; i< slist.length; i++){
		if ( slist.options[i].selected ){
			tlist.length = tlist.length + 1;
			tlist.options[tlist.length - 1].value = slist.options[i].value;
			tlist.options[tlist.length - 1].text = slist.options[i].text;
		}
	}
	rearrange_item(slist);
	//sort_item(tlist);
}

function rearrange_item(list){
	var   i, j, len;
	for ( i = 0; i < list.length; i++ ) {
		if ( list.options[i].selected ){
			list.options[i].value = "";
			list.options[i].text = "";
		}
	}
	i = 0;
	while ( i < list.length ){
		if ( list.options[i].value == "" ){
			for ( j = i; j < list.length; j++ ) {
				if ( j != list.length - 1 ){
					list.options[j].value = list.options[j+1].value;
					list.options[j].text = list.options[j+1].text;
				}
			}
			list.length = list.length - 1;
		}else i++;
	}
}
function sort_item(list){
	var i, j, ttext, tvalue;
	if ( list.length > 1 ){
		for ( i = 0; i < list.length; i++ ){
			for ( j = list.length - 1; j > i; j-- ){
				if ( list.options[j].value < list.options[j-1].value ){
					swap_item(list, j, j-1);
				}
			}
		}
	}
}
function swap_item(list, i, j){
	if ( j >= 0 ){
		var tmpt, tmpv;
		tmpv = list.options[j].value;
		tmpt = list.options[j].text;
		list.options[j].value = list.options[i].value;
		list.options[j].text = list.options[i].text;
		list.options[i].text = tmpt;
		list.options[i].value = tmpv;
	}
}
function updown_item(dir, element){
	var tmpv, tmpt, tmpi, tmpj;
	var arrSel = new Array();
	var j = 0;
	for (var i = 0;i < element.length ; i++ )
	{
		if(element[i].selected == true)
		{
			arrSel[j] = i;
			j++;
		}
	}

	for (var  i = 0;i < arrSel.length; i++)
	{
		tmpj = arrSel[i];			
		
		if ( dir == "up" ) tmpi = tmpj - 1;
		else tmpi =  tmpj + 1;


		tmpv = element.options[tmpj].value;
		tmpt = element.options[tmpj].text;
		if ( tmpi >= 0 && tmpi < element.length ){

			element.options[tmpj].value = element.options[tmpi].value;
			element.options[tmpj].text = element.options[tmpi].text;
			element.options[tmpi].value = tmpv;
			element.options[tmpi].text = tmpt;
			element.options[tmpj].selected = false;
			element.options[tmpi].selected = true;

		}
	}


}
function del_options(selectbox){

	arr = new Array();
	del = 0;
	j = 0;
	for(i = 0; i < selectbox.length ; i++){
		
		if(selectbox.options[i].selected){

			selectbox.options[i].value = '';
			selectbox.options[i].text = '';
			del++;

		}else{

			arr[j] = new Array();
			arr[j][0] = selectbox.options[i].value;
			arr[j++][1] = selectbox.options[i].text;
		}
	}
	selectbox.length = arr.length;
	for(i = 0; i < arr.length ; i++){

		selectbox.options[i].selected = false;
		selectbox.options[i].value = arr[i][0];
		selectbox.options[i].text = arr[i][1];
	}
	
	if(del < 1) alert("»èÁ¦ÇÒ ¾ÆÀÌÅÛÀ» ÇÏ³ª ÀÌ»ó ¼±ÅÃ ÇØ¾ß ÇÕ´Ï´Ù");
}
function getCookie(strName){

	var strArg = new String(strName + "=");
	var nArgLen, nCookieLen, nEnd;
	var i = 0, j;

	nArgLen    = strArg.length;
	nCookieLen = document.cookie.length;

	if(nCookieLen > 0) {
		while(i < nCookieLen) {
			j = i + nArgLen;
			if(document.cookie.substring(i, j) == strArg) {
				nEnd = document.cookie.indexOf (";", j);
				if(nEnd == -1) nEnd = document.cookie.length;
				return unescape(document.cookie.substring(j, nEnd));
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	}
	return("");
}

function setCookie( name, value, expiredays )
{
	var today = new Date();
	today.setDate( today.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}

function implode(str,array)
{
	var temp = "";
	for(var i = 0 ; i < array.length ; i++)
	{
		if(i < array.length - 1) temp += array[i]+str;
		else temp += array[i];
	}
	return temp;
}

function print_page()
{
	NewWindow("ABOUT:BLANK","print_window",0,0,0,0,0,1,0,800,600);

	var form = document.createElement("form");
	var input = document.createElement("input");

	input.setAttribute("name","content");
	input.setAttribute("type","hidden");
	input.setAttribute("value",document.getElementById("print_area").innerHTML);

	form.appendChild(input);
	form.setAttribute("name","frmprint");
	form.setAttribute("id","frmprint");
	form.setAttribute("method","POST");
	form.setAttribute("action","/statistics/print_page.php");
	form.setAttribute("target","print_window");

	document.body.appendChild(form);
	document.getElementById("frmprint").submit();
	document.body.removeChild(form);
}

function escapeSingleQuote(str) {                
		str = str.replace(/\\/g,"\\\\");
		str = str.replace(/\'/g,"\\\'");        
		return str;
}

function maxlengthLimit(el, maxByte)
{
	var bchk = document.getElementById("byte_chk");
		var strCount = 0;
		var tempStr, tempStr2;        
		for(i = 0;i < el.value.length;i++)
		{
				tempStr = el.value.charAt(i);
				if(escape(tempStr).length > 4) strCount += 2;
					  else strCount += 1 ;
			}
		if (strCount > maxByte){
				alert("ÃÖ´ë " + maxByte + "byteÀÌ¹Ç·Î ÃÊ°úµÈ ±ÛÀÚ¼ö´Â ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");                
				strCount = 0;                
				tempStr2 = "";
				for(i = 0; i < el.value.length; i++) 
				{
						tempStr = el.value.charAt(i);        
						if(escape(tempStr).length > 4) strCount += 2;
					  else strCount += 1 ;
					  if (strCount > maxByte)
					  {
							  if(escape(tempStr).length > 4) strCount -= 2;
							  else strCount -= 1 ;        
							  break;                              
					  }
					  else tempStr2 += tempStr;
				}            
				el.value = tempStr2;
		}
		else
		{
			
			
		}
		bchk.innerHTML = strCount;
}
function check_all_box(TargetObj,ClickObj)
{
	if(TargetObj)
	{
		if(TargetObj.length)
		{
			for(var i = 0;i < TargetObj.length ; i++)
			{
				if(ClickObj.checked == true)
				{
					TargetObj[i].checked = true;
				}
				else
				{
					TargetObj[i].checked = false;
				}
			}
		}
	}
}

function MemberLogin(nMNumber)
{
	action_frame.location.href="/LoginAction.php?MNumber="+nMNumber;
}

function ViewAjaxPage(strWinID,strURL,strParam,strMethod)
{
	var myAjax = new Ajax.Request(
		strURL, 
		{
			method: strMethod, 
			parameters: strParam,
			onComplete: function (originalRequest) {

				$(strWinID).innerHTML = originalRequest.responseText;
			}
		}
	);
}

function GetRadioValue(obj){
	
	var list = "";
	if(!obj.length){

		if(obj.value && obj.checked == true){

			list = obj.value;
		}

	}else{

		for(i = 0; i < obj.length ; i++){
			
			if(obj[i].checked){

				list += "," + obj[i].value;
			}
		}
		list = list.substr(1);
	}

	return list;
}