//	**************************************************
function common_load() {
	initialize();
}

//	**************************************************
function flicker_back(flag) {
	if (parent.PilotFrame.document.PilotForm.EnableBack.value == "1") {
		if (flag) {
			parent.PilotFrame.document.PilotForm.BackButton.src = back_images[3].src;
		}
		else {
			parent.PilotFrame.document.PilotForm.BackButton.src = back_images[2].src;
		}
	}
	else {
		parent.PilotFrame.document.PilotForm.BackButton.src = back_images[1].src;
	}
}

back_images = new Array();
back_images[1] = new Image();
back_images[1].src = "/n2bps/images/pilot/back.gif";
back_images[2] = new Image();
back_images[2].src = "/n2bps/images/pilot/back_off.gif";
back_images[3] = new Image();
back_images[3].src = "/n2bps/images/pilot/back_on.gif";

//	**************************************************
function flicker_faq(flag) {
	if (parent.PilotFrame.document.PilotForm.EnableFaq.value == "1") {
		if (flag) {
			parent.PilotFrame.document.PilotForm.FaqButton.src = faq_images[3].src;
		}
		else {
			parent.PilotFrame.document.PilotForm.FaqButton.src = faq_images[2].src;
		}
	}
	else {
		parent.PilotFrame.document.PilotForm.FaqButton.src = faq_images[1].src;
	}
}

faq_images = new Array();
faq_images[1] = new Image();
faq_images[1].src = "/n2bps/images/pilot/faq.gif";
faq_images[2] = new Image();
faq_images[2].src = "/n2bps/images/pilot/faq_off.gif";
faq_images[3] = new Image();
faq_images[3].src = "/n2bps/images/pilot/faq_on.gif";

//	**************************************************
function flicker_help(flag) {
	if (parent.PilotFrame.document.PilotForm.EnableHelp.value == "1") {
		if (flag) {
			parent.PilotFrame.document.PilotForm.HelpButton.src = help_images[3].src;
		}
		else {
			parent.PilotFrame.document.PilotForm.HelpButton.src = help_images[2].src;
		}
	}
	else {
		parent.PilotFrame.document.PilotForm.HelpButton.src = help_images[1].src;
	}
}

help_images = new Array();
help_images[1] = new Image();
help_images[1].src = "/n2bps/images/pilot/help.gif";
help_images[2] = new Image();
help_images[2].src = "/n2bps/images/pilot/help_off.gif";
help_images[3] = new Image();
help_images[3].src = "/n2bps/images/pilot/help_on.gif";

//	**************************************************
function flicker_menu(flag) {
	if (parent.PilotFrame.document.PilotForm.EnableMenu.value == "1") {
		if (flag) {
			parent.PilotFrame.document.PilotForm.MenuButton.src = menu_images[3].src;
		}
		else {
			parent.PilotFrame.document.PilotForm.MenuButton.src = menu_images[2].src;
		}
	}
	else {
		parent.PilotFrame.document.PilotForm.MenuButton.src = menu_images[1].src;
	}
}

menu_images = new Array();
menu_images[1] = new Image();
menu_images[1].src = "/n2bps/images/pilot/menu.gif";
menu_images[2] = new Image();
menu_images[2].src = "/n2bps/images/pilot/menu_off.gif";
menu_images[3] = new Image();
menu_images[3].src = "/n2bps/images/pilot/menu_on.gif";

//	**************************************************
function flicker_logoff(flag) {
	if (parent.PilotFrame.document.PilotForm.EnableLogoff.value == "1") {
		if (flag) {
			parent.PilotFrame.document.PilotForm.LogoffButton.src = logoff_images[3].src;
		}
		else {
			parent.PilotFrame.document.PilotForm.LogoffButton.src = logoff_images[2].src;
		}
	}
	else {
		parent.PilotFrame.document.PilotForm.LogoffButton.src = logoff_images[1].src;
	}
}

logoff_images = new Array();
logoff_images[1] = new Image();
logoff_images[1].src = "/n2bps/images/pilot/logoff.gif";
logoff_images[2] = new Image();
logoff_images[2].src = "/n2bps/images/pilot/logoff_off.gif";
logoff_images[3] = new Image();
logoff_images[3].src = "/n2bps/images/pilot/logoff_on.gif";

//	**************************************************
function pilot_load() {

}

