/*
* Filename	: project.js
* Function	:
* Comment		:
* History		: 2003/06/10, jerry, setup
*							2004/12/30, jerry, develop
* Version		:	1.0
* Author		:	Copyright (c) 2005 by JC Square Inc. All Rights Reserved.
*/

/***************************************************
*	common
****************************************************/

/* login */
function isLogin() {
	var cookieVal = getCookie("SK_MI");
	if (cookieVal == null || cookieVal == "") {return false;}
	else {return true;}
}

function openLogin() {
	openWindow("../main/loginPopupForm.jsp", 335, 220, "login");
}

/* check message */
function checkMsg() {
	try {
		if (isLogin() && parent.msg.location.href.indexOf("msgApplet") < 0) {
			parent.msg.location.href = "../message/msgApplet.jsp";
		}
	} catch(ex) {}
}

/* check session member ID */
function checkLogin(page) {
	if (!isLogin()) {loginMsg();}
	else {location.href = page;}
}

function checkLoginOpen(url, width, height, name) {
	if (!isLogin()) {loginMsg();}
	else {openWindow(url, width, height, name);}
}

/* location */
function goUrl(page) {location.href = page;}

/* help */
function openHelp(page) {
	if (page == null) {page = "index.html";}
	openWindowScroll("../help/" + page, 600, 600, "help");
}

/* support */
function openSupport(page) {
	if (page == null) {page = "index.html";}
	openWindow("../support/" + page, 310, 412, "support");
}

/* alert message */
function serviceMsg() {alert("サービス準備中です。");}
function loginMsg() {alert("ログインして下さい。");}
function alertMsg(msg) {alert(msg);}

/* window status string */
function hidestatus() {
	window.status = "- 私立クレアール学園 - オンライン学園コミュニティ";
	return true;
}

if (!IE) {document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT);}

document.onmouseover = hidestatus;
document.onmouseout = hidestatus;
//document.onmousedown = hidestatus;
//document.onmouseup = hidestatus;

/***************************************************
*	Master
****************************************************/

/* event */
function searchEvent() {
	openWindowScroll("../master/searchEvent.jsp", 450, 530, "searchEvent");
}

function sendEvent() {
	openWindow("../master/sendEventForm.jsp", 450, 340, "sendEvent");
}

/* genre */
function searchGenre() {
	openWindowScroll("../master/searchGenre.jsp", 450, 300, "searchGenre");
}

/* character */
function searchChar() {
	openWindowScroll("../master/searchChar.jsp", 450, 350, "searchChar");
}

/* image library */
function openImgLib() {
	openWindow("../master/listImgLib.jsp", 800, 405, "imgLib");
}

function selectImgLib() {
	openWindow("../master/selectImgLib.jsp", 600, 350, "selectImgLib");
}

/* cash */
function chargeCash() {
	openWindowScroll("https://" + location.host + "/master/selectCash.jsp", 447, 490, "chargeCash");
}

function refreshCash(cash) {
	try {opener.getObjectByName("cash").innerHTML = makeMoneyType(cash);} catch(ex) {}
}

function goCharge(url) {
	top.opener.top.location.href = url;
	window.close();
}

/***************************************************
*	member
****************************************************/

function checkAlias(alias) {
	var forbid = ["陵辱", "盗撮", "殺", "死", "姦", "リスカ", "リストカット", "自傷", "ユウメディア", "youmedia", "ｙｏｕｍｅｄｉａ", "クレアール", "crear", "ｃｒｅａｒ", "管理", "匿名", "登録", "名無し", "事務局", "事務室", "教師", "教員", "理事", "生徒", "学生", "スタッフ", "すたっふ", "サポート", "メンバー", "めんばー"];
	var len = forbid.length;
	for (i = 0; i < len; i++) {
		if (alias.indexOf(forbid[i]) > -1) {return false;}
	}

	return true;
}

