var msg_input_toolong="$esc.javascript($!{text.error.string.length.toolong})";

/**
 * 表示順イメージ画像クリック時処理
 *
 * @author 上海SPO HAGA
 * @param aIndex
 */
function Search(aUrl, aIndex) {
	var mainForm = document.MainForm;
	
	mainForm.searchType.value = aIndex;
	mainForm.action = aUrl;
	
	mainForm.submit();
}


/**
 * サークルアイコンまたはサークル名押下時処理
 *
 * @author 上海SPO HAGA
 * @param aId サークルID
 */
function ExecuteView(aUrl, aId) {

	var mainForm = document.MainForm;
	
	mainForm.circleId.value = aId;
	mainForm.action = aUrl;
	
	mainForm.submit();
}

/**
 * コンボボックスの作成処理を行います。
 *
 * @param aStr 開始番号
 * @param aEnd 終了番号
 * @param aPoint 該当番号
 */
function SetCombo(aStr, aEnd, aPoint) {
	var elem;
	var i;
	
	for (i = aStr; i <= aEnd; i++) {
		if (i == aPoint) elem += "<option value=" + i + " + selected>" + i;
		else elem += "<option value=" + i + ">" + i;
	}
	
	return elem;
}

/**
 * 時間文字列を改行して表示します。
 *
 * @author 上海SPO HAGA
 * @param aTime 時間文字列
 */
function formatTime(aTime) {
	var date = aTime.split(/ /);
	var time = date[1].split(/:/);
	var day  = date[0].split(/-/);
	
	return day[0] + "/" + day[1] + "/" + day[2] + "<br>" + time[0] + ":" + time[1];
}

/**
 * 引数で指定したバイト数以上の文字入力を不可にします。
 *
 * @author 上海SPO ANDREW
 * @param aId 該当オブジェクトID
 * @param aByte 制限バイト数
 */
function CheckInput(aId, aByte) {
	var elem = document.getElementById(aId);
	var temp = LTrim(elem.value);
	
	var len  = CountByte(RTrim(temp));
	
	if (len > aByte) {
		if (CountByte(elem.value.substring(elem.value.length - 1)) == 2) {
			elem.value = elem.value.substring(0, aByte - 1);
		} else {
			elem.value = elem.value.substring(0, aByte);
		}
		
		event.keyCode = 0;
	}
}

/**
 * バイト数の取得を行います。
 *
 * @author 上海SPO ANDREW
 * @param aString
 */
function CountByte(aString) {
	var count = 0;
	
	for (var i = 0; i < aString.length; ++i) {
		var sub = aString.substring(i, i + 1);
		
		if (isZenkaku(sub)) count += 2;
		else count += 1;
	}
	
	return count;
}

/**
 * 引数で与えられた文字列に全角文字が存在するか否かをチェックします。
 *
 * @author 上海SPO ANDREW
 * @param aString チェックする文字列
 * @return true: false:
 */
function isZenkaku(aString) {
	for (var i = 0; i < aString.length; ++i) {
		var c = aString.charCodeAt(i);
		
		if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) return false;
	}
	
	return true;
}

/**
 * 検索結果処理を呼び出します。
 *
 * @author 上海SPO HAGA
 * @param aId キーワードテキストボックスオブジェクト
 */
function Execute(aId) {
	if (!CheckKeepOutString(aId)) {
	    return false;
	}
	
	var elem = document.getElementById(aId);
	var mainForm = document.MainForm;
	
	mainForm.keyWord.value = RTrim(LTrim(elem.value));
	mainForm.categoryKbn.value = mainForm.category.options(mainForm.category.selectedIndex).value;
	mainForm.action = mainForm.nextPath.value;
	
	for (var i = 0; i < mainForm.search.length; i++)
		if (mainForm.search[i].checked)
			mainForm.searchType.value = mainForm.search[i].value;
	
	mainForm.submit();
}

/**
 * 検索結果処理を呼び出します。
 *
 * @author 上海SPO HAGA
 * @param aId キーワードテキストボックスオブジェクト
 * @param aLengthTitle キーワードの最大文字数(全角相当)
 */
function Execute2(aId, aLengthTitle) {
	if (!CheckKeepOutString(aId)) {
	    return false;
	}
	
	var elem = document.getElementById(aId);
	var mainForm = document.MainForm;
	
	var strKeyword = RTrim(LTrim(elem.value));

	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)

	if (CheckKeepOutString( aId ) == false) {
	    //alert( strKeyword + " は使用禁止文字列です。");
		//alert( "キーワードに使用禁止文字列が含まれています。");
		alert( "Please refrain from using forbidden keywords.");
		return;
	}

	// 長さチェック
	if( strKeyword.length > aLengthTitle ) {
		//alert("キーワードは入力可能文字数を超過しています。");
		alert("The keyword contains more letters than the maximum allowed.");
		elem.focus();
		return ;
	}

	mainForm.keyWord.value = RTrim(LTrim(elem.value));
	mainForm.categoryKbn.value = mainForm.category.options[mainForm.category.selectedIndex].value;
	mainForm.action = mainForm.nextPath.value;
	
	for (var i = 0; i < mainForm.search.length; i++){
		if (mainForm.search[i].checked){
			mainForm.searchType.value = mainForm.search[i].value;
		}
	}
	
	mainForm.submit();
}

