//----------------------------------------------------------------------------------------------------
//Name:	[javascript]功能模块  
//Function:	[javascript]功能模块  
//Author:	Generate by　Luo Xiaoping
//Date:		2006-04-30
//----------------------------------------------------------------------------------------------------
//Change History:
// Date		Who		Changes Made
//----------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function trim(s)//功能函数：去除字符串前后空格!
  {
    if (s == null)
    {
        return s;
    }

    var i;
    var beginIndex = 0;
    var endIndex = s.length - 1;

    for (i=0; i<s.length; i++)
    {
        if (s.charAt(i) == ' ' || s.charAt(i) == '　')
        {
            beginIndex++;
        }
        else
        {
            break;
        }
    }

    for (i = s.length - 1; i >= 0; i--)
    {
        if (s.charAt(i) == ' ' || s.charAt(i) == '　')
        {
            endIndex--;
        }
        else
        {
            break;
        }
    }

    if (endIndex < beginIndex)
    {
        return "";
    }

    return s.substring(beginIndex, endIndex + 1);
}
/////////////////////////////////////////////////////////////////////////////////////

function BreakDownIDCard(obj) 
{
   if (obj.value.length==15&&obj.value.substr(6,2)!="19"&&obj.value.substr(6,2)!="20")
   {
       document.getElementById("Birthday").value="19"+obj.value.substr(6,2)+"-"+obj.value.substr(8,2)+"-"+obj.value.substr(10,2)
       
       if (obj.value.substr(14,1)=="0"||obj.value.substr(14,1)=="2"||obj.value.substr(14,1)=="4"||obj.value.substr(14,1)=="6"||obj.value.substr(14,1)=="8")
       {
          document.getElementById("Sex_1").checked=true;
          document.getElementById("Sex_0").checked=false;
       }
       else
       {
         document.getElementById("Sex_0").checked=true;
         document.getElementById("Sex_1").checked=false;
       }
   }
   else if (obj.value.length>=17)
   {
       document.getElementById("Birthday").value=obj.value.substr(6,4)+"-"+obj.value.substr(10,2)+"-"+obj.value.substr(12,2)
       
       if (obj.value.substr(16,1)=="0"||obj.value.substr(16,1)=="2"||obj.value.substr(16,1)=="4"||obj.value.substr(16,1)=="6"||obj.value.substr(16,1)=="8")
       {
          document.getElementById("Sex_1").checked=true;
          document.getElementById("Sex_0").checked=false;
       }
       else
       {
         document.getElementById("Sex_0").checked=true;
         document.getElementById("Sex_1").checked=false;
       }
   }
   
   //////// 隐藏控件操作：开始
   document.getElementById("h_Birthday").value = document.getElementById("Birthday").value;
       if (document.getElementById("Sex_0").checked ==true)
          document.getElementById("h_Sex").value = '男';
       else
          document.getElementById("h_Sex").value = '女';
   //////// 隐藏控件操作：结束
}


