// 2009-03-26
var showText = "正在加载...";
function showLoad(){
    $(window).scroll(function () {
        $('#loading').animate({
            top:document.documentElement.scrollTop+10,
            right:17
        },1);
    });
    $('<div id="loading"></div>').appendTo('body');
}
function showLoading(msg){
    $('#loading').animate({
        top:document.documentElement.scrollTop+10,
        right:17
    },1);
    $('#loading').text(msg);
    $('#loading').show();
}
function hideLoading(){
    $('#loading').hide();
}
function getPageContent(address){
    $.ajax({
        url: address,
        dataType:"javascript",
        // ifModified:true,   使用这个属性firefox会有问题，无法成功响应
        beforeSubmit:  showLoading(showText),   // 提交之前执行的方法
        success: function(msg){
            $("#" + ShowDiv).html(msg);
            hideLoading();
        }
    });
}
function getOrderPageContent(address){
    $.ajax({
        url: address,
        dataType:"javascript",
        async:"false",
        beforeSubmit:  showLoading(showText),
        success: function(msg){
            $("#ajaxorderlist").html(msg);
            hideLoading();
        }
    });
}
function postcounter(){
    $.ajax({
        url: root_path+"/counter.php",
        data: "ref="+encodeURIComponent(document.referrer)+"&url="+encodeURIComponent(window.location)+"&w="+window.screen.width+"&h="+window.screen.height,
        type:'post',
        dataType:"html"
    });
}
function getmsg2(path,pcode){
    if(doccheckstate!=1)
        return false;
    $.ajax({
        url: path+'info.php',
        type: 'get',
        dataType: 'html',
        data: 'act=get_msg&rootpath='+path+'&pcode='+pcode+'&ajax=1&tm='+ Math.ceil(Math.random()*10000),
        success: function(html){
            $('#AjGuestBook').html(html);
        }
    });
}
function getstar(score){
    var strstar="";
    if(score > 4)
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/>";
    else if(score > 3)
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/>";
    else if(score > 2)
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/>";
    else if(score > 1)
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/>";
    else if(score > 0)
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar2.gif width='12' height='11'/>";
    else
        strstar = "<img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/><img src=http://www.doc88.com/skin/basic/images/prostar1.gif width='12' height='11'/>";
    return strstar;
}
var loadingCss = {
    padding:0,
    margin:0,
    width:'240px',
    height:'80px',
    left:'40%',
    top:'40%',
    textAlign:'center',
    color:'#ffffff',
    border:'0px solid #ffb64b',
    backgroundColor:'#555555',
    cursor:'default'
};
var loadingReadyCss = {
    padding:0,
    margin:0,
    width:'60px',
    height:'60px',
    left:'38%',
    top:'360px',
    textAlign:'center',
    color:'#ffffff',
    border:'0px solid #404040',
    backgroundColor:'#f2f2f2',//'#808080',//#d4d0c8',"#555555"
    cursor:'default'
};
var blockCss = {
    padding:0,
    margin:0,
    width:'600px',
    height:'300px',
    top:'20%',
    textAlign:'center',
    color:'#b43200',
    border:'0px solid #ffb64b',
    backgroundColor:'#FFFFFF',
    cursor:'default'
};
function search_submit(){
    var frm_search = document.forms['frm_search'];
    keyword = document.getElementById("keyword").value
    var regEx = /[\^\{\}\?\*\\]/g;
    keywordnew = keyword.replace(regEx, "");
    regEx = /[\[\]\(\)\/]/g;
    keywordnew = keywordnew.replace(regEx, " ");
    if(keyword != keywordnew){
        regEx = /\s+/g;
        if(keywordnew.replace(regEx, "")==""){
            keyword = "";
        }else{
            keyword = keywordnew;
        }
        document.getElementById("keyword").value = keyword;
    }
    frm_search.action = root_path+'tag/'+encodeURIComponent(keyword);
    if(keyword == ""){
        document.getElementById("keyword").focus();
        return false;
    }
    frm_search.submit();
    return false;
}
/***加载flash***/
function loadFlash(type)
{
	
	if ( $.browser.safari){
        $("#mydoc88").css("margin-top","28px");
    }
	if(navigator.userAgent.indexOf('Firefox') >= 0)
	{
		document.getElementById("divFlash").style.visibility ="hidden";
	}
	var fo = new SWFObject(site_url+"/js/flash/viewer11.swf", "docflash", "720", "540", "9.0.16.0", "#FFFFFF");
	fo.addVariable("p1",product_code);    
	if(timeLimit==""){
		fo.addVariable("p2","1");        
	}else if(mydoc>0){
		fo.addVariable("p2",mydoc);
	}	
	if(checkcode != ""){
		fo.addVariable("p3",checkcode);
	}
	
    fo.addParam("play","true");
    fo.addParam("loop","true");
    fo.addParam("scale","noscale");
    fo.addParam("wmode","window");
    fo.addParam("devicefont","false");
    fo.addParam("menu","true");
    fo.addParam("allowfullscreen","true");
    fo.addParam("allowscriptaccess","always");
    fo.addParam("align","middle");
	
    fo.write("divFlash"); 
    if($('#divFlash').html().length < 20 ){
    	$('#divFlash').html("<br/><p>文档预览需要最新版本的Flash Player支持。</p><p>您尚未安装或版本过低，建议您：</p><a href='http://get.adobe.com/cn/flashplayer/' target='_blank'><img src='"+siteurl_images+"/skin/basic/images/setupflash.gif' width='273' height='39'></a>");
    }

	if(type==1)
	{
		var flashObj = document.getElementById('docflash');
		if(flashObj!=null)
		{
			flashObj.style.visibility = 'hidden'
		}
	}
	if(navigator.userAgent.indexOf('Firefox') >= 0)
	{
		document.getElementById("divFlash").style.visibility ="visible";
	}
}
$(document).ready(function() {

		
	loadFlash(0);
    var blockinfo_reload="<div id='bldownloadinfoAlert' class='blkinfoframe' >\
            <div class='blkclosebtn'></div>\
            <div class='blkinfotitle' ><b style='font-size:16px'><img src='"+siteurl_images+"/skin/basic/images/reg_login/pic01.gif'>"+product_shortname+"</b></div>\
            <div id='blkorderinfodoc' name='blkorderinfodoc' class='blkinfodoc' >"+docpricetype+"</div>\
            <div id='blAlertPotions' name='blAlertPotions' style='font-size:14px;margin-left:20px;height:auto;line-height:25px;margin-top:5px;text-align:left;color:#C30'>&nbsp;</div>\
            <div class='blkinfobtn' style='text-align:right; padding-right:40px'>\
	    <input type='button' class='button' id='blLoginButton' name='blLoginButton' style='display:none' value='登录' onclick='windowLogin()'/><input type='button' class='button' id='blRegButton' name='blRegButton' style='display:none' value='注册' onclick='windowReg()'/><input type ='button' class='button' style='display:none' name='depositButton' id ='depositButton' value = '充值' onclick='window.open(\"/portal/usr_account.php?act=deposit\");setCookie(\"cdb_deposit_money\",downloadPrice);setCookie(\"cdb_doc_url\",window.location.href);windowClose();' /><input type='button' class='button' id='docDownloadButton' name='docDownloadButton' value='下载' onclick='checkDownload(0);' /><input type='button' class='button' name='docCloseButton' id='docCloseButton' value='关闭'  onclick='windowClose()'/>\
            </div>\
        </div>";
    document.getElementById("blkinfo").innerHTML = blockinfo_reload;
    document.getElementById("blkinfo").style.display = 'none';
    var buyordloperator = "下载文档，请勿使用下载工具";
    if(priceFree!=1){
        buyordloperator = "清晰阅读全文或下载文档"
    }
    var howinfo_reload="<div class='lis_ju01' id='howclearid' >\
            <img src='"+siteurl_images+"/skin/basic/images/20050423123030135s.gif' width='14' height='11' />\
            <a href='"+site_url+"/help/index.html#faq' target='_blank' title='此文档需要支付积分后，才可以清晰显示，请点击`下载`按钮'>为什么看不清楚？</a>\
        </div>\
        <div class='lis_ju01' id='howviewall' >\
            <img src='"+siteurl_images+"/skin/basic/images/20050423123030135s.gif' width='14' height='11' />\
            <a href='"+site_url+"/help/index.html#faq' target='_blank' title='此文档需要支付积分后，才可以浏览全部内容，请点击`下载`按钮'>为什么只能看到部分内容？</a>\
        </div>\
        <div class='lis_ju01' id='howbuy' style='display:none'>\
            <img src='"+siteurl_images+"/skin/basic/images/20050423123030135s.gif' width='14' height='11' />\
            <a href='javascript:;' onclick='onclick_howbuy();return false;' target='_blank' title='注册>登录>兑换积分>下载'>如何下载?</a>\
        </div>\
        <div class='lis_ju01' id='howdownload' style='display:none'>\
            <img src='"+siteurl_images+"/skin/basic/images/20050423123030135s.gif' width='14' height='11' />\
            <a href='"+site_url+"/help/index.html#help2_21' target='_blank' title='下载文档操作步骤'>如何下载到本地电脑？</a>\
        </div>";
    document.getElementById("howinfo").innerHTML = howinfo_reload;

    var blockinfobuy_reload="<div id='blkinfopoints_buy' style='display:none'>\
        <b>下载步骤：</b><br>\
        &nbsp;1，注册成为网站会员并登录；<br>\
        &nbsp;2，查看帐户积分(点击'我的文档')，如果积分不足，请参考<a style='color:#1E35A5;' target='_blank' href='"+site_url+"/help/index.html#help2_25'>'如何获得积分'</a>；<br>\
        &nbsp;3，点击本页面的'下载'按钮；<br>\
        &nbsp;4，在'文档下载'页面，点击'确认'；<br>\
        &nbsp;5，操作成功后，"+buyordloperator+"。<br>\
    </div>\
    <div id='blklogininfo_buy' >\
        <div class='blkclosebtn'></div>\
        <div class='blkinfotitle'><b style='font-size:16px'>"+product_shortname+"</b></div>\
        <div id='blklogininfodoc_buy' class='blkinfodoc' ></div>\
        <div id='blklogininfopoints_buy' class='blkinfopoints' ></div>\
        <div class='blkinfobtn' >\
            <input type='button' class='button' id='blkbtncancel_buy' value='关闭'   onclick='windowClose()' />\
        </div>\
    </div>";
    document.getElementById("blkinfobuy").innerHTML = blockinfobuy_reload;
    document.getElementById("blkinfobuy").style.display = 'none';


	document.getElementById("complainInfo").style.display = "none";
	document.getElementById("complainInfo").innerHTML = "<div>\
            <div class='blkinfodoc' style='padding-top:20px;font-size:14px'>&nbsp;&nbsp;&nbsp;&nbsp;若此文档涉嫌侵害了您的权利，请参照<a style='color:#1E35A5;' target='_blank' href='"+site_url+"/help/copyright.html'>“网站版权声明”</a>，或登录网站后，在线提交<br/>举报信息。</div>\
            <div style='font-size:14px;margin-left:20px;height:auto;line-height:25px;margin-top:5px;text-align:left;color:#C30'>&nbsp;</div>\
            <div class='blkinfobtn' style='text-align:right; padding-right:40px'>\
				<input type='button' class='button'  value='登录' onclick='windowLoginForComplaint()'/><input type='button' class='button' value='关闭'  onclick='windowClose()'/>\
            </div>\
        </div>";

    if(timeLimit!="" || product_pagecount<=1){
        $("#howclearid")[0].style.display = 'none';
        $("#howviewall")[0].style.display = 'none';
    }else{
        if(statePagekey == 1){
            $("#howclearid")[0].style.display = 'none';
        }else{
            $("#howviewall")[0].style.display = 'none';
        }
    }    
    if(isNaN(downloadPrice)){
        $("#downloadpriceid").html("下载积分："+downloadPrice);
		if(!isNaN(printPrice)&&printPrice>=0)
		{
			$("#downloadpriceid").html("打印积分："+Math.round(printPrice*100));
		}
    }else{
        $("#downloadpriceid").html("下载积分："+Math.round(downloadPrice*100));
    }

    $stateTimeLimit = 0;// 文档阅读期限, 0-没有权限, "notimelimit"-永久租阅, "times"-限次租阅, 其他-租阅到期时间
    if(curDownloadTimes<=0){
        if(priceFree ==1 ){
            if(freeDLoadable == 2){
                $("#howbuy")[0].style.display = 'block';
            }
        }else{
            if(timeLimit==""){
                $("#howbuy")[0].style.display = 'block';
            }
        }
    }

    if(doccheckstate==1 && logined==1 && ownPublish!=1 && curDownloadTimes>=1 ){
        if(priceFree==0 || freeDLoadable==2){
            $("#howdownload")[0].style.display = 'block';
        }
    }
    if(doccheckstate==1){

        if(msgNum>0){
            getmsg2(root_path, product_code);
        }
        if(viewNum>1){
        	getAjaxLogContent(root_path+"info.php?act=ajax_list_log&view_times="+viewNum+"&rootpath="+root_path+"&p_id="+product_id+"&tm="+ Math.ceil(Math.random()*10000));
        }	
    }
		
    if(ajaxrelated==1){
        setTimeout("getrelateddoc()", 200);
    }
    $('#zoomin').click(function(event){
        if($(".frm-right").css("display") == "block"){
            $(".frm-right").hide("slow");
            $(".frm-left").css("width","960px");
            $("#divFlash").css("width","960px");
            $("#docflash").css("width","960px");
            $('#zoomin').html("<img src='"+siteurl_images+"/skin/basic/images/suoxiao02.jpg' border='0' />");
            //$('#center-frame01title').css("width", "960px");
        }else{
            $("#docflash").css("width","720px");
            $("#divFlash").css("width","720px");
            $(".frm-left").css("width","720px");
            $(".frm-right").show("normal");
            $('#zoomin').html("<img src='"+siteurl_images+"/skin/basic/images/zhankai02.jpg' border='0' />");
            //$('#center-frame01title').css("width", "720px");
        }
    });

    if(doccheckstate==1){
		var flashObj = document.getElementById("docflash");
		if(flashObj!=null)
		{
	    	document.getElementById("buybtn").disabled = false;
			document.getElementById("collectbtn").disabled = false;
		}
		if(ownPublish==1)
			document.getElementById("editButton").disabled = false;
		else
			document.getElementById("printbtn").disabled = false;
		document.getElementById("sharebtn").disabled = false;
    }
});
//AJAX获得信息
function getAjaxLogContent(address){
	showText = "加载中...";
	$.ajax({
		url: address,
		dataType:"javascript",
		// ifModified:true,   使用这个属性firefox会有问题，无法成功响应
		beforeSubmit:  showLoading(showText),   // 提交之前执行的方法
		success: function(msg){
			$("#ajaxloglist").html(msg);
			
			hideLoading();
		}
	});
}
//***继续下载
function continueDownload()
{
	DOC88Window.setIFrame("_blank");
	 $("#form_productbuy").submit();
}
//登录
function windowLogin()
{
	if(currentDoType==0)
		DOC88Window.setIFrame("/js/home/login_init.html?act=window_login&actMethod=download");
	else
		DOC88Window.setIFrame("/js/home/login_init.html?act=window_login&actMethod=print");
}
//注册
function windowReg()
{
	if(currentDoType==0)
		DOC88Window.setIFrame("/js/home/login_init.html?act=window_reg&actMethod=download");
	else
		DOC88Window.setIFrame("/js/home/login_init.html?act=window_reg&actMethod=print");
}
//关闭
function windowClose()
{
	DOC88Window.close();
}
function getrelateddoc()
{
    docid = $('#txtPcode').val();
    doctitle = $('#txtPname').val();
    docmember = $('#txtPsellername').val();
    dotindex = doctitle.lastIndexOf(".");
    if(dotindex>0){
        doctitle = doctitle.substring(1, dotindex);
    }
    $.ajax({
        url: root_path+'doc.php',
        type: 'get',
        dataType: 'html',
        data: 'act=ajaxrelated&rootpath='+root_path+'&pid='+docid+'&searchWord='+encodeURIComponent(doctitle),
        success: function(data){
            $("#relateddoc").html(data);
        }
    });
}
function onclick_howbuy(){
    $('#blklogininfodoc_buy').html(docpricetype);
    $('#blklogininfopoints_buy').html($('#blkinfopoints_buy').html());
	DOC88Window.win({message: $('#blkinfobuy').html(),width:600,height:320,title:'如何下载',iframe:false});
}

