﻿/**********************
		ע֤
	xupznb@gmail.com
		2007-6-21
***********************/

//Ƿ
function chk_air(val)
{  
	if(typeof( val)=='undefined' || val==null || val.length<1)
		return false;
	else
	{
        var patrn = /(^\s+|\s$)/g;   
        val=val.replace(patrn, ""); 
        if(val.length<1)
            return false;
		return true;
    }
}

//ַ
function strLen(key){
	var l=escape(key),len
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4
	l=l.replace(/\%u/g,"uu")
	len=len-(l.length-l.replace(/\%/g,"").length)*2
	return len
}

//Ƿһ
function issame(str1,str2)  
{  
	if(!chk_air(str1))
	{ return false;}
	if (str1==str2)  
	{return(true);}  
	else  
	{return(false);}  
}  

//Ƿ
function chk_Num(str)
{return str.match(/\D/)==null}  

//жǷַ  true ȫַ false к
function chk_allstr(val)
{
	return !(/[^\x00-\xff]/g.test(val)) ;
}

//ʽ֤
//chkemail     
//ܽܣǷΪEmail Address     
//˵Ҫַ     
//ֵ0 1     
function chkemail(a)     
{ var i=a.length;     
var temp = a.indexOf('@');     
var tempd = a.indexOf('.');     
if (temp > 1) {     
if ((i-temp) > 3){     
if ((i-tempd)>0){     
return 1;     
}     
    
}     
}     
return 0;     
}     

//ָʽ֤
//fucCheckNUM     
//ܽܣǷΪ     
//˵Ҫ     
//ֵ1Ϊ֣0Ϊ     
function fucCheckNUM(NUM)     
{     
var i,j,strTemp;     
strTemp="0123456789";     
if ( NUM.length== 0)     
return 0     
for (i=0;i<NUM.length;i++)     
{     
j=strTemp.indexOf(NUM.charAt(i));     
if (j==-1)     
{     
//˵ַ     
return 0;     
}     
}     
//˵     
return 1;     
}  

//绰ʽ֤
//fucCheckTEL     
//ܽܣǷΪ绰     
//˵Ҫַ     
//ֵ1ΪǺϷ0ΪϷ     
function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()# ";     
for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{     
//˵ַϷ     
return 0;     
}     
}     
//˵Ϸ     
return 1;     
}    


/*ʺ
 * 0 -- 
 * 1 -- Ȳ
 * 2 -- δַ
 * 99-- Ҫ
*/
function chk_name(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//ʺ֡ĸ_
	{
		if(strLen(val)>20||strLen(val)<4)
			return 1;
		if(!/^[a-zA-Z0-9_]*$/.test(val))
			return 2;
		return 99;
	}
}

/*
 * 0 -- 
 * 1 -- Ȳ
 * 2 -- δַ
 * 99-- Ҫ
*/
function chk_pwd(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//ʺ֡ĸ_
	{
		if(strLen(val)>20||strLen(val)<6)
			return 1;
		if(!/^[a-zA-Z0-9]*$/.test(val))
			return 2;
		return 99;
	}
}
      


