﻿
/***************************************************** general utils start ****************************************************/
function imgError(obj)
{
    obj.src="/images/community/empty.gif";
}
// get cookie value
function getcookie(cookiename) {
	var cookiestring = "" + document.cookie;

	// cookie first
	var index1 = cookiestring.indexOf(cookiename);
	if (index1 == -1 || cookiename == "") {
		return "";
	}

	// cookie end
	var index2 = cookiestring.indexOf(';',index1);
	if (index2 == -1) {
		index2 = cookiestring.length; 
	}

	return unescape(cookiestring.substring(index1+cookiename.length+1, index2));
}

// set cookie
function setcookie(name, value, mins){
	// make cookie string
	cookiestring = name + "=" + escape(value) + ";expires=" + getexpirydate(mins) + ";domain=hanbiton.com;path=/;";

	// write!
	document.cookie = cookiestring;
	if (!getcookie(name)){
		return false;
	} else {
		return true;
	}
}

// trim
function trim(input) {
	if (typeof input != "string") return input;
	
	var retValue = input;

	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	
	ch = retValue.substring(retValue.length - 1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}
	
	return retValue;
}

// 현재 입력한 문자의 byte를 계산한다.
function checkLength(contents)
    {
	    var str_character;
	    var int_char_count;
	    var int_contents_length;

	    int_char_count = 0;

	    int_contents_length = contents.length;


	    // 한글과 영문 바이트수 계산하는 부분
	    // 아래 부터 수정 않아셔도 됩니다.
	    for(k=0; k < int_contents_length; k++)
	    {
		    str_character = contents.charAt(k);
		    if(escape(str_character).length > 4)
			    int_char_count += 2;  
		    else
			    int_char_count++;
	    }
	    // 여기까지는 수정 않아셔도 됩니다.

	    return int_char_count;
    }
    
// windowsopen
function openWindow(loc, name, opt) {
	var win = window.open(loc, name, opt);
	if (win == null) {
		alert("한빛온을 원활하게 이용하시려면 먼저 팝업차단설정을 꺼주세요");
	}
	else {
	    win.focus();
	}
}
// add get variable
function AddGetVariable(url, name, value) {	
	url = url + "";

	var index0 = url.indexOf("?" + name + "=");

	if (index0 == -1) {
		var index1 = url.indexOf("&" + name + "=");

		if (index1 == -1) {
			if (url.indexOf("?") == -1) {
				url = url + "?" + name + "=" + value;
			} else {
				url = url + "&" + name + "=" + value;
			}
		} else {
			var index2 = url.substr(index1 + 1).indexOf("&");
			if (index2 == -1) {
				url = url.substr(0, index1) + "&" + name + "=" + value;
			} else {
				url = url.substr(0, index1) + url.substr(index1 + index2 + 1, url.length) + "&" + name + "=" + value;
			}
		}
	} else {
		var index3 = url.substr(index0 + 1).indexOf("&");
		if (index3 == -1) {
			url = url.substr(0, index0) + "?" + name + "=" + value;
		} else {
			url = url.substr(0, index0) + "?" + name + "=" + value + url.substr(index0 + index3 + 1, url.length);
		}
	}	

	return url;
}

function GetGetVariable(url, name) {
	url = url + "";

	var index0 = url.indexOf("?" + name + "=");

	if (index0 == -1) {
		var index1 = url.indexOf("&" + name + "=");

		if (index1 == -1) {
			return "";
		} else {
			var index2 = url.substr(index1 + name.length + 2).indexOf("&");
			if (index2 == -1) {
				return url.substr(index1 + name.length + 2);
			} else {
				return url.substr(index1 + name.length + 2, index2);
			}
		}
	} else {
		var index3 = url.substr(index0 + name.length + 2).indexOf("&");
		if (index3 == -1) {
			return url.substr(index0 + name.length + 2);
		} else {
			return url.substr(index0 + name.length + 2, index3);
		}
	}
}