function getDescribe(doType)
{
	var stateDLRemainTimes = $("#stateDLRemainTimes").val();
	var describe = "";
	var closeButtonType = 0;
	var deposit = 0;
				
	if(doType==0) //下载
	{		
		if(ownPublish==1)
		{
			describe="下载提示：点击“下载”按钮下载此文档。";
			return describe+"||"+closeButtonType;
		}
		if(priceFree==1) //免费阅读
		{
			if(freeDLoadable==1) //免费下载
			{	
				if(logined==0)	//尚未登录
					describe="下载提示：登录后可下载此文档。";
				else	//已经登录
					describe="下载提示：点击“下载”按钮下载此文档。";
			}
			else if(freeDLoadable==2) //积分下载
			{
				if(logined==0)	//尚未登录
				{
					describe = "下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分。";
				}
				else
				{
					if(stateDLRemainTimes>0)
					{
						describe="下载提示：点击“下载”按钮下载此文档。";
					}
					else
					{
						if(buyerMoney-docprice<0)
						{
							deposit = 1;
						}
						if(deposit==1)
						{
							describe = "下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分。";
						}
						else
						{
							describe = "下载提示：下载此文档将会扣除<b>"+Math.round(downloadPrice*100)+"</b>积分，是否继续？"
							closeButtonType = 1;
						}
						
					}
				}
			}
			else	//为提供下载 
			{
				describe="下载提示：此文档未提供下载。";
			}
		}
		else	//积分阅读
		{

			if(downloadable==1)
			{
				if(logined==0)	//尚未登录
				{
					if(statePagekey==0)
					{
						describe="下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分,阅读此文档的清晰版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
					}
					else
					{
						describe="下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分,阅读此文档的完整版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
					}
				}
				else
				{
					if(stateDLRemainTimes>0)
					{
						describe="下载提示：点击“下载”按钮下载此文档。";
					}
					else
					{
						if(timeLimit=="notimelimit")
						{
							describe="下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分。";
						}
						else
						{
							if(statePagekey==0)
							{
								describe="下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分,阅读此文档的清晰版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
							}
							else
							{
								describe="下载提示：下载此文档需要<b>"+Math.round(downloadPrice*100)+"</b>积分,阅读此文档的完整版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
							}
						}
					}
					
				}
			}
			else
			{
				if(logined==0)	//尚未登录
				{
					if(statePagekey==0)
						describe = "下载提示：此文档仅提供在线阅读,阅读此文档的清晰版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
					else
						describe = "下载提示：此文档仅提供在线阅读,阅读此文档的完整版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
						
				}
				else
				{
				    if(timeLimit=="notimelimit")
					{
						describe="下载提示：此文档未提供下载。";
					}
					else
					{
						if(statePagekey==0)
							describe = "下载提示：此文档仅提供在线阅读,阅读此文档的清晰版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
						else
							describe = "下载提示：此文档仅提供在线阅读,阅读此文档的完整版本需要<b>"+Math.round(readPrice*100)+"</b>积分。";
					}
				}
					
			}
		}
	}
	else	//打印
	{
		
		if(ownPublish==1)
		{
			describe = "打印提示：点击“打印”按钮打印此文档。";
			return describe+"||"+closeButtonType;
		}				
		if(freePrintable==1) //免费打印
		{
			if(logined==0)	//尚未登录
				describe = "打印提示：登录后可以打印此文档。";
			else
				describe = "打印提示：点击“打印”按钮打印此文档。";
		}
		else if(freePrintable==2) //积分打印
		{
			if(logined==0)	//尚未登录
			{
				describe = "打印提示：打印此文档需要<b>"+Math.round(freePrintprice*100)+"</b>积分。";
			}
			else
			{
				if(curPrintTimes>0)
				{
					describe = "打印提示：点击“打印”按钮打印此文档。";
				}
				else
				{
					if(buyerMoney-freePrintprice<0)
					{
						deposit = 1;
					}
					if(deposit==1)
					{
						describe = "打印提示：打印此文档需要<b>"+Math.round(freePrintprice*100)+"</b>积分。";
					}
					else
					{
						describe = "打印提示：打印此文档将会扣除<b>"+Math.round(freePrintprice*100)+"</b>积分，是否继续？";
						closeButtonType = 1;
					}
					
				}
				
			}
				
		}
		else  //不允许打印
		{
			
			describe = "打印提示：此文档未提供打印。";
			
		}
	}
	return describe+"||"+closeButtonType;
}

