﻿// JScript 文件

// 获取对象值
function getObj(id)
{
    if(typeof id == 'string')
    { 
       if(IsElement(id))
       {
           return document.getElementById(id);
       }
	   else
	   {
	       alert("document.getElementById("+id+") is not exist!");
       }
	}
	else
	{
	    alert("typeof "+id+" is not string");
	}
}

// 检测对象是否存在
function IsElement(id)
{
	return document.getElementById(id)!=null ? true : false;
}

// 清除前后空格
function Trim(s)
{
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

// 获得焦点
function TextOnFocus(obj,str)
{
    if(Trim(obj.value) == str)
    {
        obj.value = "";
        obj.style.color="";
    }
    else
    {
        obj.select();
    }
}

// 失去焦点
function TextOutFocus(obj,str)
{
    if(Trim(obj.value) == "")
    {
        obj.value = str;
        obj.style.color="gray";
    }
}

// 获得焦点
function TextOnMouseOver(obj,str)
{
    if(Trim(obj.value) == str)
    {
        obj.value = "";
        obj.style.color="";
        obj.focus();
    }
    else
    {
        obj.select();
    }
}

// 失去焦点
function TextOnMouseOut(obj,str)
{
    if(Trim(obj.value) == "")
    {
        obj.value = str;
        obj.style.color="gray";
    }
}

//数字;
function IsNumber(s)
{
    return !isNaN(s);
}

// 检查是否为中文
function IsCHZN(str)
{
     var reg= /^[\u4e00-\u9fa5]+$/;  
     if (reg.test(str))
     {
	    return true;
     }
     else
     {
	    return false;
     }
} 

