﻿// Trim() , Ltrim() , RTrim() 
String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
return this.replace(/(\s*$)/g, ""); 
} 

//QA-1283 2011年6月17日 唐润君
 var checkEmail=true;
 var radioType = 1;
 function CheckEmailResult(obj)
 {
    if(obj.value.length == 0)
    {
            checkEmail= true;
            return;
     } 
    if(obj!=null && obj.value.length > 0)
       checkEmail=CheckEmail(obj);
 }

function AlertObj(obj,msg,res)
{
    
    if ( obj.getAttribute("alertobj") &&  document.getElementById(obj.getAttribute("alertobj")))
    {
        var alertObj = document.getElementById(obj.getAttribute("alertobj"));
        if ( msg && msg != "" )
        {
            if ( alertObj )
            {
                alertObj.innerHTML = msg;
            }
        }
        else
        {
            if ( res )
            {
                  if ( alertObj )
                  {
                     alertObj.innerHTML = obj.getAttribute("right");
                  }
            }else
            {
                  if ( alertObj )
                  {
                     alertObj.innerHTML = obj.getAttribute("wrong");
                  }else
                  {
                     alert(obj.getAttribute("wrong"));
                  }
            }
        }
        
    }
    if ( res )
    {
    document.getElementById(obj.getAttribute("alertobj")).innerHTML="&nbsp;";
        document.getElementById(obj.getAttribute("alertobj")).style.display = "inline";
        document.getElementById(obj.getAttribute("alertobj")).className = "user_ok";
    }
    else
    {
        document.getElementById(obj.getAttribute("alertobj")).style.display = "inline";
        document.getElementById(obj.getAttribute("alertobj")).className = "user_error";
    
     /*   if (  obj && obj.style.display != "none"  )
        {
            obj.focus();
        }*/
    }
}

function CheckWarningWord()
{
    var o = document.getElementsByTagName("input");
    var reg = new RegExp("[<|>]");
    for ( i = 0 ; i < o.length; i++ )
    {
        if ( o[i].getAttribute("type") == "text" || o[i].getAttribute("type") == "password" )
        {
            AlertObj(o[i],"",true)
            if (o[i].value.match(reg))
            {
                AlertObj(o[i],"含有非法字符，请重新输入",false)
                return false;
            }
        }
    }
    return true;
}

function CheckHTTP(obj)
{
    var reg = new RegExp("^[h|H][t|T][t|T][p|P]:\/\/");
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}

function CheckEmail(obj)
{
    var reg = new RegExp("^[a-zA-Z0-9_\_\.-]+@([a-zA-Z0-9_\_\.]+([-]?[a-zA-Z0-9_\_\.]+)*[\.])[a-zA-Z0-9\u4e00-\u9fa5]+$");
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}

function IsEnAndNum(obj)
{
    var reg = new RegExp("^[a-zA-Z0-9\_]*$");
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}



function LengthIsNotMore(obj , len)
{
    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    if ( val.length > len)
    {
       AlertObj(obj,"",false);
       return false;
    }
    AlertObj(obj,"",true);
    return true;
}
///ejq20101124中文长度判断
function ZhongWenLengthIsNotMore(obj , len)
{
    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    if ( val.length > len)
    {
       AlertObj(obj,"您的公司名称只可输入100个字符！",false);
       return false;
    }
    AlertObj(obj,"",true);
    return true;
}
function LengthIsNotLess(obj , len)
{
    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    if ( val.length < len)
    {
       AlertObj(obj,"",false);
       return false;
    }
    AlertObj(obj,"",true);
    return true;
}

function NotAllowNull(obj)
{
    if ( !obj.value || obj.value.Trim().length == 0)
    {
        AlertObj(obj,"",false);
        return false;
    }
    AlertObj(obj,"",true);
    return true;
}
// EJQ20100824
// 检查是否包含中文
function isContainChn(obj)
{

    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    
    if ( val.length > obj.value.length)
    {
        return true;
    }
    return false;
}

function NotAllowNullAndNotEquals(obj,val)
{
    if ( (!obj.value || obj.value.Trim().length == 0) || obj.value.Trim() == val)
    {
        AlertObj(obj,"",false);
        return false;
    }
    AlertObj(obj,"",true);
    return true;
}

function SelectedCheck(obj,val)
{
    if ( obj && obj.style.display != "none"  && obj.options[obj.selectedIndex].value == val )
    {
        AlertObj(obj,"",false);
        return false;
    }
    AlertObj(obj,"",true);
    return  true;
}

function SelectedCheck1(obj,val)
{
    if ( obj && obj.style.display != "none"  && val == "" )
    {
        AlertObj(obj,"",false);
        return false;
    }
    
    
    AlertObj(obj,"成功！",true);
    return  true;
}