/****下载提示
0 表示 第一次点下载提示
1 登录成功后 调用
2 购买成功后调用
doType 0.下载 1.打印
***/
var currentDoType = 0;
function downloadAlertWindow(alertType,doType)
{
	
	document.getElementById("txtDoMethod").value = doType;
	currentDoType = doType;
	document.getElementById("buybtn").disabled = true;
	document.getElementById("printbtn").disabled = true;
	var stateDLRemainTimes = $("#stateDLRemainTimes").val();
	
	if(logined==1&&doType===0)
	{
		if(ownPublish ==1||	(priceFree==1&&freeDLoadable==1)||curDownloadTimes >0) 
		{
			checkDownload(0);
			return;
		}
	}
	
	
	var doTitle = "文档下载";
	if(doType==1)
		doTitle = "文档打印";
	if(doType==1)
	{
		var flashObj = document.getElementById("docflash");
		if(flashObj==null)
		{
			var win = document.getElementById("ym-window");
			if(typeof(win)=="undefined")
			{
				DOC88Window.win({message: '',width:600,height:190,title:doTitle,iframe:false});	
			}
			else
			{
				if(win.style.display=="none")
				{
					DOC88Window.win({message: '',width:600,height:190,title:doTitle,iframe:false});	
				}
				else
				{
					
				}
			}
			checkPrint();
			return;
		}
	}
	if(alertType==0)
		DOC88Window.win({message: $('#loadDiv').html(),width:600,height:190,title:doTitle,iframe:false});

	var docid = $('#txtPcode').val();
	$.ajax({
		url: root_path+'doc.php?',
		type: 'get',
		dataType: 'json',
		 data: 'act=ajax_getstate&doccode='+product_code+'&checkorder=1&checkmoney=1&priceFree='+priceFree+"&freeDLoadable="+freeDLoadable+"&freePrintable="+freePrintable,
		success: function(data)
		{
			buyerMoney = data.stateBuyermoney;
			statePrintRemainTimes = data.statePrintRemainTimes;
			curPrintTimes = statePrintRemainTimes;
			$("#statePrintRemainTimes").val(statePrintRemainTimes);
			if(data.userID == member_id)
				ownPublish = 1
			var blLoginButton = document.getElementsByName("blLoginButton");
			var blRegButton = document.getElementsByName("blRegButton");
			var stateLogined = data.stateLogined;
			stateDLRemainTimes = data.stateDLRemainTimes;
			$("#stateDLRemainTimes").val(stateDLRemainTimes);
				curDownloadTimes = stateDLRemainTimes;
			$("#blAlertPotions").html("&nbsp;");
			var buttonAndDes = getDescribe(doType);
			document.getElementById("blkorderinfodoc").innerHTML = buttonAndDes.split("||")[0];
			var closeButtonType = buttonAndDes.split("||")[1];
			var closeButton = document.getElementsByName("docCloseButton");
			for(var i=0;i<closeButton.length;i++)
			{
				if(closeButtonType==0)
					closeButton[i].value ="关闭";
				else
					closeButton[i].value ="取消";
			}
			var exceptionLogin = false;
			if(logined!=stateLogined||(current_memeber_id!=""&&data.userID!=current_memeber_id))
			{
				exceptionLogin = true;
			}
			logined = stateLogined;
			current_memeber_id = data.userID;
			if(stateLogined!=1)
			{
				$("#blAlertPotions").html("您尚未登录。");
				var blLoginButton = document.getElementsByName("blLoginButton");
				for(var i=0;i<blLoginButton.length;i++)
				{
					blLoginButton[i].style.display ="";
				}
				var blRegButton = document.getElementsByName("blRegButton");
				for(var i=0;i<blRegButton.length;i++)
				{
					blRegButton[i].style.display ="";
				}
               
                var downloadButton = document.getElementsByName("docDownloadButton");
                for(var i=0;i<downloadButton.length;i++)
                {
                    downloadButton[i].style.display ="none";
                }
				DOC88Window.setMessage($('#bldownloadinfoAlert').html());
				//DOC88Window.win({message: $('#bldownloadinfoAlert').html(),width:600,height:190,title:doTitle,iframe:false});
				document.getElementById("buybtn").disabled = false;
				document.getElementById("printbtn").disabled = false;
				if(exceptionLogin)
				{
					setPageStateByData(data);
				}
				return;
			}

			
			 var depositButton = document.getElementsByName("depositButton");
             for(var i=0;i<depositButton.length;i++)
             {
              	 depositButton[i].style.display ="none";
             }
				
			//如果登录 并且有打印权限，直接显示打印页面
			if((doType==1&&statePrintRemainTimes>0)||(doType==1&&ownPublish==1))
			{
				var win = document.getElementById("ym-window");
				if(typeof(win)=="undefined")
				{
					//DOC88Window.win({message: '',width:600,height:190,title:doTitle,iframe:false});
					DOC88Window.setMessage("");
				}
				else
				{
					if(win.style.display=="none")
					{
						DOC88Window.setMessage("");
						//DOC88Window.win({message: '',width:600,height:190,title:doTitle,iframe:false});	
					}
					else
					{
						
					}
				}
				checkPrint();
				document.getElementById("buybtn").disabled = false;
				document.getElementById("printbtn").disabled = false;
				if(exceptionLogin)
				{
					setPageStateByData(data);
				}
				return;
			}
			
			
			if(alertType!=2)
			{
				/***隐藏登录和注册按钮***/
				for(var i=0;i<blLoginButton.length;i++)
				{
					blLoginButton[i].style.display ="none";
				}
				for(var i=0;i<blRegButton.length;i++)
				{
					blRegButton[i].style.display ="none";
				}
				
				//设置下载按钮文字
				var downloadButton = document.getElementsByName("docDownloadButton");
				for(var i=0;i<downloadButton.length;i++)
				{
					downloadButton[i].value ="下载";
					if(stateDLRemainTimes>0)
					{
						downloadButton[i].value ="下载";
					}
					else
					{
						if(priceFree!=1)
						{
							
							if(timeLimit=="notimelimit")
							{
								downloadButton[i].value ="下载";
							}
							else
							{
								if(downloadable==0)
								{
									downloadButton[i].value ="阅读";
								}
								else
								{
									downloadButton[i].value ="阅读/下载";
								}
								
							}
							
				
						}
					}
					downloadButton[i].style.display = "";
					if(ownPublish==1)
					{
						downloadButton[i].value ="下载";
					}
					if(doType==1)
					{
						downloadButton[i].value ="打印";
					}
					
				}								

				
				if(data.stateOrderChecking == 1){
					setHTMLByName("blkorderinfodoc","您对此文档的订单, 正处于待审核状态, 请等待系统处理后, 再操作。");
					setHTMLByName("blAlertPotions","&nbsp;");
					var downloadButton = document.getElementsByName("docDownloadButton");
					for(var i=0;i<downloadButton.length;i++)
					{
						downloadButton[i].style.display ="none";
					}
					var closeButton = document.getElementsByName("docCloseButton");
					for(var i=0;i<closeButton.length;i++)
					{
						closeButton[i].value ="关闭";	
					}
					stateOrderChecking = 1;
					
				}else{
				
					//如果需要 购买 的时候判断积分 情况
					if(((stateDLRemainTimes==0&&doType==0)||(statePrintRemainTimes==0&&doType==1&&freePrintable==2))&&ownPublish==0)
					{
						var stateBuyermoney = data.stateBuyermoney;
					
						var deposit = 0;
						
						if(doType==0)
						{
							if(stateBuyermoney-docprice<0){
									deposit = 1;
							}
							if(deposit==1)
							{
								var tsStr = "您的积分已不足(当前积分为"+((parseFloat(stateBuyermoney)+parseFloat(no_bizincome))*100).toFixed(0)+"";
								if(no_bizincome>0)
								{
									tsStr+=",处在<span title='交易复核期是指文档被下载所获得的积分,在3天内,不能用于提现或下载文档.' style='color:rgb(30, 53, 165);'>交易复核期</span>内的积分为"+(no_bizincome*100).toFixed(0);
								}
								tsStr+="),请及时充值兑换积分。";
								$("#blAlertPotions").html(tsStr);
								var depositButton = document.getElementsByName("depositButton");
								for(var i=0;i<depositButton.length;i++)
								{
									depositButton[i].style.display ="";
								}
							}
						}
						else
						{						
							if(stateBuyermoney-freePrintprice<0)
							{
								deposit = 1;
							}
							if(deposit==1)
							{
								var tsStr = "您的积分已不足(当前积分为"+((parseFloat(stateBuyermoney)+parseFloat(no_bizincome))*100).toFixed(0)+"";
								if(no_bizincome>0)
								{
									tsStr+=",处在<span title='交易复核期是指文档被下载所获得的积分,在3天内,不能用于提现或下载文档.' style='color:rgb(30, 53, 165);'>交易复核期</span>内的积分为"+(no_bizincome*100).toFixed(0);
								}
								tsStr+="),请及时充值兑换积分。";
								$("#blAlertPotions").html(tsStr);
								var depositButton = document.getElementsByName("depositButton");
								for(var i=0;i<depositButton.length;i++)
								{
									depositButton[i].style.display ="";
								}
							}
								
						}
						
						if(priceFree==1 && freeDLoadable==0&&doType==0)
						{
							$("#blAlertPotions").html("&nbsp;");
						}
						if(freePrintable==0&&doType==1)
						{
							$("#blAlertPotions").html("&nbsp;");
						}
					}
				}
				
                //不能下载时，隐藏下载按钮
				if(doType==0)
				{
					if((doccheckstate != 1||(priceFree==1 && freeDLoadable==0) || deposit==1 ||stateOrderChecking==1||(timeLimit=="notimelimit"&&downloadable==0))&&ownPublish==0)
					{
						var downloadButton = document.getElementsByName("docDownloadButton");
						for(var i=0;i<downloadButton.length;i++)
						{
							downloadButton[i].style.display ="none";
						}
					}
				}
				else
				{
					if((doccheckstate != 1||freePrintable==0|| deposit==1 ||stateOrderChecking==1)&&ownPublish==0)
					{
						var downloadButton = document.getElementsByName("docDownloadButton");
						for(var i=0;i<downloadButton.length;i++)
						{
							downloadButton[i].style.display ="none";
						}
					}
				}
				
				DOC88Window.setMessage($('#bldownloadinfoAlert').html());	
			}			
			document.getElementById("buybtn").disabled = false;
			document.getElementById("printbtn").disabled = false;
			//是否是登录之后 点 右边的下载 直接 返回
			if(alertType!=0||exceptionLogin)
			{
           		setPageStateByData(data);
			}
			
		}
	});
}

