﻿// JScript 文件
/*******************************************/
            //调用说明：date_obj为时间对象，date_templet为返回的日期格式模版（如：date_obj为“2006-9-23 12:34:10”；date_templet为“yy年mm月”，返回：“06年9月”）
            /*******************************************/
            function getFormatDate(date_obj,date_templet){
              var year,month,day,hour,minutes,seconds,short_year,full_month,full_day,full_day,full_hour,full_minutes,full_seconds;
              if(!date_templet)date_templet = "yyyy-mm-dd hh:ii:ss";
              year = date_obj.getFullYear().toString();
              short_year = year.substring(2,4);
              month = (date_obj.getMonth()+1).toString();
              month.length == 1 ? full_month = "0"+month : full_month = month;
              day = date_obj.getDate().toString();
              day.length == 1 ? full_day = "0"+day : full_day = day;
              hour = date_obj.getHours().toString();
              hour.length == 1 ? full_hour = "0"+hour : full_hour = hour;
              minutes = date_obj.getMinutes().toString();
              minutes.length == 1 ? full_minutes = "0"+minutes : full_minutes = minutes;
              seconds = date_obj.getSeconds().toString();
              seconds.length == 1 ? full_seconds = "0"+seconds : full_seconds = seconds;
              return date_templet.replace("yyyy",year).replace("mm",full_month).replace("dd",full_day).replace("yy",short_year).replace("m",month).replace("d",day).replace("hh",full_hour).replace("ii",full_minutes).replace("ss",full_seconds).replace("h",hour).replace("i",minutes).replace("s",seconds);
            }

            
            
            //去掉左右空格
	        function Trim(value)
	        {

		        var res = String(value).replace(/^[\s]+|[\s]+$/g,'');
		        return res;

	        }
                        
            //提交评论 
			function Insert(serviceid) 
            { 
                var name=document.getElementById("name");//评论者名字                var flag=document.getElementById("HidFlage");//评论者者状态                var type=document.getElementById("HidBusType");//商机类别
                var htmAdd=document.getElementById("HidBusHtmlAdd");//静态页地址
                var content=document.getElementById("content");//评论内容
                var Hid=document.getElementById("Hid"); //被评论的商机id
                var HsendMemberID=document.getElementById("HsenderMemberID"); //评论者的memberid（未登录则为0）               
                if(Trim(type.value)=="2")
                {
                    
                    //求购商机加如下判断                    if(flag.value=="0")
                    {
                        //会员未登录                        alert("对不起，请先登录！");
                        window.top.location.href("../member/login.aspx");
                        return;
                    
                    }
                    else if(flag.value=="1")
                    {
                        //会员没有权限
                        alert("对不起，请先升级成为付费会员,升级完成后请刷新本页面！");
                        window.open("../member/default.aspx?url=MemberUpgrade.aspx?cID=37");
                        return;
                    }
                }
                var RadioPing;//评价
                if (Trim(name.value)!="" && Trim(content.value)!="")               
                {
//                    if (serviceid!=6)//如果该登陆会员发布不超过3个评论的时候执行下面的操作
//                    {
                        if(serviceid==1)
                        {
                            if (document.getElementById("radio1").checked==true)//好评
                            {
                               RadioPing="0";
                            }
                            else if (document.getElementById("radio2").checked==true)//中评
                            {
                                RadioPing="1";
                            }
                            else//恶评
                            {
                                RadioPing="2";
                            }  
                                                  
                            //插入评论
                            Business_BusinessComment.InsertComment(Hid.value,name.value,content.value,HsendMemberID.value,RadioPing,InsertCallBack); 
                        } 
                        else
                        {
                             Service_Comment.InsertComment(Hid.value,name.value,content.value,HsendMemberID.value,RadioPing.value,InsertCallBack); 
                        }  
                                   
                        document.getElementById("div_comment").innerHTML="<img src='../images/loadding.gif'>加载中。。。";
                        alert("发表评论成功！");                       
//                    }
//                    else
//                    {
//                        alert("你只能对该条商机进行3次评价！");
//                    }
                }
                else
                {
                    alert("姓名与评论内容不能为空！");                   
                }
            }
            
            function InsertCallBack(response)
            {
            
                        
　　　　            var ds = response.value;
                    if(ds != null && typeof(ds) == "object" && ds.Tables != null && ds.Tables[0].Rows.length!=0)
                    {   
                       var divContent="";
                       var CommentCount=ds.Tables[1].Rows[0].Ccount;
                       for(var i=0; i<ds.Tables[0].Rows.length; i++)
　　　　               {
　　　　                    divContent +="<table border='0' width='100%' cellpadding='3'><tr align='left' bgcolor='#FFFFFF'><td height='25' colspan='2' valign='bottom' class='word_black13w'>"
　　　　                                  +"留言<strong>"+CommentCount+"</strong>：</td></tr><tr align='left' valign='middle' bgcolor='#ECF7FF'><td height='32' colspan='2'>"
　　　　                                  +"<table width='99%'  border='0' align='center' cellpadding='0' cellspacing='0'><tr><td width='30%' class='word_black12weight'>姓名："+ds.Tables[0].Rows[i].name+" </td>"
　　　　                                  +"<td width='70%'><span class='word_black12weight'>日期：</span><span class='date12'>"+getFormatDate(ds.Tables[0].Rows[i].publish_time,'yyyy-mm-dd hh:ii:ss')+"</span></td></tr></table></td>"
　　　　                                  +"</tr><tr bgcolor='F7F7F7' ><td colspan='2' align='left' valign='top'><p >&nbsp;&nbsp;&nbsp;&nbsp;"+ds.Tables[0].Rows[i].content+"</p></td></tr></table>";
　　　　                    CommentCount--;
　　　　               }
                       document.getElementById("div_comment").innerHTML=divContent;
                       //document.getElementById("name").value="";
                       document.getElementById("content").value="";
                       
                       
                       
                       
            
                    }
                    else
                    {
                        document.getElementById("div_comment").innerHTML="";
                    }  
                    
                    iframeAutoFit();//iframe 自适应大小      
                
            }
            
        //切换图片    
        function changePic(_this)
        {
            var BigImg=document.getElementById("IMG3");
            BigImg.src=_this.src;
            //改变A标签
             var Phref=document.getElementById("HRE3");
           Phref.href = _this.src;
        }
        
        
         function iframeAutoFit()    
        {        
            try        
            {            
                if(window!=parent)            
                {                
                    var a = parent.document.getElementsByTagName("IFRAME");                
                    for(var i=0; i<a.length; i++)                 
                    {                    
                        if(a[i].contentWindow==window)                    
                        {                        
                            var h1=0, h2=0;                        
                            a[i].parentNode.style.height = a[i].offsetHeight +"px";                        
                            a[i].style.height = "10px";                        
                            if(document.documentElement&&document.documentElement.scrollHeight)                        
                            {                            
                                h1=document.documentElement.scrollHeight;                        
                            }                        
                            if(document.body) h2=document.body.scrollHeight;                        
                            var h=Math.max(h1, h2);                        
                            if(document.all) {h += 4;}                        
                            if(window.opera) {h += 1;}                        
                            a[i].style.height = a[i].parentNode.style.height = h +"px";                    
                         }                
                     }            
                 }        
             }        
             catch (ex)
             {}    
        }    
     
