﻿/******************1.公用部分*********************/
function F(id)
{
    return document.getElementById(id);
}
        
function openUrl(url)
{
    window.open(url);
}

String.prototype.trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
    
//设置cookie值
function setCookie(name,value)
{
　　 var Days = 30; //此 cookie 将被保存 30 天
　　 var exp = new Date();　　　　 //new Date("December 31, 9998");
　　 exp.setTime(exp.getTime() + Days*24*60*60*1000);
　　 document.cookie = name + "="+ escape(value) +";expire="+ exp.toGMTString();
}
        
//得到对应的cookie值        
function getCookie(cookie_name)
{
    var allcookies = document.cookie;
    var cookie_pos = allcookies.indexOf(cookie_name);
    var value;

    // 如果找到了索引，就代表cookie存在，反之，就说明不存在。
    if (cookie_pos != -1)
    {
        // 把cookie_pos放在值的开始，只要给值加1即可。
        cookie_pos += cookie_name.length + 1;
        var cookie_end = allcookies.indexOf(";", cookie_pos);

        if (cookie_end == -1)
        {
            cookie_end = allcookies.length;
        }
        value = unescape(allcookies.substring(cookie_pos, cookie_end));
    }
    return value;
}

 //改变字体大小--Yo
function changeFontSize( size,id )
{
    var area = document.getElementById(id);
	if(!area)
	{
		return;
	}
	var fontSize=getCookie('fontSize');
	if(size!=null)
	{
	    fontSize=size;
	    setCookie('fontSize',size);
	}
	else if(fontSize==null||fontSize.trim().length==0)
	{
	    fontSize=18;
	}
	var areaChild = area.childNodes;
	area.style.fontSize = fontSize + 'px';
	//再对artibody div内的直接html节点设置fontSize属性
	for(var i = 0; i < areaChild.length; i++)
	{
		if(areaChild[i].nodeType == 1)
		{
			areaChild[i].style.fontSize = fontSize + 'px';
		}
	}		
}


//全选或清除所有结点
function checkAll(isChecked)
{  
     tree.setSubChecked("Q0001",isChecked);  
  // tree.setSubChecked(0,isChecked);
}

function tonopen() 
{
     var loginStatus=getCookie("LoginStatus");
     var msg = "";
     if(loginStatus==null ||loginStatus==0)
     {
         msg="您还未开通服务，不能浏览目录树！";
     }
     else if(loginStatus==3)
     {  
         msg="当前用户已被停用，不能浏览目录树！";
     }
     if(msg!="")
     {
         alert(msg);
         return false;
     }
     return true;
 }	


function openNode(treePath)
{  
    if(treePath.length==0) 
    {
        alert('该书不开放自首页开始阅读！');
        return;
    }
    checkAll(0);
    tree.closeAllItems(0);
    if( treePath.substr(treePath.length-1,1)==',')
    {
        treePath=treePath.substr(0,treePath.length-1)
    }
    var pathArray = treePath.split(',');   
    
    for(var i = 0; i < pathArray.length; i++)
    {
        tree.openItem(pathArray[i]);
    }
    browseBooks(pathArray[pathArray.length - 1],1);  
}

function browseBooks(categoryCode)
{
    //是否满足浏览目录树
    if(!tonopen()) return;
    
    //设置当前分页页码
    var obj = F("HiddenCategoryCode");
    obj.value = categoryCode;
    
    //执行分页事件
    __doPostBack('LinkBtnBookBrowse','');
}

//选择某本书
function selectBook(bookPath)
{                                 
    var pathArray = bookPath.split(',');
    
    for(var i = 0; i < pathArray.length - 1; i++)
    {
        tree.openItem(pathArray[i]);
    }
    
    tree.setCheck(pathArray[pathArray.length - 1],1);                                
}

//仅选此书，并收起其它展开项
function selectOnlyBook(codePath)
{
    checkAll(0);
    tree.closeAllItems(0);
    selectBook(codePath);
} 

