w3ncolor = "#999999";		// Navi番号の色　#88D9FF #A0A0A0
orgcolor = "#000000";		// Naviフィールドデフォルトの色
var navino = "navino";		// Naviフィールドのid名称
var thisno = "thisno";		// カレントページ番号保存フィールドのid名称
var nextno = "nextno";		// 次ページ番号保存フィールドのid名称
var pageno = "pageno";		// 次ページ移動フィールドのid名称
var w3ncode = "w3ncode";		// アクセスキーのid名称

if(window.addEventListener) {
	window.addEventListener('load', getNavino, false);
} else if(window.attachEvent){
	window.attachEvent('onload', getNavino);
} else {
	window.onload = getNavino;
}
// ロード時ページ番号を表示する
window.onload=function(){}
window.onUnload=function(){}

// Naviフィールドにフォーカスが入ったときクリアする
function clearNavino() {
 	if(document.getElementById(navino).style){
		document.getElementById(navino).style.color = orgcolor;
  	}
	document.getElementById(navino).value = "";
}

// Naviフィールドからフォーカスが出たときページ番号を表示する
function changeNavino() {
	if (document.getElementById(navino).value == "") {
 		if(document.getElementById(navino).style){
			document.getElementById(navino).style.color = w3ncolor;
  		}
		if (document.getElementById(thisno).value != "") {
			document.getElementById(navino).value = document.getElementById(thisno).value;
		} else {
			getNavino();
		}
	}
}

// AjaxでPHPと通信（別ドメイン）
function getNavino() {

 	if(document.getElementById(navino).style){
		orgcolor = document.getElementById(navino).style.color;
		document.getElementById(navino).style.color = w3ncolor;
  	}
	
	var w3nkey = document.getElementById(w3ncode).value;

	// パラメータの作成
	var param = 'url=' + encodeURI(location.href);
	if(w3nkey != '') param += '&key=' + encodeURI(w3nkey);

	// 別ドメインのAJAXサーバを呼び出す
   	var navi = document.getElementById('NaviForm');
	var out = document.createElement('script');
	out.src='http://w3navi.com/w3njs.php?' + param;
	navi.appendChild(out);
}

// ボタンクリック
function arrowClick() {
	if (document.getElementById(navino).value == document.getElementById(thisno).value && document.getElementById(nextno).value != "") {
		document.getElementById(pageno).value = document.getElementById(nextno).value;
	} else {
		document.getElementById(pageno).value = document.getElementById(navino).value;
 		if(document.getElementById(navino).style){
			document.getElementById(navino).style.color = w3ncolor;
  		}
		document.getElementById(navino).value = document.getElementById(thisno).value;
	}
	return true;
}