function CheckBoxIsChecked(obj)
{  
    if ( obj.checked )
    {
         AlertObj(obj,"",true);
        return true;
    }
    AlertObj(obj,"",false);
    return  false;
}

function CheckBoxIsChecked1(objs,spanobjs)
{  
    var res = false;
    for ( i = 0 ; i < objs.length; i++ )
    {
        if ( objs[i].checked )
        {
            res = true;
            break
        }
    }
    if ( res )
    {
       document.getElementById(spanobjs.id).style.display = "inline";
        document.getElementById(spanobjs.id).className = "user_ok";
        var alertObj = document.getElementById(spanobjs.id);
        alertObj.innerHTML = alertObj.getAttribute("right");
    }
    else
    {   document.getElementById(spanobjs.id).style.display = "inline";
        document.getElementById(spanobjs.id).className = "user_error";
        var alertObj = document.getElementById(spanobjs.id);
        alertObj.innerHTML = alertObj.getAttribute("wrong");     
    }
    return res;
}

//ejq20100826 多选验证
function mutiIsChecked1(objs,spanobjs)
{  
    var res = false;
    if (objs.value == "" )
    {

    }
    else
    {
        res=true;
    }

    if ( res )
    {
        document.getElementById(spanobjs.id).style.display = "inline";
        document.getElementById(spanobjs.id).className = "user_ok";
        var alertObj = document.getElementById(spanobjs.id);
        alertObj.innerHTML = "";     
    }
    else
    {   document.getElementById(spanobjs.id).style.display = "inline";
        document.getElementById(spanobjs.id).className = "user_error";
        var alertObj = document.getElementById(spanobjs.id);
        alertObj.innerHTML = "该项不能为空,请选择!";     
    }
    return res;
}

function RadioButtonIsSelected(objs,alertObj)
{
    var res = false;
    for ( i = 0 ; i < objs.length; i++ )
    {
        if ( objs.checked )
        {
            res = true;
            break
        }
    }  
  
    if ( res )
    {
       //AlertObj(alertObj,"",true);
    }else
    {
       //AlertObj(alertObj,"必须选择",false);
    }
    return res;
}
function testRadioButtonIsSelected(objs,alertObj)
{
    var res = false;
//    for ( i = 0 ; i < objs.length; i++ )
//    {
//        if ( objs.checked )
//        {
//            res = true;
//            break
//        }
//    }  
//  
//    if ( res )
//    {
     //  AlertObj(alertObj,"",true);
//    }else
//    {
       AlertObj(alertObj,"必须选择",false);
//    }
    return res;
}
function Obj2NotEquleObj1(obj2,obj1)
{
    if( obj2.value != obj1.value )
    {
        AlertObj(obj2,"",false);
        return false;
    }else
    {
        AlertObj(obj2,"",true);
        return true;
    }
}

function CheckIsCHNandEN(obj)
{
    var reg = new RegExp("^[\u4E00-\u9FA5|a-zA-Z|\040]*$");
     
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}

function CheckTel(obj)
{
    //var reg = new RegExp("^[0-9]{1,4}-[0-9]{1,8}(-[0-9]+)?$");
    //var reg = new RegExp("^[0-9]+-[0-9]+(-[0-9]+)?$");
    var reg = new RegExp("^([0-9 -]){6,32}$");
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}

function CheckMobile(obj)
{

    var reg = new RegExp("^([0-9 -]){11,32}$");
     
    if (obj.value.match(reg))
    {
        AlertObj(obj,"",true);
       return true;
    }else
    {
        AlertObj(obj,"",false);
       return false;
    }
}



function AllowNotNull(obj)
{
    if ( obj.value == "" )
    {
         AlertObj(obj,"",true);
         return true;
    }
    return false;
}

function LengthIsMore(obj , len)
{
    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    if ( val.length > len)
    {
       //AlertObj(obj,"长度不能超过"+ len + "字节");
       return false;
    }
    //AlertObj(obj,"");
    return true;
}
function LengthIsLess(obj , len)
{
    var val = obj.value.replace(/[^\x00-\xff]/g, "**"); 
    if ( val.length < len)
    {
   //    AlertObj(obj,"长度不能少于"+ len + "字节");
       return false;
    }
   // AlertObj(obj,"");
    return true;
}

function CheckEnglishAndNumbers(obj)
{
    var reg=new RegExp("^[a-zA-Z|0-9|\_]+$");
        
    if(obj.value.match(reg))
    {
       AlertObj(obj,"",false);
       return true;
    }
    else
    {
       AlertObj(obj,"",false);
       return false;
    }
}

function CheckPasswordFormat(obj)
{
    var reg=new RegExp("^[a-zA-Z|0-9|\_|?|\-|\*|\&]+$");
        
    if(obj.value.match(reg))
    {
       AlertObj(obj,"",true);
       return true;
    }
    else
    {
       AlertObj(obj,"不允许非法字符!",false);
       return false;
    }
   

}