function DeleteGetVariable(url, name) {
	url = url + "";

	var index0 = url.indexOf("?" + name + "=");

	if (index0 == -1) {
		var index1 = url.indexOf("&" + name + "=");

		if (index1 != -1) {
			var index2 = url.substr(index1 + 1).indexOf("&");
			if (index2 == -1) {
				url = url.substr(0, index1);
			} else {
				url = url.substr(0, index1) + url.substr(index1 + index2 + 1, url.length);
			}
		}
	} else {
		var index3 = url.substr(index0 + 1).indexOf("&");
		if (index3 == -1) {
			url = url.substr(0, index0);
		} else {
			url = url.substr(0, index0) + "?" + url.substr(index0 + index3 + 2, url.length);
		}
	}	

	return url;
}

function lastTrSetStyle(table, className)
{
    var obj = table.getElementsByTagName("tr");
    
    obj[obj.length-1].className = className;
}

function CopyClipBoardLink(link)
{
    window.clipboardData.setData('Text', link);
    alert("링크가 복사 되었습니다."); 
}

function GetMouseXY(e)
{
    this.x=0;
    this.y=0;

    var IE = document.all? true : false;
        
    if (!IE) document.captureEvents(Event.MOUSEMOVE)
    
    if (IE) { // grab the x-y pos.s if browser is IE
        this.x = event.clientX + document.documentElement.scrollLeft;
        this.y = event.clientY + document.documentElement.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        this.x = e.pageX;
        this.y = e.pageY;
    }  
    
    // catch possible negative values in NS4
    if (this.x < 0){this.x = 0;}
    if (this.y < 0){this.y = 0;}
}

// 웹표준에 맞추어 Iframe내의  document 객체를 가져온다.
function getIFrameDocument(aID){
  // if contentDocument exists, W3C compliant (Mozilla)
  if (document.getElementById(aID).contentDocument){
    return document.getElementById(aID).contentDocument;
  } else {
    // IE
    return document.frames[aID].document;
  }
}

function HasImage()
{
    var fileObj = document.getElementById("FileList")
    
    var isValid = false;
    
    if (fileObj != null)
    {
        var options     = fileObj.options;
        var arrOptions;        
        var optionLength = options.length;
        
        for (i = 0 ; i<optionLength; i++)
        {			
			if(options[i].value.indexOf('|gpt|') > -1 && options[i].value != "") {
				arrOptions = options[i].value.split('|gpt|');
				var arrOptionsLength = arrOptions.length;
				
				if (arrOptions[arrOptionsLength -1] == 'I')
                    isValid = true;    
			}
			
			
//            if (arrOptions.length == 3)
//            {
//                if (arrOptions[2] == 'I')
//                    isValid = true;    
//            }
        }    
    }
    return isValid
}

//function ResizeImage(id) {
//	var img = document.getElementById("UserImage" + id);
//	
//	if (img.width > 540) {
//		img.width = 540;
//	} else if (img.width == 0) {
//		setTimeout("ResizeImage('" + id + "')", 200);
//	}
//}

// 이미지 팝업
function popview(url) {
	win = window.open("/Popup/ViewImage.aspx?url=" + url, "HanbitOnpopview", "width=100,height=100,status=no,scrollbars=yes");
	win.focus();
}
/***************************************************** general utils end ****************************************************/

/***************************************************** prototype utils start ****************************************************/
// trim
String.prototype.trim = function() {
	var retValue = this;

	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length - 1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}

	return retValue;
}
/***************************************************** prototype utils end ****************************************************/

/***************************************************** multi-value cookie start ****************************************************/
/*
 * usage
 *
 * var cookie = new MCookie();
 * for (i = 0; i < 10; i++) {
 *   AppendMCookie(cookie, "name_" + i, "value_" + i);
 * }
 * SetMCookie(cookie, "sample_cookie", 10); // 10 minutes
 *
 *
 * var cookie = GetMCookie("sample_cookie");
 */

// multi name-value cookie container
function MCookie() {
	this.names = new Array();
	this.values = new Array();
	this.count = 0;

	return this;
}

