﻿// JScript 文件

var isVote = 0;
var column = '';
var arr = new Array();

function _Update(discussid, count, CZPDId, webroot)
{
    if(column == '')
    {
        alert('请选择投票项！');
        return false;
    }
    if(isVote == 1)
    {
        alert('您已经投票成功，不能连续投票！');
        return;
    }
    var ajaxObj = new Ajax.Request(
        webroot+"Data/Baike/GetVote.aspx",
        {
            method:'get',
            parameters:'val='+column+'&id='+discussid,
            onComplete:function(request)
            {
                if(request.responseText.length >= 1)
                {
                    _Clear(count, CZPDId);
                    window.open(webroot + "technology/vote_"+discussid+".html");
                    isVote = 1;
                    alert('您的投票已成功！');
                }
                else
                    alert('您的投票失败！');
            }
        });
}

function _Update(discussid, count, CZPDId, webroot, isvote)
{
    if (isvote >0 || isVote>0)
    {
        alert('您已经投过票，不能连续投票！');
        return false;
    }
    if(column == '')
    {
        alert('请选择投票项！');
        return false;
    }
    var ajaxObj = new Ajax.Request(
        webroot+"Data/Baike/GetVote.aspx",
        {
            method:'post',
            parameters:'val='+column+'&id='+discussid,
            onComplete:function(request)
            {
                if(request.responseText.length >= 1)
                {
                    _Clear(count, CZPDId);
                    window.open(webroot + "technology/vote_"+discussid+".html");
                    isVote=1;
                    column='';
                    alert('您的投票已成功！');
                }
                else
                    alert('您的投票失败！');
            }
        });
}

function isLogins(groupid,a,webroot,Url)
{
    if(groupid==-1)
    {
        return LoginOpenUrl(webroot,Url,a,1);
    }
    else
    {
         window.open(Url);
    }
}

function _Selected(val, o, type)
{
    if(type != 'checkbox')
    {
        arr[0] = val;
    }
    else if(type == 'checkbox')
    {
        if(o.checked)
        {
            var has = false;
            
            for(var i = 0; i < arr.length; i ++)
            {
                if(arr[i] != val)
                {
                    has = false;
                }
                else
                    has = true;
            }
            
            if(has == false)
            {
                arr.push(val);
            }
        }
        else
        {
            for(var i=0;i<arr.length;i++)
            {
                if(arr[i] == val)
                {
                    arr.splice(i,1);
                }
            }
        }
    }
    
    column = arr.join(',');
}

function _IsLogin(IsUser, GroupId)
{
   var isUser=IsUser;
   
   if(isUser=="True")
   {
       return true;
   }
   else
   {
       var Login = GroupId;
       if(Login=="0")
       {
         return false;
       }
       else
       {
         return true;
       }
    }
}

function _Clear(count, CZPDId)
{
    for(var i=0; i<count; i++)
    {
        if( $('tp'+ CZPDId + i) )
            if( $('tp'+ CZPDId + i).checked )
                $('tp'+ CZPDId + i).checked = false;
    }
}

