//Crossプラットフォーム用JavaScript

//javascriptファイルのリンクの仕方
//<script type="text/javascript" src="common_blog/Cross.js"></script>

/**
 * IEでは getElementsByClassNameが存在しないため
 */
function getElementsByClass(searchClass) {

	if (document.all) {
		var classElements = new Array();
		var allElements = document.all;
			for (i = 0, j = 0; i < allElements.length; i++) {
				if (allElements[i].className == searchClass) {
					classElements[j] = allElements[i];
					j++;
				}
			}   
	} else if (document.getElementsByTagName) {
		var classElements = new Array();
		var allElements = document.getElementsByTagName("*");
			for (i = 0, j = 0; i < allElements.length; i++) {
				if (allElements[i].className == searchClass) {
					classElements[j] = allElements[i];
					j++;
				}
			}	   
   } else {
	  return;
   }

	return classElements;
}

function setOpener() {
	//親ウインドウを取得する(IEでshowModalDialogを使用したとき用)
	if(!opener) {
		opener = dialogArguments;
	}
}

/**
 * 
 * @param string url 開くウィンドウのURL
 *  @param array args
 * @param int width_px ウィンドウを開く時の幅をpxで指定
 * 						この値はFFを基準に与えられブラウザがIEの場合は値を変換する
 * @param int height_px ウィンドウを開く時の高さをpxで指定
 * @param boolean _scroll 画面をスクロールするかしないかを設定するTrueする
 * 
 */
function Cross_showModalDialog(url, args, width_px, height_px, _scroll) {
	//スクロールの設定 >> ///
	var scroll_ie = '';
	var scroll_ff = '';
	if (!_scroll) {
		//デフォルト
		scroll_ie = 'scroll:no;';
		scroll_ff = 'scrollbars=no';
	} else {
		if (_scroll=='yes' || _scroll==1) {
			scroll_ie = 'scroll:yes;';
			scroll_ff = 'scrollbars=yes';
		} else {
			scroll_ie = 'scroll:no;';
			scroll_ff = 'scrollbars=no';
		}
	}
	//スクロールの設定 << ///
	var str;
	if (window.showModalDialog) {
		//IE
		//width_pxはFFを基準の数値であるため、IE用に変換する
		width_px = 860/775*width_px;
		//IEのバージョンを判定
		myAgent = navigator.userAgent;
		myTop = myAgent.indexOf("MSIE",0);
		myLast = myAgent.indexOf(";",myTop);
		myVer = myAgent.substring(myTop+5,myLast);	// IEのバージョン切り取り
		if (myVer <= 6.0) {
			height_px = height_px + 100;
		}
		
		var ieFeatures = "dialogHeight:" + height_px + "px;"
						+ "dialogWidth:" + width_px + "px;"
						+ "edge:sunken;"
						+ "help:yes;"
						+ scroll_ie
						+ "resizable:no;"
						+ "status:no;"
						+ "unadorned:no;"
						+ "center:yes;";
		var modal_window = showModalDialog(url, args, ieFeatures);
		/*
		 * showModalDialog("modal.html",window,"dialogWidth:300px;dialogHeight:240px;status:no;"); 
		 * 
		 * dialogWidth   		:**px   	  						ダイアログの幅
			dialogHeight		:**px 								ダイアログの高さ
			dialogTop 			:**px 								ダイアログの上側表示位置
			dialogLeft 			:**px 								ダイアログの左側表示位置
			center 				:{ yes | no | 1 | 0 | on | off } 	ダイアログのセンター表示
			edge 				:{ sunken | raised } 				ダイアログの外枠のスタイル
			help 				:{ yes | no | 1 | 0 | on | off } 	HELPボタンの表示
			resizable		 	:{ yes | no | 1 | 0 | on | off } 	ダイアログのリサイズ
			scroll 				:{ yes | no | 1 | 0 | on | off } 	ダイアログのスクロール
			status 				:{ yes | no | 1 | 0 | on | off } 	ダイアログのステータスバー
			unadorned 			:{ yes | no | 1 | 0 | on | off } 	ダイアログのボーダークロム
			dialogHide 			:{ yes | no | 1 | 0 | on | off } 	ダイアログの印刷 
		 */
	} else {
		//FireFox
		var windowName = "modal";
		var x = (screen.width  - width_px) / 2;
		var y = (screen.height - height_px) / 2;

		
		var mozillaFeatures = "width=" + width_px + ","
							+ "height=" + height_px + ","
							+ "left=" + x + ","
							+ "top=" + y + ","

							+ "menubar=no,"
							+ "toolbar=no,"
							+ "status=no,"

							+ "location=no,"
							+ "directories=no,"

							+ scroll_ff + ","
							+ "resizable=no,"
							+ "modal=yes";

		var modal_window = window.open(url, windowName, mozillaFeatures);

	}
	return modal_window;
}


