﻿/* --------------------------------------------------------------------------
 * Project:     IM
 * Author:      wangxinguo
 * History:     2004-09-11  Created By wxguo
 * -------------------------------------------------------------------------- */
var maxIntValue = 99999999;

/*没有记录时的提示*/
var noRecord = "没有任何记录！";
/*删除前的提示*/
var del = "你确定要删除吗？";
/*只能操作一条记录的提示*/
var onlyOne = "本操作只能选择一条列表记录！";
/*提醒选择记录*/
var checkFirst = "请选择列表记录！";
/*批量删除提示*/
var batchDel = "说明：此操作是针对所有页面的所有记录。\r\n你确定要删除吗？"
/*删除所有记录提示*/
var delall = '此操作将删除该群组下的所有记录，你确定要删除吗?';
/*时间比较提示*/
var timeCheck = '结束时间不能小于或等于开始时间';
var mmsWin;

function newin(url, w, h)
{
    //return window.open(url, "", "width=" + w + ", height=" + h + ", toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
    return openCenterWin(url, w, h);
}

function openWin(url, left, top, w, h)
{
    return window.open(url, "", "left=" + left + ", top=" + top + ", width=" + w + ",height=" + h + ",toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}
function openSameWin(url, left, top, w, h)
{
	if(mmsWin!=null)
	{
		try{
			mmsWin.focus();
		}catch(e)
		{
			mmsWin =  window.open(url, "mms", "left=" + left + ", top=" + top + ", width=" + w + ",height=" + h + ",toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
			mmsWin.focus();
		}
	}else
	{
    	mmsWin =  window.open(url, "mms", "left=" + left + ", top=" + top + ", width=" + w + ",height=" + h + ",toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
    }
}
function openCenterSameWin(url, w, h)
{
    var left = 0, top = 0;
    if(w > screen.width)
    {
        w = screen.width;
    }
    if(h > screen.height)
    {
        h = screen.height;
    }

    left = (screen.width - w) / 2;
    top = (screen.height - h) / 3;

    return openSameWin(url, left, top, w, h);
}
function openCenterWin(url, w, h)
{
    var left = 0, top = 0;
    if(w > screen.width)
    {
        w = screen.width;
    }
    if(h > screen.height)
    {
        h = screen.height;
    }

    left = (screen.width - w) / 2;
    top = (screen.height - h) / 3;

    return openWin(url, left, top, w, h);
}

function openModelWin(url, arg, w, h)
{
    return window.showModalDialog(url, arg, "dialogWidth:" + w + "; dialogHeight:" + h + "; status:no; scroll:auto");
}

function setFocus(obj)
{
    if(obj != null)
    {
        if(obj.type != "hidden" && !obj.disabled)
        {
            obj.focus();
        }
    }
}

// TAB框架页面点击TAB的事件
// secTable Tab所在的表的表名
// tabTitleArray 为Tab的数组信息，每个数组里面的元素又是一个数组
// Array[0]: 标题文字，Array[1]: url，Array[2]: 未选中时背景图片名， Array[3]: 选中时背景图片名
// index：为当前Tab的索引，值从0开始
function changeTab(secTable, tabTitleArray, index)
{
    for(i = 0; i < secTable.cells.length; i++)
    {
        if(i == index) //当前Tab索引 从0开始
        {
            secTable.cells[i].innerHTML = "<font color=#FF0000 >" + tabTitleArray[index][0] + "</font>";
            secTable.cells[i].background = tabTitleArray[index][3];
            //secTable.cells[i].className = "cpx12red";
        }
        else
        {
            secTable.cells[i].innerHTML = "<font color=#000000 >" + tabTitleArray[i][0] + "</font>";
            secTable.cells[i].background = tabTitleArray[index][2];
            //secTable.cells[i].className = "cpx12hei";
        }
    }
} 

//选中所有复选框
function selectAll(form)
{
    if(form == null || form.cb == null)
    {
        return;
    }

    if(form.cb.length != null)
    {
        for(i = 0; i < form.cb.length; i++)
            form.cb[i].checked = form.ID_ALL.checked;
    }
    else
    {
        form.cb.checked = form.ID_ALL.checked;
    }
}

//是否只选中一条记录, 是，返回选中的CHeckBox的值，否则返回""
function isCheckedOne(form)
{
    var pkValue = "";
    var count = 0;
    //当前选中的记录数
    for(var i = 0; i < form.elements.length; i++)
    {
        var e = form.elements[i];
        if(e.name != 'ID_ALL' && e.type.toLowerCase() == "checkbox")
        {
            if(e.checked)
            {
                count++;
                pkValue = e.value;
                if(count > 1)
                    break;
            }
        }
    }

    if(count == 1) //只有一个被选中
    {
        return pkValue;
    }
    else if(count == 0)
    {
        alert(checkFirst);
        return "";
    }
    else if(count > 1)
    {
        alert(onlyOne);
        return "";
    }
}

//是否有选中的记录，有选中：返回true,没有选中：返回false
function isChecked(form)
{
    var count = 0;
    for(var i = 0; i < form.elements.length; i++)
    {
        var e = form.elements[i];
        if(e.name != 'ID_ALL' && e.type.toLowerCase() == "checkbox")
        {
            if(e.checked)
            {
                count++;
                break;
            }
        }
    }

    return (count > 0);
}


//得到CheckBox 或 Radio 选中项的值，也可以作为判断选中记录条数
//返回选中的值，多值用逗号分隔，没有选中值则返回""，如果没有选中时提示参数不为空，则提示 noSelHint 的内容。
//form:Form的名字，name:CheckBox 或 Radio 的名字，noSelHint:没有选中时提示的语句，
//limitCheckNum:限定选中数目,如果为0，则不限定
function getCheckedValue(form, name, noSelHint, limitCheckNum, onlyHint)
{
    var pkValue = "";
    var count = 0;

    for(var i = 0; i < form.elements.length; i++)
    {
        var e = form.elements[i];
        if(e.name == name
            && (e.type.toLowerCase() == "checkbox" || e.type.toLowerCase() == "radio" ))
        {
            if(e.checked)
            {
                count++;
                pkValue += "," + e.value;
                if(limitCheckNum > 0 && count > limitCheckNum) //如果限定选中数目
                {
                    alert(onlyHint);
                    return "";
                    break;
                }
            }
        }
    }

    if(pkValue != "")
    {
        pkValue = pkValue.substring(1); //去掉开始的一个逗号
    }

    if(count == 0) //没有选中
    {
        if(noSelHint != null && noSelHint != "")
            alert(noSelHint);
        return "";
    }
    else if(count > limitCheckNum)
    {
        alert(limitCheckNum);
        return "";
    }
    else
    {
        return pkValue;
    }
    
}

//自动定焦select框
function SetOptionSelected(valuestr,selectobj)
{
   var foundvalue = 0;
   for(var i=0;i<selectobj.options.length;i++)
   {
          if(selectobj.options[i].value==valuestr)
          {
              selectobj.options[i].selected = true;
              foundvalue=1;
              break;
          }
   }
   if(foundvalue==0) selectobj.options[0].selected = true;
}
