﻿//显示星期
function showweek()
{
    now = new Date();
    if (now.getDay() == 0) return ("星期日");
    if (now.getDay() == 1) return ("星期一");
    if (now.getDay() == 2) return ("星期二");
    if (now.getDay() == 3) return ("星期三");
    if (now.getDay() == 4) return ("星期四");
    if (now.getDay() == 5) return ("星期五");
    if (now.getDay() == 6) return ("星期六");
} 
//显示日期
function showdate()
{ 
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    return year + "年" + month + "月" + day + "日";
} 

//隐藏脚本错误时状态栏的提
function killErrors() {return true;}
window.onerror = killErrors;

//加入收藏
function addfavorite() {
    var title = document.title
    var url = document.location.href
    if (window.sidebar) window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) {
        var mbm = document.createElement('a');
        mbm.setAttribute('rel', 'sidebar');
        mbm.setAttribute('href', url);
        mbm.setAttribute('title', title);
        mbm.click();
    }
    else if (document.all) window.external.AddFavorite(url, title);
}

function getHost(url) {
    var host = "null";
    if (typeof url == "undefined" || null == url)
        url = window.location.href;
    var regex = /.*\:\/\/([^\/]*).*/;
    var match = url.match(regex);
    if (typeof match != "undefined"
                        && null != match)
        host = match[1];
    return "http://" + host; +"/"
}

//图片按比例缩放 
var flag=false; 
function DrawImage(ImgD,iwidth,iheight){ 
 var image=new Image(); 
// var iwidth = 200;  //定义允许图片宽度 
// var iheight =200;  //定义允许图片高度 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
 flag=true; 
 if(image.width/image.height>= iwidth/iheight){ 
  if(image.width>iwidth){   
  ImgD.width=iwidth; 
  ImgD.height=(image.height*iwidth)/image.width; 
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  } 
 else{ 
  if(image.height>iheight){   
  ImgD.height=iheight; 
  ImgD.width=(image.width*iheight)/image.height;   
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  } 
 } 
} 

var filesadded="" //保存已经绑定文件名字的数组变量
function loadfile(filename, filetype){ 
	if (filesadded.indexOf("["+filename+"]")==-1){// indexOf判断数组里是否有某一项 
	  loadjscssfile(filename, filetype)  
	  filesadded+="["+filename+"]" //把文件名字添加到filesadded 
	} 
}
function loadjscssfile(filename, filetype){ 
if (filetype=="js"){ //判断文件类型 
  var fileref=document.createElement('script')//创建标签 
  fileref.setAttribute("type","text/javascript")//定义属性type的值为text/javascript 
  fileref.setAttribute("src", filename)//文件的地址 
} 
else if (filetype=="css"){ //判断文件类型 
  var fileref=document.createElement("link") 
  fileref.setAttribute("rel", "stylesheet") 
  fileref.setAttribute("type", "text/css")  
  fileref.setAttribute("href", filename) 
} 
if (typeof fileref!="undefined") 
  document.getElementsByTagName("head")[0].appendChild(fileref) 
}  
