﻿//控制最大位数输入
function SetMaxLength(obj,nMax)
{
	if(obj.value.length >nMax-1 )
	{
	  obj.value=obj.value.substring(0,nMax-1);
	  }
	
}


//锁定某一行背景色
function lockbg(obj)
{
        if(obj.style.backgroundColor=='yellow'){
            obj.style.backgroundColor='#FFFFFF';
       }else{
            obj.style.backgroundColor='yellow';
       }

}
//鼠标经过某一行时背景色改变
function changebgover(obj)
{
    if(obj.style.backgroundColor!='yellow'){
    obj.style.backgroundColor='#DDECFE';
    }
}
//鼠标离开某一行时背景色改变
function changebgout(obj)
{
    if(obj.style.backgroundColor!='yellow'){
    obj.style.backgroundColor='#FFFFFF';
    }
}
//做标记操作
function MarkInfo(id,obj,objstr)
{
    var GetObj;
    var mark;
    mark="0";
    GetObj=eval(objstr);
    if(obj.style.backgroundColor=='yellow'){
        mark="1";
    }
    if (GetObj)
    {
        var returnstr=GetObj.Upmark(id,mark);
    }
}

//显示店信息
function viewshop(shopid)
{
    var GetObj;
    GetObj=eval("Ctl_App_common_ddlShopAndMember");  
}

//去除非数字的内容
function cutOtherStr(Obj)
{
	Obj.value=Obj.value.replace(/[^\d]/g,'');
}

//检测每一项是否为空
function checkIsEmpty(array)
{
    for(i=0;i<array.length;i++)
    {
          var checkobj=document.getElementById(array[i][0]);
                if (checkobj.value=="")
               {
                    alert(array[i][1]);
                    checkobj=document.getElementById(array[i][0]).focus();
                    return false; 
               } 
    }
    return true;
}

//改变文字大小
function doZoom(size){
	document.getElementById('zoom').style.fontSize=size+'px'
}

//检测每一项是否为空
function checkIsEmpty(array)
{
    for(i=0;i<array.length;i++)
    {
          var checkobj=document.getElementById(array[i][0]);
                if (checkobj.value=="")
               {
                    alert(array[i][1]);
                    checkobj=document.getElementById(array[i][0]).focus();
                    return false; 
               } 
    }
    return true;
}

//判断是否是数字
function isNumber(pObj){
 var obj = eval(pObj);
 strRef = "1234567890.";
 for (var i=0;i<obj.value.length;i++) {
      tempChar= obj.value.substring(i,i+1);
      if (strRef.indexOf(tempChar,0)==-1) {
      obj.value="";
      return false; 
      }
 }
   return true;
}


//检测每一项否是数字
function checkAllIsNumber(array)
{
    for(var ai=0;ai<array.length;ai++)
    {
          var checkobj=document.getElementById(array[ai][0]);
                if (checkobj.value!=""&&!isNumber("getEl('"+array[ai][0]+"')"))
               {
                    alert(array[ai][1]);
                    checkobj=document.getElementById(array[ai][0]).focus();
                    return false; 
               } 
    }
    return true;
}


function checkAllPhone(array)
{
    for(var ai=0;ai<array.length;ai++){
        var checkobj=document.getElementById(array[ai][0]);
        if (checkobj.value!=""&&(checkobj.value+"").length!=8)
       {
            alert(array[ai][1]);
            checkobj=document.getElementById(array[ai][0]).focus();
            document.getElementById(array[ai][0]).select();
            return false; 
       } 
    }
   
    return true;
}

//时间正确性检测2007/12/12 09:09:28
function checkDateHMS(dateStr){
    try{

         // 尝试匹配
         var r = dateStr.split(":");
         
         //alert(r);
         if(r == null) {
              // 未匹配成功
              return false;
         }
        // 将此日期对象的年,月,日与原值对照,若有不匹配的即说明不是正确的日期格式.
         if (r[0]>23 || r[0]<0) return false;
         if (r[1]>59 || r[1]<0) return false;
         if (r[2]>59 || r[2]<0 ) return false;
         return true;
    }catch(e){
       // alert(e.name +"_"+e.message+" err function = [comm.js checkDate function dateStr = "+dateStr);
            alert("error:"+e.name+"_"+e.message);

        return false;
     }
} 

//日期正确性检测2007/12/12 09:09:28
function CheckDateHMS(dateStr){
        var strDate="";
        var strTime = "";
        if(dateStr.indexOf(" ",0)>=0){
           strTime = dateStr.substring(dateStr.indexOf(" ")+1,dateStr.length);
            strDate = dateStr.substring(0,dateStr.indexOf(" "));
        }
        //alert("["+strTime+"]");
        // alert("["+strDate+"]");
    return checkDate(strDate) && checkDateHMS(strTime);

}

//日期正确性检测2007/12/12
function checkDate(dateStr){
    try{
         // 定义日期格式的正则表达式
         var reg = /^(\d{4,4})\-(\d{1,2})\-(\d{1,2})$/;
         // 尝试匹配
         var r = dateStr.match(reg);
         //alert(r);
         if(r == null) {
              // 未匹配成功
              return false;
         }
         // 设置月份,范围为 0 - 11,因此这里要减1
         r[2] = r[2] - 1;
         // 根据匹配的年,月,日构造日期对象
         var d = new Date(r[1], r[2], r[3]);
         // 将此日期对象的年,月,日与原值对照,若有不匹配的即说明不是正确的日期格式.
         if (d.getFullYear() != r[1]) return false;
         if (d.getMonth() != r[2]) return false;
         if (d.getDate() != r[3]) return false;
         return true;
    }catch(e){
       // alert(e.name +"_"+e.message+" err function = [comm.js checkDate function dateStr = "+dateStr);
            alert("error:"+e.name+"_"+e.message);

        return false;
     }
} 

//选择框内容选择设定
function selOption(objOption,strValue){
     for(var i=objOption.length-1;i>=0;i--){
            if(objOption[i].value == strValue){
                objOption[i].selected =true;
            }else{
                objOption[i].selected =false;
            }
      }
}

//选择框内容选择设定
function getSelText(objOption){
     for(var i=objOption.length-1;i>=0;i--){
            if(objOption[i].selected){
            return objOption[i].innerHTML;
            }
      }
}

function NumberInputCheck(obj)
{
    var strCheckCode = "";
    var inputkeycode = window.event.keyCode;
   // 
	if(!(inputkeycode>=48 && inputkeycode<=57)){
	//alert(inputkeycode);
	    window.event.keyCode = 0;
	}else if(inputkeycode>255)
	{
	    window.event.keyCode = 0;
	}
	
	//	obj.value=obj.value.replace(/\D/g, '');
	
}

function CheckBrowser(){

    var browser=navigator.appName 

    var b_version=navigator.appVersion 

    var version=parseFloat(b_version)
    //ie7的场合
    if(window.XMLHttpRequest){
        version = "7";
    }
    return browser+"_"+version;

}