////////////////////////////////////////////////////////////////////////
// show a help div.
// eg:
// <div id="div01" style="position: absolute; width:150px;z-index: 100; visibility: hidden; filter: alpha(opacity=85);background: #ddeeff; border: 1pt solid steelblue;"></div>
// <span onmouseover="show_help('div01','mytestword');" onmouseout="show_help('div01','');"> just a test for my script </span>
function show_help(help_obj,help_string)
{
    eval("my_visibility=document.all."+help_obj+".style.visibility;");
    if (my_visibility=="hidden")
    {
        eval("document.all."+help_obj+".style.pixelLeft = event.clientX + document.body.scrollLeft;");
		eval("document.all."+help_obj+".style.pixelTop = event.clientY + document.body.scrollTop - 10;");
		eval("document.all."+help_obj+".innerHTML=help_string;");
        eval("document.all."+help_obj+".style.visibility='visible';");
    }
    else
    {
        eval("document.all."+help_obj+".style.visibility='hidden';");
    }
}

////////////////////////////////////////////////////////////////////////
// for mousemenu
function DrawMouseMenu(){
	var HrStr="<tr><td align=center valign=middle height=2><TABLE border=0 cellpadding=0 cellspacing=0 width=128 height=2><tr><td height=1 bgcolor=buttonshadow><\/td><\/tr><tr><td height=1 bgcolor=buttonhighlight><\/td><\/tr><\/TABLE><\/td><\/tr>";
	var MenuStr1="<tr><td align=center valign=middle height=20><TABLE border=0 cellpadding=0 cellspacing=0 width=132><tr><td valign=middle height=16 class=Mout onMouseOver=this.className='Mover'; onMouseOut=this.className='Mout'; onclick=\"";
	var MenuStr2="<\/td><\/tr><\/TABLE><\/td><\/tr>";
	var XiciMenu=["window.location.replace('\/')\">用户桌面","window.location.replace('\/online.php')\">在线信息"];
	var SysMenu=["window.print()\">打印","window.location.reload()\">刷新"];
	var MenuStr="";
	for(i=0;i<XiciMenu.length;i++){
		MenuStr+=MenuStr1+XiciMenu[i]+MenuStr2;
		DivH+=20;
	}
	MenuStr+=HrStr;
	for(i=0;i<arguments.length;i++){
		MenuStr+=MenuStr1+arguments[i]+MenuStr2;
		DivH+=20;
	}
	if(arguments.length>0){
		MenuStr+=HrStr;
		DivH+=2;
	}
	for(i=0;i<SysMenu.length;i++){
		MenuStr+=MenuStr1+SysMenu[i]+MenuStr2;
		DivH+=20;
	}
	var DivStr1="<DIV id=MouseMenu class=div1 style=\"position:absolute; left:0px; top:0px; width=150;height="+DivH+"; z-index:1; visibility:hidden;filter:alpha(opacity=100)\"><TABLE border=0 cellpadding=0 cellspacing=0 class=div2><tr><td bgcolor=#6699CC style=\"filter:progid:DXImageTransform.Microsoft.Alpha( Opacity=100, FinishOpacity=30, Style=1, StartX=0,  FinishX=0, StartY=70, FinishY=0)\" width=10 valign=bottom align=center  bgcolor=buttonface><a href=\"\/copyright.htm\"><img id=menugif src=\/images\/menu.gif width=18 height=120 border=0></a><\/td><td bgcolor=buttonface><TABLE border=0 cellpadding=0 cellspacing=0>";
	var DivStr2="<\/TABLE><\/td><\/tr><\/TABLE><\/DIV>";
	document.write(DivStr1+MenuStr+DivStr2);
}

function ShowMouseMenu(){
	MouseMenu.filters.alpha.opacity=0;
	MouseMenu.style.visibility='hidden';
	if(event.srcElement.tagName=="IMG"&&event.srcElement.id!="menugif"||event.srcElement.tagName=="A"||event.srcElement.tagName=="AREA"||event.srcElement.tagName=="INPUT"||oSelection.type!="None")
		return true;
	else{
		if(oInterval!="")clearInterval(oInterval);
		oInterval="";
		if(event.clientX+150 > document.body.clientWidth)MouseMenu.style.left=event.clientX+document.body.scrollLeft-150;
		else MouseMenu.style.left=event.clientX+document.body.scrollLeft;
		if(event.clientY+DivH > document.body.clientHeight)MouseMenu.style.top=event.clientY+document.body.scrollTop-DivH;
		else MouseMenu.style.top=event.clientY+document.body.scrollTop;
		MouseMenu.style.visibility='visible';
		oInterval=window.setInterval("if(MouseMenu.filters.alpha.opacity<100)MouseMenu.filters.alpha.opacity+=50;",1);
	}
	return false;
}

/////////////////////////////////////////////////////////////////
// INIT mousemenu
var AutoRegStr="";
var IsRoot = false;

var oSelection = document.selection;
var oInterval="";
var DivH=2;

DrawMouseMenu( "window.location.reload('\/none.htm');\">测试项目1",
               "window.location.reload('\/none.htm');\">测试项目2",
               "window.location.reload('\/none.htm');\">测试项目3",
               "window.open('/include/config.phps');\">基本配置",
               "window.open('/showcode.php?url='+document.URL);\">查看PHP代码");


