function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function change_menu(menu, path){
    var thisForm = document.form_menu;
    thisForm.MENU.value=menu;
    thisForm.STATUS.value= "0";
    if (menu == "kagaku"){
        thisForm.action=path;
    } else {
        thisForm.action=path + "/pages/top_e.jsp";
    }
    thisForm.submit();
}

function input_chk(){
        var thisForm = document.forms[0];
        flg = 0;

        if (Trim(thisForm.QUERY.value) != ''){
            flg = 1;
        }

        if (flg == 0){
            alert("Enter search items.");
            return(false);
        }

	if (!zenkaku_chk(thisForm.QUERY.value)){
                alert("Invalid Value.");
                return(false);
        }

        thisForm.submit();
        return( true );
    }

function Trim(str){
    str = str.replace(/^[ กก]+/,"");
    str = str.replace(/[ กก]+$/,"");
    return(str);
}

function input_m_chk(){
        var thisForm = document.forms[0];
        flg = 0;

        if (Trim(thisForm.COM_NAME.value) != ''){
            flg = 1;
	    if (!zenkaku_chk(thisForm.COM_NAME.value)){
            	alert("Invalid value.");
                return(false);
            }
        }

        if (Trim(thisForm.FORMULA.value) != ''){
            flg = 1;
	    if (!zenkaku_chk(thisForm.FORMULA.value)){
                alert("Invalid value.");
                return(false);
            }
        }

        var weight_flg = 0;
        var weight_l = Trim(thisForm.WEIGHT_L.value);
        if (weight_l != ''){
            //weight_l = Fulltohalf(weight_l);
            if ( isNaN( weight_l ) == true){
                alert('Enter the numerical value of lowest molecular weight.');
                return(false);
            }
            flg = 1;
            weight_flg = weight_flg + 1;
        }

        var weight_h = Trim(thisForm.WEIGHT_H.value);
        if (weight_h != ''){
            //weight_h = Fulltohalf(weight_h);
            if ( isNaN( weight_h ) == true){
                alert('Enter the numerical value of highest molecular weight.');
                return(false);
            }
            flg = 1;
            weight_flg = weight_flg + 1;
        }

        if (weight_flg == 2){
            if (weight_l - 0 > weight_h - 0){
                alert('Enter the larger numerical value in the highest molecular weight than it in the lowest molecular weight.');
                return(false);
            }

        }

        if (Trim(thisForm.LEGAL_NO.value) != ''){
            flg = 1;
            if (!zenkaku_chk(thisForm.LEGAL_NO.value)){
                alert("Invalid value.");
                return(false);
            }
        }

        if (Trim(thisForm.SN_NO.value) != ''){
            flg = 1;
            if (!zenkaku_chk(thisForm.SN_NO.value)){
                alert("Invalid value.");
                return(false);
            }
        }

        if (Trim(thisForm.CAS_RN.value) != ''){
            flg = 1;
            if (!zenkaku_chk(thisForm.CAS_RN.value)){
                alert("Invalid value.");
                return(false);
            }
        }

	if (Trim(thisForm.KEYWORD.value) != ''){
	    flg = 1;
            if (!zenkaku_chk(thisForm.KEYWORD.value)){
                alert("Invalid value.");
                return(false);
            }
	}

        if (flg == 0){
            alert("Enter search items.");
            return(false);
        }

        thisForm.submit();

        return( true );

}

function form_clear(path){
    var thisForm = document.forms[0];
    thisForm.CONTENT.value ="query";
    thisForm.STATUS.value = "0";
    thisForm.action = path + "/pages/top_e.jsp";
    thisForm.submit();
}

