function openSubWindow(url, width, height) {
	var openUrl = url;
	var attribute = "toolbar=no,lacation=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height;
	var subWindow = window.open(openUrl, 'SubWinow', attribute);
	if (subWindow != null) {
		subWindow.focus();

		var x = (screen.width - width) / 2;
		var y = (screen.height - height) / 2;

		subWindow.moveTo(x,y);
		if (subWindow.opener == null) {
			subWindow.opener = self;
		}
	}
}

function cert(url) {

	var userId   = $('#user_id').val();
	var passwd   = $('#passwd').val();
//	var saveFlag = $('#save_flag').val();
	var saveFlag  = $("input[@name='save_flag']:checked").val();

//	var url = location.href;

	$.post("/friend/cert.php", {"user_id" : userId, "passwd" : passwd, "save_flag" : saveFlag}, function(data) {

			if ("success" == data) {

				afterMessage = "" +
//				"<font color='blue'><p><b>ログイン認証に成功しました。</b></p></font><br/>" +
//				"<br/>" +
//				"以下のＵＲＬに自動的に飛びます。<br/>"+
//				"URL : " + url + "<br/>" +
//				"ログインに成功しました。" +
//				"<br/>" +
//				"前のページに自動的に戻ります。<br/>戻らない場合は、<a href='" + url + "' target='_self'>こちら</a>をクリックしてください。";

				$("#msg").html("<font color='red'>ログインに成功しました。</font>");
//				$("#support").html(afterMessage);

				// 3秒停止
				window.setTimeout(function() {sslUrl = url.replace('https:', 'http:');document.location.href = sslUrl;}, 1000);

//				document.location.href = url;
//				document.location.href = "/friend/" + userId + "/";
			} else {
				$('#passwd').val('');
				var msgTag = "<font color='red'>" + data + "</font>";
				$("#msg").html(msgTag);
			}
		}
	);
}

function redirectUrl(hostName, url) {

		if (url == '') {
			document.location.href = 'http://' + hostName  + '/friend/top/';

		} else {
			document.location.href = url;

		}
}

// --------------------------------------------------------- Location Functions


function locationHref(url) {

	location.href = url;
}

//---------------------------------------------------------- Calendar Functions

function setCalender(year, month, blogPage) {

	if (blogPage == 'true') {
		linkCalendar(year, month);
	} else {
		displayCalendar(year, month);
	}
}

function displayCalendar(year, month) {

	$.post("../user/object_calendar.php", {"year" : year, "month" : month, "blog_page" : "false"}, function(data) {

//		alert(data);
		endLoading("calendar");

		$("#calendar").html(data);
	});
}

//----------------------------------------------------------------- 読者になる

function displayReader() {

	$.post("./object_friend.php", {}, function(data) {

		endLoading("reader");

		$("#reader").html(data);
	});
}

// ------------------------------------------------------------------- Ajax処理

function executeAjax(phpUrl, divId, title) {

	setLoading(divId, title);
	$.post(phpUrl, {}, function(data) {
		$("#" + divId).html(data);
	});
}


var _map = new Array();

function initOpenClose() {
	_map = new Array();
}

function executeOpenCloseAjax(url, divId, title) {

	var value = _map[divId];
	if ('open' == value) {
		executeAjax(url, divId, title);
		_map[divId] = 'close';

	} else if ('close' == value) {
		$("#" + divId).html("");
		_map[divId] = 'open';

	} else {
		executeAjax(url, divId, title);
		_map[divId] = 'close';
	}
}

// --------------------------------------------------------------- ローディング

function setLoading(divId, title) {

	if (title == undefined) {
		title = "読み込み中・・・";
	}

	$("#" + divId).html("<img src='../img/spinner.gif' border='0' alt='処理中'/>" + title);
}

function endLoading(divId) {
	$("#" + divId).html("");
}

//-------------------------------------------------------------------- 都道府県

function inputPrefAll(prefId) {

//	alert("pref all select start");

	$.post("../gadget/prefecture.php", {"type" : "select", "pref_id" : prefId}, function(data) {
//		alert("pref all select end:" + data);

    		selectTag = "<select name='pref_id'>\r\n<option value=''>都道府県</option>\r\n" + data + "</select>";

			$("#pref_id").html(selectTag);
		}
	);
}


