﻿var lastColorUsed;
var lastColorUsedForCB;
var LastSelectedRowForCB;

function GV_changeBackColor(row, highlight)
{
  if (highlight)
  {
    lastColorUsed = row.style.backgroundColor;
    row.style.backgroundColor = '#F8F6C1';
  }
  else
  {
    row.style.backgroundColor = lastColorUsed;
    }
}


function LTrim(str)

{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
           i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

function Trim(str)
{
    return RTrim(LTrim(str));
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function IsNumberBlank(obj)
{
    if (obj.value == "")
    {
        return "0";
    }
    else
    {
        return obj.value;
    }
    
}
function IsNumberBlankLabel(obj)
{
    if (obj.innerText == "")
    {
        return "0";
    }
    else
    {
        return obj.innerText;
    }
    
}

function IfTBNumber(objID)
{
    var objField = window.document.getElementById(objID);
	var strField = new String(objField.value);
	
	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			objField.focus();
			return false;
		}

	return true;
	
}

function   IsDate(s)   
{   
    var   re   =   /^(\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/   
    var   m   =   re.exec(s);   
    if   (m   ==   null)   return   false;   
    var   d   =   new   Date(m[1],m[3]-1,m[4]);   
    return   d.getFullYear()==m[1]   &&   d.getMonth()==(m[3]-1)   &&   d.getDate()==m[4];   
} 

/*
IsNumber: 用于判断一个数字型字符串是否为数值型， 
还可判断是否是正数或负数，返回值为true或false 
sign: 若要判断是正负数是使用，是正用´+´，负´-´，不用则表示不作判断 
*/ 
function IsNumber(objID, objName, sign) 
{ 
    var obj = document.getElementById(objID);
    var string = obj.value;

    if (string== "")
    {
        alert("请输入" + objName);
        obj.focus();
        return false;
    }

    var number; 
    number = new Number(string); 
    if (isNaN(number)) 
    { 
        alert("请为" + objName + "输入正确的数值");
        obj.focus();
        return false; 
    } 
    if ((sign==null) || (sign == "-" && number<0) || (sign== "+" && number>0)) 
    {
        return true; 
    } 
    else 
    {
        alert("请为" + objName + "输入正确的数值格式");
        obj.focus();
        return false; 
    }
    return true; 
}



function OpenWinMax(sURL, sWinName)
{
    var winwidth = window.screen.availWidth;
    var winheight = window.screen.availHeight;
    
    var oWin = window.open(sURL, sWinName, 'left=0,top=0,menubar=0,toolbar=0,directories=0,location=0,status=0,resizable=1,scrollbars=1');
    oWin.resizeTo(winwidth, winheight);
    oWin.focus();
    return oWin;
}

function imgUP (image) {
image.style.borderStyle="outset";
image.style.borderWidth="1";
}

function imgDown (image) {
image.style.borderStyle="inset";
image.style.borderWidth="1";
}

function imgNormal (image) {
image.style.borderStyle="";
image.style.borderWidth="0";
}

function CheckAll(obj)
{
    var pObj;
    var iIndex;
    var thisTable;
    pObj = obj.parentElement;
    while (pObj.tagName != "TH") 
    {
        pObj = pObj.parentElement;
    }
    
    iIndex = pObj.cellIndex;
    pObj = pObj.parentElement;
    while (pObj.tagName != "TABLE")
    {
        pObj = pObj.parentElement;
    }
    thisTable = pObj;
    
    for(i=0;i<thisTable.rows.length;i++)
    {
        var objCheckBox = thisTable.rows[i].cells[iIndex].firstChild;
        if(objCheckBox.checked!=null) 
        {
        
        if (objCheckBox.checked != obj.checked)
        {
            objCheckBox.checked = obj.checked;
            if (objCheckBox != obj && objCheckBox.onclick != null)
            {
                objCheckBox.onclick();
            }
        }
        }
    }
}
    
    function CheckOneOnly(obj)
    {
        var pObj;
        var iIndex;
        var thisTable;
        var ifCheck = obj.checked;
        pObj = obj.parentElement;
        while (pObj.tagName != "TD") 
        {
            pObj = pObj.parentElement;
        }
        
        iIndex = pObj.cellIndex;        
        pObj = pObj.parentElement;
        if (LastSelectedRowForCB != null)
        {
            LastSelectedRowForCB.style.backgroundColor = lastColorUsedForCB;
        }
        
        if (ifCheck)
        {
            lastColorUsedForCB = lastColorUsed;
            LastSelectedRowForCB = pObj;
            pObj.style.backgroundColor = 'LightBlue';
            
        }
        else
        {
            pObj.style.backgroundColor = lastColorUsedForCB;
            lastColorUsedForCB = null;
            LastSelectedRowForCB = null;
        }
        lastColorUsed = pObj.style.backgroundColor;
        while (pObj.tagName != "TABLE")
        {
            pObj = pObj.parentElement;
        }
        thisTable = pObj;
        for(i=0;i<thisTable.rows.length;i++)
        {
            var objCheckBox = thisTable.rows[i].cells[iIndex].firstChild;
            if(objCheckBox.checked!=null) objCheckBox.checked = false;
         }
         obj.checked = ifCheck;

    }
    
    function CheckOneSetID(obj, objID, objGetID, objSetID)
    {
        CheckOneOnly(obj);
        var preID = obj.id;
        preID = preID.replace(objID, "");
        var objGet = window.document.getElementById(preID + objGetID);
        if (objGet == null) return;
        var objSet = window.document.getElementById(objSetID);
        if (objSet == null) return;
        
        
        if (obj.checked)
        {
        objSet.value = objGet.value;
        }
        else
        {
        objSet.value = "";
        }
                 
    }    
    
    function CheckPhone(phoneNumber, digMin, info)
    {
        if (phoneNumber == "")
        {
            return true;
        }
        if (phoneNumber.length < parseInt(digMin) )
        {
            alert(info + "最少应为" + digMin + "位！");
            return false;
        }
        return true;
    }
    
    function CheckCell(cellNumber, digFix, info)
    {
        if (cellNumber == "")
        {
            return true;
        }
        if (cellNumber.length != parseInt(digFix) )
        {
            alert(info + "应为" + digFix + "位！");
            return false;
        }
        return true;
        
    }
    
    function IfTextBoxEmpty(objID, objName)
    {
        var obj;
        var sValue;
        
        obj = window.document.getElementById(objID);
        sValue = Trim(obj.value);
        if (sValue == "")
        {
            alert("请输入" + objName);
            try{obj.focus();}catch(e){};
            return true;
        }
        return false;
    }
    
    function IfDdlSelected(objID, objName)
    {
        var obj;
        var sValue;
        
        obj = window.document.getElementById(objID);
        sValue = Trim(obj.value);
        if (sValue == "")
        {
            alert("请选择" + objName);
            try{obj.focus();}catch(e){};
            return true;
        }
        return false;
    }
    
    
    
    function EditMask(sType, e)
    {
        if (sType == "INT")
        {
            if (e.keyCode < 48 || e.keyCode > 57 ) 
            e.returnValue = false;
        }
        
        if (sType == "NUM")
        {
            if ((e.keyCode < 48 && e.keyCode != 46) || e.keyCode > 57 ) 
            e.returnValue = false;
        }
        
        if (sType == "PHONE")
        {
            if ((e.keyCode < 48 && e.keyCode != 45) || e.keyCode > 57 ) 
            e.returnValue = false;
        }
    }
    
    function textboxMultilineMaxNumber(txt,maxLen)
    {   
        try
        {   
            if(txt.value.length > (maxLen-1))return false;   
        }
        catch(e)
        {   
        }   
    } 
    
 

        

    



