
var old_menu = ''; 
var old_cell = ''; 
function menuclick( submenu ,cellbar) 
{ 
if( old_menu != submenu ){ 
if( old_menu !='' ){ 
old_menu.style.display = 'none'; 
old_cell.src= 'plus.gif'; 
} 
submenu.style.display = 'block'; 
cellbar.src = 'plus.gif'; 
old_menu = submenu; 
old_cell = cellbar; 

}else{ 
submenu.style.display = 'none'; 
cellbar.src= 'plus.gif'; 
old_menu = ''; 
old_cell = ''; 
} 
}
function MM_nbGroup(event, grpName){//v3.0 
var i,img,nbArr,args=MM_nbGroup.arguments; 
if (event == "init" && args.length > 2){ 
if ((img = MM_findObj(args[2])) != null && !img.MM_init){ 
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src; 
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array(); 
nbArr[nbArr.length] = img; 
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null){ 
if (!img.MM_up) img.MM_up = img.src; 
img.src = img.MM_dn = args[i+1]; 
nbArr[nbArr.length] = img; 
}} 
}else if (event == "over"){ 
document.MM_nbOver = nbArr = new Array(); 
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null){ 
if (!img.MM_up) img.MM_up = img.src; 
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1]; 
nbArr[nbArr.length] = img; 
} 
}else if (event == "out" ){ 
for (i=0; i < document.MM_nbOver.length; i++){ 
img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up;} 
}else if (event == "down"){ 
if ((nbArr = document[grpName]) != null) 
for (i=0; i < nbArr.length; i++){img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0;} 
document[grpName] = nbArr = new Array(); 
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null){ 
if (!img.MM_up) img.MM_up = img.src; 
img.src = img.MM_dn = args[i+1]; 
nbArr[nbArr.length] = img; 
}} 
}
     
//??????????
	 function secBoard(n)
  {
    for(i=0;i<secTable.cells.length;i++)
      secTable.cells[i].className="sec1";
    secTable.cells[n].className="sec2";
    for(i=0;i<mainTable.tBodies.length;i++)
      mainTable.tBodies[i].style.display="none";
    mainTable.tBodies[n].style.display="block";
  }
  
//????????
function framesetresize()
{
	//alert(document.body.offsetWidth);
	var bw = document.body.offsetWidth;
	dow = ((bw-865)>0)?((bw-865)/10+170):170;
	ww = dow + "," + "10,*";
	//alert(ww);
	parent.main.cols=ww;
	if(typeof(parent.leftframe.mytable)!="undefined")
	parent.leftframe.mytable.style.display = "";
	parent.middleframe.center_img.src = "/E_CommerceUI/images/i.p.zd.gif";
	if(typeof(parent.rightframe.ltitle)!="undefined")
	parent.rightframe.ltitle.style.width = "100%";
}
//?????????? 
 function changeltitle()
 {
   var bw = document.body.offsetWidth;
   if(screen.width<=1024)
   {
    if(bw>756)
    {
        ww = 760;
    }
    else
    {
       ww = 628;
    }
   }
   else
   {
    if(bw>960)
    {
       ww = 760;
    }
    else
    {
       ww = 628;
    }
   }
   ww="100%";
   document.all.ltitle.style.width = ww;
 }

//两个列表框之间的转移：添加、全添、删除及全删函数
function additem(Lname,Lselected) {
 var j=0;
 var option0;  
 var addflag=0;
 var the_select=Lname;
 var the_added=Lselected;
 for (var i = 0; i < the_select.length; i++)
  {  addflag=0;
     if (the_select.options[i].selected == true)
       {  j=the_added.length;
          for (var k = 0; k < j; k++)
             { if (the_select.options[i].value==the_added.options[k].value)
               addflag=1;
              }
          if (addflag==0)
             { option0 = new Option(the_select.options[i].text,the_select.options[i].value);
               eval("the_added.options[j]=option0");
             }
          else
             alert(the_select.options[i].text+"已经添加！");
       }     
  }
   return null
}
function addall(Lname,Lselected) {
 var j=0;
 var option0;  
 var addflag=0;
 var the_select=Lname;
 var the_added=Lselected;
 for (var i = 0; i < the_select.length; i++)
  {  addflag=0;
     j=the_added.length;
     for (var k = 0; k < j; k++)
        { if (the_select.options[i].value==the_added.options[k].value)
          addflag=1;
         }
     if (addflag==0)
        { option0 = new Option(the_select.options[i].text,the_select.options[i].value);
          eval("the_added.options[j]=option0");
        }    
  }
   return null
}
function delitem(Lselected){
 var the_added=Lselected;
   for (var i = 0; i < the_added.length; i++)
    { if (the_added.options[i].selected == true)
         {  the_added.options[i]=null;
            i=i-1;
         }
    }
  return null
}
function delall(Lselected){
 var the_added=Lselected;
   for (var i = 0; i < the_added.length; i++)
    { the_added.options[i]=null;
      i=i-1;
    }
  return null
}


//日历下拉选择
function fPopUpCalendarDlg(PropertyName)
{
	showx = event.screenX - event.offsetX -104;
	showy = event.screenY - event.offsetY +18;
	newWINwidth = 210 + 4 + 18;
	var retval;
	retval = window.showModalDialog("/E_CommerceUI/Calendar/calendar.htm", "", "dialogWidth:215px; dialogHeight:235px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes; scrollbars:no;unadorned:yes;edge:no ; Resizable=no; help: no;");
	if( retval != null )
	{
	    document.all.item(PropertyName).value = retval;
	}
}

function fPopUpCalendarDlg1(PropertyName)
{
	showx = event.screenX - event.offsetX -104;
	showy = event.screenY - event.offsetY +18;
	newWINwidth = 210 + 4 + 18;
	var retval;
	retval = window.showModalDialog("/E_CommerceUI/Calendar/calendar.htm", "", "dialogWidth:215px; dialogHeight:235px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes; scrollbars:no;unadorned:yes;edge:no ; Resizable=no; help: no;");
	if( retval != null )
	{
	    document.all.item(PropertyName).value = retval;
	}
}
function isNumberString (InString,RefString) 
{
    if(InString.length==0) return (false);
    for(Count=0; Count<InString.length; Count++)  
    {
		TempChar = InString.substring(Count, Count+1);
		if(RefString.indexOf(TempChar,0)==-1)  
		return (false);
    }
    return (true);
}