/***重新设置页面状态****/
function reloadPageState(method)
{
	var stateDLRemainTimes = $("#stateDLRemainTimes").val();
	var docid = $('#txtPcode').val();
	$.ajax({
		url: root_path+'doc.php?',
		type: 'get',
		dataType: 'json',
		async: false,
		  data: 'act=ajax_getstate&doccode='+product_code+'&checkorder=1&checkmoney=1&priceFree='+priceFree+"&freeDLoadable="+freeDLoadable+"&freePrintable="+freePrintable,
		success: function(data){
			setPageStateByData(data);
		}
	});
}
/****设置setPageState***/
function setPageStateByData(data)
{
	if(data.userID == member_id)
		ownPublish = 1
	var statePrintRemainTimes = data.statePrintRemainTimes;
	
	curPrintTimes = statePrintRemainTimes;
	$("#statePrintRemainTimes").val(statePrintRemainTimes);
	var stateLogined = data.stateLogined;
	logined = stateLogined;

	if(ownPublish == 1){
		data.stateTimeLimit = "notimelimit";
	}

	stateDLRemainTimes = data.stateDLRemainTimes;
	$("#stateDLRemainTimes").val(stateDLRemainTimes);
	curDownloadTimes = stateDLRemainTimes;

	if(priceFree==0&&data.stateTimeLimit!="0"&&(timeLimit=="0"||timeLimit==""||timeLimit!="notimelimit"))
	{
		timeLimit = data.stateTimeLimit;
		loadFlash(1);
	}
	else
	{
		var flashObj = document.getElementById("docflash");
		if(flashObj!=null)
		{
			flashObj.ld203();
		}
	}
			
	timeLimit = data.stateTimeLimit;
	
	//更新页面状态
	if(data.stateTimeLimit!="0"||data.stateRemainTimes!=0)
	{
		$("#viewTitleDiv").html("");
	}
	if(data.stateRemainTimes!=0)
	{
		$("#timelimit").html("阅读期限：在线阅读"+data.stateRemainTimes+"次");
		return;
	}
	if(data.stateTimeLimit=="0")
	{	
		$("#timelimit").html("阅读期限：没有阅读权限");
	}
	else if(data.stateTimeLimit=="notimelimit")
	{
		$("#timelimit").html("阅读期限：不限期阅读");
		$("#txtPonlydownload").val("1");
	}
	else
	{
		var now = new Date();
		now.setTime(data.stateTimeLimit*1000)
		n = now.getYear();
		y = now.getMonth()+1;
		r = now.getDate();
		h = now.getHours();
		m =now.getMinutes();
		s = now.getSeconds();
		if(n<1900) n+=1900;
		if(y<10) y="0"+y;
		if(r<10) r="0"+r;
		if(h<10) h="0"+h;
		if(m<10) m="0"+m;
		if(s<10) s="0"+s;
		var theDate = ""+ n + "-" + y + "-" + r + " "+ h + ":" + m + ":" + s;
		$("#timelimit").html("阅读期限："+theDate);
	}
}