function change_page( val, max_page ){
        var thisForm = document.forms[0];
        var page = thisForm.PAGE.value;
        page -= 0;

        if( val == "top" ){
                if( page == 1 ) return;
                page = 1;
        }
        else if( val == "prev" ){
                if( page == 1 ) return;
                page -= 1;
        }
        else if( val == "next" ){
                if( page == max_page ) return;
                page += 1;
        }
        else if( val == "last" ){
                if( page == max_page ) return;
                page = max_page;
        }
        else{
        	if ( val =="page1" ){
                    page = thisForm.page1.value;
					page = Trim(page);
					if (page == ""){
						alert("Enter the page number.");
						return(false);
					}
        }
        else if (val == "page2"){
                    page = thisForm.page2.value;
					page = Trim(page);
					if (page == ""){
						alert("Enter the page number.");
						return(false);
					}
        }

        var count;

                if( isNaN( page ) ){
			alert("Enter the numerical value in this field.");
                        return( false );
                }
                page -= 0;
                page = Math.round( page );
                if( page <= 0 ){
                        page = 1;
                }
                else if( page > max_page ){
                        page = max_page;
                }
        }
    thisForm.CONTENT.value = "itiran";
        thisForm.PAGE.value = page;
        thisForm.submit();
        return( false );
}

function back_text_query(path){
        var thisForm = document.forms[0];
    	thisForm.CONTENT.value ="query";
        thisForm.action = path + "/pages/top_e.jsp";
	thisForm.target = "top";
        thisForm.submit();

}