/**
 * カテゴリ一覧リンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aIndex カテゴリ区分
 */
function ExecuteLink(aIndex) {
	var mainForm = document.MainForm;
	
	mainForm.keyWord.value = "";
	for (var i = 0; i < mainForm.search.length; i++){
		if (mainForm.search[i].checked){
			mainForm.searchType.value = mainForm.search[i].value;
		}
	}
	mainForm.categoryKbn.value = aIndex;
	mainForm.pageNumber.value = "1";
	mainForm.action = mainForm.nextPath.value;
	
	mainForm.submit();
}

/**
 * ロード時処理
 *
 * @author 上海SPO HAGA
 */
function Message(aMessage) {
	alert(aMessage);
}

/**
 * 引数で与えられた文字列の右側の空白を削除します。
 *
 * @author 上海SPO HAGA
 * @param aString チェックする文字列
 */
function RTrim(aString) {
	var nLoop = 0;
	var strReturn = aString;
	
	while (nLoop < aString.length) {
		if (strReturn.substring(strReturn.length - 1, strReturn.length) == " " || strReturn.substring(strReturn.length - 1, strReturn.length) == "　")
			strReturn = aString.substring(0, aString.length - (nLoop + 1));
		else break;
		
		nLoop++;
	}
	
	return strReturn;
}

/**
 * 引数で与えられた文字列の左側の空白を削除します。
 *
 * @author 上海SPO HAGA
 * @param aString チェックする文字列
 */
function LTrim(aString) {
	var nLoop = 0;
	var strReturn = aString;
	
	while (nLoop < aString.length) {
		if (strReturn.substring(0, 1) == " " || strReturn.substring(0, 1) == "　")
			strReturn = aString.substring(nLoop + 1, aString.length);
		else break;
		
		nLoop++;
	}
	
	return strReturn;
}

/**
 * サークルの新規作成リンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId サービス識別ID
 */
function ExecuteCircle(aUrl, aServiceId) {
	var mainForm = document.MainForm;
	
	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;
	
	mainForm.submit();
}

/**
 * エラーMessageの表示処理を行ないます。
 *
 * @author 上海SPO HAGA
 * @param aMessage エラーMessage
 * @param aParam パラメータ
 */
function Message(aMessage, aParam) {
	var message = aMessage.replace(":arg0", aParam);
	
	alert(message);
}

/**
 * Bannedリンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 * @param aMember メンバー名
 * @param aAccountId アカウントID
 * @param aCircleName 参加者区分
 */
function ExitForce(aUrl, aServiceId, aMember, aAccountId, aCircleName) {

	//if (confirm(aMember+'を脱退させます。よろしいですか？')) {
	//if (confirm(aMember+'さんをBannedしますか？')) {
	//var strMsg = " さんをBannedさせてよろしいですか？\nBannedさせた相手が再度このサークルに参加するには、サークルオーナーの承認が必要になります。" ;
	var strMsg1 = "Are you sure you would like to Ban " ;
	var strMsg2 = " from this Group? \nThe banned person must receive permission from the Group owner in order to rejoin this Group."
	if (confirm(strMsg1+aMember+strMsg2)) {
		var mainForm = document.MainForm;

		mainForm.serviceId.value = aServiceId;
		mainForm.userAccountId.value = aAccountId;
		mainForm.circleName.value = aCircleName;
		mainForm.action = aUrl;

		mainForm.submit();
	}
}

/**
 * 脱退するリンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aServiceId サービス識別ID
 */
