//-----------------------------------------------------
// load JS
//-----------------------------------------------------
var jsFilesToImport = new Array();
var jsDirPath = "/common/js/";

jsFilesToImport[0] = "jquery.js";
jsFilesToImport[1] = "scroll.js";
jsFilesToImport[2] = "heightLine.js";
jsFilesToImport[3] = "switchTab.js";


function loadJS(){
	var jsFilesAmount = jsFilesToImport.length;
	for(i=0;i<jsFilesAmount;i++){
		var jsPath = jsDirPath + jsFilesToImport[i];
		document.open();
		document.write('<script type="text/javascript" src="'+ jsPath + '"></script>');
		document.close();
	}
}

loadJS();


//-----------------------------------------------------
// attach actions when open HTML
//-----------------------------------------------------
function set() {
	var img = document.getElementsByTagName('img');
	for ( var i = 0, imgLength = img.length ; i < imgLength ; i ++ ) {
			var cn = img[i].className.toLowerCase().split(' ');
			for ( var j = 0, varCnt = cn.length ; j < varCnt ; j ++ ) {
				if ( cn[j] == 'over' ) {
					img[i].onmouseover = function() {
						rollOverOn(this);
					}
					img[i].onmouseout = function() {
						rollOverOff(this);
					}
				}
			}
	}
	var img = document.getElementsByTagName('input');
	for ( var i = 0, imgLength = img.length ; i < imgLength ; i ++ ) {
		var cn = img[i].className.toLowerCase().split(' ');
		for ( var j = 0, varCnt = cn.length ; j < varCnt ; j ++ ) {
			if ( cn[j] == 'over' ) {
				img[i].onmouseover = function() {
					rollOverOn(this);
				}
				img[i].onmouseout = function() {
					rollOverOff(this);
				}
			}
		}
	}
}

function rollOverOn(obj) {
	if (obj.src.indexOf("_on") == -1 ){
		obj.src = obj.src.replace(/(.*)\.([a-z]{3})$/g,'$1_on.$2');
	}
}
function rollOverOff(obj) {
	if (obj.id != "ignore") {
		obj.src = obj.src.replace(/(.*)_on\.([a-z]{3})$/g,'$1.$2');
	}
}


//-----------------------------------------------------
//attach previous link
//-----------------------------------------------------

	function attachPreviousLink() {
		if ( document.referrer != "" && document.URL.indexOf(document.domain) != -1 ) {
			var td = document.createElement('td');
			td.className = "prev";
			var span = document.createElement('span');
			var a = document.createElement('a');
			a.innerHTML = "前のページに戻る";
			a.href = "javascript:history.back()";
			span.appendChild(a);
			td.appendChild(span);
			document.getElementById('appendPrevLink').insertBefore(td,document.getElementById('appendPrevLink').firstChild);
		}
	}


//-----------------------------------------------------
//- attach events when loaded
//-----------------------------------------------------
if ( window.addEventListener ) {
	window.addEventListener( "load", set, false );
} else if ( window.attachEvent ) {
	window.attachEvent( "onload", set );
} else {
	window.onload = set();
}


//-----------------------------------------------------
//- set window name
//-----------------------------------------------------
function setWindowName(){
	window.name = (document.body.className=="popup")? "mirai_form" : "mirai";
}


//-----------------------------------------------------
//- popup Window
//-----------------------------------------------------
function popupWin(obj) {
	var popupWindow=window.open(obj.href,'mirai_form','width=835,height=835,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes');
	popupWindow.focus();
}