//	**************************************************
function press_back() {
	if (parent.PilotFrame.document.PilotForm.EnableBack.value == "1") {
		submit_command("Back");
	}
}

//	**************************************************
function press_faq() {
	if (parent.PilotFrame.document.PilotForm.EnableFaq.value == "1") {
		window.open("faq.html");
	}
}

//	**************************************************
function press_help() {
	if (parent.PilotFrame.document.PilotForm.EnableHelp.value == "1") {
		window.open("help.html");
	}

	return;
}

//	**************************************************
function press_menu() {
	if (parent.PilotFrame.document.PilotForm.EnableMenu.value == "1") {
		submit_command("Menu");
	}
}

//	**************************************************
function press_logoff() {
	if (parent.PilotFrame.document.PilotForm.EnableLogoff.value == "1") {
		submit_command("Logoff");
	}
}

//	**************************************************
function scroll_message() {
	parent.FooterFrame.document.FooterForm.StatusMessage.value = status_message;
	status_message = status_message.substring(1, status_message.length) + status_message.substring (0, 1);
	timer_id = setTimeout("scroll_message()", delay);
}

var status_message;
var timer_id;
var delay = 500;

//	**************************************************
function show_message(message) {
	if (message.length == 0) {
		parent.FooterFrame.document.FooterForm.StatusMessage.value = "";
	}
	else {
		status_message = "          " + message;

		for (i = (90 - status_message.length) / 10 + 1; i > 0; i--) {
			status_message = status_message + "          ";
		}

		scroll_message();
	}
}

//	**************************************************
function scroll_end() {

}

//	**************************************************
function brain_sellers() {
	window.open("http://www.brainsellers.com");
}

//	**************************************************
function initialize() {
	last = 0;

	parent.document.title = parent.MainFrame.document.MainForm.TitleMessage.value;

	if (parent.MainFrame.document.MainForm.EnableBack.value == "1") {
		parent.PilotFrame.document.PilotForm.EnableBack.value = "1";
		parent.PilotFrame.document.PilotForm.BackButton.src = back_images[2].src;
		parent.PilotFrame.document.PilotForm.BackButton.alt = "戻る";
	}
	else {
		parent.PilotFrame.document.PilotForm.EnableBack.value = "0";
		parent.PilotFrame.document.PilotForm.BackButton.src = back_images[1].src;
		parent.PilotFrame.document.PilotForm.BackButton.alt = "使用できません";
	}

	if (parent.MainFrame.document.MainForm.EnableFaq.value == "1") {
		parent.PilotFrame.document.PilotForm.EnableFaq.value = "1";
		parent.PilotFrame.document.PilotForm.FaqButton.src = faq_images[2].src;
		parent.PilotFrame.document.PilotForm.FaqButton.alt = "ＦＡＱ";
	}
	else {
		parent.PilotFrame.document.PilotForm.EnableFaq.value = "0";
		parent.PilotFrame.document.PilotForm.FaqButton.src = faq_images[1].src;
		parent.PilotFrame.document.PilotForm.FaqButton.alt = "使用できません";
	}

	if (parent.MainFrame.document.MainForm.EnableHelp.value == "1") {
		parent.PilotFrame.document.PilotForm.EnableHelp.value = "1";
		parent.PilotFrame.document.PilotForm.HelpButton.src = help_images[2].src;
		parent.PilotFrame.document.PilotForm.HelpButton.alt = "ヘルプ";
	}
	else {
		parent.PilotFrame.document.PilotForm.EnableHelp.value = "0";
		parent.PilotFrame.document.PilotForm.HelpButton.src = help_images[1].src;
		parent.PilotFrame.document.PilotForm.HelpButton.alt = "使用できません";
	}

	if (parent.MainFrame.document.MainForm.EnableMenu.value == "1") {
		parent.PilotFrame.document.PilotForm.EnableMenu.value = "1";
		parent.PilotFrame.document.PilotForm.MenuButton.src = menu_images[2].src;
		parent.PilotFrame.document.PilotForm.MenuButton.alt = "メニュー";
	}
	else {
		parent.PilotFrame.document.PilotForm.EnableMenu.value = "0";
		parent.PilotFrame.document.PilotForm.MenuButton.src = menu_images[1].src;
		parent.PilotFrame.document.PilotForm.MenuButton.alt = "使用できません";
	}

	if (parent.MainFrame.document.MainForm.EnableLogoff.value == "1") {
		parent.PilotFrame.document.PilotForm.EnableLogoff.value = "1";
		parent.PilotFrame.document.PilotForm.LogoffButton.src = logoff_images[2].src;
		parent.PilotFrame.document.PilotForm.LogoffButton.alt = "ログオフ";
	}
	else {
		parent.PilotFrame.document.PilotForm.EnableLogoff.value = "0";
		parent.PilotFrame.document.PilotForm.LogoffButton.src = logoff_images[1].src;
		parent.PilotFrame.document.PilotForm.LogoffButton.alt = "使用できません";
	}

	show_message(parent.MainFrame.document.MainForm.StatusMessage.value);
}

