// JavaScript Document
//公共函数
function Trim(){  //去掉空格
	return this.replace(/\s+$|^\s+/g,"");
}
String.prototype.Trim=Trim;  //为String 对象添加方法

function getObject(elementId) { 	//返回dom对象
	if (document.getElementById) {
		return document.getElementById(elementId);
	} else if (document.all) {
		return document.all[elementId];
	} else if (document.layers) {
		return document.layers[elementId];
	}
}


function getObjValue(elementId){  //huodezhi
	if(getObject(elementId).value!=undefined)
		return getObject(elementId).value.Trim();
	else
		return "";
}
function isNull(elementId)  //判断是否为空
{
  if(getObjValue(elementId)=="")
  {
  return false;
  }
  else{
  return true
  }
}

function getMaxDay(year,month) {  //判断天数

if(month==4||month==6||month==9||month==11)

return "30";

if(month==2)

if(year%4==0&&year%100!=0 || year%400==0)

return "29";

else

return "28";

return "31";

}
function isNumber(elementId){  //判断是否是数字
var s=getObjValue(elementId);
var regu = "^[0-9]+$";

var re = new RegExp(regu);

if (s.search(re) != -1) {

return true;

} else {

return false;

}
}
function checkDate( value ) {  //检查日期，参数为日期，与判断每月天数的函数配合

if(value=='') return true;

if(value.length!=10) return false; 

var year = value.substring(0,4);

if(year>"2100" || year< "1900")

return false;

var month = value.substring(5,7);

if(month>"12" || month< "01") return false;

var day = value.substring(8,10);

if(day>getMaxDay(year,month) || day< "01") return false;

return true; 

}
function checkPhone(strPhone) {   //检查手机

var phoneRegWithArea = /^[0][1-9][0-9]{1,2}-[0-9]{5,10}$/;

var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/;
var mobile = /^0?1[0-9][0-9]\d{8}$/; 
if( strPhone.length > 9 ) {

if( phoneRegWithArea.test(strPhone) ){

return true;

}else{ 
if(mobile.test(strPhone)){
	return true
	}
	else
	{
		return false;
	}

}

}else{

if( phoneRegNoArea.test( strPhone ) ){

return true;

}else{
	
return false;
}
}
}

function isChinaOrNumbOrLett(elementId){ //判断是否是汉字、字母、数字组成
var s=getObjValue(elementId)
//var regu = "^[0-9a-zA-Z\u4e00-\u9fa5]+$";  
var regu = "^[a-zA-Z\u4e00-\u9fa5]+$";  //汉字字母组成，判断姓名
var re = new RegExp(regu);

if (re.test(s)) {

return true;

}else{

return false;

}
}

function isNumberOr_Letter(elementId){  //判断是否是数字或字母和下划线
var s=getObjValue(elementId)
var regu = "^[0-9a-zA-Z\_]+$";

var re = new RegExp(regu);

if (re.test(s)) {

return true;

}else{

return false;

}

}
function CompareDate(d1,d2) //比较两个时间返回
{
  return ((new Date(d1.replace(/-/g,"/"))) > (new Date(d2.replace(/-/g,"/"))));
}


function isIdno(ui){ //判断是否符合身份证格式
       var    valid=/(^\d{16}$)|(^\d{18}$)/;   
       return    (valid.test(ui));
	   } 
	   
function checkEmail(strEmail) { //检测Email地址
var s=getObjValue(strEmail)
//var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;

var emailReg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;

if( emailReg.test(s) ){

return true;

}else{

return false;
}
}

 function formatCurrency(numx) {  //格式化为金额格式，保留两位小数  传递目标对象
    num=numx.value;
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    numx.value=((sign)?'':'-') + num + '.' + cents;
    //alert(numx.value);
    //return (((sign)?'':'-') + num + '.' + cents);
}

function chkNum(event){  //控制只允许输入数字，用onkeypress方法触发，以区分上档和忽略小键盘编码
        var e=event || window.event;    
        var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;  
        if(keyCode>47&&keyCode<58){    
         return true;
        }
        else{
        return false;
        }
    }
	
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= w/h){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
}
}