function changeZX(id,cid,tp,typeid)
{
    
    var showname=document.getElementsByName("showname"+cid);
    var morelink=document.getElementsByName("morelink"+cid);
    var moretext=document.getElementsByName("moretext"+cid);
    
    for(var i=0;i<showname.length;i++)
    {
        if(showname[i]!=undefined)
        { 
           if(typeid==1)
           {
               if(document.getElementById("tt"+cid+showname[i].value))
               {    
                   document.getElementById("tt"+cid+showname[i].value).className="wh_37x19";
               }
               
               if(document.getElementById("tj"+cid+showname[i].value))
               {
                   document.getElementById("tj"+cid+showname[i].value).style.display="none";
               }
               if(document.getElementById("tp"+cid+showname[i].value))
               {
                   document.getElementById("tp"+cid+showname[i].value).style.display="none";
               }
                for(var j=0;j<150;j++)
                { 
                    if(document.getElementById("it"+cid+showname[i].value+"a"+j))
                    {
                        document.getElementById("it"+cid+showname[i].value+"a"+j).style.display="none";
                    }     
               }
           }else if(typeid==2)
           {
                
               if(document.getElementById("tt"+cid+showname[i].value))
               {    
                   document.getElementById("tt"+cid+showname[i].value).className="right2 wh_31x17";
               }
               for(var j=0;j<150;j++)
               { 
                    if(document.getElementById("it"+cid+showname[i].value+"a"+j))
                    {
                        document.getElementById("it"+cid+showname[i].value+"a"+j).style.display="none";
                    }     
               }
               for(var j=0;j<150;j++)
               { 
                    if(document.getElementById("tj"+cid+showname[i].value+"b"+j))
                    {
                        document.getElementById("tj"+cid+showname[i].value+"b"+j).style.display="none";
                    }     
               }
               for(var j=0;j<150;j++)
               { 
                    if(document.getElementById("tp"+cid+showname[i].value+"c"+j))
                    {
                        document.getElementById("tp"+cid+showname[i].value+"c"+j).style.display="none";
                    }     
               }
           }
       }
    }

   if(showname[id]!=undefined)
   {    
        if(typeid==1)
        {
           document.getElementById("tt"+cid+showname[id].value).className="on";  
           if(tp)
           {
               if(document.getElementById("tp"+cid+showname[id].value))
               {
                    document.getElementById("tp"+cid+showname[id].value).style.display="";
               }
           }
           else
           {
               if(document.getElementById("tp"+cid+showname[0].value))
               {
                    document.getElementById("tp"+cid+showname[0].value).style.display="";
               }
           }
            if(document.getElementById("tj"+cid+showname[id].value))
            {
                document.getElementById("tj"+cid+showname[id].value).style.display="";
            }           
            for(var j=0;j<150;j++)
            { 
                 if(document.getElementById("it"+cid+showname[id].value+"a"+j))
                 {
                    document.getElementById("it"+cid+showname[id].value+"a"+j).style.display="";
                 }     
            } 
          
             ChangMoreZX(id,cid,morelink,moretext);  
           
        }else if(typeid==2)
        { 
            document.getElementById("tt"+cid+showname[id].value).className="right2 no"; 
            if(tp)
            {
                for(var j=0;j<150;j++)
                { 
                     if(document.getElementById("tp"+cid+showname[id].value+"c"+j))
                     {
                        document.getElementById("tp"+cid+showname[id].value+"c"+j).style.display="";
                     }     
                }
            }
            for(var j=0;j<150;j++)
            { 
                 if(document.getElementById("it"+cid+showname[id].value+"a"+j))
                 {
                    document.getElementById("it"+cid+showname[id].value+"a"+j).style.display="";
                 }     
            }
            for(var j=0;j<150;j++)
            { 
                 if(document.getElementById("tj"+cid+showname[id].value+"b"+j))
                 {
                    document.getElementById("tj"+cid+showname[id].value+"b"+j).style.display="";
                 }     
            }        
        }
            
      }
}


function ChangMoreZX(id,cid,morelink,moretext)
{
     if (document.getElementById("More"+cid))
     {
         document.getElementById("More"+cid).innerText=moretext[id].value;                                                            
         document.getElementById("More"+cid).href=morelink[id].value;    
     }
}

function GetSize(obj,w,h)
{
    var photoUrl=obj.src;
    var image = new Image();//new一个image对象        
    image.src=obj.src;
    var widths= image.width;
    var heights= image.height;
	
    if (widths <w && heights <h)
    {  
        obj.width=image.width; 
        obj.height=image.height; 
    }
    else if(widths >w && heights >h)
    {  
        var scale = w/widths;
        var NowH =(heights*scale); 
        var NowW =(widths*scale); 
        if (NowH >h )
        {
            obj.height=h; 
        }
        else if(NowW >w)
        {
             obj.width=w; 
        }
        else 
        {
            obj.width=w; 
        }
    } 
    else if(widths >w)
    {  
        obj.width=w; 
    }
    else if(heights >h)
    {  
        obj.height=h; 
    } 
}

