function getCookie(name) {
	var key = name + "=";
	var value = null;
	var cookies = window.document.cookie.split(";");
	for (var i = 0; i < cookies.length; i++) {
		var pos = cookies[i].indexOf(key);
		if (pos >= 0) {
			value = cookies[i].substring(pos + key.length);
			if (value) break;
		}
	}
	return (value != null) ? unescape(value) : null;
}

function checkCookie() {
	return navigator.cookieEnabled;
}

function checkForLogin() {
	if (checkCookie()) {
		return true;
	} else {
		return false;
	}
}

function setIDPass() {
	var ID = getCookie('mailAddress');
	var Pass = getCookie('password');
	var frm = window.document.LoginForm;

	if (frm){
		if(ID){
			frm.mailAddress.value = ID;
		} else {
			frm.mailAddress.value = "";
		}

		if (Pass) {
			frm.password.value = Pass;
			frm.check.checked = true;
		} else {
			frm.password.value = "";
			frm.check.checked = true;
		}
	}
}

function loadGrandTop() {
	if(!checkForLogin()) {
		alert("ブラウザが Cookie を受け入れない設定になっております。\n"
			+ "登録時には Cookie を受け入れる設定に変更していただく必要がございます。");
		return false;
	}

	setIDPass();

	return;
}

function loadTop() {
	if(!checkForLogin()) {
		return false;
	}

	setIDPass();

	return;
}
