/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
* ---------------------------------------
* Modified by Marian Zamfirescu Apr 2006.
* Added text only char counter (not percentage) and removed text from progress bar.
* Added "bar" input to counter function.
* Modified color correction with "col" variable to work in FF and IE as well as change the fade from white to full red.
* Added reset form function "resetchar" with confirmation.
***********************************************/

function textCounter(field,counter,bar,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(bar).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Character Limit: "+charcnt+" of "+maxlimit+" characters"
	// color correction on style from CCFFF -> CC0000
	col = (typeof document.all)? "background":"background-color";
	setcolor(document.getElementById(bar),percentage,col);
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(100%,"+ (100-percentage) +"%,"+ (100-percentage) +"%)";
}

function resetchar(counter,bar,maxlimit,form) {
	if (confirm ("Are you sure you wish to clear all fields?")) {
		col = (typeof document.all)? "background":"background-color";
		document.getElementById(form).reset();
		document.getElementById(counter).innerHTML="Character Limit: "+ 0 +" of "+maxlimit+" characters";
		document.getElementById(bar).style.width = "0px";
		document.getElementById(bar).style[col] = "rgb(100%,100%,100%)";
	}
}