var sliclen=6;
var curSlides=((new Date()).getTime()%sliclen)+1;
var slidesTimeout = 5000;
var _thisFlashInterval="";
//setInterval("sett();", slidesTimeout);
function checkAllSildes(sId,bckPrefix,_thisPrefix){
for(var ih=1;ih<=sliclen;ih++){
	var item=document.getElementById(_thisPrefix+ih);
	var bkItem=document.getElementById(_thisPrefix+ih+bckPrefix);
	if(sId==item.id){
		bkItem.style.visibility="visible";
	}else{
		bkItem.style.visibility="hidden";
	}
}
}
function flashLoading(){
	var sId='bck'+curSlides;
	checkAllSildes(sId,'_sdk','bck');
	curSlides=((curSlides)%6)+1;
}

function clearIntervalFlash(){
	clearInterval(_thisFlashInterval);
}
function restartIntervalFalsh(){
	_thisFlashInterval=setInterval("flashLoading()",slidesTimeout);
}
//loading rampage
//checkAllSildes('bck'+curSlides,'_sdk','bck');
restartIntervalFalsh();
function changeSildesFrame(obj,bckPrefix,_thisPrefix){
var sId=obj.id;
var bkObj=document.getElementById(sId+bckPrefix);
checkAllSildes(sId,bckPrefix,_thisPrefix);
}
function SildesFrameClick(obj,bckPrefix){
	var sId=obj.id;
	var bkObj=document.getElementById(sId+bckPrefix);
	var aObj=bkObj.getElementsByTagName('a');
//	window.open(aObj[0].href,'newwindow');
}




//var topUsername=document.getElementById("topUsername").value;



function setShowName(sName)
{
    topName=sName
    topShow();
}

function gettopid(topidd)
{
    topid=topidd;
    topbian(topid);
}

function topbian(topid)
{
    var count=document.getElementById("Countss").value;
    if(topid<count)
    {
        for(var k=0;k<count;k++)
        {
            document.getElementById("tp"+k+"a").style.display="none";
        }
        for(var i=0;i<count;i++)
        {
            if(i==topid)
            {
                document.getElementById("tp"+topid+"a").style.display="";
                break;
            }
        }
        topid=topid+1;
        if (topid==count) topid=0;
    }
    else
    {
        topid=0;
    }
    setTimeout("topbian("+topid+")",10000);
}
var topisLogin;
function topLogin(name,GroupId)
{
    var topName=document.getElementById("topName").value;
    var topisLogin=document.getElementById("topisLogin").value;
    topisLogin=1;
    topGroupId=GroupId;
    topName=name;
    topShow();   
    topTryFunction("showLogin();"); 
    topTryFunction("webLogin("+name+","+GroupId+");");
    topTryFunction("LoginIsDisplayControl_1(true)"); 
    topTryFunction(" LoginIsDisplayControl_2(true)"); 
}


function topTryFunction(script)
{
     try{
           eval(script);
      
    }catch(ee){}
}
function topShow()
{
    var topName=document.getElementById("topName").value;
    
    if(topName!="")
    { 
   
        _get("TopdivName").innerHTML="欢迎您 "+topName;
       //_get("TopdivName").innerHTML="欢迎&nbsp;&nbsp;<span class='ad_hoc06'>"+topName+"</span>&nbsp;&nbsp;["+topReturnMemberLevelIcon(topGroupId)+"]&nbsp;";
       _get("LinkButton1Samp").style.display="";
       //_get("loginSamp").style.display="none"; 
      // _get("Regist").style.display="none";    
      
     }else{       
         _get("loginSamp").style.display="";
         _get("LinkButton1Samp").style.display="none";
         _get("Regist").style.display="";
     }
}
function _get(name)
{
    return   document.getElementById(name);
}
function topReturnMemberLevelIcon(gropid)
{
   var topuserLoge0=document.getElementById("topuserLoge0").value;
    return topuserLoge0["G"+gropid];
   
}

