
if(MyUtil==null)var MyUtil={};

//动态加载页面 
//id 显示页面的容器组件ID 
//url 欲加载页面网址 
MyUtil.loadPage=function(id, url){
$("#"+id).addClass("loader"); 
//$("#"+id).append("Loading......"); 
$("#"+id).append("<img src='/images/loading.gif'/>"); 
$.ajax({ 
type: "get", 
url: url, 
cache: false, 
error: function() {alert('加载页面' + url + '时出错！');}, 
success: function(msg) { 
$("#"+id).empty().append(msg); 
$("#"+id).removeClass("loader"); 
} 
}); 
}

/*选中某个ID下面的所有复选框*/
MyUtil.chkAll=function (id,checked){
$("#"+id+" input[type=checkbox]").attr("checked",checked);
}

MyUtil.doLogin=function (blockId,reloadUrl){
if(blockId==null)blockId="loginBlock";
if(reloadUrl==null){reloadUrl="/inc/login.jsp";}
var login_name=$.trim($("#login_name").val());
var login_pwd=$.trim($("#login_pwd").val());
if(login_name==""||login_pwd==""){
alert("请输入用户名和密码！");
return;
}
var pars={name:login_name,password:login_pwd.calcMD5()};
UserDwr.login(pars,1,function(data){
  if(data==1){
     MyUtil.loadPage(blockId,reloadUrl);
   }else if(data==-100){alert("用户名或密码错误，请重试！");}
});
}

MyUtil.doLoginOut=function(blockId,reloadUrl){
if(blockId==null)blockId="loginBlock";
if(reloadUrl==null){reloadUrl="/inc/login.jsp";}
UserDwr.loginout(function(data){});
MyUtil.loadPage(blockId,reloadUrl);
}

MyUtil.doPrint=function() {  
var bodyHtml=$("body").html(); 
$("body").html($("div .ScrapContent").html());
window.print();
$("body").html(bodyHtml);
}  

MyUtil.doZoom=function (size){
$("#article_Content").css("fontSize",size+"px");
}

MyUtil.chkInt=function(obj){
 var v=$.trim(obj.value);
 if(v==""||isNaN(v)){
  alert("请输入合法数值！");
  obj.value=0;
 }else{
  obj.value=parseInt(v);
 }
}

MyUtil.chkHuobi=function(obj){
 var v=$.trim(obj.value);
 if(v==""||isNaN(v)){
  alert("请输入合法数值！");
  obj.value=0;
 }else{
  obj.value=parseFloat(v).toFixed(2);
 }
}


MyUtil.chkWeight=function(obj){
 var v=$.trim(obj.value);
 if(v==""||isNaN(v)){
  alert("请输入合法数值！");
  obj.value=1;
 }else{
  var temp=parseFloat(v).toFixed(4);
  if(temp>=100){
   alert("单位重量不能超过100KG！");
   obj.value=1;
   return;
  }else{
  obj.value=temp;
  }
 }
}

//去掉字符空格
String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g,""); 
}
//判断是否为邮箱
String.prototype.isEmail = function() 
{ 
 var   myReg   =   /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;     
 return myReg.test(this);
}


 String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {  
     if (!RegExp.prototype.isPrototypeOf(reallyDo)) {  
         return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);  
    } else {  
         return this.replace(reallyDo, replaceWith);  
     }  
 }  


//格式化日期  type=1 2008-03-23  type=2  08-03-23   type=3 2008-03-23 10:34 type=4 2008/03/23 type=5 2008年03月
 MyUtil.formatDate=function(v,type){
if(type==null)type=1;  
if(v==null||v=="null" || v=="")return; 
  if(typeof v == 'string') v = MyUtil.parseDate(v);    
  if(v instanceof Date){    
    if(type==1){
    return v.getFullYear()+ '-' + MyUtil.formatDay(v.getMonth()+1) + '-' +MyUtil.formatDay(v.getDate());
    }else if(type==2){
    var year=v.getFullYear()+"";
    return year.substring(2,4)+ '-' +MyUtil.formatDay(v.getMonth() + 1) + '-' +MyUtil.formatDay(v.getDate());
    }else if(type==3){
    return v.getFullYear()+ '-' + (v.getMonth() + 1) + '-' +v.getDate()+' '+v.getHours()+':'+v.getMinutes()+':'+v.getSeconds();
    }else if(type==4){
    return v.getFullYear()+ '/' + MyUtil.formatDay(v.getMonth()+1) + '/' +MyUtil.formatDay(v.getDate());
    }else if(type==5){
    	return v.getFullYear()+ '年' + MyUtil.formatDay(v.getMonth()+1) + '月';
    }  
  }else{    
  return '';    
  }
} 

MyUtil.formatDay=function(v){
if(v<10)
return "0"+v;
else
return v;
}

MyUtil.parseDate=function (str){  
 var strArray=str.split(" ");   
var strDate=strArray[0].split("-");   
var strTime=strArray[1].split(":");   
var a=new Date(strDate[0],(strDate[1]-parseInt(1)),strDate[2],strTime[0],strTime[1],strTime[2]); 
return a; 
 }

MyUtil.chkBefore=function(obj){
 var checkbox=obj.previousSibling;
 checkbox.checked=!checkbox.checked;
}