function all_select1( check, sn_max ){
    var thisForm = document.forms[0];
    if (thisForm.ALLCHK1.checked == false) {
        thisForm.ALLCHK2.checked = false;
        for( var i=0; i<thisForm.elements.length; i++ ){
            if( thisForm.elements[i].type == "checkbox" ){
                for (var j=1; j<21; j++){
                    if (thisForm.elements[i].name == "SN_" + j){
                        if (thisForm.elements[i].checked == true){
                            thisForm.elements[i].checked = false
							var xx = parseFloat(thisForm.CHK_COUNT1.value);
							xx -= 1;
							thisForm.CHK_COUNT1.value = xx;
							thisForm.CHK_COUNT2.value = xx;
                        }
                    }
                }
            }
        }
    } else {
        thisForm.ALLCHK2.checked = true;
        for( var i=0; i<thisForm.elements.length; i++ ){
            if( thisForm.elements[i].type == "checkbox" ){
                for (var j=1; j<21; j++){
                    if (thisForm.elements[i].name == "SN_" + j){
                        if (thisForm.elements[i].checked == false){
                            thisForm.elements[i].checked = true;
							var xx = parseFloat(thisForm.CHK_COUNT1.value);
							xx += 1;
							thisForm.CHK_COUNT1.value = xx;
							thisForm.CHK_COUNT2.value = xx;
                            if (parseFloat(thisForm.CHK_COUNT1.value) > sn_max){
								var xx = parseFloat(thisForm.CHK_COUNT1.value);
								xx -= 1;
                                thisForm.elements[i].checked = false;
								thisForm.CHK_COUNT1.value = xx;
								thisForm.CHK_COUNT2.value = xx;
                                alert("Select upper limit is " + sn_max );
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
}

function all_select2( check, sn_max ){
	var thisForm = document.forms[0];
	if (thisForm.ALLCHK2.checked == false) {
		thisForm.ALLCHK1.checked = false;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				for (var j=1; j<21; j++){
					if (thisForm.elements[i].name == "SN_" + j){
						if (thisForm.elements[i].checked == true){
							thisForm.elements[i].checked = false
							var xx = parseFloat(thisForm.CHK_COUNT1.value);
							xx -= 1;
							thisForm.CHK_COUNT1.value = xx;
							thisForm.CHK_COUNT2.value = xx;
						}
					}
				}
			}
		}
	} else {
		thisForm.ALLCHK1.checked = true;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				for (var j=1; j<21; j++){
					if (thisForm.elements[i].name == "SN_" + j){
						if (thisForm.elements[i].checked == false){
							var xx = parseFloat(thisForm.CHK_COUNT1.value);
							xx += 1;
							thisForm.CHK_COUNT1.value = xx;
							thisForm.CHK_COUNT2.value = xx;
							thisForm.elements[i].checked = true;
							if (parseFloat(thisForm.CHK_COUNT1.value) > sn_max){
								var xx = parseFloat(thisForm.CHK_COUNT1.value);
								xx -= 1;
								thisForm.elements[i].checked = false;
								thisForm.CHK_COUNT1.value = xx;
								thisForm.CHK_COUNT2.value = xx;
								alert("Select upper limit is " + sn_max );
								return false;
							}
						}
					}
				}
			}
		}
	}
}

function all_unselect( uncheck ){
    var thisForm = document.forms[0];

    var cnt = 0;
    for( var i=0; i<thisForm.elements.length; i++ ){
        if( thisForm.elements[i].type == "checkbox" ){
            for (var j=1; j<21; j++){
                if (thisForm.elements[i].name == "SN_" + j){
                    if (thisForm.elements[i].checked == true){
                        cnt += 1;
                    }
                }
            }
        }
    }
    if (cnt == 0 && parseFloat(thisForm.CHK_COUNT1.value) == 0){
        alert("Nikkaji No. is not selected.");
        return false;
    }

    if (confirm("Will you cancel all selected?")){
        for( var i=0; i<thisForm.elements.length; i++ ){
            if( thisForm.elements[i].type == "checkbox" ){
                thisForm.elements[i].checked = false;
            }
        }
		thisForm.FROM_SN.value = "";
		thisForm.CHK_COUNT1.value = 0;
		thisForm.CHK_COUNT2.value = 0;
		return false;
    }
}

function show_detail(sn, path){
    var thisForm = document.forms[0];
    thisForm.action = path + "/pages/top_e.jsp";
    thisForm.CONTENT.value = "syosai";
    thisForm.SN.value = sn;
    thisForm.ANY_DETAIL.value = "";
    thisForm.method="POST";
    thisForm.submit();
}

function show_any(path){
    var thisForm = document.forms[0];
    var cnt = 0;
    for( var i=0; i<thisForm.elements.length; i++ ){
        if( thisForm.elements[i].type == "checkbox" ){
            for (var j=1; j<21; j++){
                if (thisForm.elements[i].name == "SN_" + j){
                    if (thisForm.elements[i].checked == true){
                        cnt += 1;
                    }
                }
            }
        }
    }
	if (cnt == 0 && parseFloat(thisForm.CHK_COUNT1.value) == 0){
        alert("Nikkaji No. is not selected.");
        return false;
    }
        thisForm.action = path + "/pages/top_e.jsp";
        thisForm.CONTENT.value = "syosai";
        thisForm.ANY_DETAIL.value = "1";
        thisForm.method="POST";
        thisForm.submit();
}

function count_sn_chk(chk_sn, sn_max){
    var thisForm = document.forms[0];
    for( var i=0; i<thisForm.elements.length; i++ ){
		if( thisForm.elements[i].type == "checkbox" ){
			if(thisForm.elements[i].name == chk_sn){
				if (thisForm.elements[i].checked == false){
					var xx = parseFloat(thisForm.CHK_COUNT1.value);
					xx -= 1;
					thisForm.CHK_COUNT1.value = xx;
					thisForm.CHK_COUNT2.value = xx;
                } else {
					var xx = parseFloat(thisForm.CHK_COUNT1.value);
					xx += 1;
					thisForm.CHK_COUNT1.value  = xx;
					thisForm.CHK_COUNT2.value  = xx;
                    if (parseFloat(thisForm.CHK_COUNT1.value) > sn_max){
						var xx = parseFloat(thisForm.CHK_COUNT1.value);
						xx -= 1
						thisForm.CHK_COUNT1.value = xx;
						thisForm.CHK_COUNT2.value = xx;
                        thisForm.elements[i].checked = false;
			alert("Select upper limit is " + sn_max );
                        return false;
                    }
                }
            }
        }
    }
}

//detail
function download(sn){
            var thisForm = document.forms[0];
            thisForm.SN.value = sn;
            x = (screen.availWidth)/2 - 150;
            y = (screen.availHeight)/2 - 100;
            (window.open("download_win_e.jsp", "", "top="+y+",left="+x+",toolbar=no,scrollbars=no,resizable=no,width=300,height=200")).focus();

}

function back_query(menu, context_path, kagaku_url){
            var thisForm = document.forms[0];
            if (menu == "kagaku"){
                thisForm.action = kagaku_url;
            } else {
                thisForm.action = context_path + "/pages/top_e.jsp";
            }
            thisForm.MENU.value = menu;
            thisForm.CONTENT.value = "query";
	    thisForm.target = "_self";
            thisForm.method="POST"
            thisForm.submit();

}


function back_list(menu, search_url, str_page){
            var thisForm = document.forms[0];
            thisForm.action = search_url;
            thisForm.MENU.value = menu;
            thisForm.CONTENT.value = "itiran";
            thisForm.PAGE.value = str_page;
	    thisForm.target = "_self";
            thisForm.method="POST"
            thisForm.submit();

}
function open_new(sn){
            var thisForm = document.forms[0];
            thisForm.SN.value = sn;
            //window.open("seibun_win_e.jsp", "NEW");
            window.open("seibun_win_e.jsp", "");
}

function download_mol(){
    var thisForm = document.forms[0];
    thisForm.SN.value = window.opener.document.forms[0].SN.value;
    thisForm.submit();
}

//search
function fw_servlet(path, servlet_name){
    thisForm = document.forms[0];
    thisForm.action= path + "/servlet/nkj.action." + servlet_name;
    thisForm.method="POST";
    thisForm.submit();
}

function all_print1(){
    var thisForm = document.forms[0];
	if (thisForm.CHK_ALL_PRINT1.checked == false){
		thisForm.CHK_ALL_PRINT2.checked == false;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				if (thisForm.elements[i].checked == true){
					thisForm.elements[i].checked = false;
				}
			}
		}
	} else {
		thisForm.CHK_ALL_PRINT2.checked == true;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				if (thisForm.elements[i].checked == false){
					thisForm.elements[i].checked = true;
				}
			}
		}
	}
}