//////////////////////////////////////////////////////////////////////////
function submitverify_GetBackPassword()//在提交时，进行页面验证 :
{ 
   var obj = null;
  var txt = "";
    
  obj = document.getElementById("CustomerMobile");//CustomerMobile
   
  txt = trim(obj.value);
   if (txt=="" &&obj.disabled==false) //
  {
    alert('[手机号码]不能为空！');
    return false;
  }

}
/////////////////////////////////////////////////////////////////////////////////////////
function submitverify_Register()//在提交时，进行页面验证 :
{ 
  var obj = null;
  var txt = "";
    
  obj = document.getElementById("CustomerName");//姓 名
  if (obj != null)
  {
  txt = trim(obj.value);
   if (txt=="" &&obj.disabled==false) //
  {
    alert('[姓 名]不能为空!');
    return false;
  }
   if (txt !="" &&obj.disabled==false) //正则表达式： 限制不能输入特殊字符
  {
   if (txt.match(/^[^']+$/) == null) 
    {
      alert('[姓 名]中有非法字符!');
      return false;
    }
  }
  }
  
   obj = document.getElementById("ClientId");//身份证号码
    if (obj != null)
  {
		txt = trim(obj.value);
		if (txt=="" &&obj.disabled==false) //
		{
			alert('[身份证号码]不能为空!');
			return false;
		}
		if (txt !="" &&obj.disabled==false) //正则表达式： 限制不能输入特殊字符
		{
		//if (txt.match(/\d{15}|\d{18}/) == null) 
		if (txt.match(/^[^']+$/) == null) 
			{
			alert('[身份证号码]格式不对!');
			return false;
			}
		}
  
  BreakDownIDCard(obj);//身份证号码
  }
  
     //验证[手机号码]是否合法
   obj = document.getElementById("Mobile");//手机
    if (obj != null)
  {
   txt = trim(obj.value);
    if (txt=="" &&obj.disabled==false) //
  {
     alert('[手机]不能为空!');
     return false;
  }
 if (txt!="" &&obj.disabled==false) //不为空时：
  {
    if (txt.match(/13\d{9}/) == null) //正则表达式：只能是[中国移动]和[中国联通]号码,不包括[小灵通]号码    {       alert('[手机]不合法!');
       return false;
    }
      if (txt.length !=11 ) //位数：    {       alert('[手机]位数不对:只能为11位!');
       return false;
    }
  }
  }
  
  //验证[中国固定电话号码]是否合法
   obj = document.getElementById("WorkTel");//联系电话
    if (obj != null)
  {
   txt = trim(obj.value);
 if (txt!="" ) //不为空时：
  {
   // if (txt.match(/(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}/) == null) //正则表达式：   if (txt.match(/^[^'A-Za-z]+$/) == null)      {
       alert('[联系电话]不合法!');
       return false;
    }
     /////////////////////
  }
  }
 
    //验证[电子邮件地址]是否合法
   obj = document.getElementById("Email");//Email
    if (obj != null)
  {
   txt = trim(obj.value);
  if (txt!="" &&obj.disabled==false) //不为空时：
  {
    if (txt.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == null) //正则表达式：    {       alert('[电子邮件]不合法!');
        return false;
    }
      if (txt.length > 40 ) //位数：    {     alert('[电子邮件]位数太长!');
      return false;
    }
  }
  }
  
   obj = document.getElementById("WorkUnit");//工作单位
    if (obj != null)
  {
  txt = trim(obj.value);
   if (txt !="" &&obj.disabled==false) //正则表达式： 限制不能输入特殊字符
  {
   if (txt.match(/^[^']+$/) == null) 
    {
      alert('[工作单位]中有非法字符!');
       return false;
    }
  }
  }
  
   obj = document.getElementById("WorkAdress");//地 址
    if (obj != null)
  {
  txt = trim(obj.value);
   if (txt !="" &&obj.disabled==false) //正则表达式： 限制不能输入特殊字符
  {
   if (txt.match(/^[^']+$/) == null) 
    {
      alert('[地 址]中有非法字符!');
       return false;
    }
  }
  }
  
    //验证[邮政编码]是否合法
   obj = document.getElementById("Postcode");//邮政编码
    if (obj != null)
  {
   txt = trim(obj.value);
 if (txt!="" ) //不为空时：
  {
    if (txt.match(/\d{6}/) == null) //正则表达式：    {      alert('[邮政编码]格式不对!');
       return false;
    }
  }
  }
  
   //验证[出生日期]是否合法
   obj = document.getElementById("h_Birthday");//
    if (obj != null)
  {
   txt = trim(obj.value);
 if (txt == "" ) //为空时：
  {     alert('[出生日期]不能为空!');
     return false;
    }
  }
  
  /////////////////
   obj = document.getElementById("Employment");//Employment
    if (obj != null)
  {
  txt = trim(obj.value);
   if (txt == "" ) //为空时：
  {     alert('[职业]不能为空!');
     return false;
    }
  if (txt !="" &&obj.disabled==false) //正则表达式： 限制不能输入特殊字符
  {
   if (txt.match(/^[^']+$/) == null) 
    {
      alert('[职业]中有非法字符!');
       return false;
    }
  }
  }
  ///////////////
  
  ///////////
   obj = document.getElementById("myUcMarriage_Marriage");//婚姻状况
    if (obj != null)
  {
    if (obj.selectedIndex == 0 &&obj.disabled==false ) //
   {
      alert('请选择[婚姻状况]!');
       return false;
   }
  }
  ////////////
  
  ///////////
   obj = document.getElementById("myUcEducation_Education");//文化程度
    if (obj != null)
  {
    if (obj.selectedIndex == 0 &&obj.disabled==false ) //
   {
      alert('请选择[文化程度]!');
       return false;
   }
  }
  ////////////
  
  ///////////
   obj = document.getElementById("myUcRace_Race");//民族
    if (obj != null)
  {
    if (obj.selectedIndex == 0 &&obj.disabled==false ) //
   {
      alert('请选择[民族]!');
       return false;
   }
  }
  ////////////
  
  
}
/////////////////////////////////////////////////////////////////////////////////////////////
function SetFrameHeight(height)//主框架
		{
		  parent.document.getElementById('MainFrame').height= height;//设置框架高度
		}
function GoMainPage()//去主页
{ 
    SetFrameHeight("400");//设置框架高度
	parent.document.getElementById('MainFrame').src= "KYNVoteInformation.aspx";//
}


//////////////////////////////
//功能:验证C区的TextBox
function VerifyTextBoxForC(obj)
{  
  obj.value=obj.value.replace(/[^\d.]/g,'');//只能输入数字
  
  if (obj.id.length==3)//当源对象ID为3位时
  {
   str = obj.id.substr(0,2);//获得源对象ID的前两位
   tempStr= obj.id.substr(2,1);//排除"使用量"的数据项
  }
  else
  {
   str = obj.id.substr(0,3);//获得源对象ID的前三位
   tempStr= obj.id.substr(3,1);//排除"使用量"的数据项
  }
  
  if (tempStr == 'l')
    return;//当是"使用量"数据项时,不再处理,跳出函数
    
   
   if (obj.value != "")
   {
     strObj1=str+'w';
     obj1 = document.getElementById(strObj1);
     if (obj1 != null && strObj1 != obj.id )
     {
      obj1.style.background='#CCCCCC';
      obj1.disabled=true;  
     }
       
       strObj2=str+'m';
      obj2 = document.getElementById(strObj2);
     if (obj2 != null  && strObj2 != obj.id )
     {
     obj2.style.background='#CCCCCC';
       obj2.disabled=true;  
     }
       
       strObj3=str+'d';
      obj3= document.getElementById(strObj3);
     if (obj3 != null  && strObj3 != obj.id )
     {
     obj3.style.background='#CCCCCC';
       obj3.disabled=true;   
     }
   }
   else
   {
      strObj1=str+'w';
     obj1 = document.getElementById(strObj1);
     if (obj1 != null && strObj1 != obj.id )
     {
      obj1.style.background='#ffffff';
       obj1.disabled=false;
     }
       
       strObj2=str+'m';
      obj2 = document.getElementById(strObj2);
     if (obj2 != null  && strObj2 != obj.id )
     {
      obj2.style.background='#ffffff';
       obj2.disabled=false;
     }
       
       strObj3=str+'d';
      obj3= document.getElementById(strObj3);
     if (obj3 != null  && strObj3 != obj.id )
     {
      obj3.style.background='#ffffff';
       obj3.disabled=false;
      }
   }
     
 
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//功能:验证区域里的TextBox:[整数]
function VerifyTextBoxForInteger(obj)
{  
  obj.value=obj.value.replace(/[^\d]/g,'');//只能输入数字[整数]
}
//功能:验证区域里的TextBox[小数]
function VerifyTextBoxForDecimalFraction(obj)
{  
  obj.value=obj.value.replace(/[^\d.]/g,'');//只能输入数字[小数]
}
////////////////////////////////////////////////////////////////////////////////
