var marked_row = new Array;

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');
        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

function cmd(id,act){
	if(act.indexOf("act=del")!=-1){
		if(confirm("你确定要进行删除操作嘛！\n该操作将级联删除和该信息相关的附属信息\n且该操作是不可逆转的！")){
			var tmp=act+id;
			window.location=tmp;
			return;
		}
	}
	else{	
		var tmp=act+id;
		window.location=tmp;
	}
}

function cklength(tmp){
	for(var i=0;i<tmp.length;i++){
		var obj=tmp[i].split(",");
		var val=document.getElementsByName(obj[0])[0].value;
		if(val.length>parseInt(obj[1])){
			document.getElementsByName(obj[0])[0].focus();
			document.getElementsByName(obj[0])[0].select();
			alert("该项超过长度限制："+obj[1]);
			return false;
		}		
	}
	return true;
}

function cknum(tmp){
	for(var i=0;i<tmp.length;i++){
		var val=document.getElementsByName(tmp[i])[0].value;
		if(val!=null&&val!=""&&isNaN(val)){			
			document.getElementsByName(tmp[i])[0].focus();
			document.getElementsByName(tmp[i])[0].select();
			alert("该处必须是数字！");
			return false;
		}
	}
	return true;
}

function ckempty(tmp){
	for(var i=0;i<tmp.length;i++){
		var val=document.getElementsByName(tmp[i])[0];
		if(val.value==null||val.value==""){
			//alert(val.tagName);	
			document.getElementsByName(tmp[i])[0].focus();	
			if(val.tagName!="select"&&val.tagName!="SELECT"){
				document.getElementsByName(tmp[i])[0].select();
			}
			alert("该处必须填写或选择！");
			return false;
		}
	}
	return true;
}

function chkemail(tmp){
	var objemail=document.getElementsByName(tmp)[0].value;
	var objExp=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if(objemail!=null&&objemail!=""&&!objExp.test(objemail)){
		alert("请填写正确的邮箱地址！");
		document.getElementsByName(tmp)[0].focus();	
		document.getElementsByName(tmp)[0].select();
		return false;
	}else{
		return true;
	}
}

function openNewWindow(url,wd,hg){
	var sty="left="+(window.screen .availwidth-wd)/2+",top="+(window.screen .availHeight-hg)/2+",width="+wd+"px,height="+hg+"px,status=no,toolbar=no";
	window.open(url,"_blank",sty);
	//newwin.moveTo((window.screen .availwidth-wd)/2,(window.screen .availHeight-hg)/2);
}

function openNewWindow1(url,wd,hg){
	var sty="left="+(window.screen .availwidth-wd)/2+",top="+(window.screen .availHeight-hg)/2+",width="+wd+"px,height="+hg+"px,status=no,toolbar=no,scrollbars=yes";
	window.open(url,"_blank",sty);
	//newwin.moveTo((window.screen .availwidth-wd)/2,(window.screen .availHeight-hg)/2);
}
function openNewWindow2(url,msg)
{

   if(confirm(msg))
   {
   openNewWindow(url,1,1)
   }
       else
       {
      return false;
      }
  
}
function logout(){
	
	if(MWalert( "您要退出系统") != "VbYes")
		return;
	if ("object" == typeof(gobjCommuWindow)){
		if (typeof(gobjCommuWindow.opener) == "object"){
			gobjCommuWindow.window.close();
		}
	}
	parent.navigate("index.jsp");
}


function alttt(){
	alert("11");
	//var tmp=document.getElementById("p"+(count-1)).value;
	//alert(tmp);
}
function closeW()
{
   window.opener.location.reload();
   window.close();
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function saveAsExcel(HeadName, DivName) {
          // var tmp=document.getElementById(DivName).innerHTML;
         //  var ta=document.createElement("table");
         //  ta=document.getElementById("PrintA");
         //  ta.rows(0).cell(3).innerHTML="";
           
            var s = "<center>" + HeadName + "</center>" + "\r\n";
             s += document.getElementById(DivName).innerHTML;
            while(s.indexOf("\<\A")!=-1)
            {
             s=s.substring(0,s.indexOf("\<\A"))+s.substring(s.indexOf("\<\/\A\>")+4,s.length); 
             }
            var xlsWindow = window.open("", "_blank", "width=1,height=1,scrollbars=no,toolbar=no");
             xlsWindow.document.write(s);
             xlsWindow.document.close();
             var filename="d:\\"+HeadName+".xls";
             xlsWindow.document.execCommand('Saveas', true, filename)
             xlsWindow.close();
         }