﻿function NormalShowPic(type) {
    var nor1 = $("#normalshow1");
    var nor2 = $("#normalshow2");
    var nor1div = $("#nor1div");
    var nor2div = $("#nor2div");
    if (nor1 && nor2 && nor1div && nor2div) {
        switch (type) {
            case 1:
                if (nor1.attr("class") != "to") {
                    nor1.attr("class", "to");
                    nor2.attr("class", "");
                    nor1div.attr("class", "tec_cont_007");
                    nor2div.attr("class", "tec_cont_007 noshow");
                }

                break;
            case 2:
                if (nor2.attr("class") != "to") {
                    nor2.attr("class", "to");
                    nor1.attr("class", "");
                    nor2div.attr("class", "tec_cont_007");
                    nor1div.attr("class", "tec_cont_007 noshow");
                }
                break;
        }
    }
}
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 吴国贵*/
$(document).ready(function() {
    var ViewContactByImg = $("#ViewContactByImg");
    var ViewContact = $("#ViewContact");
    ViewContactByImg.addClass("ch");
    ViewContact.addClass("ch");
    ViewContactByImg.click(showContact);
    ViewContact.click(showContact);
    ViewContact2 = $("#ViewContact_2");
    ViewContact2.click(showContact);

    //        //积分 
    var scoreSub = $("#scoreSub");
    scoreSub.click(onScore);

    var commentSubmit = $("#commentSubmit");
    commentSubmit.click(function() {
        var tecId = $("#tecid");
        window.open('http://' + document.domain.replace("tec", "comment") + '/comment_6_' + tecId.val() + '_1.html');
    });

    //载入相关技术
    LoadRelTecList();

    //载入图片技术
    LoadImgTecList();
    //        //载入感兴趣


    LoadInterest();


    var doInterest = $("#doInterest");
    doInterest.click(doInterestEvent);


    var ViewInterest = $("#ViewInterest");
    ViewInterest.click(function() {
        var tmpid = "tec_intid";
        var classna = "tec_inter_dtl";
        var teclx_ID;
        teclx_ID = document.getElementById(tmpid)
        if (teclx_ID.className == classna) {
            teclx_ID.className = classna + " noshow"
        } else {
            teclx_ID.className = classna
        }
    });



    //登陆

    var username = getCookie("K8008_LCAUTH_USERNAME");
    var login = document.getElementById("login");
    var nologin = document.getElementById("noLogin");

    if (username != "") {
        if (nologin && login) {
            nologin.className = nologin.className + " noshow";
            login.className = "f_l";
            var show_UserName = document.getElementById("show_UserName");
            if (show_UserName) {
                show_UserName.innerHTML = decodeURI(username);
            }
        }
    }
});


function LoadImgTecList() {
    var format = "<ul><li><a href=\"/detail_{id}.html\" title=\"\" target=\"_blank\"><img src=\"{simg}\" width=\"96\" height=\"80\" alt=\"\"></a></li><li class=\"tec_list_pic1 C036\" ><a href=\"/detail_{id}.html\" title=\"{ltitle}\" target=\"_blank\">{stitle}</a></li></ul>";
    var count = 4;
    var rand = parseInt(Math.random() * 2000 + 1);
    var InterestDiv = $("#piclist");
    var strDiv = "";
    var maxLength = 17;
    InterestDiv.html("");
    $.getJSON("/ajax/PicTecListJson.aspx", { 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(/{id}/g, json[i].TecId).replace(/{stitle}/g, json[i].TecName.substr(0, maxLength) + "...").replace(/{ltitle}/g, json[i].TecName).replace(/{simg}/g, "http://upload." + getDomain() + "/view/?f=" + json[i].Img + "&amp;s=1");

            }
            else {
                strDiv += format.replace(/{id}/g, json[i].TecId).replace(/{stitle}/g, json[i].TecName).replace(/{ltitle}/g, json[i].TecName).replace(/{simg}/g, "http://upload." + getDomain() + "/view/?f=" + json[i].Img + "&amp;s=1");

            } //"<a href=\"" + json[i].Url + "\" target='_blank'>" + json[i].UserName + "</a>";
        }
        // strDiv += "<div class=\"both\"></div>";
        InterestDiv.html(strDiv);
    });


}

function LoadRelTecList() {
    var format = "<li class=\"f_l tec_list_032_{i}  wid60 CF60\"><a href=\"/list_{svocId}/0-0_0-0/0-0-0-0-1.html\" title=\"\" target=\"_blank\"> {sVoc}</a></li><li class=\"f_l tec_list_037 C036\" ><a href=\"/detail_{id}.html\" title=\"{ltitle}\" target=\"_blank\">{stitle}</a></li>";
    var tecid = $("#tecid");
    var keyword = $("#hidkeyword");
    var count = 8;
    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(/{i}/g, (i + 1)).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(/{i}/g, (i + 1)).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 showContact() {
    //登陆会员为技术通 一天50次


    //登陆会员为普通 一天10次


    //只有在第一次点的时候采取判断和获取信息

    var loginUser = $("#loginusername");
    var loginGroup = $("#logingroup");
    var tecId = $("#tecid");
    var publishUser = $("#publishUser");

    if (loginUser.val() == "") {
        onLogin();
    }
    else {
        var tmpid = "tec_lx_id";
        var classna = "tec_lx_con";
        var teclx_ID;
        teclx_ID = document.getElementById(tmpid)
        if (teclx_ID.className == classna) {
            //teclx_ID.className = classna + " noshow"
        } else {
            teclx_ID.className = classna
        }

        if ($("#truename").text() == "" && teclx_ID.className == classna) {
            //判断，并获取信息
            $.getJSON("/ajax/ViewTecContact.aspx", { id: tecId.val(), loginusername: loginUser.val(), publishusername: publishUser.val(), logingroup: loginGroup.val(), random: parseInt(Math.random() * 2000 + 1) }, function(json) {
                if (json.Infomation != null && json.Infomation != "") {
                    Ext.MessageBox.alert("确认", json.Infomation, function() {
                        //window.location.href = "http://{$conDomain_service_k8008_com}/member/tecmember.html";
                    });


                }
                else {

                    //符合条件，载入信息

                    $("#truename").text(json.Contatcname);
                    $("#truename_1").text(json.Contatcname);
                    $("#email").text(json.Email);
                    $("#mobile").text(json.Mobile);
                    $("#tel").text(json.Tel);
                    $("#address").text(json.Address);
                    $("#postcode").text(json.Zip);

                }
            });
        }
    }



}
function onScore() {

    //已登陆


    var tecid = $("#tecid");

    //所有的分值


    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_"); //有效转换为生产力

    if (input__ratings_proj1_ && input__ratings_proj2_
        && input__ratings_proj3_ && input__ratings_proj4_ && input__ratings_proj5_) {
        $.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 LoadInterest() {
    var tecid = $("#tecid");
    var InterestDiv = $("#InterestDiv");
    InterestDiv.html("");
    var strDiv = "";

    $.getJSON("/ajax/interestlist.aspx", { id: tecid.val(), count: 12, 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 onLogin() {
    window.location.href = "http://"+document.domain.replace("tec","passport")+"/?ret=" + encodeURI(location.href) + "";

    //  alert("请登录");
}

function doInterestEvent() {
    var loginUser = $("#loginusername");
    var tecid = $("#tecid");
    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;
}

function show1() {
    document.getElementById("lx_dwid").href = "#lx_id"
    document.getElementById("tec_lx_id").className = "tec_lx_con"
}
