/*
common javascript functions included on all pages throughout site
*/

//change the url of a page
function changePage(url) {
	if (url != '') location.href = url;
}


//display a div
function displayBlock(ID) {
	if (ID != '') {	
		document.getElementByID(ID).style.display = 'block';
	}
}

//generic wndow opener
function openWin(url, winName, specs) {
	if (winName == '') winName = 'win';	
	window.open(url, winName, specs);								
}


//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;
}

//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>');
	}
}

//view photo lib img
function viewImg(photoID, imgName) {
	var win = window.open('closeup.cfm?photoID=' + photoID + '&imgName=' + imgName, 'win_photolib_closeup', 'width=300,height=300,resizable=1,scrollbars=0');
	win.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
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;
			}		
		}
	}
}


// pop open a window for the comments/feedback --->
var feedbackWin;
function openFeedback(site) {
	// function opens a new feedback window, or if it's already open, puts that window in focus.
	if (feedbackWin && !feedbackWin.closed) {
		feedbackWin.focus();
	} else {
		feedbackWin=window.open('http://www.provenwinners.com/feedback.cfm?referrer='+site,'feedback','height=400,width=400');
		if (window.focus) {feedbackWin.focus()}
	}
}