function fieldIsValid(id,t,fieldName,m_length)   //判断控件是否有效，对常用的验证进行了封装:吴国强 waterfish8848@163.com
{
  //////////////////////////////////////////////
	var j="",k="";
	var l=0;
	while (t!=0)
	{
		j += t%2; 
		t=Math.floor(t/2);
	}
	  
	/*
	for (var i=j.length; i>0;i--)
	{
		k += j.substring(i-1,i);
	}*/
    //////////////////////////////////////////  此段代码转化为二进制
    //alert (j); 
	for(var m =0;m <j.length; m++)
	{
		l=j.substring(m,m+1);
		if(l==1)
		{
			switch (m)
			{
				case 0: //1 不能为空  
					if(!fieldIsNull(id,fieldName))
					{
						return false;
					}
					break;
				case 1: //2 长度限制
					// if(!fieldIsNull(id,fieldName))
					//  {
					//     return true;
					// }
					if(!limitFieldLength(id,fieldName,m_length))
					{
						return false;
					}
				    break;
			    case 2: //4 金额格式
					if(!fieldIsMoney(id,fieldName))
					{
						return false;
					}
					break;
			    case 3: //8 日期格式
					if(!fieldisDate(id,fieldName))
					{
						return false;
					}
					break;
				case 4://16 是否为空,不发生alert
					if(!fieldIsNullNotAlert(id,fieldName))
					{
						return false;
					}
					break;
				case 5://32 是否是有效的email
					if(!fieldIsEmail(id,fieldName))
					{
						return false;
					}
					break;
				case 6: //64
					if(!fieldIsSex(id,fieldName))
					{
						return false;
					}
					break;
				case 7: //128
					if(!fieldIsYear(id,fieldName))
					{
						return false;
					}
					break;
				case 8: //256
					if(!fieldIsIDCard(id,fieldName))
					{
						return false;
					}
					break;
				case 9: //512
					if(!fieldISInter(id,fieldName))
					{
						return false;
					}
					break;
				case 10: //1024
					if(!fieldIsChoice(id,fieldName))
					{
						return false;
					}
					break;  
				case 11: //2048
					if(!fieldIsNumberdot2(id,fieldName))
					{
						return false;
					}
					break;  
				case 12: //4096
					if(!fieldIsNumberdot3(id,fieldName))  
					{
						return false;
					}
					break;
				case 13: //8192
					if(!fieldisTime(id,fieldName))
					{
						return false;
					}
					break;
				case 14: //16384
					if(!fieldisIPAdress(id,fieldName))
					{
						return false;
					}
					break;
				case 15: //32768
					if(!fieldIsInt(id,fieldName))
					{
						return false;
					}
					break;
				case 16: //65536 长度限制,用TrimEndStr
					if(!limitFieldLengthByTrimEnd(id,fieldName,m_length))
					{
						return false;
					}
					break;
				case 17: //131072
				    if(!fieldIsDateNoTime(id,fieldName))
				    {
				        return false;
				    }
                                    break;				
				default:
					break;
			}
		}
	}
    return true;  
}

function TrimStr(x)
{ 
    /* 旧的
	while ((x.length>0) && (x.charAt(0)==' '))
	{
		x=x.substring(1,x.length);
	}
	while ((x.length>0) && (x.charAt(x.length-1)==' '))
	{
		x=x.substring(0,x.length-1);
    }
    
    return x;
    */
    
	if(x==null || x.length<1)
	{
		return "";
	}
	  
	return x.replace(/(^\s*)|(\s*$)/g, "");
 }
 
function TrimStartStr(x)
{ 
    /* 旧的
	while ((x.length>0) && (x.charAt(0)==' '))
	{
		x=x.substring(1,x.length);
	}
	return x;
	*/
	
	if(x==null || x.length<1)
	{
		return "";
	}
	
	return x.replace(/(^\s*)/g, "");
}

function TrimEndStr(x)
{ 
    /* 旧的
	while ((x.length>0) && (x.charAt(x.length-1)==' '))
	{
		x=x.substring(0,x.length-1);
	}
	return x;
	*/
	
	if(x==null || x.length<1)
	{
		return "";
	}
	
	return x.replace(/(\s*$)/g, "");
}

