﻿var twiturl = " http://twitnanum.org #1원의행복_";

function actionUrlChange(urlname) {

}

function CommonSubmit() {
    document.form1.submit();
}

function Keycode(e) {
    var result;
    if (window.event)
        result = window.event.keyCode;
    else if (e)
        result = e.which;
    return result;
}

function number_format(numstr) {//콤마 붙이기
    var numstr = String(numstr);
    var re0 = /(\d+)(\d{3})($|.+)/;
    if (re0.test(numstr))
        return numstr.replace(re0, function(str, p1, p2, p3) { return number_format(p1) + "," + p2 + p3; });
    else return numstr;
}

function loginpopup(url) {
    newwindow = window.open(url, 'tc_popup', 'height=400,width=800,scrollbars=no', 'status=0', 'location=0', 'screenX=400', 'screenY=400');
    if (window.focus) { newwindow.focus() }
    return false;
}

function attSupporters() {
    $.post('/Twitnanum/InsertSupporter', { }, function(data) {
        document.form1.submit();
    });
}
function GetList(pagenumber) {
    if (pagenumber == null) pagenumber = "1";
    $.post('/Twitnanum/GetList', { page: pagenumber }, function(data) {
    $('#listList').html($('#listList').html() + data);
    $('#btntymore').attr('href', 'javascript:GetList(' + (pagenumber + 1) + ');');
        //alert($('#btntmore').attr('onclick'))

    });
}

function GetComment(pagenumber) {
    $('#tmore').hide();
    $('#tmore1').show();
    if (pagenumber == null) pagenumber = "1";
    $.post('/Twitnanum/Getsearch', { q: '#1원의행복_', page: pagenumber }, function(data) {
    $('#cmtList').html($('#cmtList').html() + data.replace(/&apos;/gi,"'"));
    $('#btntmore').attr('href', 'javascript:GetComment(' + (pagenumber + 1) + ');');
        //alert($('#btntmore').attr('onclick'))
        $('#tmore').show();
        $('#tmore1').hide();
    });
}

function setvalue(value) {
    $('#twitvalue').html(number_format(value));
    $.post('/Twitnanum/SetTwitValue', { value: value }, function(data) {
        document.form1.submit();
    });
}

function setgoal() {
    var inputgoal = parseInt(Number($.trim($('#inputgoal').val())));
    $('#inputgoal').val('')
    $('#tsetbox').hide();
    if (!inputgoal) {
        return;
    }
    $('#twitgoal').html(number_format(inputgoal));
    $.post('/Twitnanum/SetTwitGoal', { value: inputgoal }, function(data) {
        document.form1.submit();
    });
}

function WriteStatus(text) {
    $.post('/Twitnanum/StatuseUpd', { status: text }, function(data) {
        if (data == "error") {
            alert("글쓰기에 실패하였습니다.");
        }
    });
}


function ValueTwit() {
    var txt = "내 트윗의 나눔가치는 " + $('#nowvalue').val() + "원 입니다." + twiturl;
    $('#tvalue').html('').css('background', 'url(../img/nanum/bt_tweetv1.gif) no-repeat');
    $.unblockUI();
    $.post('/Twitnanum/StatuseUpd', { status: txt }, function(data) {
        if (data == "error") {
            alert("글쓰기에 실패하였습니다.");
        }
    });   
}

function PopValueTwit() {
    $.blockUI({
    message: $('#replyBox'),
        css: {
            left: ($(window).width() - 540) / 2 + 'px',
            border: 'none',
            width: '540px'
        }
    });
}

function WriteCmt() {
    var inputText = $('#tycomment').val();
    inputText = $.trim(inputText);
    $('#tycomment').val(inputText);
    if (inputText == null || inputText == "") return;
    while (true) {
        if (inputText.indexOf("\n") != "-1") inputText = inputText.replace("\n", "");
        else break;
    }
    var a = twiturl.length;
    var b = (140 - a - inputText.length);
    if (b <= 0) {
        alert('너무 길어요!');
        return;
    }
    var StatusText = "";
    StatusText = inputText + twiturl;
    $('#tnload').show();
    $('#tBtcom').hide();
    $('#tBtcom1').show();
    $.post('/Twitnanum/StatuseUpd', { status: StatusText }, function(data) {
        $('#tnload').hide();
        $('#tBtcom1').hide();
        $('#tBtcom').show();
        if (data == "error") {
            alert("글쓰기에 실패하였습니다.");
        } else {
            $('#tycomment').val('');
        }

    });
}

function checkcmt() {
    var inputText = $('#tycomment').val();
    //if (inputText == null || inputText == "") return;
    while (true) {
        if (inputText.indexOf("\n") != "-1") inputText = inputText.replace("\n", "");
        else break;
    }
    var a = twiturl.length;
    var b = (140 - a - inputText.length);
    if (140 - a - inputText.length < 0) {
        $('#limitcmt').css('color', '#ed1c24').html(b);
    } else {
        $('#limitcmt').css('color', '#888').html(b);
    }

}

