var isInternetExplorer = (navigator.appName.indexOf("Microsoft") != -1);

/*
future references:
var keycode = isInternetExplorer ? event.keyCode : event.which;
*/

function countSpaces(obj){
	var iLength = obj.value.length;
	var strSpaces = obj.value.match(new RegExp("( )", "g"));
	var countSpaces = strSpaces ? strSpaces.length : 0;
	return countSpaces;
}

function countLineBreaks(obj){
	var iLength = obj.value.length;
	var strLineBreaks = obj.value.match(new RegExp("(\\n)", "g"));
	var countLineBreaks = strLineBreaks ? strLineBreaks.length : 0;
	return countLineBreaks;
}

function textCounter(field, counter_field, maxlimit) {
	var lineBreaks = countLineBreaks(field);
	var adjust = isInternetExplorer ? 1 : 0;
	if (field.value.length - lineBreaks * adjust > maxlimit){
		field.value = field.value.substring(0, maxlimit + lineBreaks * adjust);
		field.focus();
	} else {
		counter_field.value = maxlimit - field.value.length + lineBreaks * adjust;
	}
}

function backToSection(backToURL, forceBackToURL){
	if(forceBackToURL == null) forceBackToURL = false;
	if(history.length > 1 && !forceBackToURL) history.back(); else window.location.href = backToURL;
}

function hideStatus(){
	window.defaultStatus='';
	window.status='';
	return true;
}

function searchReset() {
	if (document.search_form.keyword != null) document.search_form.keyword.value = "";
	if (document.search_form.promo_keyword != null) document.search_form.promo_keyword.value = "";
	if (document.search_form.event_keyword != null) document.search_form.event_keyword.value = "";
	if (document.search_form.category_id != null) document.search_form.category_id.value = "";
	if (document.search_form.country_id != null) document.search_form.country_id.value = "";
	if (document.search_form.state_id != null) document.search_form.state_id.value = "";
	if (document.search_form.region_id != null) document.search_form.region_id.value = "";
	if (document.search_form.miles != null) document.search_form.miles.value = "";
	if (document.search_form.zip != null) document.search_form.zip.value = "";
}
