﻿var maximg = 5;
var curimg = 1;
function ChangeImg(i) {

    // var img =  $("#imgchange");
    var img = document.getElementById("imgchange");
    var ImageCHange = $("#ImageCHange" + i);
    var imga = $("#imga" + i);
    var imgbeta;

    for (var j = 1; j <= 5; j++) {
        imgbeta = $("#imga" + j);
        if (imgbeta) {
            imgbeta.attr("class", "");
        }
    }
    for (var j = 1; j <= 5; j++) {
        imgbeta = $("#ImageCHange" + j);
        if (imgbeta) {
            imgbeta.attr("class", "tec_cont_007  noshow");
        }
    }

    if (img) {
        var srcimg = img.src;
    }
    if (imga) {
        imga.attr("class", "to");
    }
    if (ImageCHange) {
        ImageCHange.attr("class", "tec_cont_007 ");
    }
}
function gundong() {
    if (curimg > maximg) {
        curimg = 1;
    }
    ChangeImg(curimg);
    curimg += 1;
}
function doExpertScore() {
    var frm = document.getElementById("frm_exscore");
    if (islogin) {
        if (frm) {
            for (var i = 1; i < 5; i++) {
                var p = document.getElementById("expertscore" + i);
                if (p.value == "") {
                    alert("请选择您的评分！");
                    return false;
                }
            }
            frm.submit();
        }
    }
    else {
        alert("请登录后评分!");
        //window.location.href="{$conDomain_passport_k8008_com}/";
    }
    return true;
}


/*
20100420 吴国贵 新版技术通详细页js脚本
*/
function show(tmpid, classna) {
    var teclx_ID;
    teclx_ID = document.getElementById(tmpid);
    if (teclx_ID.className == classna) {
        teclx_ID.className = classna + " noshow";
    } else {
        teclx_ID.className = classna;
    }

}
function show1() {
    document.getElementById("lx_dwid").href = "#lx_id";
    document.getElementById("tec_lx_id").className = "tec_lx_con";
}

jQuery.fn.anchorGoWhere = function(options) {
    var obj = jQuery(this);
    var defaults = { target: 0, timer: 1000 };
    var o = jQuery.extend(defaults, options);
    obj.each(function(i) {
        jQuery(obj[i]).click(function() {
            var _rel = jQuery(this).attr("href").substr(1);
            switch (o.target) {
                case 1:                   
                    var _targetTop = jQuery("#" + _rel).offset().top;
                    jQuery("html,body").animate({ scrollTop: _targetTop }, o.timer);
                    break;
                case 2:
                    var _targetLeft = jQuery("#" + _rel).offset().left;
                    jQuery("html,body").animate({ scrollLeft: _targetLeft }, o.timer);
                    break;
            }
            return false;
        });
    });
};



$(document).ready(function() {

    //载入技术图片
    $(".goTop").anchorGoWhere({ target: 1 });
    $("#viewcontactTop").anchorGoWhere({ target: 1 });



    gallery();
    // LoadPic();

    //载入感兴趣
    //
    LoadRelTecList();


    LoadInterest();
    LoadShop();

    var doInterest = $("#doInterest");
    doInterest.click(doInterestEvent);


    var scoreSub = $("#scoreSub");
    scoreSub.click(onScore);

});


function LoadShop() {
    //<a href="/iot_{$tecid}.html" target="_blank">{$IOT}</a>
    var iot = $("#tecIOt");
    var cert = $("#certCOunt");
    var tecid = $("#interestid");

    $.getJSON("/ajax/Ishop.aspx", { infoid: tecid.val(), random: parseInt(Math.random() * 2000 + 1) }, function(json) {
   // alert(json.JoinTimes);
   // alert(json.CertCount);
    iot.text(json.JoinTimes);
       cert.text(json.CertCount);
    });
    
}