function all_print2(){
	var thisForm = document.forms[0];
	if (thisForm.CHK_ALL_PRINT2.checked == false){
		thisForm.CHK_ALL_PRINT1.checked == false;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				if (thisForm.elements[i].checked == true){
					thisForm.elements[i].checked = false;
				}
			}
		}
	} else {
		thisForm.CHK_ALL_PRINT1.checked == true;
		for( var i=0; i<thisForm.elements.length; i++ ){
			if( thisForm.elements[i].type == "checkbox" ){
				if (thisForm.elements[i].checked == false){
					thisForm.elements[i].checked = true;
				}
			}
		}
	}
}

function print_chk(path){
	var thisForm = document.forms[0];
	var chk_count = 0;
	for( var i=0; i<thisForm.elements.length; i++ ){
		if( thisForm.elements[i].type == "checkbox" ){
			if (thisForm.elements[i].name == "SN_VALUE"){
				if (thisForm.elements[i].checked == true){
					chk_count +=1;
				}
			}
		}
	}
	if (chk_count == 0){
		alert("Printing items are not selected.");
		return(false);
	} 
	thisForm.SN.value = "";
	thisForm.target = "PRINT_PAGE";
	thisForm.action = path + "/pages/print_e.jsp";
	thisForm.method="POST";
	thisForm.submit();

}

function print_normal(path, sn){
	var thisForm = document.forms[0];
	thisForm.SN.value = sn;
	thisForm.target = "PRINT_PAGE";
	thisForm.action = path + "/pages/print_e.jsp";
	thisForm.method="POST";
	thisForm.submit();	
}

function zenkaku_chk(str){
	//if(!str.match(/^(\w|\n|\r|\t|\v| |!|"|#|\$|%|&|'|\(|\)|\^|~|=|-|\+|\*|`|\{|\}|\[|\]|:|;|\/|_|\.|_|,|<|>|\?)+$/) ){
	if(!str.match(/^(\w|\n|\r| |!|"|#|\$|%|&|'|\(|\)|\^|~|=|-|\+|\*|`|\{|\}|\[|\]|:|;|\/|_|\.|_|,|<|>|\?)+$/) ){
		return(false);
	}
	return(true);
}