function checkWord(str) {
	if (str == null || str.length == 0) {return true;}
	
	var forbid = ["陵辱", "盗撮", "殺", "死", "姦", "リスカ", "リストカット", "自傷"];
	var len = forbid.length;
	for (i = 0; i < len; i++) {
		if (str.indexOf(forbid[i]) > -1) {return false;}
	}

	return true;
}

function addFriend(memId) {
	openWindow("../hp/createFriendForm.jsp?memId=" + (memId == null ? "" : memId), 350, 208, "addFriend");
}

function openFriend(inputType) {
	openWindowScroll("../hp/listFriendPopup.jsp?inputType=" + (inputType == null ? "" : inputType), 300, 300, 'listFriend');
}

/***************************************************
*	HP
****************************************************/

function mainHP(memId, redirect) {
	openWindow("../hp/loadHP.jsp?memId=" + memId + (redirect != null ? "&redirect=" + redirect : ""), 950, 600, "mainHP");
}

function profileHP(memId) {
	mainHP(memId, "viewProfile.jsp");
}

function addHpFavor(memId) {
	try {processFrame.location.href = "../hp/createFavor.jsp?tarId=" + memId;}
	catch (ex) {}
}

function addPhoto(memId, imgNo) {
	openWindow("../hp/createPhotoForm.jsp?hmi=" + memId + "&imgNo=" + imgNo, 950, 600, "mainHP");
}

function addDiary(memId, imgNo) {
	openWindow("../hp/createDiaryForm.jsp?hmi=" + memId + "&imgNo=" + imgNo, 950, 600, "mainHP");
}

function addSchedule(memId, imgNo) {
	openWindow("../hp/createScheduleForm.jsp?hmi=" + memId + "&imgNo=" + imgNo, 950, 600, "mainHP");
}

function addPoll(memId) {
	if (!isLogin()) {loginMsg();}
	else {
		try {processFrame.location.href = "../hp/createPoll.jsp?memId=" + memId;}
		catch (ex) {}
	}
}

function getDiaryDay(form) {
	return form.year.value + makeTwoDigit(form.month.value) + makeTwoDigit(form.day.value);
}

function openPhoto(memId, dirNo, photoNo) {
	openWindowScroll("popupPhoto.jsp?memId=" + memId + "&dirNo=" + dirNo + "&photoNo=" + photoNo, 300, 300, "openPhoto");
}

/***************************************************
*	message
****************************************************/

function sendMessage(memId, imgNo) {
	var redirect = "../message/createSndMsgForm.jsp?rcvId=" + memId + (imgNo == null ? "" : "&imgNo=" + imgNo);
	try {
		if (location.href.indexOf("/message/") > -1) {location.href = redirect;}
		else if (top.opener == null) {openWindow(redirect, 750, 600, "sendMessage");}
		else {top.opener.sendMessage(memId, imgNo);}
	} catch (ex) {}
}

function viewMessage(msgNo, msgDiv) {
	openWindow("../message/viewRcvMsg.jsp?msgNo=" + msgNo + (msgDiv != null ? "&msgDiv=" + msgDiv : ""), 500, 330, msgNo);
}

function openMessageBox() {
	openWindowFixed("../message/listRcvMsg.jsp", 750, 600, "messageBox");
}

function viewGift(msgNo, msgDiv) {
	openWindow("../account/viewGift.jsp?msgNo=" + msgNo + (msgDiv != null ? "&msgDiv=" + msgDiv : ""), 430, 440, "viewGift");
}

/***************************************************
*	chatting
****************************************************/

/* chatting */
function checkChatter(url, rid, type, theme) {
	var param = url == null ? ("?rid=" + rid + "&type=" + type + "&theme=" + theme) : ("?url=" + url);
	processFrame.location.href = "../chat/checkChatter.jsp" + param;
}

function createRoom(url) {openWindowScroll(url, 430, 475, "room");}

function openRoom(url) {openWindowScroll(url, 800, 580, "room");}

