/*
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 win1 = window.open(url, winName, specs);								
	win1.focus();
}

//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 (begin/end with a comma!)
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;
			}		
		}
	}
}


//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;
}

//little workaround for ie "click to activate" issue w/ objects
function writeFlashObj(str, objID) {		
	if (objID) {		
		document.getElementById(objID).innerHTML = str;		
	}
	else {
		document.write(str);
	}		
}


//hide user emails on site so they can't be farmed by spiders
function maskEmail(domain, user, strDisplay) {
	document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
	if (strDisplay == null || strDisplay == '') {
		document.write(user + '@' + domain + '</a>');
	}
	else {
		document.write(strDisplay + '</a>');
	}
}