/***提交订单***/
function submitOrder()
{
	var downloadButton = document.getElementsByName("docDownloadButton");
	for(var i=0;i<downloadButton.length;i++)
	{
		downloadButton[i].disabled = true;
	}
	DOC88Window.setMessage($('#loadDiv').html());
	$.ajax({
		url: root_path+'doc.php?',
		type: 'get',
		dataType: 'json',
		async: false,
		 data: 'act=window_order&do_method='+currentDoType+'&txtPcode='+product_code+'&radioPriceid=1&method=ajax',
		success: function(data)
		{
			//DOC88Window.setMessage($('#bldownloadinfoAlert').html());
			if(data.result==1)
			{
				
				if(currentDoType==0)
				{
					if(data.stateOrderChecking == 1){
						DOC88Window.setMessage($('#bldownloadinfoAlert').html());
						setHTMLByName("blkorderinfodoc","您对此文档的订单, 正处于待审核状态, 请等待系统处理后, 再操作。");
						setHTMLByName("blAlertPotions","&nbsp;");
						var downloadButton = document.getElementsByName("docDownloadButton");
						for(var i=0;i<downloadButton.length;i++)
						{
							downloadButton[i].style.display ="none";
						}
						var closeButton = document.getElementsByName("docCloseButton");
						for(var i=0;i<closeButton.length;i++)
						{
							closeButton[i].value ="关闭";	
						}
						stateOrderChecking = 1;
					}else{
						reloadPageState(0);
					//	setHTMLByName("blkorderinfodoc","文档下载成功。您当前的剩余积分为<b>"+data.userMoney+"</b>.");
					//	setHTMLByName("blAlertPotions","&nbsp;");
						var downloadButton = document.getElementsByName("docDownloadButton");
						for(var i=0;i<downloadButton.length;i++)
						{
							downloadButton[i].style.display ="none";
							downloadButton[i].disabled = false;
						}
						var closeButton = document.getElementsByName("docCloseButton");
						for(var i=0;i<closeButton.length;i++)
						{
							closeButton[i].value ="关闭";	
						}						
						checkDownload(0);					
					}
				}
				else
				{
					reloadPageState(0);
					checkPrint();
				}
	
			}
			else
			{
				setHTMLByName("blkorderinfodoc",data.message);
				var downloadButton = document.getElementsByName("docDownloadButton");
				for(var i=0;i<downloadButton.length;i++)
				{
					downloadButton[i].disabled = false;
				}
			}
		}
	});
}