//	**************************************************
function check_duplicate() {
	now = new Date();

	if ((parent.MainFrame.document.MainForm.SubmitCommand.value == "") || (last == 0) || ((now - last) > 500)) {
		last = now;
		return true;
	}
	else {
		return false;
	}
}

var last = 0;
var now;

//	**************************************************
function submit_cancel() {
	if (check_duplicate()) {
		parent.MainFrame.document.MainForm.SubmitCommand.value = "Cancel";
		parent.MainFrame.document.MainForm.submit();
	}
	else {
		alert("ただいま処理中です。もう少しお待ち下さい。");
	}
}

//	**************************************************
function submit_command(command) {
	if (check_duplicate()) {
		parent.MainFrame.document.MainForm.TitleMessage.value  = "";
		parent.MainFrame.document.MainForm.StatusMessage.value = "";

		status_message = "";
		timer_id = setTimeout("scroll_end()", delay);

		parent.MainFrame.document.MainForm.SubmitCommand.value = command;
		parent.MainFrame.document.MainForm.submit();
	}
	else {
		alert("ただいま処理中です。もう少しお待ち下さい。");
	}
}

//	**************************************************
function check_numeric(source) {
	for (i = 0; i < source.length; i++) {
		ch = source.charAt(i);

		if ((ch >= "0") && (ch <= "9")) {
			continue;
		}

		return false;
	}

	return true;
}

//	**************************************************
function check_signed_numeric(source) {
	for (i = 0; i < source.length; i++) {
		ch = source.charAt(i);

		if ((ch >= "0") && (ch <= "9")) {
			continue;
		}
		else if ((ch == "-") && (i == 0)) {
			continue;
		}

		return false;
	}

	return true;
}

//	**************************************************
function check_signed_numeric2(source) {
	point = 0;

	for (i = 0; i < source.length; i++) {
		ch = source.charAt(i);

		if ((ch >= "0") && (ch <= "9")) {
			point = 1;
			continue;
		}
		else if ((ch == "-") && (i == 0)) {
			continue;
		}
		else if ((ch == ".") && (point == 1)) {
			point = 2;
			continue;
		}

		return false;
	}

	return true;
}

//	**************************************************
function check_day(day) {
	if (!check_numeric(day)) {
		return false;
	}

	if ((new Number(day) < 1) || (new Number(day) > 31)) {
		return false;
	}

	return true;
}

//	**************************************************
function check_date(year, month, day) {
//	date = new Date();
//	date.setYear(year);
//	date.setMonth(month - 1);
//	date.setDate(day);
	date = new Date(year, month - 1, day, 0, 0, 0);

	if ( date.getYear() < 1900 ) {
		wyear = 1900 + date.getYear();
	} else {
		wyear = date.getYear();
	}	

//	if ((date.getYear() != year) || (date.getMonth() != (month - 1)) || (date.getDate() != day)) {
	if ((wyear != year) || (date.getMonth() != (month - 1)) || (date.getDate() != day)) {
		return false;
	}

	return true;
}

//	**************************************************
function check_date2(year, month, day, hours) {
	date = new Date();
	date.setYear(year);
	date.setMonth(month - 1);
	date.setDate(day);
	date.setHours(hours);

	if ((date.getYear() != year) || (date.getMonth() != (month - 1)) || (date.getDate() != day) || (date.getHours() != hours)) {
		return false;
	}

	return true;
}

//	**************************************************
function create_array(source) {
	tmp = new Array();
	index = 0;
	p = 0;

	for (i = 0; i < source.length; i++) {
		if (source.charAt(i) == ";") {
			tmp[index++] = source.substring(p, i);
			p = i + 1;
		}
	}

	return tmp;
}
