// 画面位置を固定する
window.onresize = function() {
	fixDisplayPositionMain();
}
window.onload   = function() {
	fixDisplayPositionMain();
}

// 画面表示設定
function fixDisplayPositionMain() {
	
	try{
		
		var nv  = navigator.userAgent;
		var dis = document.getElementById("displayControl");
		if (nv.match(new RegExp("MSIE 6", "i")) == true) {
			fixDisplayPosition();
		} else {
			dis.style.position = "fixed";
			dis.style.top   = "15px";
			dis.style.left     = (document.body.offsetWidth / 2) + 390 + "px";
		}
		
	}
	
	catch(e){
		
		// 処理しない
		
	}
}

// 画面表示設定
function fixDisplayPosition() {

	var dis = document.getElementById("displayControl");
	
	dis.style.position = "absolute";
	
	dis.style.top      = document.body.offsetHeight + document.body.scrollTop - 15 + "px";
	dis.style.left     = (document.body.offsetWidth / 2) + 390 + "px";
	
	setTimeout("fixDisplayPosition()", 10);
	
}

// 入力チェック [必須チェック]
function inputCheckForMust(oj) {

  if (oj.value.length == 0) {
    
    alert("この項目は、入力が必須になっています。お手数ですが、入力をお願いします")

    //対象エレメントの背景色をオレンジにする
    if(!!oj.style)oj.style.backgroundColor='#FFFF00'
    //oj.focus();
    
  } else {

    //対象エレメントの背景色を白に戻す
    if(!!oj.style)oj.style.backgroundColor='#FFFFFF'

  }
  
}

// 入力チェック [長さチェック]
function inputCheckForLength(oj, mixLength, maxLength, str) {

  if (oj.value.length < mixLength || oj.value.length > maxLength) {
    
    alert("この項目は、" + mixLength +"桁から" + maxLength + "桁の長さで入力してください。お手数ですが、再入力をお願いします")

    //対象エレメントの背景色をオレンジにする
    if(!!oj.style)oj.style.backgroundColor='#FFFF00'
    //oj.focus();
    
  } else {
	
	if (isErrorInputChar(oj, str) == true) {
		alert("この項目で入力が許されいている文字は、半角文字の" + str + "です。お手数ですが、再入力をお願いします")
	    //対象エレメントの背景色をオレンジにする
	    if(!!oj.style)oj.style.backgroundColor='#FFFF00'
	    //oj.focus();
	} else {
	    //対象エレメントの背景色を白に戻す
	    if(!!oj.style)oj.style.backgroundColor='#FFFFFF'
	}

  }

}

// 入力チェック [エラーリセット]
function inputCheckErrorReset(oj) {
    //対象エレメントの背景色を白に戻す
    if(!!oj.style)oj.style.backgroundColor='#FFFFFF'
}

function isErrorInputChar(oj, str){
    err = 0;
    for (i = 0; i < oj.value.length; i++) {
      if (str.indexOf(oj.value.charAt(i)) == -1) err++;
    }
    if (err != 0) {
	    return true;
    } else {
		return false;
    }
}

