
var str = null;
var select_date = null;
        
function comTDate(date1 , date2){
    if(date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate()){
        return true;
    }else{
        return false;
    }
}

YAHOO.namespace("example.calendar");
Dom = YAHOO.util.Dom;
function renderColor() {
    // Tell Dialog it's contents have changed, which allows
    // container to redraw the underlay (for IE6/Safari2)

    var a = new Array();
    var today = new Date();
    for(var i = 0 ;i < _json.dateList.length; i++){
        a.push(new Date(_json.dateList[i]));
    }
    var cell1 = null;
    for(var i = 0 ; i < a.length ; i++){//alert(YAHOO.example.calendar.cal1.getCellIndex(a[i])+"   time ="+a[i]);
        //for(var i = 0; i < 42; i++){
        //var cell_tmp = YAHOO.example.calendar.cal1.cells[i];
        //if(Dom.hasClass(cell_tmp, YAHOO.example.calendar.cal1.Style.CSS_CELL_OOM)){
        //    Dom.removeClass(cell_tmp, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTABLE);
        //}
        if(YAHOO.example.calendar.cal1.getCellIndex(a[i]) != -1){

            cell1 = YAHOO.example.calendar.cal1.cells[YAHOO.example.calendar.cal1.getCellIndex(a[i])];
            //if(!Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTED) && Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTABLE)){//CSS_CELL_RESTRICTED
            if(!Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTED)){
                //if(!Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTABLE)){
                //    Dom.addClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTABLE);
                //Dom.addClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTOR);
                //}
                //if(Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_OOM)){
                //    Dom.addClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTABLE);
                //}
                Dom.addClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTED);
            }
            //if(comTDate(a[i],today)){
            if(Dom.hasClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_TODAY)){
                Dom.removeClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_TODAY);
                Dom.addClass(cell1, YAHOO.example.calendar.cal1.Style.CSS_CELL_HIGHLIGHT3);
            }
        //CSS_CELL_HIGHLIGHT4
        //}

        }
    }

}

YAHOO.example.calendar.init = function() {
    YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","eventsDate",
    {
        mindate:"1/1/2006",
        maxdate:"12/31/2016"
    });
    //YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
    //标题中年份在第一位
    YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_YEAR_POSITION", 1);
    //标题中月份在第二位
    YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_MONTH_POSITION", 2);
    //标题中年份的后缀为"年"
    YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_YEAR_SUFFIX", "年");
    //标题中月份的后缀为"月"
    YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_MONTH_SUFFIX", "月");
    YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG", ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"]);
    //星期的短名为"日", "一", "二", "三"(注意“日”在第一个)
    YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT", ["日", "一", "二", "三", "四", "五", "六"]);

    YAHOO.example.calendar.cal1.renderEvent.subscribe(renderColor);

    YAHOO.example.calendar.cal1.render();
    YAHOO.example.calendar.cal1.changePageEvent.subscribe(function(){
        //alert("change page ="+select_date);
        }, YAHOO.example.calendar.cal1, true);
    YAHOO.example.calendar.cal1.selectEvent.subscribe(function() {
        if (YAHOO.example.calendar.cal1.getSelectedDates().length > 0) {
            var selDate = YAHOO.example.calendar.cal1.getSelectedDates()[0];
            var wStr = YAHOO.example.calendar.cal1.cfg.getProperty("WEEKDAYS_SHORT")[selDate.getDay()];
            var dStr = selDate.getDate();
            var mStr = selDate.getMonth()+1;
            var yStr = selDate.getFullYear();
            var week = selDate.getDay();
            dStr = dStr<10?"0"+dStr:dStr;
            mStr = mStr<10?"0"+mStr:mStr;
            //var weekOfMonth = getMonthWeek(yStr,mStr,dStr);
            select_date = mStr+"/"+dStr+"/"+yStr;

            renderColor();
            //for(var i = 0 ;i < _json.dateList.length; i++){
            //     if(!compareTwoDateIsEqual(new Date(_json.dateList[i]), selDate)){
            //            var cel = YAHOO.example.calendar.cal1.cells[YAHOO.example.calendar.cal1.getCellIndex(selDate)];
            //            Dom.removeClass(cel, YAHOO.example.calendar.cal1.Style.CSS_CELL_SELECTED);
            //    }
            // }
            document.location.href="/event_search_bydate.jsp?startDate="+select_date;
        //Dom.get(id).style.color="#000";
        //Dom.get(id).value = select_date;


        //alert("weekday="+weekday+"   monthday="+monthday+"  monthweekday="+monthweekday+" yearmonthday="+yearmonthday);
        } else {
    // Dom.get(id).value = "";
    }
    }, YAHOO.example.calendar.cal1, true);


}

YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);








var notCompProfileDialog = null;
var bizCardDialog = null;
function showBizCard(){
    $("bizCardDialog").show();
    bizCardDialog.center();
    bizCardDialog.render();
    bizCardDialog.show();
}
function editMicoBlog(){
    $("showMicoBlogDiv").hide();
    $("editMicoBlogDiv").show();
    $("micoBlogEdit").focus();
}

function submitMicoBlog(){
    $("microblog_submit").disabled = true;

    var microblogContent = $("micoBlogEdit").getValue().strip();
    new Ajax.Request("/Microblog.do?action=PUBLISH_MICROBLOG",
    {
        parameters : {
            "microblogContent" : microblogContent
        },
        requestHeaders : {
            Accept: 'application/json'
        },
        onCreate : function(){
        //$("micoBlogLoading").update('<img src="/images/loading.gif">');
        },
        onSuccess : function(transport){
            var json = transport.responseText.evalJSON(true);
            if(json.RETURN){
                var content = json.microblog.content;
                if(content == null || content == ""){
                    $("micoBlog").update("微博: 我在忙些什么");
                    $("micoBlog").style.color = "#999";
                }else{
                    $("micoBlog").update(content);
                }
                $("showMicoBlogDiv").show();
                $("editMicoBlogDiv").hide();
            }else{
                showMessage($("micoBlogMsg"), json.MESSAGE, false);
            }
        },
        onComplete : function(){
            //$("micoBlogLoading").update("");
            $("microblog_submit").disabled = false;
        }
    });
}

function cancelMicoBlog(){
    $("micoBlogMsg").update();
    $("micoBlogMsg").className = "clear";
    $("showMicoBlogDiv").show();
    $("editMicoBlogDiv").hide();
}

function showMessage(msgDiv, msg, type){
    msgDiv.update(msg);
    if(type){
        msgDiv.className = "ok_message";
    }else{
        msgDiv.className = "wrong_message";
    }
}

function quickInviteFocus(e){
    //if(e.innerHTML == "请输入email地址，以逗号或回车分隔"){
    //    e.style.color="#000";
    //    e.innerHTML = "";
    //}
    if(e.value == "请输入email地址"){
        e.style.color="#000";
        e.value = "";
    }
}

function quickInviteBlur(e){
    //if(e.innerHTML == ""){
    //    e.innerHTML = "请输入email地址，以逗号或回车分隔";
    //    e.style.color="#999";
    //}
    if(e.value == ""){
        e.value = "请输入email地址";
        e.style.color="#999";
    }
}

function redirectPage(url){
    document.location.href =url;
}

function editMicroblog(e){
    var len = e.value.length;
    var remainLen = 70 - len;
    if(remainLen < 0){
        $("remainLength").update("字数超过70个字符");
        $("microblog_submit").disabled = true;
    }else{
        $("remainLength").update("剩余字数:" + remainLen);
        $("microblog_submit").disabled = false;
    }
}
function notCompProfileDialogShow(){
    notCompProfileDialog = new YAHOO.widget.Dialog("notCompProfileDialog");

    $("notCompProfileDialog").show();
    notCompProfileDialog.center();
    notCompProfileDialog.render();
    notCompProfileDialog.show();

    if($("temp_type") != null && $("temp_type") != "undefined"){
        $("temp_type").hide();
    }
}

function notCompProfileDialogHide(){
    notCompProfileDialog.hide();
    if($("temp_type") != null && $("temp_type") != "undefined" ){
        $("temp_type").show();
    }
}

