﻿function limitCounter(textBox, elm, limitNum) {
    if (textBox.value.length > limitNum) {
        textBox.value = textBox.value.substring(0, limitNum);
    } else {
        document.getElementById(elm).innerHTML = textBox.value.length;
    }
}

function msgLimitCounter(textBox, elm, limitNum) {

    //    var tb = document.getElementById(textBox);
    //    if (tb.value.length > limitNum) {
    //        tb.value = textBox.value.substring(0, limitNum);
    //    } else {
    //        document.getElementById(elm).innerHTML = textBox.value.length;
    //    }

    //    document.getElementById(elm).style.fontWeight = "bold";

    //    if (textBox.value.length >= 140) {
    //        document.getElementById(elm).style.color = "red";
    //    }
    //    else if (textBox.value.length >= 100) {
    //        document.getElementById(elm).style.color = "#FC0";
    //    }
    //    else if (textBox.value.length < 100) {
    //        document.getElementById(elm).style.color = "black";

    //    }
}

/************************************************************

C# Example: tb.Attributes.Add("onkeyup", string.Format("messageLimitCounter('{0}', '{1}', {2})", tb.ClientID, lbl.ClientID, 100));

************************************************************/
function messageLimitCounter(textBox, totalCount, limitNum) {
    var tb = document.getElementById(textBox);
    var lbl = document.getElementById(totalCount);

    if (tb.value.length > limitNum) {
        tb.value = tb.value.substring(0, limitNum);
    } else {
        lbl.innerHTML = tb.value.length;
    }

    lbl.style.fontWeight = "bold";

    if (tb.value.length >= (limitNum * .9)) {
        lbl.style.color = "red";
    }
    else if (tb.value.length >= (limitNum * .8)) {
        lbl.style.color = "#FC0";
    }
    else if (tb.value.length < (limitNum * .8)) {
        lbl.style.color = "black";
    }
}

function copyToField(orgionalElm, destinationElm) {
    var orig = document.getElementById(orgionalElm);
    var dest = document.getElementById(destinationElm);
    dest.innerHTML = orig.value;
}

// Same as copyToField
function previewText(dest, source) {
    $get(dest).innerHTML = $get(source).value;
}