function isLoginToUrl(a,Url,webroot)
{   
   var topGroupId=document.getElementById("topGroupId").value;
   var topisLogin=document.getElementById("topisLogin").value;
  
    if(topGroupId==0)
    {
        topisLogin=0;
        return LoginOpenUrl(webroot,Url,a,1);
    }
    else
    {   
         window.open(Url);
    }
}
 
 
 //关键字搜索
function keywordClick(keyword)
{
    document.getElementById('txt_key').value = keyword;
    search(document.getElementById('sel_channel'));
}

function changenote(o,p,q)
{
    switch(o.value)
    {
        case "1":
                if (q==0)
                    {
                        if(p.value=='请输入产品名称')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入产品名称';
                    }
                    break;
        case "3":
                if (q==0)
                    {
                        if(p.value=='请输入企业名称')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入企业名称';
                    }
                    break;
        case "4":
                if (q==0)
                    {
                        if(p.value=='请输入技术关键字')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入技术关键字';
                    }
                    break;
        case "5":
                if (q==0)
                    {
                        if(p.value=='请输入问题关键字')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入问题关键字';
                    }
                    break;
        case "6":
                if (q==0)
                    {
                        if(p.value=='请输入新闻关键字')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入新闻关键字';
                    }
                    break;
        case "7":
                if (q==0)
                    {
                        if(p.value=='请输入华印二手机关键字')p.value='';
                    }
                else if (q==1)
                    {
                        if(p.value=='')p.value='请输入华印二手机关键字';
                    }
                    break;
        default:
                    break;
    }
}

function onChange(o)
{
    bindData(o.value);
}

function bindData(v)
{
    var sel = document.getElementById('sel_type');
    var k = document.getElementById('txt_key');
    var arr = [];
    
    if(sel&&k)
    {
        switch(v)
        {
            case "1":
                k.value = '请输入产品名称';
                arr = ["包装容器产品", "1", "加工机械产品", "2", "包装机械产品", "3"];
                break;
            case "2":
                arr = ["包装容器订单", "1", "加工机械订单", "2", "包装机械订单", "3"];
                break;
            case "3":
                k.value = '请输入企业名称';
                arr = ["包装容器企业", "1", "加工机械企业", "2", "包装机械企业", "3"];
                break;
            case "4":
                k.value = '请输入技术关键字';
                arr = [];
                break;
            case "5":
                k.value = '请输入问题关键字';
                arr = [];
                break;
            case "6":
                k.value = '请输入新闻关键字';
                arr = ["全部", "", "行情新闻", "1", "技术新闻", "2", "管理新闻", "3", "产品新闻", "4", "企业新闻", "5", "人物新闻", "6", "会议新闻", "7", "标准法规", "8", "报价新闻", "9"];
                break;
            case "7":
                k.value = '请输入华印二手机关键字';
                arr = ["华印编号", "1", "设备名称", "2", "设备品牌", "3"];
                break;
            default:
                arr = [];
                break;
        }
        
        if(k)
        {
            k.size = 10;
        }
        
        sel.style.display = "";
        
        if(arr.length > 0)
        {
            sel.length = 0;
            for(var i=0;i<arr.length/2;i++)
            {
                var opt = document.createElement("option");
                sel.options.add(opt);
                opt.innerText = arr[i*2];
                opt.value = arr[i*2+1];
            }
        }
        else
        {
            sel.style.display = "none";
            
            if(k)
            {
                k.size = 28;
            }
        }
    }
}