//--送信ボタンを押したときの全エレメントチェック
function inputCheckBeforeSubmit(oj){
	
	isError = false;
	
	if (oj.I_USER_ID.value.length == 0) {
		if(!!oj.I_USER_ID.style)oj.I_USER_ID.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_USER_ID.style)oj.I_USER_ID.style.backgroundColor='#FFFFFF'
	}
	if (oj.I_USER_PASSWORD.value.length == 0) {
		if(!!oj.I_USER_PASSWORD.style)oj.I_USER_PASSWORD.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_USER_PASSWORD.style)oj.I_USER_PASSWORD.style.backgroundColor='#FFFFFF'
	}
	if (oj.I_USER_RE_PASSWORD.value.length == 0) {
		if(!!oj.I_USER_RE_PASSWORD.style)oj.I_USER_RE_PASSWORD.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_USER_RE_PASSWORD.style)oj.I_USER_RE_PASSWORD.style.backgroundColor='#FFFFFF'
	}
	if (oj.I_NICK_NAME.value.length == 0) {
		if(!!oj.I_NICK_NAME.style)oj.I_NICK_NAME.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_NICK_NAME.style)oj.I_NICK_NAME.style.backgroundColor='#FFFFFF'
	}	
	if (oj.I_AUTH_IMG_NO.value.length == 0) {
		if(!!oj.I_AUTH_IMG_NO.style)oj.I_AUTH_IMG_NO.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_AUTH_IMG_NO.style)oj.I_AUTH_IMG_NO.style.backgroundColor='#FFFFFF'
	}
	if (oj.I_MESSAGE.value.length == 0) {
		if(!!oj.I_MESSAGE.style)oj.I_MESSAGE.style.backgroundColor='#FFFF00'
		isError = true;
	} else {
		if(!!oj.I_MESSAGE.style)oj.I_MESSAGE.style.backgroundColor='#FFFFFF'
	}
	
	// 入力必須項目に入力されていない場合
	if (isError == true) {
		alert("入力が必須になっている項目が未入力です。お手数ですが、入力をお願いします。黄色く着色した項目です。");
		return false;
	}
	
	// 希望試験種別が未選択の場合
	if (oj.I_LEVEL_TARGET != null) {
		if (oj.I_LEVEL_TARGET.value == 0) {
			if(!!oj.I_LEVEL_TARGET.style)oj.I_LEVEL_TARGET.style.backgroundColor='#FFFF00'
			alert("希望試験種別が未選択です。お手数ですが、入力をお願いします。");
			return false;
		} else {
			if(!!oj.I_LEVEL_TARGET.style)oj.I_LEVEL_TARGET.style.backgroundColor='#FFFFFF'
		}
	}
		
	// セキュリティー上、ユーザーIDとパスワードを同じ値にはできません。
	if (oj.I_USER_ID.value == oj.I_USER_PASSWORD.value) {
		alert("セキュリティー上、「ユーザーID」と「パスワード」を同じ値にはできません。");
		if(!!oj.I_USER_PASSWORD.style)oj.I_USER_PASSWORD.style.backgroundColor='#FFFF00'
		if(!!oj.I_USER_RE_PASSWORD.style)oj.I_USER_RE_PASSWORD.style.backgroundColor='#FFFF00'
		return false;
	}
	
	// セキュリティー上、ユーザーIDとニックネームを同じ値にはできません。
	if (oj.I_USER_ID.value == oj.I_NICK_NAME.value) {
		alert("セキュリティー上、「ユーザーID」と「ニックネーム」を同じ値にはできません。");
		if(!!oj.I_NICK_NAME.style)oj.I_NICK_NAME.style.backgroundColor='#FFFF00'
		return false;
	}

	// パスワードとパスワード (確認)が一致しません。
	if (oj.I_USER_PASSWORD.value != oj.I_USER_RE_PASSWORD.value) {
		alert("入力された「パスワード」と「パスワード (確認)」が一致しません。");
		if(!!oj.I_USER_PASSWORD.style)oj.I_USER_PASSWORD.style.backgroundColor='#FFFF00'
		if(!!oj.I_USER_RE_PASSWORD.style)oj.I_USER_RE_PASSWORD.style.backgroundColor='#FFFF00'
		return false;
	}
			
}

// 手書き文字の記入状況チェック
function displayHandWriteStatus(doc, command, args) {
	var msg = "";
	if (args == '') {
		msg = "未記入";
	} else if (args == 'ERASED_DATA') {
		msg = "未記入";
	} else {
		msg = '<span style="color: #CC0000; background-color: #FFD7D7">↓●処理成功</span>';
	}
	
	document.getElementById(command + '_STATUS').innerHTML = msg;
}

// 年号を取得する[4桁]
function getYearForAllBrowser() {
	var dateTimer = new Date();
	var year = dateTimer.getYear();
	if (year < 2000) {
		year = year + 1900;
	}
	return year;
}

// Enterキーを無効にする
function invalidateReturnKey(evt) {
	evt = (evt) ? evt : event; 
	var charCode=(evt.charCode) ? evt.charCode : 
		((evt.which) ? evt.which : evt.keyCode);
	if ( Number(charCode) == 13 || Number(charCode) == 3) {
		return false;
	} else {
		return true;
	}
}

// ブラウザ名を取得する
function getBrowserName() {
    var aName  = navigator.appName.toUpperCase();
    var uName = navigator.userAgent.toUpperCase();
    if (uName.indexOf("SAFARI") >= 0)  return "Safari";
    if (uName.indexOf("OPERA") >= 0)  return "Opera";
    if (uName.indexOf("FIREFOX") >= 0)  return "Firefox";
    if (aName.indexOf("NETSCAPE") >= 0)  return "Netscape";
    if (aName.indexOf("MICROSOFT") >= 0) return "Explorer";
    return "";
}

// Flashを書き込む
function reloadImage(appName, systemAccessID, questionResourcesID, index){
	inserthtml  = '<img src="/' + appName + '/res/RDM' + systemAccessID + '/' + questionResourcesID + '" alt="図表" />';
	document.getElementById('displayImage_' + index).innerHTML = inserthtml;
}