function fieldIsNull(id,fieldName)  //判断是否为空 2^0
{
	var idValue = document.getElementById(id);
	if(TrimStr(idValue.value).length<1)
	{
		alert(fieldName+'不能为空！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsNullNotAlert(id,fieldName)  //判断是否为空 2^4 
{
	var idValue = document.getElementById(id);
	if(TrimStr(idValue.value).length<1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function limitFieldLength(id,fieldName,m_length)
{
	var idValue = document.getElementById(id);
	//alert(TrimStr(idValue.value).length);
	if(m_length==0)
	{
		return true;
	}
	
	if(TrimStr(idValue.value).length>m_length)
	{
		alert(fieldName+"中字符的个数超过了"+m_length+"个！");
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
} 

function limitFieldLengthByTrimEnd(id,fieldName,m_length)
{
	var idValue = document.getElementById(id);
	// alert(TrimStr(idValue.value).length);
	if(m_length==0)
	{
		return true;
	}
	
	if(TrimEndStr(idValue.value).length>m_length)
	{
		alert(fieldName+"中字符的个数超过了"+m_length+"个！");
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
} 

function fieldISInter(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^[0-9]+[\.]?[0,5]{0,2}$/i;
	if(idValue.value.search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的数字[整数]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsInt(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^([0-9]{1}|[1-9][0-9]*)$/i;
	if(idValue.value.search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的数字[整数]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsNumberdot2(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^[\-]?[0-9]*[\.]?[0-9]{0,2}$/i;
	if(TrimStr(idValue.value).search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的数字[整数或者2位小数]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsNumberdot3(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^[\-]?[0-9]*[\.]?[0-9]{0,3}$/i;
	if (TrimStr(idValue.value).search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的数字[整数或者3位小数]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsMoney(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^[0-9]*[\.]?[0-9]{0,2}$/i;
	if(TrimStr(idValue.value).search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的金额！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldisDate(id,fieldName)
{
	var idValue  = document.getElementById(id);
	var strValue = TrimStr(idValue.value);
	/*
	var tmpStr = "";
	if (TrimStr(idValue.value).indexOf('0:00:00')>0)
	{
		tmpStr = TrimStr(idValue.value).substring(0,TrimStr(idValue.value).indexOf('0:00:00'));
	}
	alert (tmpStr);
	*/
    
    var s = /^[1-2]{1}[0,9]{1}[0-9]{2}-[0,1]{1}[0-9]{1}-[0-3]{1}[0-9]{1}$/i;
    
	if(strValue.length>10)
	{
		//alert('tst');
		var tempStr = /^[1-2]{1}[0,9]{1}[0-9]{2}-[0,1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/i;
		if(strValue.search(tempStr)==-1)  //初次判断格式
		{
			alert('请在'+fieldName+'中输入正确的日期[yyyy-MM-dd hh:mm:ss]！');
			idValue.focus();
			return false;
		}
	}
	else if(strValue.search(s)==-1)  //初次判断格式
	{
		alert('请在'+fieldName+'中输入正确的日期[yyyy-MM-dd]！');
		idValue.focus();
		return false;
	}
		
	var strTempDate = strValue.split(" ")[0];
	//alert(strTempDate);
	if(!verifyDate(TrimStr(strTempDate)))  //进行精确判断
	{
		alert('请在'+fieldName+'中输入正确的日期！');
		idValue.focus();
		return false;
	}
 
	return true;
}

function fieldIsDateNoTime(id,fieldName)
{
	var idValue  = document.getElementById(id);
	var strValue = TrimStr(idValue.value);
	if(strValue.length>10)
	{
		alert('请在'+fieldName+'中输入正确的日期[yyyy-MM-dd]！');
		idValue.focus();
		return false;
	}
	
	var s = /^[1-2]{1}[0,9]{1}[0-9]{2}-[0,1]{1}[0-9]{1}-[0-3]{1}[0-9]{1}$/i;
	if(strValue.search(s)==-1)            //初次判断格式
	{
		alert('请在'+fieldName+'中输入正确的日期[yyyy-MM-dd]！');
		idValue.focus();
		return false;
	}
		
	var strTempDate = strValue.split(" ")[0];
	//alert(strTempDate);
	if(!verifyDate(TrimStr(strTempDate)))  //进行精确判断
	{
		alert('请在'+fieldName+'中输入正确的日期！');
		idValue.focus();
		return false;
	}
 
	return true;
}

function fieldIsYear(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^[1-2]{1}[0,9]{1}[0-9]{2}$/i;
	if(idValue.value.search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的年份！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}    

function fieldIsValidShortDate(id,fieldName)
{
	var idValue = document.getElementById(id);
	var strDateTime = TrimStr(idValue.value);
	if(strDateTime.length>=1)
	{
		if(strDateTime.length>10)
		{
			strDateTime = strDateTime.substr(0,10);
		}
		idValue.value = strDateTime;
	    return true;			
	}
	else
	{
		alert(fieldName+"不能为空！"); 
		idValue.focus();
		return false;
	}
}

function fieldisTime(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^([0-9]{1}:[0-5]{1}[0-9]{1})|([0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1})$/i;
	if (TrimStr(idValue.value).search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的时间[hh:mm]或者[h:mm]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsEmail(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i;
	if(TrimStr(idValue.value).search(s)==-1)  
	{
		alert('请在'+fieldName+'中输入正确的Email！');
		idValue.focus();
		return false;
	} 
	else
	{
		return true;
	}
}

function fieldisIPAdress(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^([1-9]|[1-9]\d|1\d{2}|2[0-1]\d|22[0-3])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}$/i;//1-223.0-255.0-255.0-255
	if (TrimStr(idValue.value).search(s)==-1) 
	{
		alert('请在'+fieldName+'中输入正确的IP地址！');
		idValue.focus();
		return false;
	} 
	else
	{
		return true;
	}
}

function fieldIsIDCard(id,fieldName)
{
	var idValue = document.getElementById(id);
	var s = /^([0-9]{18}|[0-9]{15})$/i;
	if(idValue.value.search(s)==-1)
	{
		alert('请在'+fieldName+'中输入正确的身份证号码[15位或18位]！');
		idValue.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function fieldIsChoice(id,fieldName)
{
	var idValue = document.getElementById(id);
	if(idValue.selectedIndex<1)
	{
		alert('请在'+fieldName+'中进行选择！');
		idValue.focus();
		return false;
	} 
	else
	{
		return true;
	}
}

function fieldIsSex(id,fieldName)
{
	var idValue  = document.getElementById(id);
	var strValue = TrimStr(idValue.value);
	if(strValue!='男' && strValue!='女')
	{
		alert('请在'+fieldName+'中输入正确的性别[男或女]！');
		idValue.value = "";
		idValue.focus();
		return false;
	}
	else
	{ 
		return true;
	}
}

function verifyDate(str)
{ 
  // alert(str);
    var y = parseInt(str.split("-")[0]);
    var m;
    if (str.split("-")[1]=="08")
    m=8;
    else if (str.split("-")[1]=="09")
    m=9;
    else
    m = parseInt(str.split("-")[1]);
    var d;
    if (str.split("-")[2]=="08")
    d=8;
    else if(str.split("-")[2]=="09")
    d=9;
    else
    d=parseInt(str.split("-")[2]);
  
    switch(m)
    {
      
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
           if(d>31||d==0)
           {
              return false;
           }
           else
           {
              return true;
           }
           break;
        case 2:
           if (d==0)
           {
            return false;
           }
           else if((((y%4==0&&(y%100!=0)) || (y%400==0))))//润年
           {
              if (d>29)
              {
               return false;
              }
              else
              {
                return true;
              }
           }
           else if (d>28)
           {
             return false;
           }
           else 
           {
              return true;
           }
           break;
        case 4:
        case 6:
        case 9:
        case 11:
           if(d>30||d==0)
           {
              return false;
           }
           else
           {
              return true;
           }
           break;
        default:
           return false;
           break;
     }
}

function CompareShortDate(id1,id2)
{
	var idValue1 = document.getElementById(id1);
	var idValue2 = document.getElementById(id2);
	var date1 = new Date(idValue1.value.replace(/-/g, "/"));
    var date2 = new Date(idValue2.value.replace(/-/g, "/"));

    return (Date.parse(date1) - Date.parse(date2));
}

function compareDate(id1,id2)
{
	var Date1 = document.getElementById(id1).value;
	var Date2 = document.getElementById(id2).value;
	if(Date1==null || Date1.length<1 || Date2==null || Date2.length<1) 
	{
		return true;
	}
	
	var aFDate = Date1.split("-");
	var aTDate = Date2.split("-");
	var fY = aFDate[0];
	var fM = aFDate[1]-1;
	var fD = aFDate[2].substring(0,2);
	var tY = aTDate[0];
	var tM = aTDate[1]-1;
	var tD = aTDate[2].substring(0,2);
	var FDate = new Date(fY,fM,fD); 
	var TDate = new Date(tY,tM,tD);
	//alert(FDate);
	//alert(TDate);
	return FDate<=TDate;
} 

function validateControl(obj,reg,NotEmpty,len,msg,formatStr)
{
	if(NotEmpty)
	{
		if(TrimStr(obj.value).length<1)
		{
			alert(msg+'不能为空！');
			obj.focus();
			return false;
		}
	}
	   
	if(len>0)
	{
		if(TrimStr(obj.value).length>len)
		{
			alert(msg+'长度不能超过'+len+'个字符！');
			obj.focus();
			return false;
		}
	}
	   
	if(reg!=null && reg.length>=1)
	{
		var rx = new RegExp(reg);
		if(TrimStr(obj.value).search(reg)==-1)
		{
			alert(msg+'格式不对['+formatStr+']！');
			obj.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}

function OpenWidow()
{
	var sFeatures = "dialogHeight:550px;dialogWidth:700px";
	var flag = window.showModalDialog("/E_CommerceUI/Common/ImpowerDialogHost.aspx",window,sFeatures);
	if(flag)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function OpenWidow(ivalue)
{
	var sFeatures = "dialogHeight:550px;dialogWidth:700px";
	var flag = window.showModalDialog("/E_CommerceUI/Common/ImpowerDialogHost.aspx?strRightModule="+ivalue,window,sFeatures);
	if(flag)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//-------------------------------------------------
/*
var currentpos,timer; 

function initialize() 
{ 
timer=setInterval("scrollwindow()",10);
} 
function sc(){
clearInterval(timer); 
}
function scrollwindow() 
{ 
currentpos=document.body.scrollTop; 
window.scroll(0,++currentpos); 
if (currentpos != document.body.scrollTop) 
sc();
} 
document.onmousedown=sc
document.ondblclick=initialize
*/
//--------------------------------------


//----------------------------
   // 下拉区背景色
var DIV_BG_COLOR = "rgb(249,255,255)";
// 高亮显示条目颜色
var DIV_HIGHLIGHT_COLOR = "#6699CC";
// 字体
var DIV_FONT = "宋体";
// 下拉区内补丁大小
var DIV_PADDING = "2px";
// 下拉区边框样式
var DIV_BORDER = "1px solid #CCC";
// 文本输入框
var queryField;
// 下拉区id
var divName;
// IFrame名称
var ifName;
// 记录上次选择的值
var lastVal = "";
// 当前选择的值
var val = "";
// 显示结果的下拉区
var globalDiv;
// 下拉区是否设置格式的标记
var divFormatted = false;

/**
InitQueryCode函数必须在<body onload>事件的响应函数中调用,其中:
queryFieldName为文本框控件的id,
hiddenDivName为显示下拉区div的id
*/
function InitQueryCode (queryFieldName, hiddenDivName)
{
	// 指定文本输入框的onblur和onkeydown响应函数
	queryField = document.getElementById(queryFieldName);
	queryField.onblur = hideDiv;
	queryField.onkeydown = keypressHandler;

	// 设置queryField的autocomplete属性为"off"
	queryField.autocomplete = "off";

	// 如果没有指定hiddenDivName,取默认值"querydiv"
	if (hiddenDivName)
	{
		divName = hiddenDivName;
	}
	else
	{
		divName = "querydiv";
	}
	
	// IFrame的name
	ifName = "queryiframe";
	
	// 100ms后调用mainLoop函数
	setTimeout("mainLoop()", 100);
}

/**
获取下拉区的div,如果没有则创建之
*/
function getDiv (divID)
{
	//if (!globalDiv)
	//{
		// 如果div在页面中不存在,创建一个新的div
		//alert(divID);
		if (!document.getElementById(divID))
		{
			var newNode = document.createElement("div");
			newNode.setAttribute("id", divID);
			document.body.appendChild(newNode);
			divFormatted = false;
		}

		// globalDiv设置为div的引用		
		globalDiv = document.getElementById(divID);

		// 计算div左上角的位置		
		var x = queryField.offsetLeft;
		var y = queryField.offsetTop + queryField.offsetHeight;
		var parent = queryField;
		while (parent.offsetParent)
		{
			parent = parent.offsetParent;
			x += parent.offsetLeft;
			y += parent.offsetTop;
		}

		// 如果没有对div设置格式,则为其设置相应的显示样式		
		if (!divFormatted)
		{
			globalDiv.style.backgroundColor = DIV_BG_COLOR;
			globalDiv.style.fontFamily = DIV_FONT;
			globalDiv.style.padding = DIV_PADDING;
			globalDiv.style.border = DIV_BORDER;
			globalDiv.style.width = "500px";
			globalDiv.style.fontSize = "10.5pt";

			globalDiv.style.position = "absolute";
			globalDiv.style.left = x + "px";
			globalDiv.style.top = y + "px";
			globalDiv.style.visibility = "hidden";
			globalDiv.style.zIndex = 10000;

			divFormatted = true;
		}
	//}

	return globalDiv;
}

/**
根据返回的结果集显示下拉区
*/
function showQueryDiv(resultArray)
{
	// 获取div的引用
	var div = getDiv(divName);
	
	// 如果div中有内容,则删除之
	while (div.childNodes.length > 0)
		div.removeChild(div.childNodes[0]);

	// 依次添加结果
	for (var i = 0; i < resultArray.length; i++)
	{
		// 每一个结果也是一个div
		var result = document.createElement("div");
		// 设置结果div的显示样式
		result.style.cursor = "pointer";
		result.style.padding = "2px 0px 2px 0px";
		// 设置为未选中
		_unhighlightResult(result);
		// 设置鼠标移进、移出等事件响应函数
		result.onmousedown = selectResult;
		result.onmouseover = highlightResult;
		result.onmouseout = unhighlightResult;

		// 结果的文本是一个span
		var result1 = document.createElement("span");
		// 设置文本span的显示样式
		result1.className = "result1";
		result1.style.textAlign = "left";
		//result1.style.fontWeight = "bold";
		result1.innerHTML = resultArray[i];
		
		// 将span添加为结果div的子节点
		result.appendChild(result1);
		
		// 将结果div添加为下拉区的子节点
		div.appendChild(result);
	}

	// 如果结果集不为空,则显示,否则不显示
	showDiv(resultArray.length > 0);
}

/**
用户点击某个结果时,将文本框的内容替换为结果的文本,
并隐藏下拉区
*/
function selectResult()
{
	_selectResult(this);
}

// 选择一个条目
function _selectResult(item)
{
	var spans = item.getElementsByTagName("span");
	if (spans)
	{
		for (var i = 0; i < spans.length; i++)
		{
			if (spans[i].className == "result1")
			{
				queryField.value = spans[i].innerHTML;
				lastVal = val = escape(queryField.value);
				mainLoop();
				queryField.focus();
				showDiv(false);
				return;
			}
		}
	}
}

/**
当鼠标移到某个条目之上时,高亮显示该条目
*/
function highlightResult()
{
	_highlightResult(this);
}

function _highlightResult(item)
{
	item.style.backgroundColor = DIV_HIGHLIGHT_COLOR;
}

/**
当鼠标移出某个条目时,正常显示该条目
*/
function unhighlightResult()
{
	_unhighlightResult(this);
}

function _unhighlightResult(item)
{
	item.style.backgroundColor = DIV_BG_COLOR;
}

/**
显示/不显示下拉区
*/
function showDiv (show)
{
	var div = getDiv(divName);
	if (show)
	{
		div.style.visibility = "visible";
	}
	else
	{
		div.style.visibility = "hidden";
	}
	//adjustiFrame();
}

/**
隐藏下拉区
*/
function hideDiv ()
{
	showDiv(false);
}

/**
调整IFrame的位置,这是为了解决div可能会显示在输入框后面的问题
*/
function adjustiFrame()
{
	// 如果没有IFrame,则创建之
	if (!document.getElementById(ifName))
	{
		var newNode = document.createElement("iFrame");
		newNode.setAttribute("id", ifName);
		newNode.setAttribute("src", "javascript:false;");
		newNode.setAttribute("scrolling", "no");
		newNode.setAttribute("frameborder", "0");
		document.body.appendChild(newNode);
	}

	iFrameDiv = document.getElementById(ifName);
	var div = getDiv(divName);

	// 调整IFrame的位置与div重合,并在div的下一层  
	try
	{
		iFrameDiv.style.position = "absolute";
		iFrameDiv.style.width = div.offsetWidth;
		iFrameDiv.style.height = div.offsetHeight;
		iFrameDiv.style.top = div.style.top;
		iFrameDiv.style.left = div.style.left;
		iFrameDiv.style.zIndex = div.style.zIndex - 1;
		iFrameDiv.style.visibility = div.style.visibility;
	}
	catch (e)
	{
	}
}

/**
文本输入框的onkeydown响应函数
*/
function keypressHandler (evt)
{
	// 获取对下拉区的引用		
	var div = getDiv(divName);
	
	// 如果下拉区不显示,则什么也不做		
	if (div.style.visibility == "hidden")
	{
		return true;
	}

	// 确保evt是一个有效的事件	
	if (!evt && window.event)
	{
		evt = window.event;
	}
	var key = evt.keyCode;

	var KEYUP = 38;
	var KEYDOWN = 40;
	var KEYENTER = 13;
	var KEYTAB = 9;
	
	// 只处理上下键、回车键和Tab键的响应		
	if ((key != KEYUP) && (key != KEYDOWN) && (key != KEYENTER) && (key != KEYTAB))
	{
		return true;
	}

	var selNum = getSelectedSpanNum(div);
	var selSpan = setSelectedSpan(div, selNum);
	
	// 如果键入回车和Tab,则选择当前选择条目	
	if ((key == KEYENTER) || (key == KEYTAB))
	{
		if (selSpan)
		{
			_selectResult(selSpan);
		}
		evt.cancelBubble = true;
		return false;
	}
	else //如果键入上下键,则上下移动选中条目
	{
		if (key == KEYUP)
		{
			selSpan = setSelectedSpan(div, selNum - 1);
		}
		if (key == KEYDOWN)
		{
			selSpan = setSelectedSpan(div, selNum + 1);
		}
		if (selSpan)
		{
			_highlightResult(selSpan);
		}
	}

	// 显示下拉区
	showDiv(true);
	return true;
}

/**
获取当前选中的条目的序号
*/
function getSelectedSpanNum(div)
{
	var count = -1;
	var spans = div.getElementsByTagName("div");
	if (spans)
	{
		for (var i = 0; i < spans.length; i++)
		{
			count++;
			if (spans[i].style.backgroundColor != div.style.backgroundColor)
			{
				return count;
			}
		}
	}

	return -1;
}

/**
选择指定序号的结果条目
*/
function setSelectedSpan(div, spanNum)
{
	var count = -1;
	var thisSpan;
	var spans = div.getElementsByTagName("div");
	if (spans)
	{
		for (var i = 0; i < spans.length; i++)
		{
			if (++count == spanNum)
			{
				_highlightResult(spans[i]);
				thisSpan = spans[i];
			}
			else
			{
				_unhighlightResult(spans[i]);
			}
		}
	}

	return thisSpan;
}
//--------------------------

function NavigationEMail(obj)
{
   window.location.href="mailto:"+obj.value;
}

		

 function EnterKeyToTabKey()
		{
		    if(window.event.keyCode==9)
		    {
		        var e = document.activeElement;
					var b = (e.tagName == "INPUT"&& window.event.keyCode == 9&& ( e.type == "text"|| e.type == "password"|| e.type == "checkbox"|| e.type == "radio")|| e.tagName=="SELECT");
					var a = document.forms[0].elements, n=-1;
					for(var i=0; i<a.length; i++)
					{
						if(a[i]==e) n=i;
						if(n>-1 && b && n+1<a.length)
						{    
						    //alert(a[n+1].id);
							if( (!a[n+1].disabled||a[n+1].style.display!="none"||a[n+1].style.visibility!="hide")&&!a[n+1].getAttribute('readonly'))
							{
							  
							   if(a[n+1].type=="text"&&a[n+1].tagName=="INPUT"&&a[n+1].id=="tbbookingno")
							    {
									var tbbookingno =a[n+1]; 
									var rngTxt = tbbookingno.createTextRange();
									rngTxt.moveStart('character',1);
									tbbookingno.focus();
									window.event.keyCode    = 0;
									window.event.returnValue= false;
									return;
							    }
								
								
							}
							
							n=i;
						}
					}  
		    }
			if(window.event.keyCode == 13)
			{
				try
				{
					var e = document.activeElement;
					var b = (e.tagName == "INPUT"&& window.event.keyCode == 13&& ( e.type == "text"|| e.type == "password"|| e.type == "checkbox"|| e.type == "radio")|| e.tagName=="SELECT");
					var a = document.forms[0].elements, n=-1;

					for(var i=0; i<a.length; i++)
					{
						if(a[i]==e) n=i;
						if(n>-1 && b && n+1<a.length)
						{    
						   
							if( (!a[n+1].disabled||a[n+1].style.display!="none"||a[n+1].style.visibility!="hide")&&!a[n+1].getAttribute('readonly'))
							{
							   if(a[n+1].type=="text"&&a[n+1].tagName=="INPUT"&&a[n+1].id!="tbbookingno")
							    {
							      a[n+1].select();
							    }
								a[n+1].focus();
								window.event.keyCode    = 0;
								window.event.returnValue= false;
								return;
							}
							n=i;
						}
					}  
				}
				catch(e)
				{
					return;
				}
			}
			else if(window.event.keyCode == 38 || window.event.keyCode == 40 || window.event.keyCode == 37 || window.event.keyCode == 39)
			{
			   // alert('test');
			   keyDownControl(event.srcElement);
			}
		}
		
 function   keyDownControl(obj) //   
  {   
        var dgBox = obj.parentElement.parentElement.parentElement.parentElement;
        if(dgBox==null || dgBox.id.toUpperCase()!='DGBOX')
        {
         return false;
        }
      
         var k=event.keyCode;   
         var row = getParent(obj,"tr");
         var rowIndex = row.rowIndex;
         var tbCell =  getParent(obj,"td");
         var cellIndex =tbCell.cellIndex;
         
         var nextObj =null;
         var iCursorPos = 0;
         
         if(k==37)
         {
          
               if(obj.type=="text")
				{
					if(getCursorPos(obj)==0)
					{
						if(cellIndex-1>=0)
						{
							tbCell = dgBox.rows[rowIndex].cells[cellIndex-1]
							nextObj =  tbCell.firstChild;
							if(nextObj!=null)
							{
							nextObj.focus();
							}
						}
					}
				}
				else if(obj.type=="select-one")
					{
						if(cellIndex-1>=0)
						{
							tbCell = dgBox.rows[rowIndex].cells[cellIndex-1]
							nextObj =  tbCell.firstChild;
							if(nextObj!=null)
							{
							nextObj.focus();
							}
						}
		          
				}
           
         }
         
         
       
         if(k==39)
         {
          // alert(obj.type);
             if(obj.type=="text")
           {
             if(getCursorPos(obj)==obj.value.length)
             {
                if(cellIndex+1<=dgBox.rows[0].cells.length-2)
                {
					tbCell = dgBox.rows[rowIndex].cells[cellIndex+1]
					nextObj =  tbCell.firstChild;
					if(nextObj!=null)
					{
					nextObj.focus();
					}
                }
             }
           }
           else if(obj.type=="select-one")
             {
                if(cellIndex+1<=dgBox.rows[0].cells.length-2)
                {
					tbCell = dgBox.rows[rowIndex].cells[cellIndex+1]
					nextObj =  tbCell.firstChild;
					if(nextObj!=null)
					{
					nextObj.focus();
					}
                }
          
           }
         }
         
          if(dgBox.rows.length<4)
        {
			return false;
        }
         
         
         
         if(k==40)
         {
			if(rowIndex+1<=dgBox.rows.length-2)
			 nextObj = dgBox.rows[rowIndex+1].cells[cellIndex].firstChild;
			if(nextObj!=null&&nextObj.type=="text")
			{
					nextObj.select();
					nextObj.focus();
					event.returnValue=false;   
				    return   false;   
			}
         }
         
         if(k==38)
         {
			if(rowIndex-1>=1)
			 nextObj = dgBox.rows[rowIndex-1].cells[cellIndex].firstChild;
			if(nextObj!=null&&nextObj.type=="text")
			{
				nextObj.select();
				nextObj.focus();
				event.returnValue=false;   
				return   false;   
			}
         }
		       
  }  
  
  
        //登录控件Tab键与Enter键事件
        function LoginEnterKeyToTabKey()
		{
			if(window.event.keyCode==9 || window.event.keyCode==13) //Tab键与Enter键
			{
				try
				{
					var currControl = document.activeElement;
					//alert(currControl.id);
					var inputControls = document.getElementsByTagName("INPUT");
                    
                    for(var i=0; i<inputControls.length; i++)
					{
						if(inputControls[i].type == "text"|| inputControls[i].type == "password"|| inputControls[i].type == "image")  
					    {
							if(inputControls[i]==currControl)
						    {
								//alert(inputControls[i+1].id);
								if(inputControls[i+1].type=="text"|| inputControls[i+1].type=="password")
								{
									inputControls[i+1].select();
									inputControls[i+1].focus();
								}
								else if(inputControls[i+1].type=="image" && inputControls[i+1].indexOf("bnLogin")>-1)
								{
								    inputControls[i+1].click();
								}
							    else
							    {
							        inputControls[i+1].focus();
							    }
								
								window.event.keyCode    = 0;
								window.event.returnValue= false;
						        return;
							}
						}
					}  
			     }
				catch(e)
				{
					return;
				}
			}
		} 
  

  

  
  
function getParent(el, pTagName) 
{
	if (el == null) return null;
	else if (el.tagName.toLowerCase() == pTagName.toLowerCase())
	{
	return el;
	}
	else
	return getParent(el.parentNode, pTagName);
}
        
		  
function DocumentWriteDateAndWeek()
{
    today=new Date();
	year=today.getYear();
	month=today.getMonth()+1;
	day=today.getDate();
	if (year < 2000) year += 1900;
	document.write(year+"年"+month+"月"+day+"日");
	document.write("&nbsp;&nbsp;星期");
	today=new Date();
	dayofweek=today.getDay();
	Day=new Array(7);
	Day[0]="日"; Day[1]="一";
	Day[2]="二"; Day[3]="三";
	Day[4]="四"; Day[5]="五";
	Day[6]="六";
	document.write(Day[dayofweek]);
} 


function getCursorPos(obj){
  var rngSel = document.selection.createRange();//建立选择域
  var rngTxt = obj.createTextRange();//建立文本域
  var flag = rngSel.getBookmark();//用选择域建立书签
  rngTxt.collapse();//瓦解文本域到开始位,以便使标志位移动
  rngTxt.moveToBookmark(flag);//使文本域移动到书签位
  rngTxt.moveStart('character',-obj.value.length);//获得文本域左侧文本
  str = rngTxt.text.replace(/\r\n/g,'');//替换回车换行符
  return(str.length);//返回文本域文本长度
}

/*
if (window.Event) 
  document.captureEvents(Event.MOUSEUP); 

function nocontextmenu() 
{
event.cancelBubble = true
event.returnValue = false;

return false;
}

function norightclick(e) 
{
if (window.Event) 
{
  if (e.which == 2 || e.which == 3)
   return false;
}
else
  if (event.button == 2 || event.button == 3)
  {
   event.cancelBubble = true
   event.returnValue = false;
   return false;
  }

}

document.oncontextmenu = nocontextmenu;  // for IE5+
document.onmousedown = norightclick;  // for all others
*/

 //初始化控件是否显示
function InitControlIsDisplay(controlObject, controlSaveValueObject)
{
	controlObject.style.display = controlSaveValueObject.value;
}

//折叠控件
function CollapseControl(controlObject)
{
	if(controlObject.style.display=="none")
	{
		controlObject.style.display = "block";
	}
	else
	{
		controlObject.style.display = "none";
	}
}
		  
//折叠控件
function CollapseControl(controlObject, controlSaveValueObject)
{
	if(controlObject.style.display=="none")
	{
		controlSaveValueObject.value= "block";
		controlObject.style.display = "block";
	}
	else
	{
		controlSaveValueObject.value= "none";
		controlObject.style.display = "none";
	}
}

//打开控件并获取焦点
function ShowControl(controlObject, controlSaveValueObject)
{
	if(controlObject.style.display=="none")
	{
		controlSaveValueObject.value= "block";
		controlObject.style.display = "block";
	}
	controlObject.focus();
}

//折叠菜单
function ColloaspMenu(imgObjectID, tableObjectID)
{
	if(document.getElementById(tableObjectID).style.display=="none")
	{
		document.getElementById(tableObjectID).style.display="block";
		document.getElementById(imgObjectID).src = "/E_commerceUI/images/uparrows_white.gif";
	}
	else
	{
		document.getElementById(tableObjectID).style.display="none";
		document.getElementById(imgObjectID).src = "/E_commerceUI/images/downarrows_white.gif";
	}
}

//DataGrid全选
function SelectAll(dataGridId)
{
	var dg = document.getElementById(dataGridId);
	if(dg==null)
	{
		return false;
	}

	for(var i=0; i<dg.rows.length; i++)
	{
		var childControls = dg.rows[i].getElementsByTagName("INPUT");
		for(var j=0;j<childControls.length;j++)
		{
			if(childControls[j].type=="checkbox" && childControls[j].id.indexOf("chkSelect")>-1)
			{
				childControls[j].checked = true;
				break;
				    
			}
		}
	}
	return false;
}

//DataGrid不选
function UnSelectAll(dataGridId)
{
	var dg = document.getElementById(dataGridId);
	if(dg==null)
	{
		return false;
	}

	for(var i=0; i<dg.rows.length; i++)
	{
		var childControls = dg.rows[i].getElementsByTagName("INPUT");
		for(var j=0;j<childControls.length;j++)
		{
			if(childControls[j].type=="checkbox" && childControls[j].id.indexOf("chkSelect")>-1)
			{
				childControls[j].checked = false;
				break;
			}
		}
	}
	return false;
}
		
//检查DataGrid是否有选中记录
function IsSelectCheckBox(id, strDesc)
{
	var tb=document.getElementById(id);
	if(tb==null)
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
	var bFlag = false;
	for (var i=1; i<tb.rows.length; i++)
	{
		var childNodes = tb.rows[i].getElementsByTagName("INPUT");
		for(var j=0;j<childNodes.length;j++)
		{
			if(childNodes[j].type=="checkbox" && childNodes[j].id.indexOf("chkSelect")>-1&&childNodes[j].checked==true)
			{
				bFlag = true;
				break;
			}
		}
	}
	
	//alert(bFlag);
	if(!bFlag)
	{
		alert(strDesc);
		return false;
	}
	
	return true;
}

//判断在DataGrid中是否只选定一条记录
function IsSelectedOne(dataGridId, selectedNoneMsg, selectedMoreMsg)
{
	var dg = document.getElementById(dataGridId);
	if(dg==null)
	{
		alert("没有数据，不能进行操作！");			 
		return false;
	}

	var selectedNum = 0;
	for(var i=0; i<dg.rows.length; i++)
	{
		var childControls = dg.rows[i].getElementsByTagName("INPUT");
	
		/*
		if(childControls==null)
		{
			selectedNum = -1;
			break;
		}
		*/

		for(var j=0;j<childControls.length;j++)
		{
			if(childControls[j].type=="checkbox" && childControls[j].id.indexOf("chkSelect")>-1 && childControls[j].checked==true)
			{
				selectedNum += 1;
				break;
			}
		}
	}
	
	if(selectedNum==0)
	{
		alert(selectedNoneMsg);
		return false;
	}
	else if(selectedNum==1)
	{
		return true;
	}
	else if(selectedNum>1)
	{
		alert(selectedMoreMsg);
		return false;
	}
	else
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
}

function IsSelectedOneRight(strDataGridId, iColIndex, strValue)
{
	var dg = document.getElementById(strDataGridId);
	if(dg==null)
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
	
	for(var iRow=1; iRow<dg.rows.length; iRow++)
	{
		var childControls = dg.rows[iRow].getElementsByTagName("INPUT");
		for(var i=0; i<childControls.length; i++)
		{
			if(childControls[i].type=="checkbox" && childControls[i].id.indexOf("chkSelect")>-1 && childControls[i].checked==true)
			{
				var strTemp = TrimStr(dg.rows[iRow].cells[iColIndex].innerText);
				if(strValue!=strTemp) 
				{
					return false;
				}
				
				return true;
			}
		}
	}
	
	return true;
}

function IsSelectedAllRight(strDataGridId, iColIndex, strValue)
{
	var dg = document.getElementById(strDataGridId);
	if(dg==null)
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
	
	for(var iRow=1; iRow<dg.rows.length; iRow++)
	{
		var childControls = dg.rows[iRow].getElementsByTagName("INPUT");
		for(var i=0; i<childControls.length; i++)
		{
			if(childControls[i].type=="checkbox" && childControls[i].id.indexOf("chkSelect")>-1 && childControls[i].checked==true)
			{
				var strTemp = TrimStr(dg.rows[iRow].cells[iColIndex].innerText);
				if(strValue!=strTemp) 
				{
					return false;
				}
				
				break;
			}
		}
	}
	
	return true;
}

function IsSelectedOneHaveViewPower(strDataGridId, iColIndex1, iColIndex2, strValue)
{
	var dg = document.getElementById(strDataGridId);
	if(dg==null)
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
	
	var strColValue1;
	var strColValue2;
	for(var iRow=1; iRow<dg.rows.length; iRow++)
	{
		var childControls = dg.rows[iRow].getElementsByTagName("INPUT");
		for(var i=0; i<childControls.length; i++)
		{
			if(childControls[i].type=="checkbox" && childControls[i].id.indexOf("chkSelect")>-1 && childControls[i].checked==true)
			{
				strColValue1 = TrimStr(dg.rows[iRow].cells[iColIndex1].innerText);
				if(strColValue1.length>=1 && strValue==strColValue1)
				{
				    return true;
				}
				
				strColValue2 = TrimStr(dg.rows[iRow].cells[iColIndex2].innerText);
				if(strColValue2.length<1 || strValue!=strColValue2)
				{
					return false;
				}
				
				return true;
			}
		}
	}
	
	return true;
}
	


function IsSelectedAllHaveViewPower(strDataGridId, iColIndex1, iColIndex2, strValue)
{
	var dg = document.getElementById(strDataGridId);
	if(dg==null)
	{
		alert("没有数据，不能进行操作！");
		return false;
	}
	
	var strColValue1;
	var strColValue2;
	for(var iRow=1; iRow<dg.rows.length; iRow++)
	{
		var childControls = dg.rows[iRow].getElementsByTagName("INPUT");
		for(var i=0; i<childControls.length; i++)
		{
			if(childControls[i].type=="checkbox" && childControls[i].id.indexOf("chkSelect")>-1 && childControls[i].checked==true)
			{
				strColValue1 = TrimStr(dg.rows[iRow].cells[iColIndex1].innerText);
				if(strColValue1.length>=1 && strValue==strColValue1)
				{
				    break;
				}
				
				strColValue2 = TrimStr(dg.rows[iRow].cells[iColIndex2].innerText);
				if(strColValue2.length<1 || strValue!=strColValue2)
				{
					return false;
				}
				
				break;
			}
		}
	}
	
	return true;
}

//清除代码框和描述框的内容
function ClearCodeAndNameControlsValue(strCodeControlId, strNameControlId)
{
    var control = document.getElementById(strCodeControlId);
	control.value = "";
	control = document.getElementById(strNameControlId);
	control.value = "";
	
	return false;
}

//清除输入框的内容
function ClearInputControlValue(strInputControlId)
{
    document.getElementById(strInputControlId).value = "";
	
	return false;
}

//判断用户的管理级别是否为管理员
function IsHaveAdminPower(userManageGrade,adminManageGrade)
{
	if(userManageGrade==null || userManageGrade.length<1)
	{
		return false;
	}
	return userManageGrade==adminManageGrade?true:false;
}

//判断在选定的用户中是否有正在使用的用户
function IsNotDelCurrentUser(dataGridId,pidIndex,currentUserId,delCurrentUserMsg)
{
	if(currentUserId==null || currentUserId.length<1)
	{
		alert("您的用户信息不正确，不能进行删除用户操作！");
		return false;
	}
	
	var dg = document.getElementById(dataGridId);
	var flag  = 1;
	
	for (var i=0; i<dg.rows.length; i++)
	{
		var childNodes = dg.rows[i].getElementsByTagName("input");
		for(var j=0;j<childNodes.length;j++)
		{
			if(childNodes[j].type=="checkbox" && childNodes[j].id.indexOf("chkSelect")>-1 &&childNodes[j].checked==true)
			{
				var selectedUserId = dg.rows[i].cells[pidIndex].innerText;
				if(selectedUserId==null || selectedUserId.length<1) 
				{
					flag = -1;
					break;
				}
				else if(selectedUserId==currentUserId)
				{
					flag = 0;
					break;
				}
			}
		}
	}
	
	if(flag==-1)
	{
		alert("您选择了不正确的用户数据，不能进行删除操作！");
	}
	else if(flag==0)
	{
		alert(delCurrentUserMsg);
	}
	else if(flag==1)
	{
		return true;
	}
	return false;
}

function CheckLoginInfo()
{
	if(!fieldIsValid('tbUserName',1,'用户名域',8))
	{
		return false;
	}
	
	if(!fieldIsValid('tbPassword',1,'密码域',50))
	{
		return false;
	}
	
	if(!fieldIsValid('tbCheckCode',1,'验证码域',5))
	{
		return false;
	}
	
	return true;
}

function FormatDate(dt)
{
	return dt.getYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();
}
		 