﻿

function actionUrlChange(urlname) {

}


function CheckFollow() {
    $.post('/Home/CheckFollow', { user_b: $('#viewID').val() }, function(data) {
        if (data.indexOf('true') > -1) {
            SetFollow(false);
        }
        else {
            SetFollow(true);
        }
    });
}

function SetFollow(param) {
    if (param) {
        $('#follow').html('<a href="#" onclick="AddFollow();return false;" title="follow">Follow</a>').addClass('follow');
    } else {
    $('#follow').html('<span>Following</span>').addClass('following'); ;
    }
}

function WriteStatus(text) {
    //alert(text);
    $.post('/Home/StatuseUpd', { status: text }, function(data) {
        return data;
    });
}

function WriteCmtDB(cmt,statusesID) {
    $.post('/Home/CmtUpd', { ID: $('#viewID').val(), cmt: cmt, statusID: statusesID }, function(data) {
        return data;
    });
}

function TweetWorth() {
    var statusText = "";
    if ($('#viewID').val() == $('#loginID').val()) {
        statusText = $('#twitmy').text();
    }
    else {
        statusText = '@' + $('#viewname').val() + " " + $('#twityour').text();
    }
    statusText = statusText + " " + $('#twitworth').text() + " " + $.trim($('#fx').text()) + $.trim($('#fxworth').text()) + " http://tweetyam.com/" + $('#viewname').val();
    var imsiTxt = $('#btnTweetWorth>a').html();
    $('#btnTweetWorth').html('<span>' + imsiTxt + '</span>').css('background', 'url(../img/bt_tweeted.gif) no-repeat');
    var data = WriteStatus(statusText);
    if (data == "error") {
        
        //alert("Complete!");
    } else {
        
    }
}

function TweetWorthPop() {
    var TweetWorthText = "";
    if ($('#viewID').val() == $('#loginID').val()) {
        TweetWorthText = $('#twitmy').text();
    }
    else {
        TweetWorthText = '@' + $('#viewname').val() + " " + $('#twityour').text();
    }
    TweetWorthText = TweetWorthText + " " + $('#twitworth').text() + " " + $.trim($('#fx').text()) + $.trim($('#fxworth').text()) + " http://tweetyam.com/" + $('#viewname').val()+" ";
    
    $.blockUI({
        message: $('#replyBox'),
        css: {
            left: ($(window).width() - 560) / 2 + 'px',
            border: 'none',
            width: '560px' 
        }
    });
    $('#tweetvalueadd').val(TweetWorthText).focus();
    TweetWorthPopCheck();
}

function TweetWorthPopCheck() {
    var inputText = $('#tweetvalueadd').val();
    //if (inputText == null || inputText == "") return;
    while (true) {
        if (inputText.indexOf("\n") != "-1") inputText = inputText.replace("\n", "");
        else break;
    }
    var b = (140 - inputText.length) + ' / ' + 140;
    if (140 - inputText.length < 0) {
        $('#tweetvaluelimit').css('color', '#ed1c24').html(b);
    } else {
        $('#tweetvaluelimit').css('color', '#888').html(b);
    }

}

function TweetWorthGo(){
    var inputText = $('#tweetvalueadd').val();
    //if (inputText == null || inputText == "") return;
    while (true) {
        if (inputText.indexOf("\n") != "-1") inputText = inputText.replace("\n", "");
        else break;
    }
    var b = 140 - inputText.length;
    if (b < 0) {
        alert('Text Length Over');
        return;
    }
    $.unblockUI();
    var data = WriteStatus(inputText);
    if (data == "error") {

        //alert("Complete!");
    } else {

    }
   
}

function AddFollow() {
    $.post('/Home/AddFollow', { addId: $('#viewname').val() }, function(data) {
        if (data == "error" || data == "no") {
            //alert(data);
        } else {
            SetFollow(false);
        }
    });
}

function GetCmt(pagenumber) {
    $.post('/Home/GetCmt', { ID: $('#viewID').val(), page: pagenumber }, function(data) {
        //alert(data);
        var result = eval("(" + data + ")");
        if (result.status == "error") {
            $('#tyBox9').hide();
        }
        else {
            if (result.cnt == "max") {
                $('#morelink').attr('href', 'javascript:GetCmt(' + (pagenumber + 1) + ');');
                $('#tmore').show();
            } else {
                $('#tmore').hide();
            }
            if (pagenumber == 1) {
                $('#cmtList').html(result.txt);
            }
            else {
                $('#cmtList').html($('#cmtList').html() + result.txt);
            }
        }

    });
}