/****根据Name设置HTML****/
function setHTMLByName(name,html)
{
	var obj = document.getElementsByName(name);
	for(var i=0;i<obj.length;i++)
	{
		obj[i].innerHTML = html;
	}
}


/****下载/阅读/打印文档****/
function checkDownload(downloadType){
	
	var downloadLabel = "如果未弹出文件保存对话框，请到“<a href='/portal/usr_order.php?act=bought' style='color:#1E35A5;' target='_blank'>会员中心</a>-><a href='/portal/usr_order.php?act=bought' style='color:#1E35A5;' target='_blank'>已下载文档</a>”页面下载。";
	//if(ownPublish!=1&&(priceFree!=1||freeDLoadable==2))
		//setHTMLByName("blkorderinfodoc",downloadLabel);
	//文档下载/阅读
	if(currentDoType==0)
	{
		if(ownPublish==0)
		{
			var stateDLRemainTimes = $("#stateDLRemainTimes").val();
		
			if(stateDLRemainTimes=="")
				stateDLRemainTimes = 0;
			if(stateDLRemainTimes>0)
			{
				$.ajax({
					url: root_path+"member.php",
					type: 'get',
					dataType: 'html',
					data: 'act=ajax_checkdownload',
					async: false,
					success: function(data){
				
						//DOC88Window.setMessage($('#bldownloadinfoAlert').html());
						if(data=="" || data=="nologin") {//未登录
							setHTMLByName("blkorderinfodoc","尚未登录.");
							return false;
						}else{
							
							var docLink = root_path+'/doc.php?act=download&pcode='+product_code+'&dlrand='+data+'&dlcode='+dlcode;
						//	if(ownPublish!=1&&(priceFree!=1||freeDLoadable==2))
							//	setHTMLByName("blkorderinfodoc",downloadLabel);
							//if(checkdl!=1){
								windowClose();
								var flashObj = document.getElementById("docflash");
								if(flashObj!=null)
								{
									try
									{
										var reState = flashObj.gd409();
										if(reState==0)
										{
											flashObj.dl222();
										}
										else
										{
											flashObj.id191();
										}
									}
									catch(e)
									{
										
									}
								}
								document.getElementById("buybtn").disabled = false;
								document.getElementById("printbtn").disabled = false;
							//}
							var downloadButton = document.getElementsByName("docDownloadButton");
							for(var i=0;i<downloadButton.length;i++)
							{
								downloadButton[i].style.display ="none";
								downloadButton[i].disabled = false;
							}						
							if(checkdl!=1){
								curDownloadTimes--;
							}
							return false;
							
						}
					}
				});
			}
			else
			{
				if(priceFree==1)
				{
					submitOrder();
				}
				else
				{
					DOC88Window.setIFrame("_blank");
					$("#form_productbuy").submit();
					return false;
				}
			}
		}
		else
		{
			$.ajax({
					url: root_path+"member.php",
					type: 'get',
					dataType: 'html',
					data: 'act=ajax_checkdownload',
					async: false,
					success: function(data){
						//DOC88Window.setMessage($('#bldownloadinfoAlert').html());
						if(data=="" || data=="nologin") {//未登录
							  setHTMLByName("blkorderinfodoc","尚未登录.");
							 return false;
						}else{
							//var docLink = root_path+'/doc.php?act=download&pcode='+product_code+'&dlrand='+data+'&dlcode='+dlcode;
							//location.href = docLink;
							if(checkdl!=1){
								curDownloadTimes--;
							}
							windowClose();
							var flashObj = document.getElementById("docflash");
							if(flashObj!=null)
							{
								try
								{
									var reState = flashObj.gd409();
									if(reState==0)
									{
										flashObj.dl222();
									}
									else
									{
										flashObj.id191();
									}
								}
								catch(e)
								{
									
								}
							}
							document.getElementById("buybtn").disabled = false;
							document.getElementById("printbtn").disabled = false;
							return false;
						}
					}
				});
		}
	}
	else	//文档打印
	{
		
		if(ownPublish==0)
		{
			var statePrintRemainTimes = $("#statePrintRemainTimes").val();
			if(stateDLRemainTimes=="")
				statePrintRemainTimes = 0;
			if(statePrintRemainTimes>0)
			{
				checkPrint();
			}
			else
			{
				submitOrder();
			}
		}
		else
		{
			checkPrint();
		}
	}
}
//打印
var checkPirntTimes = 0;
function checkPrint()
{
	checkPirntTimes = 0;
	DOC88Window.setIFrame("/doc.php?act=printwindow&p_id="+product_id);
}

