﻿function DisplaySubMenu(id)
{
	if (document.all.item(id).style.display=="none")
	{
		document.all.item(id).style.display="";
	}
	else
	{
		document.all.item(id).style.display="none";
	}
}

//打开窗口
function OpenWindow(strURL, strName, width, height, isDialog, isScroll, isStatus)
{
	var left = (screen.width - width)/2;
	var top = (screen.availHeight - height - 50)/2;
	if(height >= screen.availHeight)
	{
	    height -= 50;
	    top = 0;
	}
	if(width >= screen.availWidth)
	{
	    width -= 10;
	    left = 0;
	}
	
	if(isDialog == 0)
	{		
	    window.open(strURL,strName,'resizable=1'
                                + ',top=' + top
                                + ',left=' + left
                                + ',width=' + width
                                + ',height=' + height
                                + ',status=' + isStatus
                                + ',scrollbars=' + isScroll);
	}
	else
	{
	     window.showModalDialog(strURL,window,'dialogtop=' + top
	                            + 'px;dialogleft=' + left
	                            + 'px;dialogWidth=' + width
	                            + 'px;dialogHeight=' + height
	                            + 'px;status=' + isStatus
	                            + ';resizable=0'
	                            + ';scroll=' + isScroll
	                            + ';scrollbars=' + isScroll);
	}
}

//打开增加窗口
function OpenAddWindow(strURL, strName, width, height, isScroll)
{
    if (width == 0)
    {
        width = window.screen.availWidth;
    }
    if (height == 0)
    {
        height = window.screen.availHeight;
    }
	OpenWindow(strURL, strName, width, height, 0, isScroll, 1);
}

//打开修改窗口
function OpenModifyWindow(strURL, strName, width, height, isScroll, strOptionName)
{
    if (width == 0)
    {
        width = window.screen.availWidth;
    }
    if (height == 0)
    {
        height = window.screen.availHeight;
    }

    var objSelect = document.getElementsByName(strOptionName);
	if(objSelect.length)
	{
	    var checkedIndex = -1;
	    var checkedCount = 0;
		for(i=0; i<objSelect.length; i++)
		{
			if(objSelect[i].checked)
			{
	            checkedIndex = i;
	            checkedCount++;
			}
		}
		if(checkedCount > 1)
		{
		    alert("您一次只能操作一条记录。");
		    return false;
		}
		else if(checkedCount == 0)
		{
		    alert("没有任何记录可供操作。");
	        return false;
		}
						
		if(strURL.indexOf("?") == -1)
		{
		    strURL = strURL + "?ID=" + objSelect[checkedIndex].value ;
		}
		else
		{
		    strURL = strURL + "&ID=" + objSelect[checkedIndex].value ;
		}
		OpenWindow(strURL, strName, width, height, 0, isScroll, 1);
	}
	else if(objSelect.length == null)
	{
	    alert("无法取得CheckBox的个数。");
	    return false;
	}
	else
	{
		alert("操作失败,没有任何数据可供操作。");
		return false;
	}
}

//检查删除
function CheckDelete(strOptionName, hidDelIDs)
{
	var objSelect = document.getElementsByName(strOptionName);
    
	var deleteID = "";	
	
	if(objSelect.length)
	{
	    var checkedCount = 0;
		for(i=0; i< objSelect.length; i++)
		{
			if(objSelect[i].checked)
			{
				deleteID += "," + objSelect[i].value;
				checkedCount++ ;
			}
		}
		if( checkedCount == 0)
		{
		    alert("没有任何记录可供删除。");
		    return false;
		}
		
		hidDelIDs.value = deleteID.substr(1);
		return true;
	}
	else if(objSelect.length == null)
	{
	    alert("无法取得CheckBox的个数。");
	    return false;
	}
	else
	{
		alert("操作失败,没有任何数据可供操作。");
		return false;
	}
}

// 全选
function SelectAll(chk,strName) 
{
    var chkArray=document.getElementsByName(strName);
    if(chkArray.length < 1)
    {
        return false;
    }
    for (i=0; i<chkArray.length; i++)
    {
        chkArray.item(i).checked=chk.checked;
    }            
}

//打开日期选择窗口
function SelectDate(txt,rooturl)
{
    //var rootUrl = window.location.href.split("/")[3];
    var url= rooturl+"VCalendar.Aspx";
	var showX = event.screenX;
	var showY = event.screenY;	
	var returnValue = window.showModalDialog(url + "?x=" + Math.random(), "calendar", "dialogWidth:196px; dialogHeight:245px; dialogLeft:" + showX + "px; dialogTop:" + showY + "px;directories:yes; scrollbars:no; Resizable=no;");
	if( returnValue != null )
	{		
		txt.value = returnValue;
	}
}

// 调整图片大小
function ImgResize(obj,OrgWidth,MaxWidth,OrgHeight,MaxHeight)
{
    if (OrgHeight > MaxHeight)
    {
        OrgWidth = OrgWidth*(MaxHeight/OrgHeight);
		OrgHeight = OrgHeight*(MaxHeight/OrgHeight);
	}
	if (OrgWidth>MaxWidth)	
	{
	    OrgHeight=OrgHeight*(MaxWidth/OrgWidth);
		OrgWidth=OrgWidth*(MaxWidth/OrgWidth);
    }
	obj.width = OrgWidth;
	obj.height = OrgHeight;
}