function Exit(aUrl) {
	//if (!confirm(aCircleName+" サークルを脱退しますか？")) return;
	//var strMsg = "このサークルを脱退してよろしいですか？" ;
	var strMsg = "Are you sure you would like to leave this Group?" ;
	if (!confirm(strMsg)) return;

	var mainForm = document.MainForm;

	mainForm.serviceId.value = 3;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * サークルBBS画面への遷移処理を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl
 * @param aThreadId
 */
function ExecuteBBS(aUrl, aThreadId) {
	var mainForm = document.MainForm;
	mainForm.threadId.value = aThreadId;
	mainForm.action         = aUrl;
	mainForm.pageNumber.value = 0;
	mainForm.circlePageNumber.value = 1;

	mainForm.submit();
}

/**
 * エラーMessageの表示処理を行ないます。
 *
 * @author 上海SPO HAGA
 * @param aMessage エラーMessage
 * @param aParam 変換文字列
 */
function Error(aMessage, aParam) {
	var message = aMessage.replace(":arg0", aParam);

	alert(message);
}

/**
 * ページ切替リンク押下時処理を行います。
 *
 * @author 上海SPO HAGA
 * @param aPageNumber ページ番号
 * @param aId オブジェクトID
 */
function ChangePage(aPageNumber, aId) {
	document.getElementById(aId).value = aPageNumber;

	document.MainForm.submit();
}

/**
 * サークル編集押下時処理
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId サービス識別ID
 */
function ExecuteEdit(aUrl, aServiceId) {
	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;

	mainForm.submit();
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init == true)
		with (navigator) {
			if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
		}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

/** エラーMessage保存すること */
var msg_input_toolong="$esc.javascript($!{text.error.string.length.toolong})";

/**
 * 画面遷移を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function ExecuteThread(aUrl, aServiceId, aMsgTitle, aMsgBody) {
	var mainForm = document.MainForm;
	
	mainForm.threadTitle.value = trim(mainForm.threadTitle.value);
	mainForm.threadBody.value = trim(mainForm.threadBody.value);
	
	if (mainForm.threadTitle.value.length == 0) {
		alert(aMsgTitle);
		mainForm.threadTitle.focus();
		return;
	} else if ( CheckKeepOutString("threadTitle") == false ){
	    //alert("Thread Titleに使用禁止文字列が入っています。");
		alert("The Thread Title contains forbidden words.");
		return;
	}

	if (mainForm.threadBody.value.length == 0) {
		alert(aMsgBody);
		mainForm.threadBody.focus();
		return;
	} else if ( CheckKeepOutString("threadBody") == false ){
	    //alert("スレッド本文に使用禁止文字列が入っています。");
		alert("The Thread content contains forbidden words.");
		return;
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * 取消ボタン押下時処理を行ないます。
 *
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function ExecuteBack(aUrl, aServiceId) {
	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;

	// validation 対策
	mainForm.threadTitle.value = "" ;
	mainForm.threadBody.value = "" ;

	mainForm.submit();
}

/**
 * サークルのTOPへボタン押下時処理を行ないます。
 *
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function CircleTop(aUrl, aServiceId) {
	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.topFlg.value = "true";
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * スレッド削除処理を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function ExecuteDeleteThread(aUrl, aServiceId, aMsg) {
	if (!confirm(aMsg)) return;

	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * 削除処理を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aResNo レス番号(DB上の管理番号)
 * @param aServiceId 制御識別ID
 * @param aNo レス番号(スレッド毎の画面上の番号)
 */
function ExecuteDeleteRes(aUrl, aResNo, aServiceId, aMsg, aNo) {
	aMsg = aMsg.replace(":arg0", aNo);
	if (!confirm(aMsg)) return;

	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.resNo.value = aResNo;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * 書込みリンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aServiceId 制御識別ID
 * @param aUrl 遷移先URL
 */
function ExecuteKakikomi(aServiceId, aUrl, aMsg) {
	var mainForm = document.MainForm;
	mainForm.comment2.value = trim(mainForm.comment2.value);
	
	if ( trim(mainForm.comment2.value).length == 0) {
		alert(aMsg);
		mainForm.comment2.focus();
		return;
	} else if ( CheckKeepOutString("comment2") == false ){
	    //alert("コメントに使用禁止文字列が入っています。");
		alert("The comment contains forbidden words.");
		return;
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.comment.value   = mainForm.comment2.value;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * 編集処理を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 */
function ExecuteUpdate(aUrl, aServiceId) {
	var mainForm = document.MainForm;

	mainForm.action = aUrl;
	mainForm.serviceId.value = aServiceId;
//	mainForm.comment.value = mainForm.comment1.value;

	mainForm.submit();
}

/**
 *
 */
 
 function ExecuteMy() {
 alert("MyPageに移動のはずだが残念TTまだできないよ！");
 }
 

/**
 * サークル解散処理を行ないます。
 *
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 * @author 上海SPO HAGA
 */
function ExecuteFree(aUrl, aServiceId, aMsg) {
	if (!confirm(aMsg)) return;

	var mainForm = document.MainForm;

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;
	
	// validation対策
	mainForm.circleWord.value = "";

	mainForm.submit();
}

/**
 * サークルの新規作成処理を呼び出します。
 * 当該処理は、サークル名とサークル紹介文が入力されており、かつ、禁則文字が
 * 入力されていない場合、かつ、サークルアイコンファイルは、拡張子がJPGまたは
 * GIFまたはPNGのみに、かつ、サークルアイコンファイル名長が30バイト以内の場合
 * に実行されます。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function ExecuteNewCircle(aUrl, aServiceId, aNoCircleWord, aFileNameLength, aFileNameLengthMsg, aFileTypeMsg ) {
	var mainForm = document.MainForm;
	var iconFile = mainForm.circleIcon;

    mainForm.circleWord.value = trim(mainForm.circleWord.value);

	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	

	if ( mainForm.circleWord.value.length == 0 ) {
		alert(aNoCircleWord);
		mainForm.circleWord.focus();
		
		return;
	}	else if (CheckKeepOutString("circleWord") == false) {
	    //alert("サークル紹介文に使用禁止文字列が入っています。");
		alert("The Group description contains forbidden keywords.");
		return;
	}

	if (iconFile.value.length > 0) {
		var fileName = iconFile.value.substring(iconFile.value.lastIndexOf("\\") + 1);
		var fileNamemaxLength = aFileNameLengthMsg;
		
		if (CountByte(fileName) > fileNamemaxLength) {
			var msg = aFileNameLengthMsg;
			msg = msg.replace(":arg0", fileNamemaxLength);
			alert(msg);

			iconFile.focus();
			iconFile.select();

			return;
		}

		var fileExt  = fileName.substring(fileName.lastIndexOf(".") + 1);

		if (!fileExt.toUpperCase().match(/JPG|GIF|PNG/)) {
			alert(aFileTypeMsg);

			iconFile.focus();
			iconFile.select();

			return;
		}
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;
	mainForm.submit();
}

/**
 * 新規サークル作成処理
 */
 
 function ExecuteMakeNewCircle(aUrl, aServiceId, aNoCircleWord) {
    var mainForm = document.MainForm;
	var iconFile = mainForm.circleIcon;
	
	mainForm.circleName.value = trim(mainForm.circleName.value);
	
	if (mainForm.circleName.value.length == 0) {
		alert(aNoCircleWord);
		mainForm.circleName.focus();
		
		return;
	}	else if (CheckKeepOutString("circleName") == false) {
	    //alert("サークル名に使用禁止文字列が入っています。");
		alert("The Group name contains forbidden words.");
		return;
	}
	
	if (iconFile.value.length > 0) {
		var fileName = iconFile.value.substring(iconFile.value.lastIndexOf("\\") + 1);
		var fileNamemaxLength = aFileNameLengthMsg;
		
		if (CountByte(fileName) > fileNamemaxLength) {
			var msg = aFileNameLengthMsg;
			msg = msg.replace(":arg0", fileNamemaxLength);
			alert(msg);

			iconFile.focus();
			iconFile.select();

			return;
		}

		var fileExt  = fileName.substring(fileName.lastIndexOf(".") + 1);

		if (!fileExt.toUpperCase().match(/JPG|GIF|PNG/)) {
			alert(aFileTypeMsg);

			iconFile.focus();
			iconFile.select();

			return;
		}
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;
	mainForm.submit();
 }


/**
 *
 */
function NewCircleBack(aUrl) {
    var mainForm = document.MainForm;

	mainForm.action = aUrl;
	mainForm.encoding = "application/x-www-form-urlencoded";
	mainForm.submit();
	
}

/**
 * エラーMessageの表示処理を行ないます。
 *
 * @author 上海SPO HAGA
 * @param aMessage エラーMessage
 * @param aParam パラメータ
 */
function ErrorMessage(aMessage, aParam) {
	var message = aMessage.replace(":arg0", aParam);

	alert(message);
}

/**
 * ページ切替えコンボボックス変更時
 *
 * @author 上海SPO HAGA
 */
function ExecutePageChange(aUrl) {
	var mainForm = document.MainForm;

	mainForm.action = aUrl;
	mainForm.submit();
}

/**
 * ページ切替えコンボボックス変更時（ページ下側）
 *
 * @author 上海SPO HAGA
 */
function ExecutePageChange2(aUrl) {
	// 下のページ選択コンボの値を上のコンボにもコピー
	//document.MainForm.pageNumber.value = document.MainForm.pageNumber2.value ;
	// 元々のページ切り替え submit 処理
	ExecutePageChange( aUrl ) ;
}


/**
 * 半角相当で、文字数をカウントする
 * (半角を 1, 全角を 2として、文字数をカウントする。
 * ただし、半角カナは 2として、文字数をカウントする。)
 *
 */
function getCountChar( obj ) {
	var i ;
	var ch ;
	var cnt ;

	for( i = 0, cnt = 0 ; i < obj.length ; i++ ) {
		ch = escape( obj.charAt(i) ) ;		
		// UTF-8 でのカウント
		if( ch.length < 3 ){
			cnt++ ;
		} else {
			cnt += 2 ;
		}
	}
	//alert( "CountChar()\n" + obj + ": " + cnt +" 文字" ) ;
	return( cnt ) ;

}


/**
 * サークルの新規作成処理を呼び出します。
 * 当該処理は、サークル名とサークル紹介文が入力されており、かつ、禁則文字が
 * 入力されていない場合、かつ、サークルアイコンファイルは、拡張子がJPGまたは
 * GIFまたはPNGのみの場合に実行されます。
 * postgreSQLのvarcherなのでシングルバイトとマルチバイトを切り分けは行い
 * ません。
 * ファイル名はサークルIDに置き換わるのでLengthチェックは不要でした。
 * 
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
//function ExecuteNewCircle(aUrl, aServiceId, aNoCircleWord, aFileNameLength, aFileNameLengthMsg, aFileTypeMsg ) {
//function ExecuteNewCircle2(aUrl, aServiceId, aNoCircleName, aNoCircleWord, aFileNameLength, aFileNameLengthMsg, aFileTypeMsg, aLengthTitle, aLengthComment ) {
function ExecuteNewCircle2(aUrl, aServiceId, aNoCircleName, aNoCircleWord, aFileTypeMsg, aLengthTitle, aLengthComment ) {
	var mainForm = document.MainForm;
	var iconFile = mainForm.circleIcon;

    mainForm.circleWord.value = trim(mainForm.circleWord.value);

	// 未入力チェック
	if( mainForm.circleName != undefined ) {
		if ( mainForm.circleName.value.length == 0 ) {
			alert(aNoCircleName);
			mainForm.circleName.focus();
			
			return;
		}
	}
	if ( mainForm.circleWord.value.length == 0 ) {
		alert(aNoCircleWord);
		mainForm.circleWord.focus();
		
		return;
	}

	// 長さチェック
	if( mainForm.circleName != undefined ) {
		if( mainForm.circleName.value.length > aLengthTitle ) {
			//alert("サークル名が入力可能文字数を超過しています。");
			alert("The Group name contains more letters than the maximum allowed.");
			mainForm.circleName.focus();
			return ;
		}
	}
	var escStr = encodeEntities(mainForm.circleWord.value);
	//if( getCountChar( mainForm.circleWord.value ) > ( aLengthComment * 2 ) ) {
	if( escStr.length > aLengthComment ) {
		//alert("紹介文が入力可能文字数を超過しています。");
		alert("The Group description contains more letters than the maximum allowed");
		mainForm.circleWord.focus();
		return ;
	}

	// 禁止文字チェック(サークル名)
	if( mainForm.circleName != undefined ) {
		//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
		DWREngine.setTimeout(1000);		// DWR実行タイムアウト
		DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	
		if (CheckKeepOutString("circleName") == false) {
		   // alert("サークル名に使用禁止文字列が入っています。");
		   alert("The Group name contains forbidden words.");
			mainForm.circleName.focus();
			return;
		}
	}

	// 禁止文字チェック(サークル紹介文)
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	
	if ( mainForm.circleWord.value.length == 0 ) {
		alert(aNoCircleWord);
		mainForm.circleWord.focus();
		
		return;
	}	else if (CheckKeepOutString("circleWord") == false) {
	   // alert("サークル紹介文に使用禁止文字列が入っています。");
	   alert("The Group description contains more letters than the maximum allowed");
		mainForm.circleWord.focus();
		return;
	}

	//  
	if (iconFile.value.length > 0) {
		// ファイル名はサークルIDに置き換わるのでLengthチェックは不要 
		var fileName = iconFile.value.substring(iconFile.value.lastIndexOf("\\") + 1);
		var fileExt  = fileName.substring(fileName.lastIndexOf(".") + 1);

		if (!fileExt.toUpperCase().match(/JPG|GIF|PNG/)) {
			alert(aFileTypeMsg);

			iconFile.focus();
			iconFile.select();

			return;
		}
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;
	mainForm.submit();
}


/**
 * 画面遷移を行います。
 *
 * @author 上海SPO HAGA
 * @param aUrl 遷移先URL
 * @param aServiceId 制御識別ID
 */
function ExecuteThread2(aUrl, aServiceId, aMsgTitle, aMsgBody, aLengthTitle, aLengthBody ) {
	var mainForm = document.MainForm;

	var strHtml = editor.getHTML(); 
	var re = /bgcolor\s*=\s*\"([0-9]+)\"/;
	var strRep = strHtml.match(re);
	while (strRep) {
		var colorrgb = parseInt(RegExp.$1);
		strHtml = strHtml.replace(strRep[0],"bgcolor=\""+ HTMLArea._colorToRgb(colorrgb) +"\"");
		strRep = strHtml.match(re);
	}
	document.MainForm.threadBody.value = strHtml;

	mainForm.threadTitle.value = trim(mainForm.threadTitle.value);
	mainForm.threadBody.value = trim(mainForm.threadBody.value);
	

	// 未入力チェック（タイトル）
	if (mainForm.threadTitle.value.length == 0) {
		alert(aMsgTitle);
		mainForm.threadTitle.focus();
		return;
	}
	if (mainForm.threadBody.value.length == 0) {
		alert(aMsgBody);
		mainForm.threadBody.focus();
		return;
	}
	
	// 長さチェック
	// 全角１６文字入ればよい。Validatorが３２バイトではじいているので、全角チェックを行う
	if( countByte( mainForm.threadTitle.value ) > ( aLengthTitle * 2 ) ) {
		//alert("Thread Titleが入力可能文字数を超過しています。");
		alert("The Thread Title contains more letters than the maximum allowed.");
		mainForm.threadTitle.focus();
		return ;
	}
	var escStr = encodeEntities(mainForm.threadBody.value);
	if( escStr.length > aLengthBody ) {
		//alert("スレッド本文が入力可能文字数を超過しています。");
		alert("The Thread content contains more letters than the maximum allowed.");
		mainForm.threadBody.focus();
		return ;
	}

	// 禁止文字列チェック（タイトル）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("threadTitle") == false ){
	    //alert("Thread Titleに使用禁止文字列が入っています。");
		alert("The Thread Title contains forbidden words.");
		mainForm.threadTitle.focus();
		return;
	}

	// 禁止文字列チェック（本文）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("threadBody") == false ){
	    //alert("スレッド本文に使用禁止文字列が入っています。");
		alert("The Thread content contains forbidden words.");
		mainForm.threadBody.focus();
		return;
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.action = aUrl;

	mainForm.submit();
}


/**
 * 書込みリンク押下時処理
 *
 * @author 上海SPO HAGA
 * @param aServiceId 制御識別ID
 * @param aUrl 遷移先URL
 */
function ExecuteKakikomi2(aServiceId, aUrl, aMsg, aLengthComment) {
	var mainForm = document.MainForm;
	mainForm.comment2.value = trim(mainForm.comment2.value);
	
	// 未入力チェック（
	if ( trim(mainForm.comment2.value).length == 0) {
		alert(aMsg);
		mainForm.comment2.focus();
		return;
	}
	
	// 長さチェック
	var escStr = encodeEntities(mainForm.comment2.value);
	if( escStr.length > aLengthComment ) {
		//alert("コメントが入力可能文字数を超過しています。");
		alert("The comment contains more letters than the maximum allowed.");
		mainForm.comment2.focus();
		return ;
	}
	
	// 禁止文字列チェック（本文）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("comment2") == false ){
	    //alert("コメントに使用禁止文字列が入っています。");
		alert("The comment contains forbidden words.");
		mainForm.comment2.focus();
		return;
	}

	mainForm.serviceId.value = aServiceId;
	mainForm.comment.value   = mainForm.comment2.value;
	mainForm.action = aUrl;

	mainForm.submit();
}

/**
 * マジカルメーカ画像の件数チェックを行う
 *
 */
function checkMagicalIMGTag() {
	var checktext = document.MainForm.threadBody.value;
	
	ret = checktext.match(/<\w{0,}[^<>]{0,}>/g);
	var imgcount = 0;

	if(ret == null) {
		return true;
	}

	for(i=0; i<ret.length; i++) {
		if( ret[i].match(/<param/g) ) {
			
			if(ret[i].match(/<param name="movie" value="http:\/\/www\.magicalmaker\.com\/.{0,}" \/>/g)) {
//			if(ret[i].match(/<param name="movie" value="http:\/\/www\.nikolaschka\.jp\/.{0,}" \/>/g)) {
					imgcount = imgcount + 1;
			}
		}
	}

	if(imgcount > 3) {
		//alert("スレッド1件につき画像は3までです。");
		alert("The maximum number of images for one thread is 3.");
		return false;
	}
	
	return true;
}


/**
 * マジカルメーカーから起動される関数
 *
 */
function setMMTag(id, userid, url, jpg, width, height) {
	tag = createScriptTag(id, userid, url, jpg, width, height);
	setMagicalTag(tag);
}


/**
 * マジカルメーカーから渡された情報を元に
 * オブジェクトタグを生成する。
 */
function createScriptTag(id, userid, url, jpg, width, height) {
	var swf = 'http://www.magicalmaker.com' + url;
//	var swf = 'http://www.nikolaschka.jp' + url;
	var str = "";
	str += '<object width="' + width + '" height="' + height + '" id="' + id + '" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
	str += '<param name="movie"';
	str += ' value="' + swf + '" />';
	str += '</object>';

	return str;
}


/**
 * 生成したScriptタグをテキストエリアに設定する
 *
 */
function setMagicalTag(tag) {
	if(minipage_flg) {
		var threadBodyText = document.MainForm.threadBody.value;
		document.MainForm.threadBody.value = threadBodyText + tag;
	} else {
		if(edit_flg) {
			editor.focusEditor();
			editor.insertHTML(tag);
			var threadBodyText = document.MainForm.threadBody.value;
			document.MainForm.threadBody.value = threadBodyText + tag;
		} else {
			//alert('[タグの非表示]モードを選択してください。');
			alert('Please select the \"Don\'t show tags\" mode');
		}
	}
}
/**
 * 貼り付けてあるボイスを外す
 *
 */
function deleteVoiceComment(actionUrl, resNo) {
	document.MainForm.resNo.value = resNo;
	document.MainForm.action = actionUrl;
	document.MainForm.submit();
}

function leaveCircle() {
	document.leaveCircleForm.submit();
}

function joinCircle() {
	document.joinCircleForm.submit();
}

function forceLeave(accountId, nickname) {
	//if (confirm(nickname + " さんをBannedさせてよろしいですか？\nBannedさせた相手が再度このサークルに参加するには、サークルオーナーの承認が必要になります。")) {
	if (confirm("Are you sure you would like to Ban "+nickname+" from this Group? \nThe banned person must receive permission from the Group owner in order to rejoin this Group.")) {
		document.forceLeaveForm.accountId.value = accountId;
		document.forceLeaveForm.submit();
	}
}

function makeThreadDisp() {

	document.makeThreadDispForm.submit();
}

function dispCircle() {
	document.dispForm.submit();
}

function editDispCircle() {
	document.editDispForm.submit();
}

function makeDispCircle() {
	document.makeDispForm.submit();
}

function makeCircle(url) {
	var mainForm = document.MainForm;
	var iconFile = mainForm.formFile;

    mainForm.circleIntroComment.value = trim(mainForm.circleIntroComment.value);

	// 未入力チェック
	if( mainForm.circleName != undefined ) {
		if ( mainForm.circleName.value.length == 0 ) {
			//alert("サークル名を入力してください。");
			alert("Please enter the Group name.");
			mainForm.circleName.focus();
			
			return;
		}
	}
	if ( mainForm.circleIntroComment.value.length == 0 ) {
		//alert("サークル紹介文を入力してください。");
		alert("Please enter the Group description.");
		mainForm.circleIntroComment.focus();
		
		return;
	}

	// 長さチェック
	if( mainForm.circleName != undefined ) {
		if( mainForm.circleName.value.length > 20 ) {
			//alert("サークル名が入力可能文字数を超過しています。");
			alert("The Group name contains more letters than the maximum allowed.");
			mainForm.circleName.focus();
			return ;
		}
	}
	var escStr = encodeEntities(mainForm.circleIntroComment.value);
	// for cafesta ---------------------------------------------------
	if( escStr.length > 45000 ) {
	//if( escStr.length > 2048 ) {
	// for cafesta ---------------------------------------------------
		//alert("紹介文が入力可能文字数を超過しています。");
		alert("The Group description contains more letters than the maximum allowed.");
		mainForm.circleIntroComment.focus();
		return ;
	}

	// 禁止文字チェック(サークル名)
	if( mainForm.circleName != undefined ) {
		//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
		DWREngine.setTimeout(1000);		// DWR実行タイムアウト
		DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	
		if (CheckKeepOutString("circleName") == false) {
		    //alert("サークル名に使用禁止文字列が入っています。");
			alert("The Group name contains forbidden words.");
			mainForm.circleName.focus();
			return;
		}
	}

	// 禁止文字チェック(サークル紹介文)
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	
	if ( mainForm.circleIntroComment.value.length == 0 ) {
		//alert("サークル紹介文を入力してください。");
		alert("Please enter the Group description.");
		mainForm.circleIntroComment.focus();
		
		return;
	}	else if (CheckKeepOutString("circleIntroComment") == false) {
	    //alert("サークル紹介文に使用禁止文字列が入っています。");
		alert("The Group description contains more letters than the maximum allowed.");
		mainForm.circleIntroComment.focus();
		return;
	}

	//  
	if (iconFile.value.length > 0) {
		// ファイル名はサークルIDに置き換わるのでLengthチェックは不要 
		var fileName = iconFile.value.substring(iconFile.value.lastIndexOf("\\") + 1);
		var fileExt  = fileName.substring(fileName.lastIndexOf(".") + 1);

		if (!fileExt.toUpperCase().match(/JPG|GIF|PNG/)) {
			//alert("アイコンファイルはJPG,PNG,GIFのみ可能です。");
			alert("The icon file can only be in the JPG, PNG, or GIF format.");

			iconFile.focus();
			iconFile.select();

			return;
		}
	}
	mainForm.action = url;
	mainForm.submit();
}

function threadDisp(threadId) {
	document.threadDispForm.threadId.value = threadId;
	document.threadDispForm.submit();
}

function deleteThread() {
	//if (confirm('このスレッドを削除してよろしいですか？')) {
	if (confirm('Are you sure you would like to delete this Thread?')) {	
		document.deleteThreadForm.submit();
	}
}

function editThread() {
	document.editThreadForm.submit();
}

function makeRes() {
	var mainForm = document.MainForm;
	mainForm.comment2.value = trim(mainForm.comment2.value);
	
	// 未入力チェック（
	if ( trim(mainForm.comment2.value).length == 0) {
		alert("You did not fill in the required fields.");
		mainForm.comment2.focus();
		return;
	}
	
	// 長さチェック
	var escStr = encodeEntities(mainForm.comment2.value);
	if( escStr.length > 1024 ) {
		//alert("コメントが入力可能文字数を超過しています。");
		alert("The comment contains more letters than the maximum allowed.");
		mainForm.comment2.focus();
		return ;
	}
	
	// 禁止文字列チェック（本文）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("comment2") == false ){
	    //alert("コメントに使用禁止文字列が入っています。");
		alert("The comment contains forbidden words.");
		mainForm.comment2.focus();
		return;
	}

	document.makeResForm.res.value   = mainForm.comment2.value;
	document.makeResForm.voiceId.value = mainForm.registVoiceId.value;
	document.makeResForm.voiceType.value = mainForm.voiceType.value;
	document.makeResForm.voiceURL.value = mainForm.voiceURL.value;
	document.makeResForm.submit();
}

function deleteRes(dispResNo, resNo) {
	//if (confirm("コメント番号 " + dispResNo + " 番のコメントを削除してよろしいですか？")) {
	if (confirm("Are you sure you would like to delete comment number " + dispResNo + "?")) {
		document.deleteResForm.resNo.value = resNo;
		document.deleteResForm.submit();
	}
}
function breakCircle() {
	//if (confirm("サークルを解散します。よろしいですか？")) {
	if (confirm("Are you sure you would like to close this Group?")) {
		document.breakForm.submit();
	}
}

function makeThread(url) {
	var mainForm = document.MainForm;

	var strHtml = editor.getHTML(); 
	var re = /bgcolor\s*=\s*\"([0-9]+)\"/;
	var strRep = strHtml.match(re);
	while (strRep) {
		var colorrgb = parseInt(RegExp.$1);
		strHtml = strHtml.replace(strRep[0],"bgcolor=\""+ HTMLArea._colorToRgb(colorrgb) +"\"");
		strRep = strHtml.match(re);
	}
	document.MainForm.threadBody.value = strHtml;

	mainForm.threadTitle.value = trim(mainForm.threadTitle.value);
	mainForm.threadBody.value = trim(mainForm.threadBody.value);
	

	// 未入力チェック（タイトル）
	if (mainForm.threadTitle.value.length == 0) {
		alert("You did not fill in the required fields.");
		mainForm.threadTitle.focus();
		return;
	}
	if (mainForm.threadBody.value.length == 0) {
		alert("You did not fill in the required fields.");
		mainForm.threadBody.focus();
		return;
	}
	
	// 長さチェック
	// 全角１６文字入ればよい。Validatorが３２バイトではじいているので、全角チェックを行う
	// for cafesta ---------------------------------------------------
	if( mainForm.threadTitle.value.length > 65 ) {
	//if( countByte( mainForm.threadTitle.value ) > ( 32 * 2 ) ) {
	// for cafesta ---------------------------------------------------
		//alert("Thread Titleが入力可能文字数を超過しています。");
		alert("The Thread Title contains more letters than the maximum allowed.");
		mainForm.threadTitle.focus();
		return ;
	}
	var escStr = encodeEntities(mainForm.threadBody.value);
	// for cafesta ---------------------------------------------------
	if( escStr.length > 305000 ) {
	//if( escStr.length > 6144 ) {
	// for cafesta ---------------------------------------------------
		//alert("スレッド本文が入力可能文字数を超過しています。");
		alert("The Thread content contains more letters than the maximum allowed.");
		mainForm.threadBody.focus();
		return ;
	}

	// 禁止文字列チェック（タイトル）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("threadTitle") == false ){
	    //alert("Thread Titleに使用禁止文字列が入っています。");
		alert("The Thread Title contains forbidden words.");
		mainForm.threadTitle.focus();
		return;
	}

	// 禁止文字列チェック（本文）
	//使用禁止文字列のチェックの為に同期化(CheckKeepOutString()の前に必要)
	DWREngine.setTimeout(1000);		// DWR実行タイムアウト
	DWREngine.setAsync(false);		// 同期的に実行(false で同期)
	if ( CheckKeepOutString("threadBody") == false ){
	    //alert("スレッド本文に使用禁止文字列が入っています。");
		alert("The Thread content contains forbidden words.");
		mainForm.threadBody.focus();
		return;
	}

	mainForm.action = url;
	mainForm.voiceId.value = mainForm.registVoiceId.value;
	mainForm.submit();
}

function backCirclePage(url) {
	document.MainForm.action = url;
	document.MainForm.submit();
}

function threadSummary() {
	document.circleThreadSummaryForm.submit();
}

function circleMember() {
	document.circleMemberForm.submit();
}
