// JavaScript Document///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// FILE: gh_script_textboxprogress.js                                  //
/////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////
// FUNCTION: textCounter()                //
// PURPOSE: This function counts and      //
//          limits the number of chars in //
//          a text box including the use  //
//          of a progress bar.            //
////////////////////////////////////////////
function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	} else { 
		
		// progress bar percentage
		var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit);
		document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
		document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
		
		// color correction on style from CCFFF -> CC0000
		setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

///////////////////////////////////////////
// FUNCTION: setcolor()                  //
// PURPOSE: This function sets the color //
//          of the progress bar's        //
//          color.                       //
///////////////////////////////////////////
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(0%,0%,"+(100-percentage)+"%)";
}