// append multi name-value cookie
function AppendMCookie(cookie, name, value) {

	var index = cookie.count;
	// if exists cookie, update that
	for (i = 0; i < cookie.count; i++) {
		if (cookie.names[i] == name) {
			index = i;
			break;
		}
	}

	cookie.names[index] = name;
	cookie.values[index] = value;
	cookie.count++;
}

// delete one cookie in multi name-value cookie
function DeleteMCookie(cookie, index) {
	for (i = index + 1; i < cookie.count; i++) {
		cookie.names[i - 1] = cookie.names[i];
		cookie.values[i - 1] = cookie.values[i];
	}

	cookie.count--;
}

// multi name-value cookie seperator
var s1 = "||";
var s2 = "|||";

// set multi name-value cookie
function SetMCookie(cookie, name, mins) {

	var value = "";
	for (i = 0; i < cookie.count; i++) {
		value += escape(cookie.names[i]) + s1 + escape(cookie.values[i]);
		if (i + 1 < cookie.count) {
			value += s2;
		}
	}
	setcookie(name, value, mins);
}

// get multi name-value cookie
function GetMCookie(name) {
	var str = getcookie(name);
	var cookie = new MCookie();

	if (str != "") {
		var array = str.split(s2);

		for (i = 0; i < array.length; i++) {
			tmp = array[i].split(s1);
			AppendMCookie(cookie, tmp[0], tmp[1]);
		}

		cookie.count = array.length;
		return cookie;
		
	} else {
		return new MCookie();
	}
}
/***************************************************** multi-value cookie end ****************************************************/

/***************************************************** HOPopup start ****************************************************/
var minibl_id = "";
//
// 실제 호출할 때 사용
//

function exec_menuitem(key) {
	switch(key) {
		case "HOEVENT1":
			goMinibl(minibl_id);
			break;
		case "HOEVENT2":
		    ho_SendNote(minibl_id);
		    break;		    
		case "HOEVENT4":
			ho_AddNeighbor(minibl_id);
			break;		  
	}
}

// 미니블 가기
function goMinibl(id) 
{    
	openWindow("http://www.hanbiton.com/miniblblog/default.aspx?id="+ id +"&FirstView=true", "blogwindow", "");
}

//쪽지보내기
function ho_SendNote(id) 
{    
	openWindow("https://members.hanbiton.com:8080/paper/popup/Reply.aspx?bid=" + id, "HanbitOnNote", "width=335,height=320,status=no,scrollbars=no");
	

}

function HOPopup(e, m_nick) 
{
	minibl_id = m_nick;
	
	var loc = window.location + "";
    if (loc.indexOf('GuildList') > -1){		
        document.getElementById("ui_menu").innerHTML = guild_ui_menu;
    }else{   
		document.getElementById("ui_menu").innerHTML = full_ui_menu;	    
	}     
	
	var mouseXY = new GetMouseXY(e);

	document.getElementById("ui_menu").style.left       = mouseXY.x-10 + "px";
	document.getElementById("ui_menu").style.top        = mouseXY.y-10 + "px";
	document.getElementById("ui_menu").style.display    = "block";
}

var full_ui_menu = "<table width=\"80\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#B6B6B6\"><tr><td> ";
full_ui_menu += "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">";
full_ui_menu += "<tr><td style=\"padding-left: 7px;\" height=\"20\" onmouseout=\"this.style.background = '#FFFFFF';\" onmouseover=\"this.style.background = '#EEEEEE';\" onclick=\"exec_menuitem('HOEVENT1');\" style=\"cursor:hand\"><font color=#404040>미니블보기</font></td></tr>";
full_ui_menu += "<tr><td height=\"1\" background=\"/images/line_dot_02.gif\"></td></tr>";
full_ui_menu += "<tr><td style=\"padding-left: 7px;\" height=\"20\" onmouseout=\"this.style.background = '#FFFFFF';\" onmouseover=\"this.style.background = '#EEEEEE';\" onclick=\"exec_menuitem('HOEVENT2');\" style=\"cursor:hand\"><font color=#404040>쪽지보내기</font></td></tr>";
full_ui_menu += "</table>";
full_ui_menu += "</td></tr></table>";



