/** submitの状況フラグ。ルチサブミを防止するために、このフラグを使 */
var checkSubmitFlg = false;

/** submitの時ENTキーのキーコードを格納す */
//var checkSubmitKeycode;

/** onkeydownの処数はcheckSubmitKeydownに設定す */
//window.document.onkeydown = checkSubmitKeydown;

/**
*	formが繰り返し提することを防止する
*	@author weifeng 新規作 2006/12/08
*/
function submitForm(form){
	if(checkSubmitFlg){
		return;
	}
	
	checkSubmitFlg=true;
	form.submit();
}

/**
 * ENTERキーを押したかを検査する
 *
 * @author zhanjc 新規作 2004/07/26
 */
//function checkSubmitKeydown() {
//	if ((window.event.keyCode == 13) && (window.event.srcElement.type == "text")) {
//		checkSubmitKeycode = window.event.keyCode;
//	}
//}

/**
 * のショートカキーおよび部の機を無効にする
 * マウスのクリ(重リクエス)
 *
 * @author zhanjc 新規作 2004/07/03
 */
function doconclick() {
		if (checkSubmitFlg) {
		window.event.returnValue = false;
	}
}

/**
 * マルチサブミ防止処
 *
 * @author zhanjc 新規作 2004/07/27
 */
function checkSubmit() {
	if (checkSubmitFlg == true) {
		return false;
	}
	// checkSubmitFlgのフラグを設定す
	checkSubmitFlg = true;
	return true;
}

function linkSubmit(url) {
	if (checkSubmit()) {
		top.location = url;
	}
}

/**
 * のショートカキーおよび部の機を無効にする
 * ファンクションキーの無効
 *
 * @author zhanjc 新規作 2003/03/03
 */
document.onkeydown = function keyDownHandler() {
	try {
		var key;
		key = window.event.keyCode; // key code (112 to 123) = (F1 to F12)
		if ((key > 111) && (key < 124)) {
			window.event.keyCode = 0;
			window.event.returnValue = false;
		}
		if (key == 8) { // BackSpace
			if (window.event.srcElement.type != "text" && window.event.srcElement.type != "textarea" && window.event.srcElement.type != "password") {
				window.event.keyCode = 0;
				window.event.returnValue = false;
			}
		}
//		if (key == 13) { // Enter
//			if (window.event.srcElement.type == "text") {
//				window.event.keyCode = 0;
//				window.event.returnValue = false;
//			}
//		}
		if (key == 27) { // ESC
			window.event.keyCode = 0;
			window.event.returnValue = false;
		}
//		if (window.event.altKey) { // ALT
//			alert("[Alt]キーは使用できません");
//		}
		if (window.event.shiftKey) { // shift key
			switch (key) {
				case 121 : // F10
				case 8 : // BackSpace
					window.event.keyCode = 0;
					window.event.returnValue = false;
			}
		}
		if (window.event.ctrlKey) { // ctrl key
			switch (key) {
				case 82 : // R
				case 116 : // F5
				case 9 : // Tab
				case 76 : // L
				case 79 : // O
				case 78 : // N
				case 87 : // W
				case 83 : // S
				case 219 : // [
				case 221 : // ]
				case 69 : // E
				case 73 : // I
				case 72 : // H
				case 68 : // D
				case 66 : // B
					window.event.keyCode = 0;
					window.event.returnValue = false;
			}
			if (key == 80) { // P
				window.event.keyCode = 0;
				window.event.returnValue = false;
			}
		}
		if (window.event.ctrlKey && window.event.shiftKey && key == 9) { // ctrl + shift + Tab
			window.event.keyCode = 0;
			window.event.returnValue = false;
		}
	} catch (any_exp) {
	}
}

/**
 * のショートカキーおよび部の機を無効にする
 * ヘルプ無効
 *
 * @author zhanjc 新規作 2003/03/03
 */
document.onhelp = function keyDownHandlerF1() {
	try {
		window.event.keyCode = 0;
		window.event.returnValue = false;
	} catch (any_exp) {
	}
}

/**
 * コンストメニューの無効
 */
document.oncontextmenu = function contextMenuHandler() {
	try {
		return false;
	} catch(any_exp){
	}
}

/**
 * initial variable for safari
 */
window.onunload = function loadHandler() {
	checkSubmitFlg = false;
	//alert("onunload");
}

/**
 * Add a item into pulldown box.
 * @author zhanjc
 * @return
 */
function addSelectOption(obj,value,displayValue){
	deletePointOption(obj,value);
	var oOption = document.createElement("OPTION");
	oOption.text=displayValue;
	oOption.value=value;
	obj.add(oOption);
}


/**
 * Delete the selected item from pulldown box.
 * @author zhanjc
 * @return 
 */
function deleteSelectedOption(obj){
	if (obj.options.length == 0) {
		return;
	}	
	var vIndex1 = 0;
	var vIndex2 = 0;
	while (vIndex1 < obj.options.length) {
		if (!obj.options[vIndex1].selected) {
			if (vIndex2 < vIndex1) {
				obj[vIndex2].text = obj[vIndex1].text;
				obj[vIndex2].value = obj[vIndex1].value;
				obj[vIndex2].selected = false;
			}
			vIndex2 ++;
		}	
		vIndex1 ++;					
	}
	obj.options.length = vIndex2;
	
}

