//后台管理界面用到的一些函数

//alert("enter admin.js");

//进度条开始
var writeProcessbar="";
writeProcessbar+= "<div id='processbar' align='center' style='display:none;z-index:99;background:#ffffff;width:110%;height:110%;position:absolute;left:0px;top:0px;filter:alpha(opacity=80);' ><br><br><br><br><br><br><br><br><br><br><br><br>"; 
writeProcessbar+= "<div id=sb style='border-right: #ffffff 1px solid; border-top: #ffffff 1px solid; background: #dcdcdc; width: 400px; border-bottom: #cccccc 1px solid; height: 14px; text-align: left'>";
writeProcessbar+= "<div id=sbchild1 style='filter: alpha(opacity=0, finishopacity=80, style=1, startx=0, starty=0, finishx=100, finishy=0); overflow: hidden; width: 400px; position: absolute; height: 12px'>";
writeProcessbar+= "<div hidden overflow: height:12px; style='background: #0000ff; width: 400px'></div>";
writeProcessbar+= "</div><div style='font-size: 10px; width: 400px; color: white; font-family: arial; position: absolute; height: 14px; text-align: center'></div>";
writeProcessbar+= "</div><br><br><div id=infor style='font-size: 13px; width: 400px; color: #ff0000; font-family: arial; position: relative; height: 16px; text-align: center'></div></div>";
document.write(writeProcessbar);

var ie5 = (document.all && document.getElementsByTagName);
var step = 0;
function setSB(v, el, inforEl, message) {
if (ie5 || document.readyState == "complete") {
filterEl = el.children[0];


if (filterEl.style.pixelWidth > 0) {
var filterBackup = filterEl.style.filter;
filterEl.style.filter = "";
filterEl.style.filter = filterBackup;
}

filterEl.style.width = v + "%";
inforEl.innerText = message;
}
}
function setSBByStep(v, el, inforEl, message) {
if (ie5 || document.readyState == "complete") {
step = step + v;
filterEl = el.children[0];

if (filterEl.style.pixelWidth > 0) {
var filterBackup = filterEl.style.filter;
filterEl.style.filter = "";
filterEl.style.filter = filterBackup;
}

filterEl.style.width = step + "%";
inforEl.innerText = message;
}
}

function fakeProgress(v, el) {
//bodyHidden.style.display = "none";
processbar.style.display = "";
if (v < 101) {
setSB(v, el, infor, "操作中，请稍候……");
window.setTimeout("fakeProgress(" + (v + 1) + ", document.all['" + el.id + "'])", 120);
}
}
//进度条结束

//模式对话框，使用方法 openDialog("<c:url value='/scripts/wait.htm'/>" ,"_blank",150,200);
function openDialog(url, args, width, height) {
	if (!width) width = 600;
	if (!height) height = 400;
    var returnVal = window.showModalDialog(url, args, "dialogWidth=" + width + "px; dialogHeight=" + height + "px; status=yes;scroll=yes;help=no;");
    return returnVal;
}

function selectAllcheckBox() {
  var objs = document.getElementsByTagName("input");
  for(var i=0; i<objs.length; i++) {
    if(objs[i].type.toLowerCase() == "checkbox" )
      objs[i].checked = true;
  }
}

function unSelectAllcheckBox() {
  var objs = document.getElementsByTagName("input");
  for(var i=0; i<objs.length; i++) {
    if(objs[i].type.toLowerCase() == "checkbox" )
      objs[i].checked = false;
  }
}

function batch_do(entityName, action)
{
    if (confirm("确定要" + entityName + "?"))
    {
        if (!atleaseOneCheck())
        {
            alert('请至少选择一' + entityName + '！');
            return;
        }
        fakeProgress(0,sb);
        var form = document.forms.ec;
        form.action = action + '&autoInc=false';
        form.submit();

    }
}

function openwin(url, width, height, scroll)
{
    if (!document.all)
    {
        document.captureEvents(Event.MOUSEMOVE);
        x = e.pageX + width - 30;
        y = e.pageY + height - 30;
    }
    else
    {
        x = document.body.scrollLeft + event.clientX + width - 30;
        y = document.body.scrollTop + event.clientY + height - 30;
    }
    window.open(url, "newWindow", "height=" + height + ", width=" + width + ", toolbar =no, menubar=no, scrollbars=" + scroll + ", resizable=no, location=no, status=no, top=" + y + ", left=" + x + "") //写成一行
}

//checkbox中至少有一项被选中
function atleaseOneCheck()
{
    var items = document.getElementsByName('itemlist');
    if (items.length > 0) {
        for (var i = 0; i < items.length; i++)
        {
            if (items[i].checked == true)
            {
                return true;
            }
        }
    } else {
        if (items.checked == true) {
            return true;
        }
    }
    return false;
}

//设为主页
function setHomepage(){
	try{ 
        document.body.style.behavior='url(#default#homepage)';
  		document.body.setHomePage('http://www.csdn.net');
  	}catch (e) {  
    	if(window.netscape){
        	try{  
            	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         	}catch (e) {  
    			alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );  
         	}
         	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    		prefs.setCharPref('browser.startup.homepage','http://www.csdn.net');
    	} 
   }
}
//加入收藏
function addFavorite(){
 	try{
 	 	window.external.addFavorite('http://www.360doc.com/content/09/0703/15/16915_4124754.shtml','中国海商法协会网站');
 	}catch (e) {  
 		try{ 
    		window.sidebar.addPanel('中国海商法协会网站', 'http://www.360doc.com/content/09/0703/15/16915_4124754.shtml', "");
    	}catch (e) { 
    		alert("加入收藏失败，请使用CTRL+D进行添加");
    	}
 	}
}
//显示当前时间
function currentTime(){
	var today = new Date();
	var year = today.getFullYear(); 
	var month = today.getMonth()+1;
	var riqi = today.getDate();
	var week = today.getDay();
	if(week==0){ 
		week="星期日";
	}
	if(week==1){ 
		week="星期一";
	}
	if(week==2){ 
		week="星期二";
	}
	if(week==3){ 
		week="星期三";
	}
	if(week==4){ 
		week="星期四";
	}
	if(week==5){ 
		week="星期五";
	}
	if(week==6){ 
		week="星期六";
	}
	document.getElementById("current_time").innerHTML="今日："+year+"年"+month+"月"+riqi+"日 " + week;
}
//显示菜单(包括一级和二级)
function showMenu(num){
	subMenu = document.getElementById("nav2");
	tds = subMenu.getElementsByTagName("td");
	for(var i=1;i<tds.length;i++){
		tds[i].style.display="none";
	}
	tds[0].style.width=106*num+"px";
	tds[num].style.display="";
}


