/////////////////////////////////////////////////////
// change_smartbar
// Requires jquery
/////////////////////////////////////////////////////

function change_smartbar(state){
	var smartbarTabs = $('.smartbar_tab');
	var currentTab = document.getElementById(state);
	for (var i = 0; i < smartbarTabs.length; i++){
		if(smartbarTabs[i].id != state){
			smartbarTabs[i].style.display="none";
		}
		else if (state == 'smartbar_admin') {
			smartbarTabs[i].style.display="block";
		}
		else {
			smartbarTabs[i].style.display="";
		}
	}
	return false;
}

/////////////////////////////////////////////////////
// 
/////////////////////////////////////////////////////


var confirmAbort = {
	confirmAbortActiveFlag: false,
	textObject: null,

	confirmAbortActive: function(caafParm, textIdParm) {
		var callingError = false;

		if (caafParm == true || caafParm == false) {
			confirmAbortActiveFlag = caafParm;
			textObject = confirmAbortActiveFlag ? document.getElementById(textIdParm) : null;

			if (confirmAbortActiveFlag && textObject == null) {
				callingError = true;
			}
		}
		else {
			callingError = true;
		}

		if (callingError) {
			alert("confirmAbort.confirmAbortActive not called correctly! [" +
				caafParm + ", " + textIdParm + "]");
		}
	},

	handleConfirmAbort: function() {
		if (typeof confirmAbortActiveFlag != 'undefined' && confirmAbortActiveFlag && textObject != null && !confirmAbort.isBlank(textObject.value)) {
			return "You have an unsaved post on this page.";
		}
		else {
			return;
		}
	},

	isBlank: function(stringCheck) {
		var blank = true;
		var inDirective = false;
		var currentChar;
		if (stringCheck != null && stringCheck.length > 0) {
			for (var index = 0; index < stringCheck.length; ++index) {
				currentChar = stringCheck.charAt(index);
				if (currentChar == '<') {
					if (!inDirective) {
						inDirective = true;
					}
					else {
						blank = false;
						break;
					}
				}
				else if (inDirective && currentChar == '>') {
					inDirective = false;
				}
				else if (!inDirective && currentChar == '&') {
					if ("&nbsp;" == stringCheck.substring(index, index + 6).toLowerCase()) {
						index += 5;
					}
					else {
						blank = false;
						break;
					}
				}
				else if (!inDirective && currentChar != ' ') {
					blank = false;
					break;
				}
			}
		}
		return blank;
	}
};
