// div copy functions 
function copyDiv( srcId, destId)
{
	var src = document.getElementById(srcId);
	var dest = document.getElementById( destId);
	if (src != null && dest != null) {
		dest.innerHTML = src.innerHTML;
	}
	else {
		if (src == null) {
//			alert( srcId + " does not exist");
		}
		if (dest == null) {
//			alert( destId + " does not exist");
		}
	}
}

function copyDivToIFrame( destId, destUrl)
{
	var dest = document.getElementById( destId);
	dest.innerHTML = '<iframe src="' + destUrl + '" width= "100%" height="400" id="center1" name="center1"></iframe>';
}

function copyToDiv( destId, src)
{
	var dest = document.getElementById( destId);
	dest.innerHTML = src;
}

function showDiv( id)
{
	var div = document.getElementById( id);
	div.style.display = 'block';
}

function hideDiv( id)
{
	var div = document.getElementById( id);
	div.style.display = 'none';
}

// Layout functions


function layoutPanel( panel, layoutNames, start, pmax) {
// copies as many divs as possible into the panel
// returns the next div to be copied or -1 if no more are to be copied
// panelName: the name of the panel
// layoutNames: the array that has names of the divs to be layed out
// start: the array index to start with
	var max = start + pmax; // this should be computed from the desired size of the pane
	if (pmax == -1) {
		max = 32767; // effectively make sure that all portlets are displayed in this panel
	}
	var src = false;

	if (panel != null && start < layoutNames.length) { // check whether the index is valid
		panel.innerHTML = ""; // reset it
		for ( var i = start; i < max && i < layoutNames.length; i++) {
			src = document.getElementById(layoutNames[i][0]);
			var style = '';
			var borderColor = layoutNames[i][1];
			var borderWidth = layoutNames[i][2];
			var bottomPadding = layoutNames[i][3];
			if (borderWidth > 0) {
				style = " style='border: " + borderColor + " " + borderWidth + "px solid;'";
			}
			var divContent = "<div id=" + layoutNames[i] + "_l" + style + ">" + src.innerHTML + "</div>";
			panel.innerHTML += divContent;
			if (bottomPadding > 0) {
				panel.innerHTML += "<div id=" + layoutNames[i] + "_sp" + " style='height:" + bottomPadding + "px;font-size:0;'" + "></div>";
			}
		}
		return max;
	}
	else { // nothing to be done;
		return -1;
	}
}

function layout( layoutList, leftPane, rightPane, bottomPane){
	var next  = 0;
	var leftPanel = document.getElementById( leftPane);
	var rightPanel = document.getElementById( rightPane);
	var bottomPanel = document.getElementById( bottomPane);
	var nLeftDiv = 6; // starting guess
	if (leftPanel != null && rightPanel != null) {
		nLeftDiv = Math.floor((layoutList.length + 1)/2);
	}
	if (rightPanel == null && bottomPanel == null) {
		nLeftDiv = layoutList.length;
	}
	next = layoutPanel( leftPanel, layoutList, next, nLeftDiv);
	if (next != -1) {
		next = layoutPanel( rightPanel, layoutList, next, -1);
		if (next != -1) {
			next = layoutPanel(bottomPanel, layoutList, next, -1);
		}
	}
}

function setStatus( src)
{
	copyToDiv( 'Status', src);
}

function showJobAlertWindow( titleStr, source,w, h)
{
	style = '';
	if (w != -1 && h != -1) {
		var left = (screen.width-w)/2;
	  	var top = (screen.height-h)/2;
	
		style = 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left;
	}
	if (style.length > 0) {
		style += ',';
	}
	style += 'toolbar=yes,menubar=yes,status=yes,resizable=yes,scrollbars=yes';
//	awindow = window.open(source,'jobAlertwindow',style);
	awindow = window.open(source);
	awindow.focus();
}

function replacePage( newSource)
{
	window.location = newSource;
}

function test()
{
	alert("test");
}



