
// used for form fields where you want to display default example/placement text (replaced onfocus/blur)
function formDefaultText (field, formText, mode) {
	var thisField = document.getElementById(field);
	switch (mode) {
		case "blur":
			if (thisField.value == "") {
				thisField.value = formText;	
			}
		break;
		
		case "focus":
			if (thisField.value == formText) {
				thisField.value = "";	
			}
		break;
		default:
			thisField.value = formText;
		break;
	}
}

// general functions for hiding/displaying blocks of content
function displayBlock(id, display, testCurrentState) {
	if (display == "") var display = "block";
	divBlock = document.getElementById(id);
	
	// test for current state and either hide or show the display
	if (testCurrentState == 1) {
		currentState = divBlock.style.display;
		if ((currentState == "none")||(currentState == "")) {
			divBlock.style.display = display;
		} else {
			divBlock.style.display = "none";
		}
	// default behavior - apply desired display value
	} else {
		divBlock.style.display = display;	
	}
}
function displayNone(id) {
	document.getElementById(id).style.display = "none";
	//setTimeout(document.getElementById(id).style.display = "none", 5000);
}
// use this for hiding multiple generated objects (do-while)
function hideMultiples(position, totalCount, divPrefix) {
	for (i=1; i<=totalCount; i++) {
		if (i != position) {
			document.getElementById(divPrefix + i).style.display = "none";
		} 
		else if (i == position) {
			document.getElementById(divPrefix + i).style.display = "block";
		}
	}
}
// this one functions similarly to hideMultiples() but uses an array of name values, looks for the match, and then toggles visibility
function hideMultiplesArray(currentValue, arrayValue, divPrefix) {
	// first convert arrayValue to an array
	thisArray = arrayValue.split(",");
	
	for (i=0; i<thisArray.length; i++) {
		if (thisArray[i] != currentValue) {
			document.getElementById(divPrefix + thisArray[i]).style.display = "none";
		} 
		else if (thisArray[i] == currentValue) {
			document.getElementById(divPrefix + thisArray[i]).style.display = "block";
		}
	}
}

// use this for tabs to switch tab color based on selection (do-while)
function applyClassMultiples(position, totalCount, divPrefix, classNameCurrent, classNameDefault) {
	for (i=1; i<=totalCount; i++) {
		if (i != position) {
			document.getElementById(divPrefix + i).className = classNameDefault;
		} 
		else if (i == position) {
			document.getElementById(divPrefix + i).className = classNameCurrent;
		}
	}
}

function toggle(id){
    var n = document.getElementById(id);
    n.style.display =  (n.style.display != 'none' ? 'none' : '' );
}


// function for grabbing source content and inserting it into target div
function insertBlock(sourceDiv, targetDiv) {
	document.getElementById(targetDiv).innerHTML = document.getElementById(sourceDiv).innerHTML;	
}


// trim white space (for on-blur events)
function trim(id) {
	stringToTrim = document.getElementById(id).value;
	document.getElementById(id).value = stringToTrim.replace(/^\s+|\s+$/g,"");
}

// function for applying classes to a block element
function applyClassName (id, thisClassName) {
	document.getElementById(id).className = thisClassName;
	
}


function showSubMenu(parentBlock, parent) {
	if (parent == 1) {
		childBlock = parentBlock + "_1";
	} else {
		childBlock = parentBlock;
	}
	displayBlock(childBlock, 'block', '');
}


