//预先载入图像
//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');
function preloadImages(){
  if(document.images){
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++){
      if (args[i].indexOf("#")!=0){
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }}
}
// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload(){ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

//重定向
function redirect(URLStr) { location = URLStr; }
//右键禁止
function disableRightClick(e){
//Example: disableRightClick();
  var message = "";
  if(!document.rightClickDisabled){ // initialize
    if(document.layers){
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }

  if(document.layers || (document.getElementById && !document.all)){
    if (e.which==2||e.which==3){
      alert(message);
      return false;
    }
  }else{
    alert(message);
    return false;
  }
}
//信息窗口
//wid	窗口宽度
//hei	窗口高度
//title	窗口标题
//msg	窗口内容
function messageWindow(wid, hei, title, msg){
  var width=wid, height=hei;
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var body = '<center>'+msg+'<br><form><input type="button" value="确认并关闭" onClick="self.close()"></form>';
  msgWindow.document.write(head + body);
}
//弹出式窗口
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height){
  if(popUpWin)  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
//弹出窗口
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}

//写入 Cookie
// Example: writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null)  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
//读取 Cookie
// Example: alert( readCookie("myCookie") );
function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
//切换图像
function switchImage(imgName, imgSrc){
  if (document.images)  {
    if (imgSrc != "none")    {
      document.images[imgName].src = imgSrc;
    }
  }
}
// BODY Example:
// <body onLoad="mySlideShow1.play(); mySlideShow2.play();">
// <img src="originalImage1.gif" name="slide1">
// <img src="originalImage2.gif" name="slide2">

// SCRIPT Example:
// var mySlideList1 = ['image1.gif', 'image2.gif', 'image3.gif'];
// var mySlideShow1 = new SlideShow(mySlideList1, 'slide1', 3000, "mySlideShow1");
// var mySlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];
// var mySlideShow2 = new SlideShow(mySlideList2, 'slide2', 1000, "mySlideShow2");
function SlideShow(slideList, image, speed, name){
  this.slideList = slideList;
  this.image = image;
  this.speed = speed;
  this.name = name;
  this.current = 0;
  this.timer = 0;
}
function SlideShow_play(){
  with(this)  {
    if(current++ == slideList.length-1) current = 0;
    switchImage(image, slideList[current]);
    clearTimeout(timer);
    timer = setTimeout(name+'.play()', speed);
  }
}
SlideShow.prototype.play = SlideShow_play;
//打印页面
function printPage() { print(document); }
//随机数
function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}
function selectBox(obj,str,maxs){
	for(i=1;i<maxs;i++){
		document.getElementById(obj+i).className = "nor";
		document.getElementById(obj+"cont"+i).style.display = "none";
		document.getElementById(obj+str).className = "hot";
		document.getElementById(obj+"cont"+str).style.display = "block";
	}
}
function selectmenu(obj,str,maxs){
	for(i=0;i<maxs;i++){
		//document.getElementById(obj+i).className = "nor";
		document.getElementById(obj+"cont"+i).style.display = "none";
		//document.getElementById(obj+str).className = "hot";
		document.getElementById(obj+"cont"+str).style.display = "block";
		document.getElementById(obj+"cont0").style.display = "block";
	}
}



function loadForm(){
  editor.HtmlEdit.document.body.innerHTML=document.form1.Content.value;
  return true
}
//新闻添加修改检测
function check(){
if (editor.EditMode.checked==true)
	  document.form1.Content.value=editor.HtmlEdit.document.body.innerText;
else
	  document.form1.Content.value=editor.HtmlEdit.document.body.innerHTML; 

if (form1.Content.value ==""){
alert("请输入文章内容");
return false;
}
return true;
}


function divdisplay(obj){
	objdiv = document.getElementById(obj)
	if (objdiv.style.display == "none"){objdiv.style.display = "block"}else{objdiv.style.display = "none"}
}

function insert(obj,x,files){
	str="<div id='"+x+"' class='fileup'><a class='fr' onclick='resetdiv('"+x+"')'>取消</a>附件"+x+"："+files+"</div>"
	document.getElementById(obj).innerHTML += str;
	check('fileid','fid');
	divdisplay('fileselect');
}
function insertcon(obj,x,contact){
	clrbtn('conts','请选择收件人');
	document.getElementById(obj).value += contact+"; ";
	//document.getElementById("receptuser").value += x+",";
	divdisplay('userselect');
}
function resetdiv(obj){
	document.getElementById(obj).style.display="none";
	//document.from1.btn.value =- x+",";
}
function clrbtn(obj,val){
	if (document.getElementById(obj).value == val){document.getElementById(obj).value = "";}
}
///////////////////////////////////////////
function checkx(obj,box){
    var sum=checkedNum(box);
    document.form1(obj).value = sum;
}
function checkedNum(obj){
    var items=document.getElementsByName(obj);
    var size=items.length;   //checkbox 总数
    var count="";
	var str="";
    for(var i=0;i<size;i++){
        if(items[i].checked){
            count += items[i].value+"; ";
			str   += "<div id='f"+(i+1)+"' class='fileup'>附件"+(i+1)+"："+items[i].value+"</div>"
        }
    }
	document.getElementById("upfiles").innerHTML = str;
    return count;
}