//***********************************************
// Functions to use for E-mail Forms
//***********************************************




//LIMIT THE INPUT BY x AMOUNT OF CHARACTERS AND SHOW COUNTER
<!-- Web Site: http://www.shiningstar.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
// End -->




//SHOWS/HIDES SUB-SELECTS OF 'REASON' SELECT
function displaySubSelects(selectval) {

var upgrades = document.getElementById('upgradeli');
var other = document.getElementById('otherli');
var program = document.getElementById('programli');

var findli,i;
findli = document.getElementsByTagName('li');

var findselect,j;
findselect = document.getElementsByTagName('select');

	for (i in findli) {
		if (/showthis/.test(findli[i].className)) {
			findli[i].className = 'hidethis';
		} 
	}
	
	for (j in findselect) {
		if (/hidethis/.test(findselect[j].className)) {
			findselect[j].text = '';									   
		}
	}

	if (findli == 'showthis') {	
		findli = 'hidethis';		
	}
	
	else if (selectval == "Other:") {
		other.className = 'showthis';
	}
	
	else {
		program.className = 'showthis';	
	}

}


//ENABLES/DISABLES "OTHER" FIELD
function setElements() {
var reason = document.getElementById('r_Reason');
var other = document.getElementById('other');
var otherli = document.getElementById('otherli');

		if (reason.options[reason.selectedIndex].value == "Other:") {
			other.disabled = false;
			other.className = 'otherenabled';
			otherli.className = 'showthis';
			other.focus();
		}
		
		else {
			other.disabled = true;
			other.className = 'otherdisabled';
			other.value = "";
			otherli.className = 'hidethis';
		}
		
}


//LIMIT THE INPUT BY x AMOUNT OF CHARACTERS AND SHOW COUNTER
<!-- Web Site: http://www.shiningstar.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) { // if too long...trim it!
	alert('You have reached the maximum number of characters: '+maxlimit);
	field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else {
	countfield.value = maxlimit - field.value.length;
	}
}
// End -->



//VALIDATE FORM FIELDS
function validForm() {

var elementid = document.getElementById;

var reason = document.SupportMail.r_Reason;
var other = elementid('other');
var upgrades = elementid('upgradelist');
var programlist = elementid('programlist');


	if (reason.selectedIndex == 0) {
		alert('Please select a reason for e-mailing Customer Service/Sales.');	
		reason.focus();
		return false;
	}
	
	else if (reason.options[reason.selectedIndex].value == 'Upgrades' && upgrades.selectedIndex == 0) {
		alert('Please select a program to upgrade.');
		upgrades.focus();
		return false;
	}
	
	else if (programlist.options[programlist.selectedIndex].value == 'NoProg')  {
		alert('Please select a program.');	
		programlist.focus();
		return false;
	}

	else if (!other.disabled && other.value == '') {
		alert('Please type in a value for the (other) field');
		other.focus();
		return false;
	}
	
	else {
		return true;
	}
	
}


//REPLACE DOUBLE QUOTES WITH SINGLE QUOTES IN PROBLEM/COMMENTS FIELD
function replaceChars(entry) {
out = '"'; // replace this
add = "'"; // with this
temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}

	document.SupportMail.r_Comments.value = temp;
}


function disableSubmit() { 
//Disables submit button on last page to prevent duplicate emails
	var button = document.getElementById('Submit');
	if (!button.disabled) {
		button.disabled = true;
	}
}


//***********END OF DOCUMENT******************