function initFrame_NotUsed(){
    //set_calendar("eventsDate");
    
    var json = jsonContacts.evalJSON(true);
    if(!json.RETURN){
        return;
    }
    var myContacts  = json.contacts;

    // Define a custom search function for the DataSource
    var matchNames = function(sQuery) {
        // Case insensitive matching
        var query = decodeURI(sQuery).toLowerCase(),
        contact,
        i=0,
        l=myContacts.length,
        matches = [];

        // Match against each name of each contact
        for(; i<l; i++) {
            contact = myContacts[i];
            if((contact.name.toLowerCase().indexOf(query) > -1) ||
                (contact.otherName.toLowerCase().indexOf(query) > -1)) {
                matches[matches.length] = contact;
            }
        }

        return matches;
    };

    // Use a FunctionDataSource
    var oDS = new YAHOO.util.FunctionDataSource(matchNames);
    oDS.responseSchema = {
        fields : ["name","otherName", "company","occupation"]
    };
    //oDS.queryMatchContains = true;

    // Instantiate AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("search_text", "searchContainer", oDS);
    oAC.resultTypeList = false;

    // Custom formatter to highlight the matching letters
    oAC.formatResult = function(oResultData, sQuery, sResultMatch) {
        var query = decodeURI(sQuery).toLowerCase(),
        name = oResultData.name,
        otherName = oResultData.otherName || "",
        company = oResultData.company || "",
        occupation = oResultData.occupation || "",
        query = decodeURI(sQuery).toLowerCase(),
        nameMatchIndex = name.toLowerCase().indexOf(query),
        otherNameMatchIndex = otherName.toLowerCase().indexOf(query),
        displayName, displayOtherName, displayCompanyOccupation;
        if(nameMatchIndex > -1) {
            displayName = highlightMatch(name, query, nameMatchIndex);
        }else{
            displayName = name;
        }
        if(otherNameMatchIndex > -1) {
            displayOtherName = "(" + highlightMatch(otherName, query, otherNameMatchIndex) + ")";
        }else{
            displayOtherName = otherName ? "(" + otherName + ")" : "";
        }


        if(company == "" && occupation == ""){
            displayCompanyOccupation = "";
        }else if(company == ""){
            displayCompanyOccupation = occupation;
        }else if(occupation == ""){
            displayCompanyOccupation = company;
        }else{
            displayCompanyOccupation = company + " | " + occupation;
        }

        return displayName +  displayOtherName + "<div class='autoCompGray'>" + displayCompanyOccupation + "</div>";
    };

    // Helper function for the formatter
    var highlightMatch = function(full, snippet, matchindex) {
        return full.substring(0, matchindex) +
        "<span class='match'>" +
        full.substr(matchindex, snippet.length) +
        "</span>" +
        full.substring(matchindex + snippet.length);
    }

    bizCardDialog = new YAHOO.widget.Dialog("bizCardDialog");
}
function checkSearchForm(form){
    if($("search_text").getValue() == ""){
        return false;
    }else{
        form.submit();
        return true;
    }
}

var suggestionDialog = null;

var Suggestion = {

    showDialog : function(){
        if(suggestionDialog == null){
            suggestionDialog = new YAHOO.widget.Dialog("suggestionDialog");
            $("suggestionDialog").show();
            suggestionDialog.center();
            suggestionDialog.render();
        }
        Suggestion.hideResult();
        suggestionDialog.show();
    },

    hideDialog : function(){
        suggestionDialog.hide();
        $("sug_subject").clear();
        $("sug_content").clear();
    },

    showResult:function(){
        $("suggestBeforeSubmit").hide();
        $("suggestAfterSubmit").show();
    },

    hideResult:function(){
        $("suggestBeforeSubmit").show();
        $("suggestAfterSubmit").hide();
    },

    send : function(){
        if($F("sug_content").strip() == ""){
            show_error_msg("sug_msg", "请输入意见或建议");
            return false;
        }
        
        new Ajax.Request("/Comment.do?action=SEND_SUGGESTION", {
            parameters : {
                "sug_subject" : $F("sug_subject").strip(),
                "sug_content" : $F("sug_content").strip()
            },
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
                $("sug_sending").update('<img src="/images/loading.gif">');
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    $("sug_sending").update('');
                }else{
                    show_error_msg("sug_msg",json.MESSAGE);
                }
            }.bind(this),
            onComplete : function(){
                Suggestion.showResult();
            }
        })
    }
}

var hzLoginSignupDialog = null;
function showHzLoginSignupDialog(){
    if(hzLoginSignupDialog == null){
        hzLoginSignupDialog = new YAHOO.widget.Dialog("hzLoginSignupDialog");
        $("hzLoginSignupDialog").show();
        hzLoginSignupDialog.center();
        hzLoginSignupDialog.render();
    }
    hzLoginSignupDialog.show();
}

