/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var Slide = {
    upload : function(){
        var str1 = ".ppt";
        var str2 = ".pps";
        var fname = $F('fileField');
        if($('fileField').value == ''){
            show_error_msg("error_Message","请选择要上传的PPT文件");
            return;
        }
        //       if(($('fileField').value).indexOf(str1) == -1 && ($('fileField').value).indexOf(str2) == -1){
        //            show_error_msg("error_Message","请选择.ppt或者.pps文件");
        //            return;
        //        }
        //$('submit_btn').disabled = true;
        
        $('slide_upload_div').hide();
        $('file_name').update(this.get_upload_filename(fname)+" 上传中,请稍候");
        $('uploading').show();
        $('slide_upload_form').submit();
        
    },
    get_upload_filename : function(fname){
        var beginIndex    = fname.lastIndexOf("/");
        var winbeginIndex = fname.lastIndexOf("\\");
        var orginalName   = "";
        
        if(beginIndex !=-1){

            beginIndex = beginIndex + 1;
            orginalName = fname.substring(beginIndex);
            
        }            
        if(winbeginIndex !=-1){

            winbeginIndex = winbeginIndex + 1;
            orginalName = fname.substring(winbeginIndex);
            
        }
        return orginalName;
    },
    
    save_setting: function(){        
        //$('uploading').show();
        if($('title').value ==''){
            show_error_msg("setting_error","请输入名称");
            return;
        }else if($("perm_passcode_radio").checked){
            if($("perm_code").value.trim() ==''){
                show_error_msg("setting_error","请输入密码");
                return;
            }
        }else if($("perm_grant_radio").checked){
            var checkbox = $("perm_grant_div").select('[type="checkbox"]');
            var checked =0;
            for (var i=0; i<checkbox.length; i++){
                if (checkbox[i].checked==true){
                    checked++;
                }
            }
            if(checked==0){
                show_error_msg("setting_error","请选择群组或活动");
                return;
            }
        }

        $('submit_btn').disabled = true;
        $("setting_error").style.display ="none";
        
        $('slide_setting_form').submit();
    },

    save_upload: function(){
        if($('fileField').value == ''){
            show_error_msg("error_Message","请选择要上传的PPT文件");
            return;
        }

        if($('title').value ==''){
            show_error_msg("error_Message","请输入名称");
            return;
        }else if($("perm_passcode_radio").checked){
            if($("perm_code").value.trim() ==''){
                show_error_msg("error_Message","请输入密码");
                return;
            }
        }else if($("perm_grant_radio").checked){
            var checkbox = $("perm_grant_div").select('[type="checkbox"]');
            var checked =0;
            for (var i=0; i<checkbox.length; i++){
                if (checkbox[i].checked==true){
                    checked++;
                }
            }
            if(checked==0){
                show_error_msg("error_Message","请选择群组或活动");
                return;
            }
        }

        //////////////////////////
        $('slide_upload_div').hide();
        $('submit_btn').disabled = true;
        $("error_Message").style.display ="none";

        var fname = $F('fileField');
        $('file_name').update(this.get_upload_filename(fname)+" 上传中,请稍候");
        $('uploading').show();
        $('slide_upload_form').submit();
    },
    pagination: function(page){

        $("slide_page_num").value = page;
        $("slide_search_form").submit();
    },
    
    slide_onmouseover: function(id){
        $(id).style.display ="block";
    },
    slide_onmouseout: function(id){        
        $(id).style.display ="none";
    },
    deleteSlide : function(id){
        if(!confirm("确定删除?"))
            return;
        document.location.href = "/Slide.do?action=DELETE&slideId="+id;
    },
    slide_play_window : function(slideId){
        var width  = null;
        var height = null;
        var left   = null;
        var top    = null;
        var common_multiple = null;
        var w_constant = 16;
        var h_constant = 9;
        var top_constant = screen.height > 960 ?0.090:0.059;
        //        if ((screen.width == 1280) && (screen.height == 1024)){
        //            width  = 1268;height =797; left = 7; top  =70;
        //        }else if ((screen.width == 1280) && (screen.height == 768)){
        //            width  = 1264;height =600; left = 7; top  =40;
        //        }else if ((screen.width == 1280) && (screen.height == 960)){
        //            width  = 1264;height =734; left = 7; top  =65;
        //        }else if((screen.width == 1280) && (screen.height == 720)){
        //            width  = 1264;height =541; left = 5; top  =35;
        //        }else if((screen.width == 1024) && (screen.height == 768)){
        //            width  = 1003;height =564; left = 5; top  =35;
        //        }

        width = Math.round(screen.width*0.98);
        common_multiple = Math.round(width/w_constant);
        height = common_multiple*h_constant;
        left = width < 1000?5:7;
        top = screen.height * top_constant;
        
        window.open('/slides/'+slideId+'/show','','toolbar=no,menubar=no, scrollbars=yes, resizable=yes, location=no, status=no,width='+width+',height='+height+',left='+left+',top='+top);
    },
    copy_code : function(copyText){
        if (window.clipboardData){
            copyText.select();
            window.clipboardData.setData("Text", copyText.value);
        }
        else {
            var flashcopier = 'flashcopier';
            if(!document.getElementById(flashcopier)){
                var divholder = document.createElement('div');
                divholder.id = flashcopier;
                document.body.appendChild(divholder);
            }
            document.getElementById(flashcopier).innerHTML = '';
            copyText.select();
            var divinfo = '<embed src="/swf/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
            document.getElementById(flashcopier).innerHTML = divinfo;
        }
    }
    ,
    share : function(){
        if($F("shareTo").strip() == "" || $F("shareTo").strip() == "请输入朋友的恒知ID或者电子邮件，使用逗号分隔"){
            Slide._setShareMessage("请输入朋友的恒知ID或者电子邮件", false);
            this._timer = setTimeout(function(){
                $("slideShareMsg").update("");
                $("slideShareMsg").className = "clear";
                $("slideShareLoading").className = "clear";
            },3000);
            return false;
        }
        var shareNotes = $F("shareNotes").strip();
        if(shareNotes == "" || shareNotes == "向你推荐一个幻灯片"){
            shareNotes ="向你推荐一个幻灯片";
        }
        new Ajax.Request("/Slide.do?action=SLIDE_SHARE", {
            parameters : {
                "shareTo" : $F("shareTo").strip(),
                "slideid" : $("slideid").getValue(),
                "notes"   : shareNotes
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
                $("slideShareLoading").className = "";
                $("slideShareLoading").update('<img src="/images/loading.gif">');
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);                
                if(json.RETURN){
                    Slide._setShareMessage("已发送", true);
                    $("shareTo").value = "请输入朋友的恒知ID或者电子邮件，使用逗号分隔";
                    $("shareTo").style.color="#999";
                    $("shareNotes").value =mailContent;
                }else{
                    Slide._setShareMessage(json.MESSAGE, false);
                }

                this._timer = setTimeout(function(){
                    $("slideShareMsg").update("");
                    $("slideShareMsg").className = "clear";
                    $("slideShareLoading").className = "clear";
                },3000);
            }.bind(this),
            onComplete : function(){
                $("slideShareLoading").update("");
            }
        })
    },
    _setShareMessage : function(msg, type){
        $("slideShareMsg").update(msg);
        if(type){
            $("slideShareMsg").className = "ok_message";
        }else{
            $("slideShareMsg").className = "wrong_message";
        }
    }