function goRoom(rid, type, theme) {
	if (theme != null && theme == "410100") {
		if (type == OPENED_RTYPE) {
			openRoom("../chat/goAdminRoom.jsp?rid=" + rid);
		} else if (type == CLOSED_RTYPE) {
			openWindow("../chat/checkPassword.jsp?rid=" + rid + "&adminYn=Y", 300, 200, "password");
		}
	} else {
		if (type == OPENED_RTYPE) {
			openRoom("../chat/enterRoom.jsp?rid=" + rid + "&inittype=enter");
		} else if (type == CLOSED_RTYPE) {
			openWindow("../chat/checkPassword.jsp?rid=" + rid, 300, 200, "password");
		}
	}
}

function createTalkRoom(url) {openWindow(url, 620, 210, "room_talk");}

function openTalkRoom(url) {openWindow(url, 770, 550, "room_talk");}

function goTalkRoom(id, type, theme) {
	openTalkRoom("enterRoom.jsp?id=" + id);
}

function goPrivateTalkRoom(id) {processFrame.location.href = "createPrivateTalker.jsp?id=" + id;}
function openPrivateTalkRoom(id) {openTalkRoom("enterPrivateRoom.jsp?id=" + id);}

function requestPrivateChat(memId) {
	if (top.opener == null) {openWindow("../chat/requestPrivateChat.jsp?memId=" + memId, 350, 250, new Date().getTime());}
	else {top.opener.requestPrivateChat(memId);}
}

function viewRequestChat(msg, memId) {
	openWindow("../chat/viewRequestChat.jsp?msg=" + msg + "&memId=" + memId, 400, 330, new Date().getTime());
}

function viewPrivateChat(msg, memId) {
	openWindow("../chat/viewPrivateChat.jsp?msg=" + msg + "&memId=" + memId, 400, 330, new Date().getTime());
}

/***************************************************
*	avatar, item
****************************************************/

/* avatar maker */
function loadImage(file, zorder, imgkey, fileBL) {
	try {avatarFrame.loadImage(file, zorder, imgkey, fileBL);}
	catch (errorObject) {
		try {avatarFrame.location.href = "../common/avatarFrame.jsp";}
		catch (errorObject) {}
	}
}

function checkAvatar() {
	if (avatarFrame.isAvatar()) {return true;}
	else {
		alert("アバターのイメージがローディングされていません。");
		avatarFrame.location.href = "../common/avatarFrame.jsp";
		return false;
	}
}

/* mall menu */
function goMall(menuUrl, subMenu, itemMenu) {
	if (!isLogin()) {loginMsg();}
	else {
		var param = "subMenu=" + subMenu + "&itemMenu=" + itemMenu;
		try {
			itemFrame.location.href = menuUrl + (menuUrl.indexOf("?") > -1 ? "&" : "?") + param;
			menuBold(subMenu, itemMenu);
		}	catch (errorObject) {
			location.href = "../mall/mainItem.jsp?menuUrl=" + menuUrl + "&" + param;
		}
	}
}

function goHead() {
	if (getSexCookie() != getItemSexCookie()) {alert("顔のアイテムはプレゼント不可能です。");}
	else {goMall("../mall/listHeadItem.jsp", "2", "0");}
}

/* item sex */
function changeSex(sex) {
	var ckVal = getCookie("SK_REMARK");
	sex = sex == "M" ? "001001" : "001002";
	ckVal = ckVal.substring(0, 12) + sex + sex;
	setCookie("SK_REMARK", ckVal);
	this.location.reload();
//	location.href = "../main/main.jsp";
}

function changeItemSex() {
	try {
		if (itemFrame.location.href.indexOf("listHeadItem") > -1) {
			alert("顔のアイテムはプレゼント不可能です。");
			return;
		}
	} catch (errorObject) {}

	/** change opposite sex mode */
	if (getSexCookie() == getItemSexCookie()) {changeOppositeSex();}
	else {recoverItemSex()}

	try {
		avatarFrame.location.href = "../common/avatarFrame.jsp";
		itemFrame.location.href = itemFrame.location.href;
//		setMenuItemSex();
	}	catch (errorObject) {goMall("../mall/listDressItem.jsp?ctgryCd=302F11", "1", "0");}
}

