var highestElement;
var currentActiveCase;

function swapDepths(id) {
	if (!highestElement){
		document.getElementById(id).style.zIndex = getNextHighestDepth()+1;
	}else{
		var d = document.getElementById(id).style.zIndex;
		document.getElementById(id).style.zIndex = highestElement.style.zIndex;
		highestElement.style.zIndex = d;
	}

	highestElement = document.getElementById(id);
}

function getNextHighestDepth() {
	var depth = 0;
	var doc = document.getElementsByTagName('div');
	for (var i = 0; i < doc.length; i++){
	   //Do Work on doc[i], this sets the border of the Div black
	   var newDepth = (doc[i].style.zIndex) ? doc[i].style.zIndex : 0;
	   if (newDepth > depth){
	   	depth = newDepth;
	   }
	}
	return parseInt(depth)+1;
}

function drop(id, dropStart, dropEnd, duration) {
    var timer = 0;
    if (dropStart > dropEnd) {
    	var dropspeed = dropStart / (duration/10);
    	for (i = 0; i >= (duration/10); i++){
		setTimeout("changePosition("+(dropStart - (dropspeed*timer))+",'"+id+"')",(timer * 10));
		timer++;
	}
	setTimeout("changePosition("+dropStart+",'"+id+"')",duration);
    }else if (dropStart < dropEnd) {
    	var dropspeed = dropEnd / (duration/10);
    	for (i = 0; i <= (duration/10); i++){
		setTimeout("changePosition("+(dropspeed*timer)+",'"+id+"')", (timer * 10));
		timer++;
	}
	setTimeout("changePosition("+dropStart+",'"+id+"')", duration);
    }
}
function changePosition(pos, id) {
	var object = document.getElementById(id);
	object.style.left = pos+"px";
}


function opacity(id, opacStart, opacEnd, duration) {
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
    	var opacityspeed = opacStart / (duration/10);
        for(i = 0; i <= (duration/10); i++) {
            setTimeout("changeOpac(" +(opacStart - (opacityspeed * timer)) + ",'" + id + "')", (timer * 10));
            timer++;
        }
    } else if(opacStart < opacEnd) {
    	var opacityspeed = opacEnd / (duration/10);
        for(i = 0; i <= (duration/10); i++)
            {
            setTimeout("changeOpac(" + (opacityspeed * timer) + ",'" + id + "')",(timer * 10));
            timer++;
        }
    }
}

function changeDisplay(type, id) {
	 var object = document.getElementById(id).style;
	object.display = type;
}

//change the opacity for different browsers
function changeOpac(opacity, 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 swapCase
* Swap cases
* @Param	id	current id to swap.
*/
function swapCase(id) {
	if (currentActiveCase != id){
	opacity(id, 0, 100, 1000);
	setTimeout("changeDisplay('block','"+id+"')", 0);
	if (currentActiveCase){
	  opacity(currentActiveCase, 100,0,1000);
	  setTimeout("changeDisplay('none','"+currentActiveCase+"')", 1000);
	}

	currentActiveCase = id;
	}
}

function fold(id,img) {
 var listtoshow = document.getElementById(id);
 var image = document.getElementById(img);
 if(listtoshow.style.display == 'block') {
 listtoshow.style.display = 'none';
 image.style.backgroundPosition = '0 0px';
 } else {
 listtoshow.style.display = 'block';
 image.style.backgroundPosition = '0 11px';
 }
}


function check(id) {
	checkThis = document.getElementById(id);
	checkThis.checked = 'checked';
}

function submitform() {
	document.orderBy.submit();
}
function submitpaging() {
	document.paging.submit();
}

function showTab(which) {
	groupMsg = document.getElementById('groupMsg');
	myMsg = document.getElementById('myMsg');
	
	if(which == 'myMsg') {
		groupMsg.className = 'hiddenTab';
		myMsg.className = 'showTab';
	} else {
		groupMsg.className = 'showTab';
		myMsg.className = 'hiddenTab';
	}
}
