// Re-color a DIV element
function reColor(whichEl, mark){
	if (mark == true) {
		whichEl.className = 'highlightRow';  
	} else {
		whichEl.className = 'normalRow';  
	}
}


// Select all the items in the form
function SelectAllChecks(form, idlist, mark) {
	for (i = 0; i < form.elements.length; i++) {
		var item=form.elements[i];
		if (item.name == idlist) {
			item.checked = mark;
			reColor(eval('row'+item.value), mark)
		};
	}
}

// Confirm Delete
function ConfirmDelete(text) {
	if ( text == '' || text == null ) {
		text = 'item';
	}
	return(confirm("Are you sure you want to delete this " + text + "?"));
}

// Relocate the user to the correct folder
function rePost() {
	var citySelected = document.cityForm.cgcity.selectedIndex;
	var folder = 'cities/' + document.cityForm.cgcity.options[citySelected].text.toLowerCase();
	document.location.href = rootFolder + folder + '/index.cfm';
}

// get the band/venue
function pickSearch(tfield, hfield, search_type, nextField, allowMultiples) {
	
	textField = tfield;
	hiddenField = hfield;
	
	var textVar = tfield.value;
	var newstr;
	
	// Replace '&' with its hex equivalent
	if (textVar.length > 0) {
		var re = new RegExp ('&', 'gi') ;
		newstr = textVar.replace(re, '%26') ;
		re = new RegExp (' ', 'gi');
		newstr = newstr.replace(re, '+');
	} else {
		newstr = "";
	}
		
	if (is_nav4up) {
		newHidden = "";
	} else {
		newHidden = hfield.value;
	}
	url = rootFolder + "getthem.cfm?Search_String=" + newstr + "&picked=" + newHidden + "&search_type=" + search_type + "&allowMultiples=" + allowMultiples;
	var win = window.open (url,'picker','location=0,menubar=0,status=1,titlebar=0,toolbar=0,hotkeys=0,scrollbars=1,resizable=1,width=570,height=420,left=0,top=0');  
	if (!win.opener) win.opener = self; // For JS1.0
	if (win.focus) win.focus();
	//init(nextField);
}

function init(nextField) {
	nextField.focus();
}

// SHOW OR HIDE A DIV ELEMENT
function showhide(whichEl){
    whichEl.style.display = (whichEl.style.display == "none" ) ? "" : "none";
}

function clearField(fieldName) {
	fieldName.value = '';
}

// Display the appropriate ticket agents
function ticketShowHide(showNum) {
	if (is_ie) { 
		var city = "TicketAgentsID" + showNum + eval('document.eventsform.cgcityid'+showNum).value;
		var cityDiv = eval(city);
		cityDiv.style.display = "block";
	}
}       

function checkSize(element1, element2, maxLen){
	var len = element1.value.length;
	
	if (len  > maxLen) {
		alert ("Your description has reached the maximum length allowed!");
	   return false;
	} else {
	   element2.value = len;
	}
}

function RadioCheckBox(e1, e2) {
	if ( e1.checked ) {
		e2.checked = false;
	} else if ( e2.checked ) {
		e12.checked = false;
	}
} 

function SetTimeDefaults(varName) {
	if ( eval('document.eventsform.' + varName + "_Hour").selectedIndex != 0 ) {
		eval('document.eventsform.' + varName + "_Minute").selectedIndex = 1;
		eval('document.eventsform.' + varName + "_Suffix").selectedIndex = 2;
	}
}

// Confirm Bulk Delete
function CheckBulk(form, position, item) {
	var len = form.elements.length;
	var i = 0, num_checked = 0;

	for ( i = 0 ; i < len ; i++) {
		if ((form.elements[i].name == 'idList') && (form.elements[i].checked)) {
			num_checked = num_checked + 1;
		}
	}
		
	if (num_checked == 0) {
		alert("You must select at least one " + item);
		return(false);
	} else {	
		if ( form.BulkAction.selectedIndex == position ) {
			return confirm("Are you sure you want to delete the " + item + "(s)");
		}
	}
}

// Toggle an element's css class
function toggleClass(id, class1, class2) {
	if (document.getElementById(id).className == class1) {
		document.getElementById(id).className = class2;
	} else {
		document.getElementById(id).className = class1;
	}
}
	
// Append an item to a list
function listAppend(list, item) {
	if (list.length == 0) {
		return item;
	} else {
		return list + "," + item;
	}
}

// Display a status message
function showStatus(mesg) {
    window.status = mesg ;
    return true ;
}

