function changeTxt_cp(f) {
    if (f.value == 1) {
        document.getElementById("cp_ltitle").innerHTML = "<b>I use</b>";
        document.getElementById("cp_rtitle").innerHTML = "<b>I use supports or assistance to</b>";
    } else if (f.value == 0) {
        document.getElementById("cp_ltitle").innerHTML = "<b>The person or people I know with a disability use / I use</b>";
        document.getElementById("cp_rtitle").innerHTML = "<b>The person or people I know with a disability use supports or assistance to / I use supports or assistance to</b>";
    } else {
        document.getElementById("cp_ltitle").innerHTML = "<b>The person or people I know with a disability use</b>";
        document.getElementById("cp_rtitle").innerHTML = "<b>The person or people I know with a disability use supports or assistance to</b>";
    }
}
function hide_divs(total) {
    var i=1;
    for(i=1;i<=total;i++) {
        if (document.getElementById("block"+i)) {
            document.getElementById("block"+i).style.display = "none";
        }
    }
}
function hide_divs_NEW(total) {
    var i=1;
    for(i=1;i<=total;i++) {
        if (document.getElementById("block"+i)) {
            document.getElementById("block"+i).style.display = "none";
        }
    }
}
function unhide_div(d) {
    if (document.getElementById(d).style.display == "block")
        document.getElementById(d).style.display = "none";
    else
        document.getElementById(d).style.display = "block";
}

//FUNCTIONS FOR NEW REVIEW FORM
function toggleNewReviewOver(optionId) {

    if (optionId) {

        var optionElement = "newReviewOption_"+optionId;
        var optionClass = "optionCell rating_"+optionId+"_over";
        var selectedClass = "optionCell rating_"+optionId+"_selected";
        if (document.getElementById(optionElement)) {
            if (document.getElementById(optionElement).className != selectedClass) {
                document.getElementById(optionElement).className = optionClass;
            }
        }

    }

}

function toggleNewReviewOut(optionId) {

    if (optionId) {

        var optionElement = "newReviewOption_"+optionId;
        var optionClass = "optionCell rating_"+optionId+"_norm";
        var selectedClass = "optionCell rating_"+optionId+"_selected";
        if (document.getElementById(optionElement)) {
            if (document.getElementById(optionElement).className != selectedClass) {
                document.getElementById(optionElement).className = optionClass;
            }
        }

    }

}

function toggleNewReviewClick(optionId) {

    if (optionId) {

        //GO THROUGH ALL AND SELECT OR UNSELECT AS NECESSARY
        for (var counter=1; counter<=5; counter++) {

            var optionElement = "newReviewOption_"+counter;
            var optionRadio = "ratingOption_"+counter;

            if (counter == optionId) {
                var optionClass = "optionCell rating_"+counter+"_selected";
                var radioSelected = true;
            } else {
                var optionClass = "optionCell rating_"+counter+"_norm";                        
                var radioSelected = false;
            }

            if (document.getElementById(optionElement)) {
                document.getElementById(optionElement).className = optionClass;
            }
            if (document.getElementById(optionRadio)) {
                document.getElementById(optionRadio).checked = radioSelected;
            }

        }
        
    }

}

function textCounter(newEvent) {

    //GET KEY ENTERED
    var keyID = newEvent.keyCode;

    //DISPLAY WORD COUNTER
    if (document.getElementById("wordCountHolder")) {
        document.getElementById("wordCountHolder").style.display = "block";
    }                
    
    //SET LIMIT
    var maxlimit = 150;

    //SET FIELD
    var field = document.getElementById("review");

    //GET NUMBER OF WORDS
    numWords = countWords(field.value);

    //alert(numWords);

    //ALWAYS ALLOW BACKSPACE AND DELETE                
    if (numWords > maxlimit && (keyID != 8 && keyID != 46)) {

        //IF TOO LONG, RETURN FALSE
        var toReturn = false;
    
    } else {
    
        var toReturn = true;
    
    }

    //DISPLAY LIMIT
    if (document.getElementById("wordCount")) {
        document.getElementById("wordCount").innerHTML = numWords;
    }

    //UPDATE CLASS
    if (document.getElementById("wordCountHolder")) {

        if (numWords >= maxlimit) {

            document.getElementById("wordCountHolder").className = "newReviewMax";

        } else {

            document.getElementById("wordCountHolder").className = "newReviewNorm";
        
        }
    }

    return toReturn;

}

function countWords(string) {
    var numWords = 0;
    a=string.replace(/\s/g," ");
    a=a.split(" ");
    for (z=0; z<a.length; z++) {
        if (a[z].length > 0) numWords++;
    }
    return numWords;
} 

