﻿function ChkValite(obj,type,num)
{
    obj=document.getElementById(obj);
   switch(type)
   {
       case 1: //不能为空
      // alert(obj.value);
           
            if(obj.value.trim()=="")
            {
              alert('此项不能为空,请根据您的情况进行填写！');
              obj.focus();
              return true;              
            }
            else
            {
            return false;
            }
            break;
       case 2: //只能输入数值
            
            //
            if(obj.value.trim()=="")    
            {
              return false;
              }
            if (obj.value.trim().replace('￥','').replace('.','').search(/^[0-9,]+$/)==-1) 
            {
              alert('只能输入数字格式！');
              obj.value="";
              obj.focus();
               return true;
            }
             break;
       case 3://输入字符不能超过字符
            if(obj.value.trim().length>num)
            {
               alert('输入的字符太长！，不能超过'+num+"个字！");
              obj.focus();
               return true;
            }
            return false;
            break;
       case 4: //日期格式
            var flag=true; 
            getdate=obj.value.trim();  
            if(getdate=="")
               return false;       
            if (getdate.search(/^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/)==-1) // 判断输入格式时候正确
            {
               flag=false;
            }
            else
            {
                var year=getdate.substr(0,getdate.indexOf('-'))  // 获得年
                // 下面操作获得月份
                var transition_month=getdate.substr(0,getdate.lastIndexOf('-')); 
                var month=transition_month.substr(transition_month.lastIndexOf('-')+1,transition_month.length);
                if (month.indexOf('0')==0)
                {
                month=month.substr(1,month.length);
                }
                // 下面操作获得日期
                var day=getdate.substr(getdate.lastIndexOf('-')+1,getdate.length);
                if (day.indexOf('0')==0)
                {
                day=day.substr(1,day.length);
                }
                if ((month==4 || month==6 || month==9 || month==11) && (day>30)) // 4,6,9,11月份日期不能超过30
                {
                flag=false; 
                 }
                if (month==2)  // 判断2月份
                {
	                if (LeapYear(year))
	                {
		                if (day>29 || day<1){ flag=false; }
	                }
	                else
	                {
		                if (day>28 || day<1){flag=false; }
	                }
                }
                else
                {
                flag=true;
                }
            }
            if(!flag)
             {
                alert('日期格式不正确！');
                obj.focus();
                return true;
             }
            break;
        
        case 5:  //主键重复
            return true;
            break;
          case 6: //价格
            if(obj.value.trim()=="")
              return false;
            if (obj.value.replace('￥','').replace('.','').search(/^\d+(\.\d+)?$/)==-1) 
            {
               return true;
            }
             break;
 
           
            
   }
      
}
function DdlValidate(type,name)
{
   switch(type)
   {
       case "1":
        if(document.getElementById(name).value=="省份")
         {
         alert('请选择您所在的省份！');
         document.getElementById(name).focus();
         return true;
         }
       break;
       
       case "2":
         if(document.getElementById(name).value=="地级市")
         {
         alert('请选择您所在的地级市！');
         document.getElementById(name).focus();
         return true;
         }
       break;
       }
       return false;
}
//判断是否闰年
//参数		intYear 代表年份的值
//return	true: 是闰年	false: 不是闰年
function LeapYear(intYear) {
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}
String.prototype.trim= function()  
{  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}
function chk(){
  if(ChkValite('ctl00_cph_txtName',1,0)) return false;
  if(ChkValite('ctl00_cph_txtPrice',1,0)) return false;
  if(ChkValite('ctl00_cph_txtPrice',2,0)) return false;
  if(ChkValite('ctl00_cph_txtCent',1,0)) return false;
  if(ChkValite('ctl00_cph_txtCent',2,0)) return false;
  if(ChkValite('ctl00_cph_txtVipPrice',1,0)) return false;
  if(ChkValite('ctl00_cph_txtVipPrice',2,0)) return false;
  if(ChkValite('ctl00_cph_txtProducingArea',1,0)) return false;
  if(ChkValite('ctl00_cph_txtProducingArea',2,0)) return false;
  if(ChkValite('ctl00_cph_txtCuXiaoPrice',1,0)) return false;
  if(ChkValite('ctl00_cph_txtCuXiaoPrice',2,0)) return false;return true;
}


//   合并某一列相同的行   
  function MergeCellsVertical(tbl,cellIndex)   
  {   
      if   (tbl.rows.length   <   2)   return;   
      var   i,   j;   
      var   last   =   tbl.rows(0).cells(cellIndex).innerHTML;   
      var   lastIndex   =   0;       
      for   (i   =   1;   i   <   tbl.rows.length;i++)   
      {         
          if   (tbl.rows(i).cells(cellIndex).innerHTML   !=   last)   //   发现新的值   
          {         
              if   (i   >   lastIndex   +   1)   
              {   
                  for   (j   =   lastIndex   +   1;   j   <   i;   j++)   
                  {   
                      tbl.rows(j).cells(cellIndex).removeNode();   
                  }   
                  tbl.rows(lastIndex).cells(cellIndex).rowSpan   =   i   -   lastIndex;   
              }   
              last =tbl.rows(i).cells(cellIndex).innerHTML;   
              lastIndex   =   i;   
          }   
      }   
      //   最后一行要特别处理   
      if   (lastIndex!= tbl.rows.length -1)   
      {         
          for   (j   =   lastIndex   +   1;   j <tbl.rows.length;j++)   
          {             
              tbl.rows(j).cells(cellIndex).removeNode();   
          }   
          tbl.rows(lastIndex).cells(cellIndex).rowSpan   =   tbl.rows.length   -   lastIndex   +   1;   
      }   
  }   
