// JavaScript Document
function check_form(theform)
{

if (theform.username.value.length<1)
	{alert("请输入您的名字！");
	 document.theform.username.focus();
     document.theform.username.select();
	 return false;	}
  if(!test_username(document.theform.username.value))
{
   alert("姓名格式不正确");
   document.theform.username.focus();
   document.theform.username.select();
   return false;}
   
 
 if(!chktelph(document.theform.telph.value))
{
   alert("手机号码或电话号码不正确");
   document.theform.telph.focus();
   document.theform.telph.select();
   return false;}
 
if (theform.department.value.length<1)
	{alert("请选择部门！");
	return false;}
if (theform.info_type.value==0)
	{alert("请选择问题类型！");
	return false;}
if (theform.question_title.value.length<1)
	{alert("请输入问题标题！");
	document.theform.question_title.focus();
    document.theform.question_title.select();
	return false;}
if (theform.question.value.length<10)
	{alert("问题内容过于简单！");return false;} 

if (theform.question.value.length>2500)
	{alert("问题内容不能多于2500字！");return false;} 
}




 
function test_username(str_username) 
{ 
var pattern = /[\u4e00-\u9fa5]/ 
if(pattern.test(str_username)) 
return true; 
else
return false; 
}

function DataLength(fData)
{
    var intLength=0
    for (var i=0;i<fData.length;i++)
    {
        if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
            intLength=intLength+2
        else
            intLength=intLength+1    
    }
    return intLength
}
function isPosInteger(e)
{   for(i=0;i<e.length;i++){
    var oneChar=e.charAt(i);
    if(oneChar<'0'||oneChar>'9'){
      return false;
    }
    }
  return true;
}

String.prototype.Trim = function() { 
var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/); 
return (m == null) ? "" : m[1]; 
}

String.prototype.isMobile = function() { 
return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim())); 
}

String.prototype.isTel = function()
{
    
    return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}

function chktelph() { 
    with(document.theform){
        if (telph.value.isMobile()||telph.value.isTel()) { 
            telph.value = telph.value.Trim(); 
            return true; 
        }}} 
function isEmail(email) {
var strEmail=document.getElementById(email).value;
   if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
{
   alert("Email格式正确！");
   return true;
   }else{
     alert("Email格式不正确！");
     document.getElementById(email).value="";
     document.getElementById(email).focus();
     return false;
    }
}



