﻿//----------------------------
//全局变量申明区
//-----------------------------
var Imgflag=false;//是否进行图片按比例缩放
var nI  = 0;
var kI  = 0;
var run = false;
var BookPage=0;//当前翻到样本书的页数
var IsMove = false; //是否移动图层
var Editions = 2010; //当前书版本
//var ExactBookPage = 0;//保存精确的书本页

//----------------------------
//获取对象ID
//----------------------------


function $Y() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}

//-----------------------------
//关闭DIV
//-----------------------------
function UnDiv(id){
    //if(confirm('您確定要關閉嗎！')){
        var divs=id.split(',');
        for(var i=0;i<divs.length;i++){
            if($Y(divs[i])){
                $Y(divs[i]).removeNode(true);
            }             
        } 
    //}   
}

//-----------------------------
//返回鼠标X坐標(相對屏幕)
//-----------------------------
function px(){
	//return event.screenX;
	return event.clientX;
}

//-----------------------------
//返回鼠标Y坐標(相對屏幕)
//-----------------------------
function py(){
    //return event.screenY;
    return event.clientY;
}

//-----------------------------
//返回窗口的中間位置--TOP
//-----------------------------
function CenterTop(T){
    return ((document.body.clientHeight)-T)/2;
}

//-----------------------------
//返回窗口的中間位置--LEFT
//-----------------------------
function CenterLeft(L){
     return ((document.body.clientWidth)-L)/2;
}

//-----------------------------
//檢查參數类型
//-----------------------------
function CheckType(Type){
    switch(typeof(Type)){
            case "undefined":
                return "undefined";
                break;
            case "string":
                return "string";
                break;
            default:
                return null;
        } 
}

//-----------------------------
//显示DIV
//-----------------------------
function ShowDiv(id,left,top){
    if($(id)){
        $(id).style.visibility="visible";
        $(id).style.left=left;
        $(id).style.top=top;
    }
}

//-----------------------------
//移动图层
//-----------------------------
function DivMove(obj){
    var x, y;
    $(obj).onmousedown = function(e) {
    debugger
	    $(obj).style.cursor="move";
		IsMove=true;
		with($(obj)){
			style.position="absolute";
			var temp1=offsetLeft;
			var temp2=offsetTop;
			    x=window.event.clientX;
			    y=window.event.clientY;
			    $(obj).onmousemove=function(e){
				    if(!IsMove){ 
				        return false;
				    }
				    with($(obj)){
				        	style.left=temp1+window.event.clientX-x+"px";
					        style.top=temp2+window.event.clientY-y+"px";
				    }
			    }
		    }
		    $(obj).onmouseup=function(e){
		        IsMove=false;
		        $(obj).style.cursor='hand';
		    }
	    }
}

//-----------------------------
//改变当前行的颜色
//-----------------------------
function TurnColor(){	
	source=event.srcElement;
	if (source.tagName=="TD" ){
		source=source;
	}
	else if	 (source.tagName=="A" ){
		source=source.parentElement.parentElement;
	}
	else
	{
		source=source.parentElement
	}
	if (OldEl!=null){
		OldEl.style.backgroundColor="";
	}
	CurEl=source.parentElement;
	CurEl.style.backgroundColor="#fed179";
	OldEl=CurEl;
}

