/*
common javascript functions included on all pages throughout site
*/

//change the url of a page
function changePage(url) {
	if (url != '') location.href = url;
}


//generic wndow opener
function openWin(url, winName, specs) {
	if (winName == '') winName = 'win';	
	var win = window.open(url, winName, specs);								
	win.focus();
}

//count characters left in a form field
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...this trims it!
		field.value = field.value.substring(0, maxlimit);
	else // otherwise, update 'characters left' counter
		countfield.value = maxlimit - field.value.length;
}

//clear all form fields
//whichForm: name of form we're dealing with
//ignoreFields: comma-delimited list of field names we don't want to touch
function clearForm(whichForm, ignoreFields) {	
	for (var i=0; i<whichForm.elements.length; i++) {
		curElement = whichForm.elements[i];
		//alert(curElement.type)
		if (ignoreFields.indexOf(',' + curElement.name + ',') == -1) {
			if (curElement.type == 'text') {		
				curElement.value = '';
			}
			else if (curElement.type == 'select-one') {		
				curElement.selectedIndex = 0;
			}		
			else if (curElement.type == 'checkbox') {		
				curElement.checked = false;
			}		
			else if (curElement.type == 'radio') {		
				curElement.checked = false;
			}
		}
	}
}

//hide user emails on site so they can't be farmed by spiders
function hideEmail(domain, user, strDisplay) {
	document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
	if (strDisplay == null || strDisplay == '') {
		document.write(user + '@' + domain + '</a>');
	}
	else {
		document.write(strDisplay + '</a>');
	}
}