function search(o)
{
    var txt = document.getElementById('txt_key');
    
    if(txt)
    {
        switch(o.value)
            {
                case "1":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入产品名称')
                        {
                            alert('请输入产品名称！');
                            txt.focus();
                            return false;
                        }
                        break;
                case "3":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入企业名称')
                        {
                            alert('请输入企业名称！');
                            txt.focus();
                            return false;
                        }
                        break;
                case "4":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入技术关键字')
                        {
                            alert('请输入技术关键字！');
                            txt.focus();
                            return false;
                        }
                        break;
                case "5":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入问题关键字')
                        {
                            alert('请输入问题关键字！');
                            txt.focus();
                            return false;
                        }
                        break;
                case "6":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入新闻关键字')
                        {
                            alert('请输入新闻关键字！');
                            txt.focus();
                            return false;
                        }
                        break;
                case "7":
                    if(!ValidateNotSpace(txt.value) || txt.value.length == 0 || txt.value == '请输入华印二手机关键字')
                        {
                            alert('请输入华印二手机关键字！');
                            txt.focus();
                            return false;
                        }
                        break;
            
            }
    }
    
    var link = document.getElementById('a_search');
    
    if(link && txt)
    {
        var val;
        
        var sel = document.getElementById('sel_type');
        
        if(sel)
        {
            switch(o.value)
            {
                case "0":
                    val="http://www.512121.com/search/searchlist.aspx?1=1";
                    break;
                case "1":
                    if(sel.value == "1")
                    {
                        val = "http://bzrq.512121.com/Resolvent/SearchInfo.aspx?tagsid=2888";
                    }
                    else if(sel.value == "2")
                    {
                        val = "http://bzjx.512121.com/Machine/SearchInfo.aspx?tagsid=3061";
                    }
                    else if(sel.value == "3")
                    {
                        val = "http://bzjx.512121.com/Machine/SearchInfo.aspx?tagsid=1558";
                    }
                    break;
                case "2":
                    if(sel.value == "1")
                    {
                        val = "http://bzdd.512121.com/order/list.aspx?tagsid=2888";
                    }
                    else if(sel.value == "2")
                    {
                        val = "http://bzdd.512121.com/order/list.aspx?tagsid=3061";
                    }
                    else if(sel.value == "3")
                    {
                        val = "http://bzdd.512121.com/order/list.aspx?tagsid=1558";
                    }
                    break;
                case "3":
                    if(sel.value == "1")
                    {
                        val = "http://bzhy.512121.com/enterprise/searchinfo.aspx?type=rq&tagsid=2888";
                    }
                    else if(sel.value == "2")
                    {
                        val = "http://bzhy.512121.com/Enterprise/Searchinfo.aspx?type=jx&tagsid=3061";
                    }
                    else if(sel.value == "3")
                    {
                        val = "http://bzhy.512121.com/Enterprise/Searchinfo.aspx?type=jx&tagsid=1558";
                    }
                    break;
                case "4":
                    val = "http://bzjs.512121.com/Technology/SearchInfo.aspx?type=1&sub=0113";
                    break;
                case "5":
                    val = "http://bzjs.512121.com/Technology/SearchInfo.aspx?type=3&sub=0101";
                    break;
                case "6":
                    val = "http://bzxw.512121.com/packagenews/productlist2.aspx?type=" + sel.value;
                    break;
                case "7":
                    if(sel.value == "1")
                    {
                        val = "http://hyesj.512121.com/hyesj/list.aspx?id=0&type=1";
                    }
                    else if(sel.value == "2")
                    {
                        val = "http://hyesj.512121.com/hyesj/list.aspx?id=0&type=2";
                    }
                    else if(sel.value == "3")
                    {
                        val = "http://hyesj.512121.com/hyesj/list.aspx?id=0&type=3";
                    }
                    break;
                default:
                    val = "";
                    break;
            }
        }
        
        if(val != "")
        {
            link.href = val + "&key="+encodeURI(txt.value);
            link.click();
        }
    }
}

function ValidateNotSpace(date)
{//是否含有不是空格的字符
    var patrn=/[^\s]/;
    if (!patrn.exec(date)) return false;
    return true;
}

// 头部登录功能实现
function zhuxiao(webroot)
{
    var url = webroot;
    url += "&zx=1";
    var ajaxObj=new Ajax.Request(
            url,
            {
                method: 'post',
                parameters: '',
                onComplete:function(request)
                {
                    //alert('complete！');
                    location.replace(location.href);
                }
            });
}