﻿var NewWin = null;
function OpenWindow(path,title,height,width,left,top,resizable,scrollbars)
{
   var arg = "height="+height+",width="+width+",left="+left+",top="+top+",resizable="+resizable+",scrollbars="+scrollbars+",status=no,toolbar=no,menubar=no,location=no";
   NewWin = window.open(path,title,arg);
   NewWin.focus();
}
var FallWin = null;
function OpenWin(path,title,resizable,scrollbars)
{
   var args = "resizable="+resizable+",scrollbars="+scrollbars+",status=no,toolbar=no,menubar=no,location=no";
   FallWin = window.open(path,title,args);
   FallWin.resizeTo(screen.availWidth,screen.availHeight);
   FallWin.moveTo(0,0);
   FallWin.focus();
}
function ResizeWindow()
{
    var sx=screen.availWidth;
    var sy=screen.availHeight;
    window.resizeTo(sx,sy);
    window.moveTo(0, 0);
    var winHeight = document.documentElement.offsetHeight;
    getId('tabspace').style.height = (winHeight - 370) + "px";
    getId('main').style.height = (winHeight - 372) + "px";
    getId('bookcontent').style.height = (winHeight - 50) + "px";
}
// 加入收藏
function addFavorite(url, sitename) {
    var url = url;
    var webos = GetOs();
    //alert(webos + url + sitename);
    if (webos == "MSIE") {
        window.external.AddFavorite(url, sitename);
    }
    else if (webos == "Firefox") {
        window.sidebar.addPanel(sitename, url, "");
    }
}
function ShowImage(imgObject,iwidth)
{
  var image=new Image();
  image.src=imgObject.src;
  var FitWidth = iwidth;
 if(image.width>FitWidth)
 {
  imgObject.width=FitWidth;
  imgObject.height=(image.height*FitWidth)/image.width;
 }
 else
 {
  imgObject.width=image.width;
  imgObject.height=image.height;
 } 
}
function RePicSize(imgObject,iwidth,iheight)
{
  var image=new Image();
  image.src=imgObject.src;
  var FitWidth = iwidth;
  var FitHeight = iheight;
  if(image.width>0 && image.height>0)
  {
    if(image.width/image.height >= FitWidth/FitHeight)
    {
     if(image.width>FitWidth)
     {
      imgObject.width=FitWidth;
      imgObject.height=(image.height*FitWidth)/image.width;
     }
     else
     {
      imgObject.width=image.width;
      imgObject.height=image.height;
     }
    }
    else
    {
     if(image.height>FitHeight)
     {
      imgObject.height=FitHeight;
      imgObject.width=(image.width*FitHeight)/image.height;
     }
     else
     {
      imgObject.width=image.width;
      imgObject.height=image.height;
     }
   }
  }
}
function getId(id) {
    return (typeof (id) == "string") ? document.getElementById(id) : id;  
}
function elementsByName(name, tagname) {
    var returns = document.getElementsByName(name);
    if (returns.length > 0)
        return returns;
    returns = new Array();
    var tags = document.getElementsByTagName(tagname);
    for (i = 0; i < tags.length; i++) {
        if (tags[i].getAttribute("name") == name) {
            returns[returns.length] = tags[i];
        }
    }
    return returns;
}
function elementsByCssName(cssname, tagname) {
    var returns = new Array();
    var tags = document.getElementsByTagName(tagname);
    for (i = 0; i < tags.length; i++) {
        if (tags[i].getAttribute("class") == cssname) {
            returns[returns.length] = tags[i];
        }
    }
    return returns;
}
function StopEvent(evt)
{
   if (evt.preventdefault)
   {
     evt.preventdefault();
     evt.stopPropagation();
   }
   else
   {
      evt.cancelBubble = true;
      evt.returnValue = false;
   }
}
function IsEmpty(strtext){
   var testText = strtext;
   var testLength = testText.length;
   for(i = 0;i < testLength; i++){
     var testEmpty = testText.substring(i,i+1);
     if(testEmpty != " "){
       return false;
     }
   }
  return true;
}
function checkRate(str) {
    var re = /^\-?[0-9\,]*\.?\d*$/;   //判断字符串是否为数字/^[0-9]+.?[0-9]*$/或者^\d+(\.\d+)?$判断正整数 /^[1-9]+[0-9]*]*$/   
    if (re.test(str)) {
        return true;
    }
    return false;
}
//不准确
function IsNumber(str){
  var Letters = "1234567890."; //可以自己增加可输入值
  var i,c;
  if(str.charAt( 0 )=='-' || str.charAt(str.length - 1) == '-'){
    return false;
  }
  for(i=0; i<str.length; i++){
    c = str.charAt( i );
    if (Letters.indexOf(c)<0){
      return false;
    }
  }
  return true;
}
function CheckLogin(cu,cp){
   var ctcu = getId(cu);
   var ctcp = getId(cp);
   if (IsEmpty(ctcu.value)){
      alert("用户名不能为空！");
      ctcu.value = "";
      ctcu.focus();
      return false;
   }
   if(IsEmpty(ctcp.value)){
      alert("密码不能为空！");
      ctcp.value = "";
      ctcp.focus();
      return false;
   }
   return true;
}
function CheckPagerBox(objbox,currindex,pagecount){
    var pageindex = getId(objbox).value;
    if(isempty(pageindex) || isNaN(pageindex)){
       alert("页索引不是有效的数值!");
       return false;
    }
	else{
	  var pindex = parseInt(pageindex);
	  if(pindex < 1 || pindex > pagecount){
       alert("页索引超出范围!");
       return false;
	  }
	  else if(pindex == currindex){
	    return false;
	  }
	}
	return true;
}
function CheckSearch(txtobj)
{
   var inputobj = getId(txtobj);
   if (IsEmpty(inputobj.value)){
      alert("请输入搜索关键字！");
      inputobj.value = "";
      inputobj.focus();
      return false;
   }
   return true;
}
 function GetOs() 
{ 
   var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        OsObject = "MSIE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        OsObject = "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        OsObject = "Safari"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        OsObject = "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko")>0){ 
        OsObject = "Gecko"; 
   }
   return OsObject;
} 
function ieVersion()
{
    var iv = 8;
    if(GetOs() == "MSIE")
    {
        for(i = 4;i<10;i++)
        {
          if(navigator.userAgent.indexOf("MSIE "+i)>0)
            iv = i;
        }
    }
    return iv;
}
function doZoom(objcontrol,fontsize)
{
    var cs = 1;
    if(isNaN(fontsize)){
	   cs = parseFloat(getId(objcontrol).style.fontSize);
	  if(fontsize == "+"){
          cs += 0.1;
       }
       else if(fontsize == "-"){
          cs -= 0.1;
       }
	}
    else{
       cs = fontsize;
    }
	cs = Math.round(cs*10)/10;
    if(cs > 0.6 && cs < 1.8){
        getId(objcontrol).style.fontSize=cs+'em';
    }
    else{
       alert("字号调整超出范围 !");
    }
}
var isIe=GetOs();
function highlightit(cur)
{ 
    if(ieVersion() < 8)
    {
       if (cur.filters.alpha.opacity > 50) 
          cur.filters.alpha.opacity -= 10; 
       else if (window.highlighting) 
          clearInterval(highlighting);
    }
    else
    {
       if (cur.style.opacity > 0.5) 
          cur.style.opacity -= 0.1; 
       else if (window.highlighting) 
          clearInterval(highlighting);
    }
}
function high(which)
{ 
     theobject = which;
     highlighting = setInterval("highlightit(theobject)",60);
} 
function low(obj)
{ 
    clearInterval(highlighting);
    if(ieVersion() < 8)
      obj.filters.alpha.opacity = 100;
    else
      obj.style.opacity = 1;
} 