﻿// JScript 파일
// 마이페이지
/////////////sentense.js///////////////////////////
function showSentenceCount(obj, scategory)
{
    highlightBtn(obj);
    new Ajax('SentenceCount.aspx?cat='+scategory+(uid?"&uid="+uid:""), {update:'divSentenceCount'});
    showSentence(null, scategory, '');
}
function showSentence(obj, scategory, sbid, noshow)
{
    highlightText(obj);
    category =  scategory;
    bid = sbid;
    alterParam(category, bid);
    showViewType();
    hideViewTypes(bid);
    if (!noshow) {p=1; showList();}
}
function alterParam(scategory, sbid)
{
    if (sbid == 'edu' || sbid == 'forum') {category = sbid; bid = '';}
    if (scategory == 'newsfocus' || scategory == 'spoll') {category = 'surae'; bid = scategory;}
}
function hideViewTypes(sbid)
{
    if (sbid == "spoll") hideViewType();
}
function highlightBtn(obj)
{
    if (!obj) return;
    var as = obj.parentNode.parentNode.getElementsByTagName("SPAN");
    for (var i=0; i<as.length; i++) {
        var fb = as[i].className.lastIndexOf("B");
        if (fb < 1) as[i].className = (as[i].className + "B");
        else continue;
    }
    var cname = obj.className;
    obj.className = cname.substring(0, cname.length-1);
}
function highlightText(obj)
{
    if (!obj) return;
    var as = obj.parentNode.parentNode.parentNode.getElementsByTagName("A");
    for (var i=0; i<as.length; i++) {
        if (as[i].style.fontWeight=="bold") as[i].style.fontWeight="normal";
    }
    obj.style.fontWeight = "bold";
}
function showViewType()
{
    $('btnViewTypeA').style.display='inline-block';
    $('btnViewTypeW').style.display='inline-block';
    //onViewTypeClick($('btnViewTypeA'));
}
function hideViewType() {$HIDEB('btnViewTypeA'); $HIDEB('btnViewTypeW'); onViewTypeClick($('btnViewTypeC'));}
function onViewTypeClick(obj)
{
    if ($('btnViewTypeA')) $('btnViewTypeA').className = "BtnmytextTab1B";
    if ($('btnViewTypeW')) $('btnViewTypeW').className = "BtnmytextTab2B";
    if ($('btnViewTypeC')) $('btnViewTypeC').className = "BtnmytextTab3B";
    switch (obj.id) {
        case "btnViewTypeA" : viewType = "A"; obj.className = "BtnmytextTab1"; setViewTypeA(); break;
        case "btnViewTypeW" : viewType = "W"; obj.className = "BtnmytextTab2"; setViewTypeW(); break;
        case "btnViewTypeC" : viewType = "C"; obj.className = "BtnmytextTab3"; setViewTypeC(); break;
    }
    p=1; showList();
}
function setViewTypeA() {$('spnH1').innerHTML="제목";$('spnH2').innerHTML="댓글작성일";$('spnH3').innerHTML="조회/추천";}
function setViewTypeW() {$('spnH1').innerHTML="제목";$('spnH2').innerHTML="등록일";$('spnH3').innerHTML="조회/추천";}
function setViewTypeC() {$('spnH1').innerHTML="내가 작성한 댓글";$('spnH2').innerHTML="등록일";$('spnH3').innerHTML="공감/비공감";}
function onSortClick2(o)
{
    if ($('SortingM1')) $('SortingM1').className = "SortingM1";
    if ($('SortingM2')) $('SortingM2').className = "SortingM2";
    switch (o.id) {
        case "SortingM1" : ot = "C"; o.className = "SortingMM1C"; break;
        case "SortingM2" : ot = "R"; o.className = "SortingMM2C"; break;
    }
    p=1; showList();
}
function historyMypageChange(loc, data)
{
    var arg = loc.split("|")[1];
    if (!arg) return;
    p = parseInt(getArgVal(arg, "p"));
    category = getArgVal(arg, "gro");
    bid = getArgVal(arg, "bid");
    viewType = getArgVal(arg, "viw");
    showSentenceCount($('btn' + ($('hidUType').value=="D"?"D":"C") + category), category);
    showSentence($('btnE' + (bid.length>0?bid:category)), category, bid, true);
    onViewTypeClick($('btnViewType'+viewType));
    ot = getArgVal(arg, "ot");
    onSortClick2($('SortingM'+(ot=='C'?'1':'2')));
    //alert("p="+p+"|category="+category+"|bid="+bid+"|viewType="+viewType+"|ot="+ot);
    showList();
}
/////////////sentense.js///////////////////////////
/////////////friend.js///////////////////////////
function getFlagList() {return "신청:0|지인:A|거절:R|취소:C";}
function getTypeList() {return "일반:FR01|고객:FR05|동료:FR02";}
function changeTypeFriend(fid,type) {expertAjax('ctm', '&fid='+fid+'&typ='+type, onFriendAjax);}
function changeFlagFriend(fid,flag)
{
    if (flag == "F" && !confirm("취소하시겠습니까?")) return;
    if (flag == "C" && !confirm("취소하시겠습니까?")) return;
    if (flag == "R" && !confirm("거절하시겠습니까?")) return;
    expertAjax('cfm', '&fid='+fid+'&fla='+flag, onFriendAjax);
}
function onFriendAjax(retstr)
{
    if (trim(retstr)=="0") {alert('시스템에러입니다. 잠시 후 다시 시도하시기 바랍니다.');return;}
    alert("정상처리되었습니다."); showList();
}
/////////////friend.js///////////////////////////
