﻿/*Count the characters man*/

function textCounter(field, countfield, maxlimit) 
{
    if (field.value.length > maxlimit)
    { field.value = field.value.substring(0, maxlimit); }
    else
    { countfield.value = maxlimit - field.value.length; }
}

function wordCounter(field, countfield, maxlimit) 
{
    wordcounter = 0;
    for (x = 0; x < field.value.length; x++) {
        if (field.value.charAt(x) == " " && field.value.charAt(x - 1) != " ") { wordcounter++ }  // Counts the spaces while ignoring double spaces, usually one in between each word.
        if (wordcounter > 250) { field.value = field.value.substring(0, x); }
        else { countfield.value = maxlimit - wordcounter; }
    }
}

function part2() 
{
    var part2 = document.getElementById('addComment');
    if (part2.className == 'hidden') {
        part2.className = 'visible';
    } else {
        part2.className = 'hidden';
    }
}

function toggle(flag) {
    var div1 = document.getElementById('divTxt1');
    var div2 = document.getElementById('divTxt2');
    if (div1) {
        div1.style.display = flag ? 'block' : 'none';
    }
    if (div2) {
        div2.style.display = flag ? 'block' : 'none';
    }
}