// video_play : function(){
//    document.location.href = "/video_detail.jsp";
//}
};



var Slide_Card = {
    _toUid          : null,      //接收评价人的id
    _isMyProfile    : null,      //判断是自己还是别人的profile
    _degreeWithMe   : null,      //和我的关系
    _myUid          : null,      //我自己的id
    _json           : null,
    _basicProfile   : null,
    _eduResumeList  : null,
    _workResumeList : null,
    _comments       : null,
    _myComment      : null,
    _pro_return     : null,
    _connectionPath : null,
    _connect        : null,
    profileInit     : function(_json){
        this._json = _json;
        this._pro_return = _json.RETURN;
        if(!this._pro_return){
            document.location.href ="/index.jsp";
            return;
        }
        this._isMyProfile = _json.isMyProfile;
        this._degreeWithMe = _json.degreeWithMe;
        this._myUid = _json.myUid;
        this._basicProfile = _json.basicProfile;
        this._comments = _json.comments;

        //判断此字段是否存在，若存在，再赋值
        if(!_json.connectionPath == false){
            this._connectionPath = _json.connectionPath;
        }
        //        if(!_json.eduResume == false){
        //            this._eduResumeList = _json.eduResume;
        //        }
        //        if(!_json.workResume == false)
        //            this._workResumeList = _json.workResume;
        if(!this._isMyProfile && typeof _json.myUid !="undefined")
            this._toUid = _json.basicProfile.id;
        //        if(!_json.comments == false){
        //            //if(typeof _json.comments.myComment != "undefined" || _json.comments.myComment != null || _json.comments.myComment != ""){
        //            this._myComment = _json.comments.myComment;
        //        }
        ProfileCard.initialize(this._basicProfile,this._isMyProfile,this._degreeWithMe,this._myUid,this._connectionPath);
        
    },
    connectInit : function(_connect){
        this._connect = _connect;
        Slide_Card._connectInfoShow(_connect);
    },
    showProfile : function(){
        ProfileCard.showInviteButton();
        ProfileCard.showSendMessageButton();
        //如果是和我没有关系或者没有登陆时的search会显示showBasicInfo()信息，包括情况:
        //1 没有登陆只显示profileCart（没有维度和button)

        if(!this._myUid == true && !this._degreeWithMe == true || this._degreeWithMe == 0 || this._degreeWithMe >1 || this._myUid ==null || this._myUid ==""){
            ProfileCard.showBasicInfo();
        //Resume_Profile.showPersonal();

        //            if(this._degreeWithMe == 0 || this._degreeWithMe >1){
        //
        //                Resume_Profile.showRelation();
        //                Resume_Profile.showEducation();
        //                Resume_Profile.showWork();
        //                CommentsList.showComments();
        //                CommentsList.showPageNumber();
        //            }
        }else{//和我有关系、维度小于3大于0、在恒知内部搜所操作,profile页面的信息包括profileCart,resume,comments
            ProfileCard.showCard();
            //Resume_Profile.showPersonal();
            if(this._degreeWithMe >1)
                Resume_Profile.showRelation();
        //            Resume_Profile.showEducation();
        //            Resume_Profile.showWork();
        //            CommentsList.showComments();
        //            CommentsList.showPageNumber();
        }
    //ProfileCard.showConnectPaht();
    },
    _connectInfoShow : function(_connect){
        var contant = _connect.toUser.name+" 你好:"+
        "\r\n\n     你是我信任和尊敬的朋友，希望能通过恒知网与您建立职业联系.\r\n\r\n"+"          此致,"+"\r\n\n"+_connect.fromName;
        var label  = "恒知网 | "+_connect.fromName+"希望建立联系 ";
        $('invite_name_conn').setValue(_connect.toUser.name);
        $('invite_name_conn').disabled = true;
        $('connect_user_name').setValue(_connect.fromName);
        $('connect_user_name').disabled = true;
        $('invite_subject_conn').setValue(label);
        $('invite_message_conn').setValue(contant);
    },
   
    //当一个div onmouseover,让这个div高亮
    show_HighLight : function(s_div){
        $(s_div).style.background = '#FFE7A6';
    },
    //当一个div onmouseout时,让这个div的高亮消失
    hide_HightLight : function(h_div){
        $(h_div).style.background = '#ffffff';
    },
    displayConnPage : function(result){

        $("personal").style.display ="none";
        $('addConnection').style.display = "";
        var foundbutton = $('myprofile').select('tr');
        foundbutton.each(function(f){
            if(f.id =="addConnectionButton")
                f.style.display ="none";
        });
        $('addConnectionButton').style.display ="none";
        if(result !=0){
            //$('leterSendSuccess').style.display ="none";

            $('leterSendSuccess').style.display ="";
            $('leter_div').style.display ="none";
            $('leterSendSuccess').update("链接已过期或已被使用");
        }

        else
            $('leter_div').style.display="";

    }
};