function goToPage(pageIndex)
{
    //设置当前分页页码
    var obj = F("HiddenCurrPageIndex");
    obj.value = pageIndex;
    
    //执行分页事件
    __doPostBack('LinkBtnPager','');
}
        
//添加评论
function addRemark(uniquecode,src)
{
    var p = src.parentElement || src.parentNode;
    while( p.tagName != 'TD')
    {
        p = p.parentElement||p.parentNode;
    }
    var objContent = F("recordContent");
    var content = p.innerHTML.replace('【意見回饋】','').replace('【申請開放】','');  
    content=content.replace('【選擇此書】','').replace('【僅選此書】','');    
    objContent.value = content.replace('【進入目錄頁】',''); 
    window.open('AddUserFeedBack.aspx?UniqueCode='+uniquecode,'_blank','','');
}

//只是显示时，缩放图片，并不生成新的图片，当另存图片时，存储的是实际图片的大小。
function DrawImg(ImgD,ThumbnailWidth,ThumbnailHeight) 
{
    if(ImgD.width>ThumbnailWidth||ImgD.height>ThumbnailHeight)
    {
        var xImage=new Image(); 
        xImage.src=ImgD.src;     
        var iScale = (xImage.width * 1.0 / ThumbnailWidth) > (xImage.height * 1.0 / ThumbnailHeight) ? (xImage.width * 1.0 / ThumbnailWidth) : (xImage.height * 1.0 / ThumbnailHeight);    
        ImgD.width = xImage.width / iScale;
        ImgD.height = xImage.height / iScale;
        //ImgD.alt=xImage.width+"x"+xImage.height;
    }
}
var request = {
     QueryString : function(val) {
         var uri = window.location.search;
         var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
         return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
     },
     QueryStrings : function() {
        var uri = window.location.search;
 
        if(uri.indexOf("?")!=-1)  
        {  
            var str = uri.substr(1);     //去掉?号   
            return str;
        }
      },
     setQuery : function(val1, val2)  {
         var a = this.QueryStrings();
         var retval = "";
         var seted = false;
         var re = new RegExp("^" +val1+ "\=([^\&\?]*)$", "ig");
         for(var i=0; i<a.length; i++) 
         {
             if (re.test(a[i])) 
             {
                 seted = true;
                 a[i] = val1 +"="+ val2;
             }
         }
         retval = a.join("&");
         return "?" +retval+ (seted ? "" : (retval ? "&" : "") +val1+ "=" +val2);
     }
}
    
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var dragobject={
    z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
    initialize:function(){
        document.onmousedown=this.drag;
        document.onmouseup=function(){this.dragapproved=0;};
    },
    drag:function(e){
        var evtobj=window.event? window.event : e;
        this.targetobj=window.event? event.srcElement : e.target;
        if (this.targetobj.id=="imgView"){
            this.dragapproved=1;
            if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0;}
            if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0;}
            this.offsetx=parseInt(this.targetobj.style.left);
            this.offsety=parseInt(this.targetobj.style.top);
            this.x=evtobj.clientX;
            this.y=evtobj.clientY;
            if (evtobj.preventDefault) evtobj.preventDefault();
            document.onmousemove=dragobject.moveit;
        }
    },
    moveit:function(e){
        var evtobj=window.event? window.event : e;
        if (this.dragapproved==1){
            this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
            this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";
            return false;
        }
    }
}

function setImage(url)
{
    var img = F("imgView");
    if(img!=null && img.src!=url) 
         img.src = url;
}

function chkmode() 
{
    var table = $('#rbtnlst')[0];
    if (table) 
    {            
        var rbtnlist = table.getElementsByTagName('input');    
        var disabled=true;
        var css="btnFalse"
        if (rbtnlist.item(1).checked) 
        {
           css="btn";
           disabled=false;
        }       
       $("#BtnNot").attr("class",css);
       $("#BtnResult").attr("class",css);
       $("#BtnNot").attr("disabled",disabled);
       $("#BtnResult").attr("disabled",disabled);     
    }
}