function hzLoginSignupDialog_Login_Submit(){
    if(!$('hzLoginSignupDialog_email_id').present()){
        show_error_msg('hzLoginSignupDialog_message_div', '请输入邮箱地址');
        $('hzLoginSignupDialog_email_id').focus();
        return ;
    }
    if(!$('hzLoginSignupDialog_passwd').present()){
        show_error_msg('hzLoginSignupDialog_message_div', '请输入密码');
        $('hzLoginSignupDialog_passwd').focus();
        return ;
    }
    $('hzLoginSignupDialog_email_value').value = $F('hzLoginSignupDialog_email_id');
    $('hzLoginSignupDialog_passwd_value').value = MD5($F('hzLoginSignupDialog_passwd'));
    $('hzLoginSignupDialog_loading_msg').show();
    $('hzLoginSignupDialog_message_div').hide();
    //$('hzLoginSignupDialog_login_btn').disable();
    $('hzLoginSignupDialog_login_form').submit();
}

function hzLoginSignupDialog_Signup_Submit(){
    if ( !$( 'hzLoginSignupDialog_email_address' ).present() ) {
        show_error_msg('hzLoginSignupDialog_show_msg', "请输入电子邮件地址");
        $( 'hzLoginSignupDialog_email_address').focus();
        return false;
    }
        
    if ( !$( 'hzLoginSignupDialog_pass_word1' ).present() ) {
        show_error_msg('hzLoginSignupDialog_show_msg', "请输入密码");
        $( 'hzLoginSignupDialog_pass_word1' ).focus();
        return false;
    }
    if ( $F( 'hzLoginSignupDialog_pass_word1' ).length < 6) {
        show_error_msg('hzLoginSignupDialog_show_msg', "密码长度最少6位");
        $( 'hzLoginSignupDialog_pass_word1' ).focus();
        return false;
    }
    if ( !$('hzLoginSignupDialog_pass_word2' ).present() ) {
        show_error_msg('hzLoginSignupDialog_show_msg', "请输入重复密码");
        $( 'hzLoginSignupDialog_pass_word2' ).focus();
        return false;
    }
    if ($F( 'hzLoginSignupDialog_pass_word1' ) != $F( 'hzLoginSignupDialog_pass_word2')) {
        show_error_msg('hzLoginSignupDialog_show_msg', "两次密码不一致");
        $( 'hzLoginSignupDialog_pass_word2' ).focus();
        return false;
    }
    var email = $F( 'hzLoginSignupDialog_email_address' );
    var pwd1 = MD5($F( 'hzLoginSignupDialog_pass_word1' ));
    $( 'hzLoginSignupDialog_e' ).value = email;
    $( 'hzLoginSignupDialog_e2' ).value = email;
    $( 'hzLoginSignupDialog_passwd1' ).value = pwd1;
    $( 'hzLoginSignupDialog_passwd2' ).value = MD5($F( 'hzLoginSignupDialog_pass_word2' ));
    new Ajax.Request("/Login.do?action=POP_SIGNUP", {
        parameters : $('hzLoginSignupDialog_signup_form').serialize(true),
        requestHeaders : {
            Accept: 'application/json'
        },
        onCreate : function(){
        //$("add_opinion_sending").update('<img src="/images/loading.gif">');
        },
        onSuccess : function(transport){
            //$("add_opinion_sending").update('');
            var json = transport.responseText.evalJSON(true);
            if(json.RETURN){
                redirectPage("/pop_signup_redirect.jsp?section=SUCCESS&email=" + email + "&pwd=" + pwd1);
            }else{
                if(json.MESSAGE == "用户已存在") {
                    redirectPage("/pop_signup_redirect.jsp?section=EMAIL_USED&email=" + email);
                    return;
                }
                show_error_msg("hzLoginSignupDialog_show_msg",json.MESSAGE);
            }
        }.bind(this),
        onComplete : function(){

        }
    })
    //$('hzLoginSignupDialog_signup_form').submit();
    return true;
}

function hzResendVerifyEmail_Submit(){
    
    new Ajax.Request("/Profile3.do?action=RESEND_VERIFY_EMAIL", {
        requestHeaders : {
            Accept: 'application/json'
        },
        onCreate : function(){
        },
        onSuccess : function(transport){
            var json = transport.responseText.evalJSON(true);
            if(json.RETURN){
                alert("邮件已经发送");
            }else{
                alert(json.MESSAGE);
            }
        }.bind(this),
        onComplete : function(){
        }
    })
    
    return false;
}

var FrameHeader = {
    hideNewCountTip : function() {
        $("new_count_tip_div").hide();
        new Ajax.Request("/Profile3.do?action=RESET_NEW_COUNT", {
            requestHeaders : {
                Accept: 'application/json'
            },
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    //alert("成功");
                }else{
                    //alert(json.MESSAGE);
                }
            }.bind(this),
            onComplete : function(){
            }
        })
    }
}