var ProfileCard = {
    _profile_card_info   : "myprofile",
    _invitebutton        : "invitebutton",
    _button_sent_big     : "button_sent_big",
    _degreeWidthImg      : "degreeWidthBasicImg",
    _cartbutton_div      : "cartbutton_div",
    _cardInfoDisplay     : "Template_BasicInfoDisplay",
    _basicInfoDisplay    : "Template_BasicInfoDisplay",
    _workTotaldiv        : "work",
    _eduTotaldiv         : "EducatianalBackground",
    _workbutton_modify   : "workbutton_modify",
    _edubutton_modify    : "edubutton_modify",
    _comments_div        : "comments",
    _profiledegreeBasic  : "profiledegreeBasic",
    _degreeWidthBasicImg : "degreeWidthBasicImg",
    _photoman            : "/images/man.gif",
    _photowomen          : "/images/women.gif",
    _basicProfile        : null,
    _isMyProfile         : null,
    _degreeWithMe        : null,
    _myUid               : null,
    _screenName          : null,
    _photoLarge          : null,
    _connectionPath      : null,
    _isShowPath          : null,
    _pName               : null,
    initialize : function(basicProfile,isMyProfile,degreeWithMe,myUid,connectionPath){
        this._basicProfile   = basicProfile;
        this._isMyProfile    = isMyProfile;
        this._degreeWithMe   = degreeWithMe;
        this._myUid          = myUid;
        this._screenName     = basicProfile.screenName;
        this._connectionPath = connectionPath;
        this._pName          = basicProfile.name;
    },

    //是登陆过后，维度在>0和<=3之间时显示全部的card信息
    showCard : function(){
        //初始化数据
        var fillCardData = this._basicData(this._basicProfile,this._degreeWithMe);
    
        //是我的firends，说明也不是我自己的profile
        if(this._degreeWithMe == 1){
            $('sendMessagebutton').style.display ="";
            //$('commentbutton_my').style.display ="";
            $(this._cartbutton_div).style.display ="none";
            $('invitebutton').style.display ="none";
            $('degreenolink').style.display ="";

        }else if(this._isMyProfile == true || this._degreeWithMe =="" || this._degreeWithMe ==null){
                         
            //是我自己的profile 或者和我没有关系,不用显示维度
            $(this._degreeWidthImg).style.display ="none";
        }else{
            //和我有关系，但不是朋友 故显示invite button
            $('invitebutton').style.display ="";
            $(this._cartbutton_div).style.display ="none";
            $('sendMessagebutton').style.display ="none";

        }

        if(this._isMyProfile){//是我的profile 就显示"编辑"按钮
            $(this._cartbutton_div).style.display ="";
            $('sendMessagebutton').style.display ="none";
        }
    
        //让空的字段的div不要显示
        if(this._basicProfile.occupation == "")
            $('occupationIdB').style.display ="none";
        //if(this._basicProfile.industry == "")
        //$('industryIdB').style.display ="none";
        $(this._profile_card_info).insert(this._fillCardTemplate(fillCardData));
    },
    //这些都是在登陆情况下
    _fillCardTemplate : function(fillCardData){
        var myObj = ProfileCard._createCardTemplate();
        var fillResult = myObj.evaluate(fillCardData);
        return fillResult;
    },
    _createCardTemplate : function(){
        var myObjHtml = $(ProfileCard._cardInfoDisplay).innerHTML.templateDecode();
        var myObj = new Template(myObjHtml);
        return myObj;

    },

    showInviteButton : function(){
        var hash = new Hash();
        hash.set("name",ProfileCard._pName);
        hash.set("screenName",ProfileCard._screenName);
        var myObjHtml = $('Template_invite_button').innerHTML.templateDecode();
        var myObj = new Template(myObjHtml);
        var fillResult = myObj.evaluate(hash);
        $('invitebutton').insert(fillResult);
    },
    showSendMessageButton : function(){
        var hash = new Hash();
        hash.set("name",ProfileCard._pName);
        hash.set("screenName",ProfileCard._screenName);
        var myObjHtml = $('Template_Icommentbutton_div').innerHTML.templateDecode();
        var myObj = new Template(myObjHtml);
        var fillResult = myObj.evaluate(hash);
        $('sendMessagebutton').insert(fillResult);
    },
    showConnectPath : function(){
        if(ProfileCard._degreeWithMe >= 2){
            ProfileCard._isShowPath = 1;
            $("connectionPath_div").style.display ="";
            $("connectionPath_tr_div").update("");
            ProfileCard.showBasicInfo();
        }

    },
    hideConnectPath : function(){
        //$("invaite_resume_distant").style.display ="none";
        ProfileCard.showBasicInfo(3);

    },
    showAlertInfo : function(){

        var gendern = null;
        if(this._basicProfile.gender == 0)
            gendern ="她";
        else if(this._basicProfile.gender == 1)
            gendern ="他";
        var info = this._basicProfile.name+" 是我认识并信任的朋友, 希望和"+gendern+"建立联系";
        var foundbutton1 = $('myprofile').select('input');

        foundbutton1.each(function(f){
            if(f.id =="bulidRelationCardButton")
                new PopupForButton(f,info);
        });


    },
    //有两种情况:1 没有登陆只显示profileCart（没有维度和button) 2 登陆了但维度大于3只能看基本信息(有维度和button)
    showBasicInfo : function(showhideParm){
        //初始化数据
        var basicHash = ProfileCard._basicData(ProfileCard._basicProfile,ProfileCard._degreeWithMe);
        //隐藏不要的信息，只显示profileCard
        //$(this._workbutton_modify).style.display ="none";
        //$(this._edubutton_modify).style.display  ="none";
        
        $('sendMessagebutton').style.display     ="none";
         
        $(this._cartbutton_div).style.display    ="none";
        //$('relation_bdiv').style.display         = "none";
        if(!Slide_Card._myUid == true && !Slide_Card._degreeWithMe == true  || Slide_Card._myUid ==null || Slide_Card._myUid ==""){
            $('addConnectionButton').style.display = "";

        //$('personal_resume_bdiv').style.display  = "none";
        }else
            $('invitebutton').style.display ="";
        //让空的字段的div不要显示
        if(this._basicProfile.occupation == "")
            $('occupationIdB').style.display ="none";
        //        if(this._basicProfile.industry == ""){
        //            $('industryIdB').style.display ="none";
        //        }
      
        if(this._degreeWithMe == 0)
            $(this._degreeWidthBasicImg).style.display ="none";
        if(this._degreeWithMe == 1){
            
            $('degreenolink').style.display ="";
        }
        if(this._degreeWithMe > 1 ){
            $('degreeislink').style.display ="";
        }

        if(this._degreeWithMe =="" || this._degreeWithMe ==null){
            //就是没有登陆 与我的关系维数不显示
            if( this._myUid ==null || this._myUid ==""){
                $(this._degreeWidthBasicImg).style.display ="none";
                $('invitebutton').style.display ="none";
            //$(this._comments_div).style.display ="none";
            //$('work').style.display ="none";
            //$(this._eduTotaldiv).style.display ="none";
            //$('comments').style.display ="none";
            }
        }
        //关闭事件,隐藏维度div
        if(showhideParm == 3){
            if($('Template_BasicInfoDisplay') != null){
                var pathdiv = $('Template_BasicInfoDisplay').select('div');
                pathdiv.each(function(b){
                    if(b.id =="connectionPath_div"){
                        b.style.display='none';
                    }
                });
            }
        }
        //显示维度信息
        if(ProfileCard._connectionPath != null && showhideParm !=3){
            if(ProfileCard._isShowPath == 1){
                $("connectionPath_div").style.display ="";
            }

            if(ProfileCard._degreeWithMe >= 3){
                $('path3_name').style.display ="";
                $('path3_point').style.display ="";
            }
            var size = ProfileCard._connectionPath.size();
            for(var j=0;j<ProfileCard._connectionPath.size();j++){

                $("connectionPath_tr_div").insert(this._fillConnectPathTemplate(ProfileCard._connectionPath[j],j,size));

            }

        }
        $(this._profile_card_info).update(this._fillBasicTemplate(basicHash));

    },

    _basicData : function(basicProfile,degreeWithMe){
      
        var hash       = new Hash();
        var phone      = "手机保密";
        var email      = "邮箱保密";
        var company    = basicProfile.company;
        var occupation = basicProfile.occupation;
        var genderv    = null;
        //var birthDay   = ProfileCard._getBeginDate(basicProfile.birthDay);//"生日保密";
        //var birthPlace = basicProfile.birthPlace;//"出生地保密";
        if(basicProfile.gender == 0)
            genderv ="她";
        else if(basicProfile.gender == 1)
            genderv ="他";
        //当这些字段存在时就说明不是保密的
        if(typeof basicProfile.phone != "undefined"){
            phone = basicProfile.phone+"(保密)";
            if(basicProfile.phone =="" || basicProfile.phone == null)
                phone = "未设";
        }

        if(typeof basicProfile.email != "undefined"){
            email = "<a href=''>"+basicProfile.email+"</a>"+"(保密)";
            if(basicProfile.email =="" || basicProfile.email == null)
                email = "未设";
        }

        /*if(typeof basicProfile.birthDay != "undefined"){
            if(basicProfile.birthDay != null)
                birthDay = ProfileCard._getBeginDate(basicProfile.birthDay);
            else
                birthDay = "";
        }
        if(typeof basicProfile.birthPlace != "undefined")
            birthPlace  = basicProfile.birthPlace;*/
        if(basicProfile.otherName != null && basicProfile.otherName.strip() != "" ){
            if(basicProfile.otherName != null)
                hash.set("otherName" , "("+basicProfile.otherName+")");
        }
        //if(basicProfile.company.length >24)
        //  company = company.substr(0,18)+"...";
        // if(basicProfile.occupation.length >10)
        //   occupation = occupation.substr(0,8)+"...";
        //hash.set("detail" ,TextReplace(basicProfile.recentDesc));//basicProfile.recentDesc);
        hash.set("id",basicProfile.id);
        hash.set("screenName",basicProfile.screenName);
        hash.set("name" , basicProfile.name);
        hash.set("location" , basicProfile.location);
        hash.set("motto" , '"&nbsp;'+basicProfile.motto+'&nbsp;"');
        hash.set("occupation" ,occupation);
        hash.set("industry" , basicProfile.industry);
        hash.set("company" , company);
        hash.set("DegreeWidthMe" , degreeWithMe);
        hash.set("degree1Count" , basicProfile.degree1Count);
        hash.set("degree2Count" , basicProfile.degree2Count);
        hash.set("degree3Count" , basicProfile.degree3Count);
        hash.set("email" , email);
        hash.set("phone" , phone);
        hash.set("birthPlace" , basicProfile.birthPlace);
        hash.set("locationn",basicProfile.location)
        hash.set("occupationn" ,occupation);
        hash.set("companyy" ,company);
        hash.set("buttontitle",basicProfile.name+'是 我认识并信任的朋友,希望和'+genderv+'建立联系');
        hash.set("the_page","/profile");
        if(Slide_Card._myUid == true && !Slide_Card._degreeWithMe == true||Slide_Card._myUid ==null || Slide_Card._myUid ==""){
            if(Slide_Card._isMyProfile)
                hash.set("the_page","/profile");
        }

        if(typeof hash.get("otherName") != "undefined")
            hash.set("namee" , basicProfile.name+hash.get("otherName"));
        else
            hash.set("namee" , basicProfile.name);
        if(Prototype.Browser.IE){
            if(typeof hash.get("otherName") != "undefined")
                hash.set("namee" , '"'+basicProfile.name+hash.get("otherName")+'"');
            else
                hash.set("namee" , '"'+basicProfile.name+'"');
            hash.set("buttontitle",'"'+basicProfile.name+'是 我认识并信任的朋友,希望和'+genderv+'建立联系"');
            hash.set("locationn",'"'+basicProfile.location+'"')
            hash.set("occupationn" ,'"'+occupation+'"');
            hash.set("companyy" , '"'+company+'"');
        }
        if(!basicProfile.motto == false){
            if((basicProfile.motto).strip() == "" || (basicProfile.motto).strip() == null)
                hash.set("motto" , basicProfile.motto);
        }else if(!basicProfile.motto == true){
            hash.set("motto" , basicProfile.motto);
        }

        ProfileCard._photoLarge = 'src="'+basicProfile.photoLarge+'"';
        if(basicProfile.photoLarge == null || basicProfile.photoLarge == ""){
            ProfileCard._photoLarge = 'src="'+ProfileCard._photoman+'"';
            if(typeof basicProfile.gender !="undefined"){

                if(basicProfile.gender == 0)
                    ProfileCard._photoLarge = 'src ="'+ProfileCard._photowomen+'"';
            }

        }
        hash.set("photo_large" ,ProfileCard._photoLarge);
        if(basicProfile.birthDay != null)
            hash.set("birthDay" ,ProfileCard._getBeginDate(basicProfile.birthDay));

        return hash;
    },
    _fillBasicTemplate : function(basicHash){
        var myObj = this._createBasicTemplate();
        var fillResult = myObj.evaluate(basicHash);

        return fillResult;
    },
    _fillConnectPathTemplate : function(connectionPath,num,size){
        var hash  = new Hash();

        for(var j=0;j < connectionPath.size();j++){
            if(j >1){
                hash.set("path"+3+"_name",connectionPath[connectionPath.size()-1].name);
                break;
            }else{
                hash.set("path"+j+"_name",connectionPath[j].name);
            }
        }
        var myObjHtml = null;
        if(size > 1){
            if(size == 2){
                if(num == 0){
                    myObjHtml = $("Template_pathConnectionxxx").innerHTML.templateDecode();
                }else
                    myObjHtml = $("Template_pathConnection").innerHTML.templateDecode();
            }else{
                if(num == 1){
                    myObjHtml = $("Template_pathConnectionxxx").innerHTML.templateDecode();
                }else
                    myObjHtml = $("Template_pathConnection").innerHTML.templateDecode();
            }

        }else
            myObjHtml = $("Template_pathConnectionxxx").innerHTML.templateDecode();

        var myObj = new Template(myObjHtml);
        var fillResult = myObj.evaluate(hash);

        return fillResult;
    },
    _createBasicTemplate : function(){

        var myObjHtml = $(this._basicInfoDisplay).innerHTML.templateDecode();

        var myObj = new Template(myObjHtml);
        return myObj;
    },
    _getPhoneData : function(phone){
        var num = null;
        var  n  = 2;
        for(var i = 1;i<5;i++){
            if(i == 1){
                num = phone.substr(0,n++);
            }else{
                if(n == 2)
                    n++;
                num = phone.substr(n,n+3);
            }


        }
    },
    _getBeginDate : function(str){
        var bdate = new Date();
        bdate.setTime(str);
        bdate = ProfileCard.calcTime("+8",bdate);
        var month = bdate.getMonth()+1;
        var day   = bdate.getDate();
        if(month < 10)
            month = "0"+month;
        if(day   < 10)
            day   = "0"+day;

        var dateStrB = bdate.getFullYear()+"-"+month+"-"+day;
        return dateStrB;
    },
    calcTime : function(offset,date) {
        var utc = date.getTime() + (date.getTimezoneOffset() * 60000);
        var nd = new Date(utc + (3600000*offset));
        return  nd;
    },
    forwordtoEdit : function(){
        document.location.href ="/profile_edit.jsp";
    },
    addConnectionPage : function(){

        $('slide_all_div').style.display ="none";
        $('AddConnectionCheck').style.display ="";
        $('fund_code').update("在和  <span class='style7'> "+ProfileCard._pName+" </span>  建立联系之前, <br/>恒知网会通过两个步骤来确认您的身份 :<br/><br/>1.  确认您的邮箱地址<br><br>2.  征求 "+ProfileCard._pName+"  的同意");
        //$('power_point').style.display ="none";
        $("label_card").update("和 "+ProfileCard._pName+"  建立联系&nbsp;|&nbsp;确认您的邮箱地址");
    },

    hiddenAddConnectionPage : function(){
        $('addConnection').style.display ="none";
        $('slide_all_div').style.display = "";
        $('AddConnectionCheck').style.display ="none";
        $('addConnection_error').update('');
        $('addConnection_error').style.display = "none";
        $('email_me').setValue('');
        $('email_mea').setValue('');
        $('name_me').setValue('');
        $('imageCode').setValue('');
    },
    hiddenAddConnectionPageEmail : function(){
        $('addConnection').style.display ="none";
        $('AddConnectionCheck').style.display = "none";
        $('slide_all_div').style.display = "";
    //       if(!Profile._basicProfile.summary == true && !Profile._basicProfile.interest == true &&
    //          !Profile._basicProfile.speciality == true || ((Profile._basicProfile.summary.strip() == null ||Profile._basicProfile.summary.strip() == "")
    //          && (Profile._basicProfile.interest.strip() == null ||Profile._basicProfile.interest.strip() == "")
    //          && (Profile._basicProfile.speciality.strip() == null ||Profile._basicProfile.speciality.strip() == ""))){
    //       }else{
    //           $('personal').style.display ="";
    //       }
    },
    AddConnectionCheckFunc : function(){
        var email_me = $('email_me').value;
        var name_me  = $('name_me').value;
        var imageCode = $('imageCode').value;
        var email_mea = $('email_mea').value;
        if(email_me.strip() == "" || email_me.strip() == null || email_mea.strip()== "" || email_mea.strip() ==null|| name_me == "" || name_me == null || imageCode =="" || imageCode == null){
            //$('addConnection_error').style.display ="";
            if(email_me.strip() == "" || email_me.strip() == null ){
                show_error_msg('addConnection_error',"请输入Email地址!");
                // $('addConnection_error').update("请输入Email地址!");
                return;
            }
            if(email_mea.strip() == "" || email_mea.strip() == null ){
                show_error_msg('addConnection_error',"请输入重复Email地址!");
                // $('addConnection_error').update("请输入Email地址!");
                return;
            }
            if(name_me.strip() == "" || name_me.strip() == null ){
                show_error_msg('addConnection_error',"请输入姓名!");
                //$('addConnection_error').update("请输入姓名!");
                return;
            }
            if(imageCode.strip() == "" || imageCode.strip() == null ){
                show_error_msg('addConnection_error',"请输入验证码!");
                //$('addConnection_error').update("请输入验证码!");
                return;
            }
        }
        if(ProfileCard._isSingleEmail(email_me) == false){
            show_error_msg('addConnection_error',"请输入正确的Email地址!");
            return;
        }
        if(email_me.strip() != email_mea.strip()){
            show_error_msg('addConnection_error',"两次的Email地址不一致!");
            return;
        }

        new Ajax.Request('/Network.do?action=VALIDATE_INVITATION_REQUEST_EMAIL',{
            parameters:{
                "email_address":email_me,
                "name":name_me,
                "imageCode":imageCode,
                "screen_name":ProfileCard._screenName
            },
            requestHeaders:{
                Accept :"application/json"
            },
            onCreate: function(){
                $('addConnection_error').style.display ="";
                show_send_msg('addConnection_error','处理中....');
            },
            onSuccess:function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    $('addConnection_error').style.display ="none";
                    $('checkMyEmailTable').style.display ="none";
                    $('checkMyEmailInfo').style.display ="";
                    $('checkMyEmailInfo_tr').style.display ="";
                    if(json.FLAG =="0" || json.FLAG =="1" || json.FLAG =="2"){
                        if(json.FLAG == 0)
                            $('checkMyEmailInfo').update(ProfileCard._pName+" 已经发了邀请赛函到你您的邮箱("+email_me+")，请查收。<br/>如果信箱里找不到这封邮件，请查看'垃圾邮箱'，某些电邮服务可能做了不正确的过滤。");
                        if(json.FLAG == 1)
                            $('checkMyEmailInfo').update("确认邮件已发至您的邮箱（"+email_me+")，请查收。<br/>如果信箱里找不到这封邮件，请查看'垃圾邮箱'，某些电邮服务可能做了不正确的过滤。");
                        if(json.FLAG == 2){
                            $('checkMyEmailInfo').update("恒知已将您的请求发送给"+ProfileCard._pName+", 请耐心等候");
                        }

                    }else
                        $('checkMyEmailInfo').update("确认邮件已发至您的邮箱（"+email_me+")，请查收。<br/>如果信箱里找不到这封邮件，请查看'垃圾邮箱'，某些电邮服务可能做了不正确的过滤。");


                }else{
                    show_error_msg('addConnection_error',json.MESSAGE);
                //$('addConnection_error').style.display ="";
                //$('addConnection_error').update(json.MESSAGE);
                //if(json.MESSAGE == "输入邮箱地址已注册"){
                //   window.setTimeout("ProfileCard.autoNextPage()",5000);
                //}
                }
            }

        });

    },
    _isSingleEmail : function(s){
        var flag=true;
        var emailRegS=/^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!emailRegS.exec(s))
            flag=false ;
        return flag ;
    },
    hiddenAddConnectLetterPage : function(){
        $('addConnection').style.display = "none";
    },
    autoNextPage : function(){
        document.location.href ="/index.jsp";
    }
}

