﻿
/***************************************************** general utils start ****************************************************/

document.title = "AIKA Online";

function imgError(obj)
{
    obj.src="/images/common/img_sampleL.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;
	}
}
// get cookie expire day
function getexpirydate(mins){
	var Today = new Date();
	var nomilli = Date.parse(Today);
	Today.setTime(nomilli + mins * 60 * 1000);
	return Today.toUTCString();
}
// 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;
}

function removeTag(input) {
    var ret = input.replace(/<\/?[^>]+(>|$)/g, "");
    
    while (ret.indexOf("&nbsp;") != -1)
    {
        ret = ret.replace("&nbsp;", "");
    }
    return trim(ret);
}
// 현재 입력한 문자의 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.body.scrollLeft;
        this.y = event.clientY + document.body.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;
        for (i = 0 ; i<options.length ; i++)
        {           
            arrOptions = options[i].value.split('|gpt|');
            
            if (arrOptions.length == 3)
            {
                if (arrOptions[2] == 'I')
                    isValid = true;    
            } else if (arrOptions.length == 6) {
                if (arrOptions[5] == '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("/Community/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) {
    var LeftPosition = (screen.width) ? (screen.width-335)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height-320)/2 : 0;
    openWindow("https://members.hanbiton.com:8080/paper/popup/Reply.aspx?bid=" + id, "HanbitOnNote", "width=350,height=335,status=no,scrollbars=no,top=" + TopPosition + ",left=" + LeftPosition + "");
}

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=aika", "HanbitMemberShip","");
}

// 회원수정
function GoEditMember() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=MyInfoModify&regsite=aika", "HanbitMemberShip", "");
}

// 회원탈퇴
function GoOutMember() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=InfoOut&regsite=aika", "HanbitMemberShip", "");
}

// 아이디/패스워드 찾기
function GoSearchIdPass() {
	openWindow("https://webservice.hanbiton.com/Info/AccountSearch.aspx?regsite=aika","SearchIDPass","");
}

// 멤버쉽 페이지로
function GoMembership() {
	openWindow("https://members.hanbiton.com:8080/myinfo/default.aspx?menu=MyInfoModify&regsite=aika", "HanbitMemberShip", "");
}
// 보호자 동의서
function OpenAgree()
{
    openWindow("http://member.hanbiton.com/h_member/h_hms/junior_join.html","Agreement","width=650, height=600");
}

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 GoPcZone()
{
    openWindow('https://pcbang.hanbiton.com/homepage/search/search.asp?searchType=AIKA', 'PCZone','');
}
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 ****************************************************/




/***************************************************** Aika Function Start ****************************************************/

// WebService
function CallHanbitONWebService(methodName, paramNames, paramValues, func) {
	//alert(methodName);
	if (window.XMLHttpRequest) {// native XMLHttpRequest object  
	
		objHttp = new XMLHttpRequest();
	}	
	else if (window.ActiveXObject) { // IE/Window ActiveX version
	
		objHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else { // sorry
		
		return;
	}
	
	var strEnvelope = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
	" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
	" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
	"<soap:Body>" +
	"  <" + methodName + " xmlns=\"http://aika.hanbiton.com/service\">";

	// parameters	      
	for (i = 0; i < paramNames.length; i++) {
		strEnvelope += "<" + paramNames[i] + ">" + paramValues[i] + "</" + paramNames[i] + ">";
	}

	strEnvelope = strEnvelope + "  </" + methodName + ">" +
	"</soap:Body>" +
	"</soap:Envelope>";

	// add event handler
	objHttp.onreadystatechange = func;

	var szUrl = "/Service/HanbitOnAikaService.asmx";

	// send the POST to the Web service	
	
	objHttp.open("POST", szUrl, false);
	objHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	objHttp.setRequestHeader("SOAPAction", "http://aika.hanbiton.com/service/" + methodName);
	objHttp.send(strEnvelope);
}



/***************************************************** Aika Function end ****************************************************/