// Flashを書き込む
function reloadHWNew(index, flashBackGroundColor, flashFontColor, resURL){
	inserthtml  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	inserthtml += '        codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
	inserthtml += '        width="630" ';//420-630
	inserthtml += '        height="252"';//168-252
	inserthtml += '        swLiveConnect="true"';
	inserthtml += '        id="movie' + index + '"';
	inserthtml += '        name="movie' + index + '"';
	inserthtml += '        align="middle">';
	inserthtml += '<param name="allowScriptAccess" value="always" />';
	inserthtml += '<param name="movie" value="' + resURL + '/flash/handwrite.swf" />';
	inserthtml += '<param name="quality" value="high" />';
	inserthtml += '<param name="bgcolor" value="#ffffff" />';
	inserthtml += '<param name="flashvars" value="copyright=www.kanjihakase.com&q=I_HAND_WRITE_' + index + flashBackGroundColor + flashFontColor + '" />';
	inserthtml += '<embed src="' + resURL + '/flash/handwrite.swf" ';
	inserthtml += '       quality="high" ';
	inserthtml += '       bgcolor="#ffffff" ';
	inserthtml += '       width="630" ';//420
	inserthtml += '       height="252" ';//148
	inserthtml += '       align="middle" ';
	inserthtml += '       allowScriptAccess="always" ';
	inserthtml += '       swLiveConnect="true"';
	inserthtml += '       id="movie' + index + '" ';

	inserthtml += '       name="movie' + index + '" ';

	inserthtml += '       flashvars="copyright=www.kanjihakase.com&q=I_HAND_WRITE_' + index + flashBackGroundColor + flashFontColor + '"';
	inserthtml += '       type="application/x-shockwave-flash" ';
	inserthtml += '       pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	inserthtml += '</object>';

	inserthtml += '<SCRIPT event=FSCommand(command,args) for=movie' + index + '>movie' + index + '_DoFSCommand(command,args);</SCRIPT>';
	
	document.getElementById('displayHandWrite_' + index).innerHTML = inserthtml;
	
	// リセットする
	document.getElementById('I_HAND_WRITE_' + index + '1_STATUS').innerHTML='未記入';
	document.getElementById('I_HAND_WRITE_' + index + '2_STATUS').innerHTML='未記入';
	document.getElementById('I_HAND_WRITE_' + index + '3_STATUS').innerHTML='未記入';
	document.getElementById('I_HAND_WRITE_' + index + '4_STATUS').innerHTML='未記入';
	
}

// Flashを書き込む
function writeFlashNew(index, flashBackGroundColor, flashFontColor, resURL){

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
	document.write('        codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');
	document.write('        width="630" ');//420-630
	document.write('        height="252"');//168-252
	document.write('        swLiveConnect="true"');
	document.write('        id="movie' + index + '"');
	document.write('        name="movie' + index + '"');
	document.write('        align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="' + resURL + '/flash/handwrite.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="flashvars" value="copyright=www.kanjihakase.com&q=I_HAND_WRITE_' + index + flashBackGroundColor + flashFontColor + '" />');
	
	document.write('<embed src="' + resURL + '/flash/handwrite.swf" MAYSCRIPT="true" ');
	document.write('       quality="high" ');
	document.write('       bgcolor="#ffffff" ');
	document.write('       width="630" ');//420
	document.write('       height="252" ');//148
	document.write('       align="middle" ');
	document.write('       allowScriptAccess="always" ');
	document.write('       swLiveConnect="true"');
	document.write('       id="movie' + index + '" ');

	document.write('       name="movie' + index + '" ');

	document.write('       flashvars="copyright=www.kanjihakase.com&q=I_HAND_WRITE_' + index + flashBackGroundColor + flashFontColor + '"');
	document.write('       type="application/x-shockwave-flash" ');
	document.write('       pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	document.write('</object>');
	
	document.write('<SCRIPT event=FSCommand(command,args) for=movie' + index + '>movie' + index + '_DoFSCommand(command,args);</SCRIPT>');

}

// 書き順イメージを書き込む
function writeFlashForDisplayImageNew(handwriteImage, warningCnt, printingChar, hStrock, resURL){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
	document.write('        codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');
	document.write('        width="66" ');
	document.write('        height="90"');
	document.write('        swLiveConnect="true"');
	document.write('        id="common" ');
	document.write('        name="common"');
	document.write('        align="middle" ');
	document.write('        style="display: inline; z-index: 1">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="' + resURL + '/flash/displayHandWrite.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="flashvars" value="copyright=www.kanjihakase.com&r=' + printingChar + '&q=' + handwriteImage + '&w=' + warningCnt + '&h=' + hStrock + '" />');
	document.write('<embed src="' + resURL + '/flash/displayHandWrite.swf" ');
	document.write('       quality="high" ');
	document.write('       bgcolor="#ffffff" ');
	document.write('       width="66" ');
	document.write('       height="90" ');
	document.write('       align="middle" ');
	document.write('       allowScriptAccess="always" ');
	document.write('       swLiveConnect="true"');
	document.write('       id="common" ');

	document.write('       name="common" ');

	document.write('       flashvars="copyright=www.kanjihakase.com&r=' + printingChar + '&q=' + handwriteImage + '&w=' + warningCnt + '&h=' + hStrock  + '"');
	document.write('       type="application/x-shockwave-flash" ');
	document.write('       pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	document.write('</object>');
}