/////////////////////////////////////////////////////////////////////
// for php window
var the_flag="";
function window_update()
{
	if (the_flag=="1")
	{
		if (window.name=="pop")close();
		else document.URL="/";
	}
}

/////////////////////////////////////////////////////////////////////
// for php window
function window_close()
{
	window.showModelessDialog("/include/dialog.php",window,"dialogHeight: 240px; dialogWidth: 320px; dialogTop: 200px; dialogLeft: 200px; center: Yes; help: No; resizable: No; status: No;");
}

/////////////////////////////////////////////////////////////////////
// for php window
function window_quit()
{
	if (window.name)close();
	else document.URL="/";
}

/////////////////////////////////////////////////////////////////////
// for php window
function open_pop(theurl, wname, W, H) {
/*
--rewrited by jimmy,
--becasuse of newmodel
--2002.3.21

	wname="pop";
	
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) isie=true
	else											     isie=false


	if (isie) r = ",resizable=0"
	else       r = ",resizable=1"
	if (isie) { H=H; W=W+16; }

	s = ",width="+W+",height="+H;

	var windowW = W;
	var windowH = H;
	var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
	var windowY = Math.ceil( (window.screen.height - windowH) / 2 );

	var splashWin = window.open("", wname, "fullscreen=1,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1"+r+s)

	splashWin.resizeTo( Math.ceil( W )       , Math.ceil( H ) )
	splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) )

	splashWin.document.open("text/html", "replace");
	splashWin.document.write("<html><style type='text/css'>\n");
	splashWin.document.write("#lineLDiv 		{ position: absolute; left:         0px; top:                  0px; width:     1px; height: "+H+"px; z-index: 2; background-color: #000000; layer-background-color: #000000; clip:rect(0,1,"+H+",0);}");
	splashWin.document.write("#lineRDiv			{ position: absolute; left: "+(W-1)+"px; top:                  0px; width:     1px; height: "+H+"px; z-index: 2; background-color: #000000; layer-background-color: #000000; clip:rect(0,1,"+H+",0);}");
	splashWin.document.write("#lineBDiv 		{ position: absolute; left:         0px; top: "+         (H-1)+"px; width: "+W+"px; height:     1px; z-index: 2; background-color: #000000; layer-background-color: #000000; clip:rect(0,"+W+",1,0);}");
	splashWin.document.write("#lineTDiv 		{ position: absolute; left:         0px; top:                  0px; width: "+W+"px; height:     1px; z-index: 2; background-color: #000000; layer-background-color: #000000; clip:rect(0,"+W+",1,0);}");
	splashWin.document.write("#stillloadingDiv 	{ position: absolute; left:         0px; top: "+Math.ceil(H/2)+"px; width: "+W+"px; height: "+H+"px; z-index: 1; background-color: #C0C0C0; layer-background-color: #C0C0C0; clip:rect(0,"+W+",19,0);}");
	splashWin.document.write("</style>\n");
	splashWin.document.write("<body onload=\"self.document.location.href='"+theurl+"'\" style='border: 1px; overflow: hidden;'>");
	splashWin.document.write("<div id='lineLDiv'></div>");
	splashWin.document.write("<div id='lineRDiv'></div>");
	splashWin.document.write("<div id='lineBDiv'></div>");
	splashWin.document.write("<div id='lineTDiv'></div>");
	splashWin.document.write("<div id=stillloadingDiv><table width=100% height=22 cellspacing=0 cellpadding=0><tr><td align=left valign=middle width=100%><FONT size=1 face=verdana color=#000000><a href='javascript:self.close();'>CLOSE</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L o a d i n g . . .</font></td></tr></table></div>");
	splashWin.document.write("</body></html>");
	splashWin.document.close();

	splashWin.focus();

	eval(wname+"=splashWin")
*/

	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) isie=true;
	else isie=false;

	if (isie) { H=H; W=W; }

	s = ",width="+W+",height="+H;
	
    window.open(theurl,wname,"toolbar=0,location=0,resizable=yes,directories=0,top=0,left=0,status=1,menubar=0,scrollbars=yes"+s)
}

/////////////////////////////////////////////////////////////////////
//
// Add by jimmy 2002.12.09
//
/////////////////////////////////////////////////////////////////////
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor') == null?theRow.getAttribute('bgcolor'):theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function
/**
 * 检查输入的字符串是否符合MIS中日期规定格式
 *
 * @param   string   
 *
 * @return  integer  
 * 					 0:有输入值且为合法日期格式
 * 					 1:有输入值但为默认空值输入
 * 					-1:没有输入值 
 * 					-2:有输入值、非空值、非合法日期
 */
function checkDateFormatValid(str)
{
	if (str == "") return -1;
	if (str == "0000-00-00") return 1;
	boo = str.match(/^([1-2]{1}[0-9]{3})\-{1}([0-9]{2})\-{1}([0-9]{2})$/);
	if (!boo) return -2;
	a = Date.parse(boo[2] + "/" + boo[3] + "/" + boo[1]);
	if (isNaN(a)) return -2;
	else return 0;
}

function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g, "");
}