function changeClass(elementid, classname) {
	//alert('changing ' + elementid + ' to ' + classname);
	// Level 1 DOM code	
	if (document.getElementById) {
    	document.getElementById(elementid).className = classname;
	}
	// Microsoft DOM code
	else if (document.all) {
		document.all[elementid].className = classname;
	}
}

function changeBack(elementid, bgcolor) {
	if (document.getElementById) {
    	document.getElementById(elementid).style.backgroundColor = bgcolor;
	}
	// Microsoft DOM code
	else if (document.all) {
		document.all[elementid].style.backgroundColor = bgcolor;
	}
}

function resizeBody() {
	var bodyHeight = document.getElementById('b_lonly').offsetHeight;
	var navHeight = document.getElementById('l').offsetHeight+ 120;
		
	if (navHeight > bodyHeight) {
		document.getElementById('b_lonly').style.height=navHeight + 'px';		
	}
}

function clearForm(){
	for(i=0; i<document.forms[0].elements.length; i++)
	{
		if(document.forms[0].elements[i].type=="text"){
			document.forms[0].elements[i].value="";
		}
		
		if(document.forms[0].elements[i].type=="radio"){
			document.forms[0].elements[i].checked=false;
		}
	}
}

function returnToPreviousPage(){
document.write('&lt;&lt; <A HREF="/logout.html">Log Out</A></br>');
document.write('&lt;&lt; <a href="#" onClick="history.go(-1);">Return to Prior Page</a>');
}

function checkCalendarSubmit() {
	for(i=0; i<document.forms[0].elements.length; i++)
	{
		if(document.forms[0].elements[i].type=="text"){
			document.forms[0].elements[i].value="";
		}
		
		if(document.forms[0].elements[i].type=="radio"){
			document.forms[0].elements[i].checked=false;
		}
	}
}

// BalanceCalendarFeel BalanceCalendarTextArea 
function calendarSubmit(sourceElementID) {

    sourceElement = document.getElementById(sourceElementID);
    destElement = document.getElementById("BalanceCalendarFeelSaving");

    // Make sure the width is a bit smaller than the element it is replacing
    // b/c the CSS on the page is funky. 
    w = sourceElement.offsetWidth - 14;
    h = sourceElement.offsetHeight;

    // Load the background image
    destElement.style.backgroundImage = "url(/img/base/calendar/balance/wellness_entry_progress.gif)";
    
    // Make sure to include units to be compatible with Mozilla 
    destElement.style.height = h+"px";
    destElement.style.width = w+"px";
    
    // Hide the form elements and show the placeholder 
    destElement.style.display = "block";
    sourceElement.style.display = "none";
}

//Change image Source, by name
function changeImageSrc(imageToChange, newImage){
	if(document.images){
		//alert(document.images[imageToChange].src);
		//alert(newImage);
		if(document.images[imageToChange] && newImage){
			document.images[imageToChange].src = newImage;
			//alert("Image changed! " + document.images[imageToChange].src);
		}
	}
	return;
}



/*** Methods for changing opacity of elements ***/
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	//alert(id);
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


/*** Methods to resize an iFrame *****/
function resizeIframeToFitContent(iframe) {
    // This function resizes an IFrame object
    // to fit its content.
    // The IFrame tag must have a unique ID attribute.
	//alert(iframe.id);
    iframe.height = document.frames[iframe.id]
                    .document.body.scrollHeight;
}

function autofitIframe(id){
	if (!window.opera && !document.mimeType && document.all && document.getElementById){
		parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
	}
	else if(document.getElementById) {
		parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px";
	}
}

function autofitIframeByFrameObject(iframe){
	if (!window.opera && !document.mimeType && document.all && document.getElementById){
		parent.document.getElementById(iframe.id).style.height=this.document.body.offsetHeight+"px";
	}
	else if(document.getElementById) {
		parent.document.getElementById(iframe.id).style.height=this.document.body.scrollHeight+"px";
	}
}

// Get the children divs of the element
function getElementChildren(element) {
	var children = new Array();
	// If the element is set
	if(element){
		var child = null;
		var childNodes = element.childNodes;
		var childLength = childNodes.length;

		// Loop through the children
		for(var i = 0; i < childLength; i++){
			child = childNodes[i];
			// If the child and tag name are set
			if(child && child.tagName=='DIV'){
				children.push(child);
			}
		}
	}
	return children;
}

function getElementChildrenRecursive(element) {
	var children = new Array();
	// If the element is set
	if(element){
		var child = null;
		var childNodes = element.childNodes;
		if(childNodes){
			var childLength = childNodes.length;
	
			// Loop through the children
			for(var i = 0; i < childLength; i++){
				child = childNodes[i];
				// If the child and tag name are set
				if(child && child.tagName=='DIV'){
					//alert(child.tagName);
					children.push(child);
					//if the child has child nodes call recursively
					if(child.childNodes.length>0){
						var childChildren = getElementChildrenRecursive(child);
						for(var j=0; j<childChildren.length; j++){
							var childChild = childChildren[j];
							if(childChild && childChild.tagName=='DIV'){
								//alert(childChild.tagName);
								children.push(childChild);
							}
						}
					}
				}
			}
		}
	}
	return children;
}

function displayExampleText(id,visible) {
	//if an element is invisible, make it visible, else make it ivisible
	
	idText = id + "Text";
	idShow = id + "Show";
	idHide = id + "Hide";
	if(document.getElementById(idText)&& document.getElementById(idShow) && document.getElementById(idHide) && visible==1) {
		document.getElementById(idText).style.display="block";
		document.getElementById(idShow).style.display="none";
		document.getElementById(idHide).style.display="inline";
	} else if(document.getElementById(idText)&& document.getElementById(idShow) && document.getElementById(idHide) && visible==0) {
		document.getElementById(idText).style.display="none";
		document.getElementById(idShow).style.display="inline";
		document.getElementById(idHide).style.display="none";
	}
}