/**
 * Delete the appointing item from pulldown box.
 * @author zhanc
 * @return 
 */
function deletePointOption(obj,value){
	if (obj.options.length == 0) {
		return;
	}	
	var vIndex1 = 0;
	var vIndex2 = 0;
	while (vIndex1 < obj.options.length) {
		if ( obj[vIndex1].value != value) {
			if (vIndex2 < vIndex1){
				obj[vIndex2].text = obj[vIndex1].text;
				obj[vIndex2].value = obj[vIndex1].value;
				obj[vIndex2].selected = false;
			}
			vIndex2 ++;
		}	
		vIndex1 ++;					
	}
	obj.options.length = vIndex2;
	
}

/**
 * Delete all item from pulldown box.
 * @author zhanjc
 * @return 
 */
function deleteAllOption(obj){
	if (obj.options.length == 0) {
		return;
	}	
	obj.options.length = 0;
	
}

/**
 * Select all items of pulldown box
 * @author zhanjc
 * @return 
 */
function selectAllSelectOption(obj){
	if (obj.options.length == 0) {
		return;
	}	
	var vIndex1 = 0;
	while (vIndex1 < obj.options.length) {
		obj.options[vIndex1].selected = true;
		vIndex1++;
	}
}

/**
 * Get the value of checked item from radio boxes.
 * @author zhanjc
 * @param the name of radio boxes
 * @return the value of checked radio
 */	
function getRadioObjectValue(name) {
	if(name==null || name=="") {
		return "";
	}
	var objs = document.all[name];
	if(objs==null) {
		return "";
	}else {
		if (objs.length!=null&& typeof (objs.length) !='undefined'){
			for(var i=0; i<objs.length; i++) {
				if(objs[i].checked)
			       return objs[i].value;
			}
		}else{
			if(objs.checked)
			  return objs.value; 
		}
	}
	return "";
}

function upItem(select2)
{

    var j = select2.selectedIndex;
    var i = j-1;
    var v1,v2;
	var k=2;
	var l=2;

    if (j>0)
    {
	 if(j>8)
		 k=3;
	  if(i>8)
		 l=3;
     v1 = select2.options[i].value;
     v2 = select2.options[i].text.substring(l,select2.options[i].text.length);

        select2.options[i].value=select2.options[j].value;
        select2.options[i].text= (i+1)/1+"."+ select2.options[j].text.substring(k,select2.options[j].text.length);;
        select2.options[j].value = v1;
        select2.options[j].text = (j+1)/1+"."+ v2;
        select2.selectedIndex = i;
      }
    if (i<0)
        select2.selectedIndex = -1;
}

function downItem(select2)
{

    var j = select2.selectedIndex;
    var i = j+1;
    var v1,v2;
	var k=2;
	var l=2;

    if (j>=0 && i<select2.options.length)
    {
	  if(j>8)
		 k=3;
	  if(i>8)
		 l=3;

     v1 = select2.options[i].value;
     v2 = select2.options[i].text.substring(l,select2.options[i].text.length);

        select2.options[i].value=select2.options[j].value;
        select2.options[i].text= (i+1)/1+"."+select2.options[j].text.substring(k,select2.options[j].text.length);;
        select2.options[j].value = v1;
        select2.options[j].text = (j+1)/1+"."+  v2;
        select2.selectedIndex = i;
      }
     if (i==select2.options.length)
        select2.selectedIndex = -1;

}


function addAllItem(select1,select2)
{
  var idx1= select1.options.length;

  select2.options.length=idx1;
  for(i=0;i<idx1;i++)
  {
      select2.options[i].value=select1.options[i].value;
      select2.options[i].text=(i+1)/1+"."+select1.options[i].text;
  }
  select2.selectedIndex = 0;
}

//3级下拉动
function exchangeSelect3(select1,select2,select3){
	if(select1.value==""){
		select2.value="";
		select3.value="";
		select2.disabled=true;
		select3.disabled=true;
	}else{
		select2.disabled=false;
	}
}

//2级下拉动
function exchangeSelect2(select1,select2){
	if(select1.value==""){
		select2.value="";
		select2.disabled=true;
	}else{
		select2.disabled=false;
	}
}

/**
 * Windowのフォーカスを設定す
 *
 * @author zhanjc 新規作 2004/07/04
 */
function setWindowFocus(window) {
	var bfocus = true;
	var br = (navigator.appName.indexOf ("Mic", 0) != -1) ? "e" : "n";
	if (br == "e" && navigator.appVersion.indexOf("MSIE 5.0") != -1) bfocus = false;
	if (bfocus) {
		window.focus();
	}
}

/**
 * 设置窗口的title
 *
 * @author weifeng 新規作 2007/01/24
 */
function setWindowTitle(wTitle) {
	document.title = wTitle;
}