function setMenuItemSex() {
	var result = "";

	if (getSexCookie() == getItemSexCookie()) {result = "異性にプレゼント";}
	else {result = "自分のショップへ";}

	try {getObjectByName("menuItemSex").innerHTML = result;}
	catch (errorObject) {}
}

function recoverItemSex() {setItemSexCookie(getSexCookie());}
function changeOppositeSex() {setItemSexCookie(getSexCookie() == "001001" ? "001002" : "001001");}

function getFaceTpCookie() {
	var ckVal = getCookie("SK_REMARK");
	return ckVal.substring(6, 12);
}

function getSexCookie() {
	var ckVal = getCookie("SK_REMARK");
	return ckVal.substring(12, 18);
}

function getItemSexCookie() {
	var ckVal = getCookie("SK_REMARK");
	return ckVal.substring(18, 24);
}

function setItemSexCookie(itemSex) {
	var ckVal = getCookie("SK_REMARK");
	ckVal = ckVal.substring(0, 18) + itemSex;
	setCookie("SK_REMARK", ckVal);
}

/* contest */
function registerContest(eventNo) {
	openWindowScroll("../mall/registerContestForm.jsp?eventNo=" + eventNo, 520, 545, "registerContest");
}

function registerAlert() {
	alert("既にコンテストに参加しています。");
}

/* view */
function viewItem(itemCd) {
	openWindowFixed("../account/viewItem.jsp?itemCd=" + itemCd, 430, 300, "viewItem");
}

function viewAlbum(memId) {
	openWindowFixed("../mall/listMemAvatar.jsp?memId=" + memId, 500, 340, "viewAlbum");
}

function previewItem(itemCd) {
	openWindowFixed("../mall/previewItem.jsp?itemCd=" + itemCd, 950, 600, "previewItem");
}

/* to display long item name */
var tID = null;
var getObj = null;
var mq = new classMQ();

function classMQ() {}

classMQ.prototype.set = function(obj) {
	getObj	= obj;
	this.BLANK = "                 ";
	this.CONTENT = getObj.value;
	this.SCROLL = this.BLANK + this.CONTENT + this.BLANK + this.CONTENT;
}

classMQ.prototype.scroll = function() {
	if (!getObj) {return;}

	var value = getObj.value;
	getObj.value = value.substring(1);
	if ("" == getObj.value.length) {getObj.value = this.SCROLL;}
}

classMQ.prototype.init = function() {
	if (!getObj)	return;
	getObj.value = this.CONTENT;
}

/***************************************************
*	etc
****************************************************/

/* submit */
function changePage(combo) {
	combo.form.pageNo.value = combo.options[combo.selectedIndex].value;
	combo.form.submit();
}

function changeRows(combo) {
	combo.form.rows.value = combo.options[combo.selectedIndex].value;
	combo.form.submit();
}

function changeOrder(order) {
	var form = document.tranMgr;
	form.order.value = order;
	form.submit();
}

function gotoPage(pageNo) {
	var form = document.tranMgr;
	form.pageNo.value = pageNo;
	form.submit();
}

function goSubPage(subPageNo) {
	var form = document.tranMgr;
	form.subPageNo.value = subPageNo;
	form.submit();
}

function resizeFrame() {
	var objBody = parent.itemFrame.document.body;
//	var innerWidth = objBody.scrollWidth + (objBody.offsetWidth - objBody.clientWidth);
	var innerHeight = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);

	if (innerHeight > 800) {
		var objFrame = parent.document.all["itemFrame"];
	//	objFrame.style.width = innerWidth;
		objFrame.style.height = innerHeight;
	}
}

/* test */
function openTest(testNo) {
	openWindow("../event/loadTest.jsp?no=" + testNo, 420, 350, "test");
}