var printTimeOutId; 


function getCurrentLoadPage(obj)
{
	if(printTimeOutId)
	{
		clearTimeout(printTimeOutId);
	} 
	var currentPage = document.getElementById("docflash").gp301();
	if(currentPage<parent.product_pagecount)
	{
		try
		{
			printTimeOutId = window.setTimeout(function(){getCurrentLoadPage(obj)},1000); 
			obj.setLodding(currentPage);
		}
		catch(e)
		{
			clearTimeout(printTimeOutId);
		}
	}
	else
	{
		obj.setLodding(currentPage);
		obj.setDivState("print");
	}
}
var checkTimeOutId ;
function checkPrintSupported(obj)
{
	var flashObj = document.getElementById("docflash");
	if(flashObj==null)
	{
		obj.setDivState("error");
		return;
	}
	var state = document.getElementById("docflash").isPrintSupported();
	if(state==1)
	{
		obj.setDivState("flash");
		return;
	}
	else if(state==2)
	{
		if(checkTimeOutId)
		{
			clearTimeout(checkTimeOutId);
		} 
		checkPirntTimes++;
		if(checkPirntTimes>10)
		{
			obj.setDivState("error");
			return;
		}
		obj.setDivState("loading");
		checkTimeOutId = window.setTimeout(function(){checkPrintSupported(obj)},1000); 
		return;
	}
	else if(state==3)
	{
		 obj.setDivState("loading");
		 getCurrentLoadPage(obj);
		 return;
	}
	else if(state==0||state==6)
	{
		obj.setDivState("print");
	}
	else
	{	
		flashObj.ld203();
	}
}