var guild_ui_menu = "<table width=\"80\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#B6B6B6\"><tr><td> ";
guild_ui_menu += "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">";
guild_ui_menu += "<tr><td style=\"padding-left: 7px;\" height=\"20\" onmouseout=\"this.style.background = '#FFFFFF';\" onmouseover=\"this.style.background = '#EEEEEE';\" onclick=\"exec_menuitem('HOEVENT1');\" style=\"cursor:hand\"><font color=#404040>미니블보기</font></td></tr>";
guild_ui_menu += "<tr><td height=\"1\" background=\"/images/line_dot_02.gif\"></td></tr>";
guild_ui_menu += "<tr><td style=\"padding-left: 7px;\" height=\"20\" onmouseout=\"this.style.background = '#FFFFFF';\" onmouseover=\"this.style.background = '#EEEEEE';\" onclick=\"exec_menuitem('HOEVENT2');\" style=\"cursor:hand\"><font color=#404040>쪽지보내기</font></td></tr>";
guild_ui_menu += "<tr><td height=\"1\" background=\"/images/line_dot_02.gif\"></td></tr>";
guild_ui_menu += "<tr><td style=\"padding-left: 7px;\" height=\"20\" onmouseout=\"this.style.background = '#FFFFFF';\" onmouseover=\"this.style.background = '#EEEEEE';\" onclick=\"exec_menuitem('HOEVENT4');\" style=\"cursor:hand\"><font color=#404040>이웃추가</font></td></tr>";
guild_ui_menu += "</table>";
guild_ui_menu += "</td></tr></table>";



document.write("<div id=\"ui_menu\" onfocusout=\"this.style.display='none';\" style=\"position:absolute;display:none;top:0;left:0;z-index:9;\">");
document.write("</div>");

/***************************************************** HOPopup end ****************************************************/

/***************************************************** Member Link end ****************************************************/
// 회원가입
function GoJoinMember() {
	openWindow("https://members.hanbiton.com:8080/register/default.aspx?regsite=mythos", "HanbitMemberShip","");
}

// 회원수정
function GoEditMember() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=MyInfoModify&regsite=mythos", "HanbitMemberShip", "");
}

// 회원탈퇴
function GoOutMember() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=InfoOut&regsite=mythos", "HanbitMemberShip", "");
}

// 아이디/패스워드 찾기
function GoSearchIdPass() {
	openWindow("https://webservice.hanbiton.com/Info/AccountSearch.aspx?regsite=mythos","SearchIDPass","");
}

// 멤버쉽 페이지로
function GoMembership() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=MyInfoModify&regsite=mythos", "HanbitMemberShip", "");
}
// 보호자 동의서
function OpenAgree()
{
    openWindow("http://member.hanbiton.com/h_member/h_hms/junior_join.html","Agreement","width=650, height=600");
}

//한빛캐쉬 충천
function GoCashFill(id)
{
    if(id == "")
        alert("로그인 해주세요.");
    else
        openWindow("http://member.hanbiton.com/h_realname/default.aspx?userid=" + id + "&gm=WHG", "HanbitOn_Article", "width=800,height=615,status=no,scrollbars=no");
}

//내 한빛캐쉬 충전 내역
function GoMyCashInfo()
{
    openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=CashInfo", "HanbitMemberShip", "");
}

//내 한빛캐쉬 구입 내역
function GoMyBuyInfo()
{
    openWindow("https://members.hanbiton.com:8080/MyInfo/Default.aspx?menu=CashInfo&cashType=buy", "HanbitMemberShip", "");
}

//서비스 이용약관
function GoServiceClause()
{
    openWindow('http://help.hanbiton.com/Agreement/ServiceClause.aspx', 'Help','');
}
//캐쉬 이용약관
function GoCashClause()
{
    openWindow('http://help.hanbiton.com/Agreement/CashClause.aspx', 'Help','');
}


/***************************************************** Member Link end ****************************************************/