function GetVisiter(a) {
    $.post('/Home/GetVisiter', { ID: $('#viewID').val(), cnt: a }, function(data) {
        var arrData = String(data).split('!:!');
        $('#visituserlist').html(arrData[1]);
        if (a <= 40 && Number(arrData[0] >= 40)) {
            $('#visitmore').show();
        } else {
            $('#visitmore').hide();
        }
    });
}
function GetInterest(a) {
    $.post('/Home/GetInterest', { ID: $('#category_id').text(), cnt: a }, function(data) {
        var arrData = String(data).split('!:!');
        $('#samecateuserlist').html(arrData[1]);
        if (a <= 40 && Number(arrData[0] >= 40)) {
            $('#commonmore').show();
        } else {
            $('#commonmore').hide();
        }
    });
}

function SaveInterest() {
    $.post('/Home/SaveInterest', { ID: $('#cate').val(), viewID: $('#viewID').val() }, function(data) {
        if (data.toString() != "error") {
           
        }
        else {
            //alert("Error - Not Save");
        }
        document.form1.submit();
    });
}
var tid;
var tidCount=0;

function GetValueID() {
    $.post('/Home/GetValueID', { ID: $('#viewID').val() }, function(data) {
        if (data.toString() == "error") {
            clearTimeout(tid);
            alert("Not Loding Value");
        }
        else {
            var dataes = data.toString().split(':');
            if (Number(dataes[0]) < 100) {
                $('#rate').html(dataes[0] + "%");
                if (tidCount > 30 && Number(dataes[0]) == 0) {
                    //동작중지
                    clearTimeout(tid);
                    $('#tyLoading').show();
                    $('#filmLayer').hide();
                }
                else {
                    tidCount++;
                    tid = setTimeout(GetValueID, 1000);
                }
            }
            else {
                clearTimeout(tid);
                $('#exKrw').text(dataes[1]);
                $('#exUsd').text(dataes[2]);
                $('#exEur').text(dataes[3]);
                $('#exJpy').text(dataes[4]);
                $('#exCny').text(dataes[5]);
                //$('#filmLayer').hide();
                $('#tyPrice').show();
                $('#filmLayer').hide();
                var fxstr = $('#fx').text();
                if (fxstr == '￦') $('#fxworth').text(dataes[1]);
                //else if (fxstr == 'EUR') $('#fxworth').text(dataes[3]);
                else if (fxstr == '￥') $('#fxworth').text(dataes[4]);
                else $('#fxworth').text(dataes[2]);

            }
        }
    });
}

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 viewuser = $('#viewname').val();
    var a = viewuser.length * 2 + 21;
    var b = (140 - a - inputText.length) + ' / ' + (140 - a);
    if (140 - a - inputText.length < 0) {
        $('#limitcmt').css('color', '#ed1c24').html(b);
    } else {
        $('#limitcmt').css('color', '#888').html(b);
    }

}

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 viewuser=$('#viewname').val();
    var a = viewuser.length * 2 + 21;
    var b = (140 - a - inputText.length);
    if (b <= 0) {
        alert('Text Length Over');
        return;
    }
    var StatusText = "";
    if ($('#viewID').val() != $('#loginID').val()) StatusText = "@" + $('#viewname').val() + " ";
    StatusText = StatusText + inputText + " http://tweetyam.com/" + viewuser;
    $.post('/Home/StatuseUpd', { status: StatusText }, function(data) {
        if (data == "error") {
            alert(data);
        } else {
            $.post('/Home/CmtUpd', { ID: $('#viewID').val(), cmt: inputText, statusID: data }, function(data) {
                if (data == "error") {
                    alert(data);
                }
                else {
                    GetCmt(1);
                    $('#tycomment').val('');
                }
            });
        }
    });

}



function WriteCmtRun(cmtText, statusText) {
    alert(cmtText + ":" + statusText);
    
}