//-----------------------------
//动态创建遮照层类
//-----------------------------
function CreateDiv(){
    var bgObj;
        this.Index=10000;
        //遮照层
        this.sWidth=document.documentElement.offsetWidth;
        this.sHeight=screen.Height+document.documentElement.scrollTop;
        this.color="#777";
        
        //图层
        this.id="div1";
        this.w=300;
        this.h=0;
        this.left=200;
        this.top=100;
        this.bottom=-1;
        this.border="1px solid #09387E";
        this.position="absolute";
        this.background="#DFE9F5";
        
    
    this.AlphaBgDiv=function(){//创建透明遮照层
                            bgObj=document.createElement("div");
		                    bgObj.setAttribute('id','bgDiv');
		                    bgObj.style.position="absolute";
		                    bgObj.style.top=0;
		                    bgObj.style.background="#777";
		                    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75)";
		                    bgObj.style.opacity="0.6";
		                    bgObj.style.left=0;
		                    bgObj.style.width=this.sWidth + "px";
		                    bgObj.style.height=this.sHeight + "px";
		                    bgObj.style.zIndex = parseInt(this.Index);
		                    document.body.appendChild(bgObj);
                    }
    this.ImgBgDiv=function(){ //创建纯色遮照层
                            bgObj=document.createElement("div");
		                    bgObj.setAttribute('id','bgDiv');
		                    bgObj.style.position="absolute";
		                    bgObj.style.top=0;
		                    bgObj.style.background=this.color;
		                    bgObj.style.left=0;
		                    bgObj.style.width=this.sWidth + "px";
		                    bgObj.style.height=this.sHeight + "px";
		                    bgObj.style.zIndex = parseInt(this.Index);
		                    document.body.appendChild(bgObj);
                    }
    
    this.getDiv=function(){
    	                    bgObj=document.createElement("div");
		                    bgObj.setAttribute("id",this.id);
		                    bgObj.setAttribute("align","center");
		                    bgObj.style.background=this.background;
		                    bgObj.style.cursor="hand";
		                    bgObj.style.border=this.border;
		                    bgObj.style.position = this.position;
		                    bgObj.style.left = parseInt(this.left);
		                    if(this.bottom<0){
			                    bgObj.style.top = parseInt(this.top);
		                    }else{
			                    bgObj.style.bottom=parseInt(this.bottom);
		                    }
		                    bgObj.style.width = parseInt(this.w) + "px";
		                    if(this.h!=0){
		                        bgObj.style.height=parseInt(this.h)+"px";
		                    }
		                    bgObj.style.textAlign = "center";
		                    bgObj.style.lineHeight ="25px";
		                    bgObj.style.zIndex = parseInt(this.Index)+1;		
	                        document.body.appendChild(bgObj);
                    }
}
//-----------------------------
// 按比例缩放图片
//iwidth:允许的宽度
//iheight:允许的高度
//-----------------------------
function DrawImage(ImgD,iwidth,iheight){
    var image=new Image();
        image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        Imgflag=true;
        if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){ 
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
                
                if($("ImgClose")){
                    $("ImgClose").width=iwidth;
                }
            }else{
                ImgD.width=image.width; 
                ImgD.height=image.height;
                if($("ImgClose")){
                    $("ImgClose").width=image.width;
                }
            }
        }else{
            if(image.height>iheight){ 
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;
                if($("ImgClose")){
                    $("ImgClose").width=(image.width*iheight)/image.height;
                } 
            }else{
                ImgD.width=image.width; 
                ImgD.height=image.height;
                if($("ImgClose")){
                    $("ImgClose").width=image.width;
                }
            }
        }
    }
}
//-----------------------------
//加载分页
//-----------------------------
function ShowPrintPage(ln, edition) {
    var pg = new ShowPage();
        if (parseInt(edition, 10) == 2010)
            pg.pageCount = 462;
        if (parseInt(edition, 10) == 2009)
            pg.pageCount = 484;
        if (parseInt(edition, 10) == 2008)
            pg.pageCount = 437;
        if (parseInt(edition, 10) == 2007)
            pg.pageCount = 0;
        pg.ln = ln;
        pg.edition = parseInt(edition, 10);
        pg.id = 'bookPage';
        pg.PrintPage();
    
   
    
}

//-----------------------------
//页面加载时运行
//-----------------------------
function addLoadEvent(func){
	var oldonload=window.onload;
	if(typeof window.onload!='function')
	{
		window.onload=func;
	}else{
	window.onload=function()
	{
		oldonload();
		func();
	}
	}		
}

//-----------------------------
//顯示加載信息
//-----------------------------
function getPlease(Error){
	var str;
		str='<table width="100%"><tr><td height="50" align="center" valign="middle"><img src="../Images/loading.gif" align="absmiddle"/>'+Error+'</td></tr></table>';
		return str;
}

//-----------------------------
//顯示數據操作步驟
//-----------------------------
function getDataPlease(str){
    var id="DataPlease";//DIV名稱
    var left,top;
        left=screen.width;
        top=screen.height;
        if(!$(id)){
            //名称,宽度,左边距,高度距,是否底部对齐(大于0则底部对齐),边框,边框颜色,背景色,层定位,Z轴
	        //CreateDiv(id,300,(left-300)/2,top/2,35,1,"#09387E","#5E97DE","absolute",99999);//创建图层	        
	        var IsDiv=new CreateDiv();
                IsDiv.id=id;
                IsDiv.w=300;
                IsDiv.left=(left-300)/2;
                IsDiv.top=(top/2)-100;
                IsDiv.Index=999999;
                IsDiv.getDiv();
        }
        $(id).innerHTML=getPlease(str);
}

//-----------------------------
//JS永不出错
//-----------------------------
function killErrors() 
{ 
    return true; 
}   
window.onerror = killErrors;