//////////////////////////
//Helpなどの表示のみのWindowをPopupする
// target :表示するURL
// @param url string
//				 PopupするWindowのURL
// @param width_pix integer
//					 PopupするWindowの幅pixel
// @param height_pix integer
//						 PopupするWindowの高さpixel
//////////////////////////
function ShowPopUpWindow(url, width_pix, height_pix, _scroll) {
	if (_scroll == undefined) {
		_scroll='yes';
	}
	
	var x_pix;
	if (width_pix) {
		x_pix= width_pix;
	} else {
		x_pix=320 * 2;
	}
	var y_pix;
	if (height_pix) {
		y_pix = height_pix;
	} else {
		y_pix=240 * 2;
	}
	//ブラウザを特定する
	var _mf_ = navigator.userAgent.match(/(gecko|firefox)/i) != null; //Moz/Firefox
	if (_mf_ == true) {
		//FireFox
		var args = "";
		Cross_showModalDialog(url, args, x_pix, y_pix, _scroll);
	} else {
		//IE
		var args = new Array();
		args[0] = window;
		str = Cross_showModalDialog(url, args, x_pix, y_pix, _scroll); 
	}
}




//////////////////////////
//mode=0:ポップアップ mode=1削除：mode=2編集
//type 表示する画面URL
//id 削除の場合　削除するID
//////////////////////////

/////////////////////////////////////////////////////////////////////////
//ログインポップアップ type=new ログイン画面 ：logout　ログアウト確認画面
//////////////////////////////////////////////////////////////////////////
function ShowLoginDialog(type, action_url) {
	var args = new Array();
	args[0] = window;
	var target = "http://" + location.host + "/blog/login/login_dialog.php?type=" + type + "&action_url=" + action_url;
	//IEVersionによって高さがいうことを聞かないのでversionを特定する
	var x_px;
	if (navigator.appVersion.indexOf("MSIE 7") != -1) {
		//IE7
		x_px = 210;
	} else {
		//IE6
		x_px = 270;
	}

	var str = Cross_showModalDialog(target, args, 360, x_px);
	//ブラウザを特定する
	var _mf_ = navigator.userAgent.match(/(gecko|firefox)/i) != null; 
	if (_mf_ == true) {
		//Moz/Firefox
		//親windowの画面遷移または、reloadが子windowで行う
	} else  {
		//IE
		if (str=='ok' || str=='logout_ok') { 
		//ログイン成功
			location.reload();
		}
		if (str=='redirect') {
			location.replace(action_rui);
		}
	}
}


/* 使用例：
<script language="javascript" type="text/javascript"><!--
//////////////////////////////////////////////
//mode=0:ポップアップ mode=1削除：mode=2編集
//type 表示する画面タイプ
//id 削除の場合　削除するID
/////////////////////////////////////////////
//function ShowDialog(mode, type, id) {
//	var args = new Array();
//	args[0] = window;
//  	args[1] = mode;
//
//	if (mode == 'popup') {
//		var args = new Array();
//		args[0] = window;
//	  	args[1] = id;
//
//		//ポップアップ
//		Cross_showModalDialog(type, args, '360', '210'); 
//	} else {
//		//ブラウザを特定する
//		var _mf_ = navigator.userAgent.match(/(gecko|firefox)/i) != null; //Moz/Firefox
//		if (_mf_ ==true) {
//			//FireFox
//			var args = "";
//			var target = "http://" + location.host + "/blog/tools/passwd_check_dialog.php?mode=" + mode + "&type=" + type + "&id=" + id;
//			Cross_showModalDialog(target, args, '360', '210');
//		} else {
//			//IE
//			var args = new Array();
//			args[0] = window;
//	  		args[1] = mode;
//			var target = "http://" + location.host + "/blog/tools/passwd_check_dialog.php";
//			//IEVersionによって高さがいうことを聞かないのでversionを特定する
//			if (navigator.appVersion.indexOf("MSIE 7") != -1) {
//				str = Cross_showModalDialog(target, args, '360', '210');
//			} else {
//				str = Cross_showModalDialog(target, args, '360', '270');
//			}
//			 
//			if (str) { 
//				document.main_form.passwd.value = str;
//				document.main_form.mode.value = mode;
//				document.main_form.message_type.value = type;
//				changeSubmit(type,id);
//			}
//		}
//	}
//}
// --></script>
*/
