﻿// JScript 文件
window.IncludeFile={"header":"head.html","tailer":"tail.html"};
window.JsModule=["system/jqframe.js","js/all_jpgys.js"]; 
window.EhaiGrid={curPage:1,curRowNum:1,totalRecord:-1,curFun:null,bDiv:null,sc:null};
function WebMain()
{
	getAdsInfo(7);
	pm :"<@ehai_detail,ehai_menu%16ehai_detail.Id%16ehai_detail.Id,Title,DATE_FORMAT(ehai_detail.CreateTime,'%y-%m-%d'),ehai_menu.mName%16%16%16Isup desc,ehai_detail.CreateTime desc%160%16IsCheck=1 and ehai_detail.MenuId=ehai_menu.Id and MenuId=@>"+$.PageParam.mid+"%16",
    $.SetFormat("zh","settypesmall","<a class='qiyeli' style='width:70px;color:#17367E;' href=\"productlist.html?{'Sort':'#1#'}\">#0#</a>","","");
 	/*产品分类列表*/$.SendMessage({callback:setbigtype,bLoading:false,type:"DBSelect",id:"getproducttypebig",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=2%16@>"});
 	/*导航*/$.SendMessage({callback:setdaohang,bLoading:false,type:"DBSelect",id:"setdaohang", pm :"<@ehai_detail,ehai_menu%16ehai_detail.Id%16ehai_detail.Id,Title,DATE_FORMAT(ehai_detail.CreateTime,'%y-%m-%d'),ehai_menu.mName,ehai_menu.Id%16%16%16Isup desc,ehai_detail.CreateTime desc%160%16IsCheck=1 and ehai_detail.MenuId=ehai_menu.Id and ehai_detail.Id=@>"+$.PageParam.id+"%16"});
	/*获取访问量*/$.SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_detail%16Id%16Counts%16%16%16%160%16Id@>=%16"+$.PageParam.id+"",callback:addcountquestion},true);
};
function getNewsContent()
{
	if(!$.PageParam.id) document.getElementById("newtitle").innerHTML="抱歉，找不到文章！";
    else 
    {
        $("#news_cont").SendMessage({callback:setnewsinfo,type:"DBSelect",id:"news_cont",pm :"<@ehai_detail%16Id%16Id,Title,DATE_FORMAT(CreateTime,'%y-%m-%d'),dContent,Keywords,SubTitle,Reference,Author,Imgurl,MenuId%16%16%16%160%16IsCheck=1 and Id=@>"+$.PageParam.id+"%16"});
	}
}
//获取访问量
function addcountquestion(re)
{
    if(re&&re[0])
    {
     num=Math.floor(re[0][0])+1;
     $.SendMessage({type:"DBInsert",pm :"<@ehai_detail%16Counts%16@>"+num+"%16Id%16'"+$.PageParam.id+"'%16"},true);
     }

};

//产品分类
function setbigtype(re)
{
    if(re)
    {
        var h=""
        for(i=0;i<re.length;i++)
        {
            h+="<ul style='width:260px'><li class=\"sort\"><a style='color:#17367E;font-weight:bold;' href=\"productlist.html?{'Sort':'"+re[i][1]+"'}\">"+decodeURIComponent(re[i][0])+"</a></li><li id=\"bigtypeli"+re[i][1]+"\"></li></ul>";
        }
         $("#gq_left").html(h);
        for(i=0;i<re.length;i++)
        {
            /*产品小类*/$("#bigtypeli"+re[i][1]).SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=4 and left(Class,2)='@>"+re[i][1]+"'%16",format:"settypesmall"});
        }
    }
};
function setnewsinfo(re)
{
        $.SetFormat("zh","lTitle",'<a style=\"color:#4C4C4C;\" href="news.html?{\'id\':\'#0#\'}">上一篇：#1#</a>','','');
        $.SetFormat("zh","nTitle",'<a style=\"color:#4C4C4C;\" href="news.html?{\'id\':\'#0#\'}">下一篇：#1#</a>','','');
        $("#lTitle").SendMessage({bLoading:false,type:"DBSelect",id:"newsl",pm :"<@ehai_detail%16Id%16Id,Title,CreateTime%16%16%16Id desc%160%16@>Id<"+$.PageParam.id+" and  MenuId="+re[0][9]+"%16",format:"lTitle",start:0,total:1});
         $("#nTitle").SendMessage({bLoading:false,type:"DBSelect",id:"newsn",pm :"<@ehai_detail%16Id%16Id,Title,CreateTime%16%16%16Id asc%160%16@>Id>"+$.PageParam.id+" and  MenuId="+re[0][9]+"%16",format:"nTitle",start:0,total:1});

        
        $.SendMessage({callback:setdaohang,bSave:false,type:"DBSelect",id:"getdaohang",pm :"<@ehai_Menu AS a LEFT JOIN ehai_Menu AS b ON (left(a.Class,2)=b.Class and LENGTH(a.Class)=4)%16id%16a.mName,b.mName,a.ColRight,b.url%16%16%16%160%16a.ColRight='@>"+decodeURIComponent(re[0][4])+"'%16"},true);
    if(re[0][8]=="" || re[0][8]== "请选择")
    picimg="images/nophoto.gif";
    else
    picimg=re[0][8];
    $("#newtitle").html(re[0][1]);//读取文章标题
    $("#subtitle").html(re[0][5]);//读取文章副标题
    document.title=re[0][1];
    $("#author").html(re[0][7]);//读取作者
    $("#concome").html(re[0][6]);//读取来源
    $("#condata").html(re[0][2]);//读取时间
    $("#newcontent").append(jQuery.htmldecode(HTMLDecode(re[0][3])));//读取内容
    

	
	//设置相关新闻
	var kw = re[0][4].replace(/,/g,"，").split("，");
	$.SetFormat("zh","xgwzformat","<li><a style=\"color:#2#; width: 500px;\" href=\"news.html?{'id':#0#}\" target=\"_blank\">#1#</a><a>#3#</a></li>","","");
	$("#relativeNewsList").SendMessage({bSave:false,type:"DBSelect",id:"getxiangguan",pm :"<@ehai_detail%16Id%16Id,Title,Color,CreateTime%16%16%16Isup,CreateTime desc%160%16IsEnglish=0 and IsCheck=1 and Keywords like '%@>"+ kw[0]+"<@%' and Id<>@>"+$.PageParam.id+"%16",format:"xgwzformat",start:0,total:5},true);
};

/*
功能：替换掉文章中的特殊符号
*/
function HTMLDecode ( text )
{
    if ( !text ) return '' ;
    text = text.replace( /&gt;/g, '>' ) ;
    text = text.replace( /&lt;/g, '<' ) ;
    text = text.replace( /&amp;/g, '&' ) ;
	text = text.replace( /\\n/g, '' ) ;
    return text ;
};

//****************  评论部分  ***************************/
function setdaohang(re)
{
    if(re[0][4]==3 || re[0][4]==4)
    $("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"association.html\">协会</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取协会类页面当前位置  
    else if(re[0][4]==17)
    $("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"specialist.html\">专家委员会</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取专家委员会类页面当前位置 
    else if(re[0][4]==25)
    $("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"quotation.html\">报价系统</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取报价系统类页面当前位置   
     else if(re[0][4]==28 || re[0][4]==29)
	{
		$("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"newslist.html?{'mid':28}\">招投标</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取招投标类页面当前位置  
		//对招投标进行限制
		checkPermission();
		return;
	}
	 else if(re[0][4]==31 || re[0][4]==32 || re[0][4]==33 || re[0][4]==34)
    $("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"newslist.html?{'mid':31}\">资源</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取资源类页面当前位置  
    else
    $("#position").html("<div class=\"position\"><a href=\"index.html\">首页</a> > <a href=\"information.html\">资讯</a> > <a href=\"newslist.html?{'mid':"+re[0][4]+"}\">"+re[0][3]+"</a> > <a href=\"#\">详细内容页</a></div>"); //读取资讯类页面当前位置
    
	getNewsContent();

};

//-------------------------- 对招投标进行限制	--------------------------------------------------
/*
a.	对于普通会员只能查看以当前日期为准一周前所发布信息具体内容
b.	未注册登陆限制查看
c.	标题列表均可查看
d.	于权限禁止页面提示申请高级会员方可产看
0为普通会员，1为高级会员 2个人会员 3专家会员
判断日期
如果不可以查看提示申请高级会员可以查看
不登陆，肯定不能查看
*/
function checkPermission()
{
	//判断是否登录
	$.SendMessage({type:"Session",callback:getSessionUser,pm :"<@@>"},true);
}
function getSessionUser(re)
{
	if(re[0][0]) //如果已经登录
    {
		getUserInfo(re[0][0]);
		//getNewsContent();
	}
	else
	{
		alert("登录后才能查看此栏目！");
	}
}
function getUserInfo(username)
{
	$.SendMessage({callback:checkUserInfo,type:"DBSelect",id:"userinfo",pm :"<@ehai_user%16Id%16id,roleType,DATEDIFF(now(),starttime),DATEDIFF(now(),DATE_ADD(StartTime,INTERVAL ValidTime day))%16%16%16%160%16username=@>'"+username+"'%16"});
}
function checkUserInfo(re)
{
	//0为普通会员，1为高级会员 2个人会员 3专家会员
	var roletype = re[0][1];
	if(roletype == "3")
	{
		getNewsContent();
	}
	else if(roletype == "1")
	{
		//判断高级会员未过期
		if(re[0][3]<1)
		{
			getNewsContent();
		}
		else
		{
			alert("高级会员已到期，请续费");
		}
	}
	else
	{
		if(re[0][2]>7)  //普通用户或个人用户 注册超过7天
		{
			//限制查看,一周前的招投标信息
			getNewsBeforeOneWeek();
		}
		else
			getNewsContent();
	}
}

function getNewsBeforeOneWeek()
{
	if(!$.PageParam.id) document.getElementById("newtitle").innerHTML="抱歉，找不到文章！";
    else 
    {
        $("#news_cont").SendMessage({callback:limitOneWeek,type:"DBSelect",id:"news_cont",pm :"<@ehai_detail%16Id%16Id,Title,DATE_FORMAT(CreateTime,'%y-%m-%d'),dContent,Keywords,SubTitle,Reference,Author,Imgurl,MenuId,DATEDIFF(now(),CreateTime)%16%16%16%160%16IsCheck=1 and Id=@>"+$.PageParam.id+"%16"});
	}
}
function limitOneWeek(re)
{
	if(re[0][10]>7)
		setnewsinfo(re);
	else
		alert("申请高级会员查看招投标最新信息！");
}
//--------------------------- 限制结束 ---------------------------------------------------


function isAnonChange()
{
    if($("#isAnonymous").attr("checked")) $("#commentor").val("匿名").attr("readonly","readonly"); 
    else $("#commentor").val("").removeAttr("readonly"); 
};
function resetComment()
{
    $("#newComment").val("");
    $("#commentor").val("");
    $("#validateCode").val("");
//        getCode();
}
 function insertComment()
    {
        if($("#newComment").val().length>100){alert("评论数字限制在100字以内！");return;}
        if($("#commentor").val()=="")
        {alert("请留下您的大名或选择匿名发表");return false;}
//        if($("#validateCode").val()!=code)
//        {alert("验证码不正确，请重新输入");return false;}
        if($("#newComment").val()=="")
        {alert("留言内容不能为空");return false;}
        $.SendMessage({type:"GetVatidationCode",pm:"<@@>",callback:getvalcode},true);
//        $.SendMessage({type:"Insert",id:"comment",pm:"<@ehai_comments%16Comment,ComUser,newsId,status,ComTime,IP@>%16'"+$("#newComment").val()c+"','"+$("#commentor").val().replace(/'/g,"''")+"','"+$.PageParam.id+"',0%16%16",callback: issueSuc,bDefCall:false},true);
    };
    function getvalcode(re)
    {
        if(re && re[0])
        {
            if(re[0][0]==$("#validateCode").val())
                {$.SendMessage({type:"Insert",id:"comment",pm:"<@ehai_comments%16Comment,ComUser,newsId,status,ComTime,IP@>%16'"+$("#newComment").val().replace(/'/g,"''")+"','"+$("#commentor").val().replace(/'/g,"''")+"','"+$.PageParam.id+"',0%16%16",callback: issueSuc,bDefCall:false},true); changeCode();}
            else
            {alert("验证码错误");changeCode();}
        }
        else
            {alert("验证码错误");changeCode();}
    };
    function issueSuc(re,msg)
    {
        if(re=="success")alert("恭喜评论成功，请等待审核。");
        else alert("发表失败！");  
        resetComment();
    };
//    function getCode()
//    {
//        var temp,sum_num = [];
//        for(var i=0;i<=3;i++)
//        {
//            temp =Math.random()*10;
//            sum_num[i] = Math.floor(temp);
//        }
//        var str=sum_num[0]+""+sum_num[1]+""+sum_num[2]+""+sum_num[3];
//        $("#valCode").text(str);
//        code=str;
//    };
    function fabiaodiv()
    {
         $("#fabiao").css("display","block");
         $("#chakan").css("display","none");
         $("#fabiaobtm").removeClass("bgcgrew");
         $("#fabiaobtm").addClass("bgcblue");
         $("#chakanbtm").removeClass("bgcblue");
         $("#chakanbtm").addClass("bgcgrew");
    };
    function chakandiv()
    {
         $("#chakan").css("display","block");
         $("#fabiao").css("display","none");
         $("#fabiaobtm").removeClass("bgcblue");
         $("#fabiaobtm").addClass("bgcgrew");
         $("#chakanbtm").removeClass("bgcgrew");
         $("#chakanbtm").addClass("bgcblue");
		 loadComment();
    }
    function loadComment()
    {
        EhaiGrid.grid = $("#commentList").jqGrid( {
		    height: 170, 
				width:690,
		    url: 'Default.aspx',
		    colNames : ['网友发表的评论'],
		    colModel : [{name : 'message_title', width : 690, sortable : false, align: 'left'}],
		    rowNum   : 3,
            rowList  : [3,15,25,40],
            pager    : $("#pager"),
            sortname: "date_update",
            viewrecords: true,
            recordtext: "条记录",
            sortorder: "desc",
            datatype:"json",
            imgpath:"Controls/comment/img",
            barAreaWidth:380
	    });
	    $("#pager img").css({"float":"left"});
	    $("#pager span:eq(1)").css({"margin":"3px 0px 0px 3px","font-size": "13px","float":"left"});	
	    $("#pager span:eq(0)").css({"margin":"3px 0px 0px 0px","font-size": "13px","float":"right"});	
	    $("#pager select").css("float","left");
	    $(".commentHead img").toggle(function(){var obj=$(this).parent().parent().parent().next();obj.css("display","block");$(this).attr("alt","折叠");},function(){var obj=$(this).parent().parent().parent().next();obj.css("display","none");$(this).attr("alt","展开");});
    };
    function getNews(page,rowNum,sortname,sortorder,fun,bd)
    {
        EhaiGrid.curPage=page;
        EhaiGrid.curRowNum=rowNum;
        EhaiGrid.curFun=fun;
        EhaiGrid.bDiv=bd;
        if(EhaiGrid.curPage==1)
        $("div.r_slider").css("left","0px");
        if(EhaiGrid.totalRecord==-1)
            getTotalRecord();
        else
            sendMsg();
    };
    function getTotalRecord()
    {
        $.SendMessage({type:"DBSelect",bDefCall:false,callback:sendMsg,pm :"<@ehai_comments%16id%16Count(*)%16%16%16%160%16status=1 and newsId@>="+$.PageParam.id+"%16"},true);
    };
    function sendMsg(re,msg)
    {
        var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"comments",pm :"<@ehai_comments%16id%16id,Comment,ComUser,ComTime,IP%16%16%16ComTime desc%160%16status=1 and newsId=@>"+$.PageParam.id+"%16",start:EhaiGrid.curRowNum*(EhaiGrid.curPage-1),total:EhaiGrid.curRowNum};
        if(re)
        {
            EhaiGrid.totalRecord=re[0][0];
            t.bRefresh=true;
        }
        $.SendMessage(t,true);
    };
    function newsCallback(re,msg)
    {
        var records={total:Math.ceil(EhaiGrid.totalRecord/EhaiGrid.curRowNum),page:EhaiGrid.curPage,records:EhaiGrid.totalRecord};
        var rows="[";
        for(var i=msg.start,j=msg.start+msg.total;i<j;i++)
        {
            rows+="{id:'"+re[i][0]+"',cell:['<div class=\"commentHead\"><ul style=\"float:right\"><li style=\"width:25%;\">网友："+decodeURIComponent(re[i][2])+"</li><li style=\"width:25%;\">来自："+decodeURIComponent(re[i][4])+"</li><li style=\"width:35%;margin-right:10px;\">发表于："+decodeURIComponent(re[i][3])+"</li></ul></div><div class=\"commentContent\">"+decodeURIComponent(re[i][1])+"</div>']},";
        }
        if(rows.lastIndexOf(',')==rows.length-1)
            rows=rows.substring(0,rows.length-1);
        rows+="]";
        records.rows=eval("("+rows+")");
        EhaiGrid.curFun(records,EhaiGrid.bDiv);
    };
    //add this msg after set content $("#news_cont").SendMessage({callback:checkTips,type:"DBSelect",pm :"<@ehai_wordexplain%16Id%16Id,Word@>%16%16%16%160%16%16"});
    function checkTips(re){
        var reg,len,tiptag,content,tipArray=[];
        content=$("#article_content").html();
        len=re.length;
        for(var i=0;i<len;i++){
            reg=new RegExp(""+re[i][1]+"");
            if(content.match(reg)){
                tiptag="<a class='basic' style='color:Green;' id='"+re[i][0]+"tag' title='"+re[i][1]+"|' href='#'>"+re[i][1]+"</a>";
                content=content.replace(reg,tiptag);
                $("#article_content").html(content);
                tipArray.push(re[i][0]);
            }
        }
        if(tipArray.length>0)
                $.SendMessage({callback:tipExplainCallback,type:"DBSelect",pm :"<@ehai_wordexplain%16Id%16Path,Explaination,Id%16%16%16%160%16Id in(@>"+tipArray.join(',')+")%16"});
    }
    function tipExplainCallback(re){
        var linkId;
        for(var i=0;i<re.length;i++){
            linkId=re[i][2]+"tag";
            if(!(re && re[i]&&$("#"+re[i][2]+"tag").length>0)){
                $("#"+linkId).attr("title",$("#"+linkId).attr("title")+"<p>抱歉，找不到词条解释！</p>");
            }
            else{
                if(re[i][0]!='')$("#"+linkId).attr("title",$("#"+linkId).attr("title")+"<img class='tipImg' src='"+re[i][0]+"'><p>"+re[i][1]+"</p>");
                else $("#"+linkId).attr("title",$("#"+linkId).attr("title")+"<p>"+re[i][1]+"</p>");
            }
        }
        $("a.basic").cluetip({splitTitle: '|',arrows:true});
    }
    function changeCode()
{
$("#randImg").attr("src","authImage.aspx?id=" + Math.random());
//	document.getElementById("randImg").src="authImage.aspx";
}
//**************** 结束 评论部分  **************************/