var SlideBookmark = {
    _bookmark_req_url : "/Slide.do?action=BOOKMARK",
    bookmark : function(slideId , page){
        new Ajax.Request(this._bookmark_req_url, {
            method: "post",
            parameters : {
                "slideId" : slideId
            },
            requestHeaders: {
                Accept : "application/json"
            },
            onCreate : function(){
                $("bookmark" + page + slideId).update('<img src="/images/loading.gif" />');
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    //                   var myDialog = new YAHOO.widget.Dialog("myDialog");
                    //                   myDialog.center();
                    //                   myDialog.render();
                    //                   myDialog.show();
                    alert("收藏成功");
                    $("bookmark_link" + page + slideId).remove();
                }
            },
            onComplete : function(){
                $("bookmark" + page + slideId).update();
            }
        })
    },
    remove_bookmark : function(bookmarkId){
        $("remove_bookmark_" + bookmarkId).hide();
        document.location.href = "/Slide.do?action=REMOVE_BOOKMARK&bookmarkId="+bookmarkId;
    }
}

var SlideComment = {
    showCreateComment : function(createCommentDiv){
        $(createCommentDiv).show();
    },
    cancelCreateComment : function(createCommentDiv){
        $(createCommentDiv).hide();
    },
    showComment : function(showCommentDiv,editCommentDiv){
        $(showCommentDiv).hide();
        $(editCommentDiv).show();
    },

    cancelComment : function(showCommentDiv,editCommentDiv){
        $(showCommentDiv).show();
        $(editCommentDiv).hide();
    },
    createSlideComment : function(target_type, target_id,total){
        var comment = $F("slideCommentTextarea").strip();
        if(comment == ""){
            alert("请输入内容");
            return;
        }        
        new Ajax.Request("/Comment.do?action=CREATE_SIMPLE", {
            parameters : {
                "target_type" : target_type,
                "target_id" : target_id,
                "message"   : comment
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){                
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    var com_id = json.commentId;
                    total = json.totalPage;
                    if(total >1){
                        document.location.href ="/slide_detail.jsp?slideId="+target_id+"&endPage=end&page_num="+total;//+"#slideComment"+com_id;
                    }else{
                        document.location.href ="/slides/"+target_id;
                    }
                   

                }else{
                    //Slide._setShareMessage(json.MESSAGE, false);
                }
            }.bind(this),  
            onComplete : function(){
                
            }
        });

    },
    removeComment : function(target_id , comment_id){
        if(removeConfirm()){                    
          new Ajax.Request("/Comment.do?action=DELETE_SIMPLE", {
            parameters : {
                "comment_id" : comment_id
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                   document.location.href ="/slides/"+target_id;
                }else{
                    //Slide._setShareMessage(json.MESSAGE, false);
                }
            }.bind(this),
            onComplete : function(){

            }
          });
        }       
    },
     removeSimpleReply : function(target_id, comment_id){
        if(removeConfirm()){
          new Ajax.Request("/Comment.do?action=REMOVE_SIMPLE_REPLY", {
            parameters : {
                "comment_id" : comment_id
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                   document.location.href ="/slides/"+target_id;
                }else{
                    //Slide._setShareMessage(json.MESSAGE, false);
                }
            }.bind(this),
            onComplete : function(){

            }
          });
        }
    },
    updateComment : function( target_id, comment_id,edit_comment_div){
        var comment = $F(edit_comment_div).strip();
        if(comment == ""){
            alert("请输入内容");
            return;
        }
        new Ajax.Request("/Comment.do?action=UPDATE_SIMPLE", {
            parameters : {                
                "comment_id" : comment_id,
                "message"   : comment
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                   document.location.href ="/slides/"+target_id;
                }else{
                    //Slide._setShareMessage(json.MESSAGE, false);
                }
            }.bind(this),
            onComplete : function(){

            }
        });
    },

    updateSimpleReply : function(target_id, comment_id,edit_reply_div){
         var reply = $F(edit_reply_div).strip();
        if(reply == ""){
            alert("请输入内容");
            return;
        }
        new Ajax.Request("/Comment.do?action=UPDATE__SIMPLE_REPLY", {
            parameters : {
                "comment_id" : comment_id,
                "reply"   : reply
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                   document.location.href ="/slides/"+target_id;
                }else{
                    //Slide._setShareMessage(json.MESSAGE, false);
                }
            }.bind(this),
            onComplete : function(){

            }
        });
    }
}
function removeConfirm(){
    if(confirm("确定删除?")){
        return true;
    }
    return false;
}
function focusHide(e,v){
    if(e.value == v){
        e.value = "";
        e.style.color="#000";
    }
}

function BlueShow(e,v){
    if(e.value == ""){
        e.style.color="#999";
        e.value = v;
    }
}