function onScore() {

    //已登陆



    var tecid = $("#interestid");

    var loginUser = $("#loginUser");


    if (loginUser.val() == "") {
        onLogin();
        return false;
    }


    //所有的分值



    var input__ratings_proj1_ = $("#input__ratings_proj1_"); //创新程度
    var input__ratings_proj2_ = $("#input__ratings_proj2_"); //社会效益
    var input__ratings_proj3_ = $("#input__ratings_proj3_"); //行业领先程度
    var input__ratings_proj4_ = $("#input__ratings_proj4_"); //经济效益
    var input__ratings_proj5_ = $("#input__ratings_proj5_"); //有效转换为生产力

    //全部0分不能提交


    if (input__ratings_proj1_ && input__ratings_proj2_
        && input__ratings_proj3_ && input__ratings_proj4_ && input__ratings_proj5_) {
        if (input__ratings_proj1_.val() == 0 ||
        input__ratings_proj2_.val() == 0 ||
        input__ratings_proj3_.val() == 0 ||
                input__ratings_proj4_.val() == 0 ||
        input__ratings_proj5_.val() == 0) {
            alert("请选择分值");
        }
        else {
            $.get("/usercenter/ExpertScroeSave.asp", { tecid: tecid.val(), expertscore1: input__ratings_proj1_.val() * 2, expertscore2: input__ratings_proj2_.val() * 2, expertscore3: input__ratings_proj3_.val() * 2, expertscore4: input__ratings_proj4_.val() * 2, expertscore5: input__ratings_proj5_.val() * 2, random: parseInt(Math.random() * 2000 + 1) },
              function(data) {
                  var tips = data.toString();
                  tips = tips.slice(tips.indexOf("\""), tips.indexOf(");</"));
                  alert(tips);
              });
        }
    }


    //ajax提交到结果页
}
function onLogin() {
    //http://passport.k8008.test/?ret=http://product.k8008.test/detail_79154.html
    window.location.href = "http://"+document.domain.replace("tec","passport")+"/?ret=" + encodeURI(location.href) + "";
}
function LoadRelTecList() {
    var format = "<dt class=\"red\"><a href=\"/list_{svocId}/0-0_0-0/0-0-0-0-1.html\" title=\"\" target=\"_blank\">[{sVoc}]</a></dt><dd class=\"dd2 ell\"><span class=\"C3f7fb4\"><a href=\"/detail_{id}.html\" title=\"{ltitle}\" target=\"_blank\">{stitle}</a></span></dd>";
    var tecid = $("#interestid");
    var keyword = $("#hidkeyword");
    var count = 9;
    var rand = parseInt(Math.random() * 2000 + 1);
    var InterestDiv = $("#relTecDiv");
    var strDiv = "";
    var maxLength = 17;
    InterestDiv.html("");
    $.getJSON("/ajax/RelTecJson.aspx", { id: tecid.val(), keyword: encodeURI(keyword.val()), count: count, random: parseInt(Math.random() * 2000 + 1) }, function(json) {
    for (var i = 0; i < json.length; i++) {

        if (json[i].Tecname.length > maxLength) {
            strDiv += format.replace(/{svocId}/g, json[i].Clsid).replace(/{sVoc}/g, json[i].Clsname).replace(/{id}/g, json[i].Id).replace(/{stitle}/g, json[i].Tecname.substr(0, maxLength)+"...").replace(/{ltitle}/g, json[i].Tecname);

            }
            else {
                strDiv += format.replace(/{svocId}/g, json[i].Clsid).replace(/{sVoc}/g, json[i].Clsname).replace(/{id}/g, json[i].Id).replace(/{stitle}/g, json[i].Tecname).replace(/{ltitle}/g, json[i].Tecname);

            } //"<a href=\"" + json[i].Url + "\" target='_blank'>" + json[i].UserName + "</a>";
        }
        // strDiv += "<div class=\"both\"></div>";
        InterestDiv.html(strDiv);
    });
    
     
}
function LoadInterest() {
    var tecid = $("#interestid");
    var InterestDiv = $("#InterestDiv");
    var strDiv = "";
    InterestDiv.html("");
    $.getJSON("/ajax/interestlist.aspx", { id: tecid.val(), random: parseInt(Math.random() * 2000 + 1) }, function(json) {
        for (var i = 0; i < json.length; i++) {
            strDiv += "<a href=\"" + json[i].Url + "\" target='_blank'>" + json[i].UserName + "</a>";
        }
        strDiv += "<div class=\"both\"></div>";
        InterestDiv.html(strDiv);
    });

}
function doInterestEvent() {
    var loginUser = $("#interestusername");
    var tecid = $("#interestid");
    var publishuser = $("#publishUser");

    if (loginUser.val() == "") {
        onLogin();
        return false;
    }
    else {
        if (publishuser.val() == loginUser.val()) {
            alert("不能对自己的技术进行该操作");
            return false;
        }
        //异步提交，重载页面



        $.get("/ajax/interest.aspx", { id: tecid.val(), username: loginUser.val(), random: parseInt(Math.random() * 2000 + 1) },
              function(data) {
                  switch (parseInt(data)) {
                      case 1: //成功
                          //重载
                          // alert("您已经成功对该技术感兴趣");
                          LoadInterest();
                          //数目+1
                          var interCount = $("#interCount");
                          if (interCount) {
                              var count = parseInt(interCount.text());
                              interCount.text(count + 1);
                          }
                          var ViewInterest = $("#ViewInterest");
                          ViewInterest.click();
                          break;
                      case 2: //已经感兴趣过
                          alert("您已对本条技术进行过感兴趣操作！");
                          var ViewInterest = $("#ViewInterest");
                          ViewInterest.click();
                          break;
                      case -1: //失败
                          //alert("失败");
                          break;
                  }

              });
    }
    return true;
}