function startPrint(startPage,endPage)
{
	
	var state = document.getElementById("docflash").isPrintSupported();
	if(state==0||state==6)
	{
		var result = document.getElementById("docflash").interfacePrint(startPage,endPage);//页数范围
		if(result==0)
		{
			alert("文档加载失败.")
			return;
		}
		if(result==-1)
		{
			
		}
		if(result==-2)
		{
			
		}
		if(result==1)
		{
			$.ajax({
					url: root_path+"doc.php",
					type: 'get',
					dataType: 'html',
					data: 'act=print&pcode='+product_code+'&printcode='+statePrintSpcode,
					async: false,
					success: function(data){
							curPrintTimes--;
							if(curPrintTimes<=0)
							{
								DOC88Window.close();
								return false;
							}
					}
				});
		}
		return;
	}

}
	
//收藏
function checkcollectproduct(){
	addToFolder(product_id)
    return false;
}
//举报文档
function complaint()
{
	var login_if = getCookie("cdb_login_if");
	if(login_if != 1){
		shortcutComplaint();
	}
	else
	{
		window.location.href='/portal/usr_complaint.php?act=report_product&step=one&code='+product_code;
	}
}
/****举报登陆***/
function windowLoginForComplaint()
{
	DOC88Window.setIFrame('/js/home/login_init.html?act=window_login&actMethod=complaint&p_code='+product_code);
}
//快捷举报文档
function shortcutComplaint()
{
	DOC88Window.win({message: '/info.php?act=shortcut_complaint&actMethod=complaint&p_code='+product_code,width:600,height:286,title:'举报文档',iframe:true});
}
//侵权举报
function complaintAlert()
{
	DOC88Window.resizeWin(600,190);
	DOC88Window.setMessage($('#complainInfo').html());
}
//删除留言
function deleteMsg(mid, pcode){
    if(confirm("您确认删除留言吗?")==false)
        return;
    var address = root_path + "docmessage.php?act=del&messageid="+mid;
    $.ajax({
        url: address,
        dataType:  'json',
        success: function(msg){
            alert(msg.message);
            getmsg2(root_path, pcode)
        }
    });
}
function replyMsg(mid, pcode){
    ShowDiv = "AjGuestBook";
    getPageContent(root_path+"docmessage.php?act=re&rootpath="+root_path+"&messageid="+mid);
}

function setOrderChecking(orderCheck){
    stateOrderChecking = orderCheck;
}

