var iframeIDChain = new Array();
var zindex = 2;

/**
 * This is the main function that creates the iframeWindow
 * @param	id of the window
 * @param	url to to display page
 * @param	x position
 * @param	y position
 * @param	w dimension
 * @param	h dimension
 * @param	isScoll (true) with scrollbars on the borders, (false) no scrollbars
 * @param	isVisible define the to be shown or not
 */
function createBrowserWindow(id, url, x, y, w, h, isScroll, isVisible) {
	//create iFrame
	var iFrame = null;
	try {
		iFrame = document.createElement("<iframe name='" + id + "'/>");
	} catch (error) {
		iFrame = document.createElement('iframe');
	}
	
	iFrame.setAttribute('src', url);
	iFrame.setAttribute('id', id);
	iFrame.name = id;
	iFrame.target = '_self';
	iFrame.style.width = w + "px";
	iFrame.style.height = h + "px";
	iFrame.style.left = x + "px";
	iFrame.style.top = y + "px";
	iFrame.style.position = "absolute";
	///iFrame.style.zIndex = iframeIDChain.length;
	iFrame.style.border = 0 + "px";
	iFrame.frameborder = 0 + "px";
	if (isVisible) {
		iFrame.style.display = "block";
	} else {
		iFrame.style.display = "none";
	}
	
	if (isScroll) {
		iFrame.setAttribute('scrolling', 'auto');
	} else {
		iFrame.setAttribute('scrolling', 'no');
	}
	
	document.body.appendChild(iFrame);
	iframeIDChain.push(id);
}

/**
 * Moves iframe to different location.
 * @param	id of iframe
 * @param	x new position
 * @param	y new position
 */
function moveTo(id, x, y) {
	var iFrame = top.document.getElementById(id);
	iFrame.style.left = x + "px";
	iFrame.style.top = y + "px";
}

/**
 * Resize iframe dimensions.
 * @param	id of iframe
 * @param	w new dimension
 * @param	h new dimension
 */
function sizeTo(id, w, h) {
	var iFrame = top.document.getElementById(id);
	iFrame.style.width = w + "px";
	iFrame.style.height = h + "px";
}

/**
 * Moves and resizes iframe
 * @param	id of iframe
 * @param	x new postion
 * @param	y new postion
 * @param	w new dimension
 * @param	h new dimension
 */
function sizeToMoveTo(id, x, y, w, h) {
	zindex++;
	var iFrame = top.document.getElementById(id);
	iFrame.style.left = x + "px";
	iFrame.style.zIndex = zindex;
	iFrame.style.top = y + "px";
	iFrame.style.width = w + "px";
	iFrame.style.height = h + "px";
}

/**
 * Close iframe.
 * @param	id of iframe.
 */
function goClose(id) {
	var iFrame = document.getElementById(id);
	top.document.body.removeChild(iFrame);
}

/**
 * Go to url page in iframe.
 * @param	id of iframe.
 * @param	url URL.
 */
function goURL(id, url) {
	var iFrame = document.getElementById(id); 
	iFrame.src = url;
}

/**
 * Refresh iframe content.
 * @param	id of iframe.
 */
function goRefresh(id) {
	window.frames[id].reload(true);
}

/**
 * Go back.
 * @param	id of frame.
 */
function goBack(id) {
	//var x = document.getElementById(id);
	//x.contentWindow.history.go(-1);
	window.history.back();
}

/**
 * Go forward
 * @param	id of iframe.
 */
function goForward(id) {
	//var x = document.getElementById(id);
	//x.contentWindow.history.go(1);
	window.history.forward();
}

/**
 * Hide and show iframe
 * @param	id of iframe
 * @param	flag (hide) hide and (frue) for show, then x,y,w,h values are used
 * @param	x position for show
 * @param	y position for show
 * @param	w dimenson for show
 * @param	h dimension for show
 */
function visible(id, flag, x, y, w, h) {
	if (flag) {
		zindex++;
		var iFrame = top.document.getElementById(id);
		iFrame.style.left = x + "px";
		iFrame.style.top = y + "px";
		iFrame.style.width = w + "px";
		iFrame.style.height = h + "px";
		iFrame.style.display = "block";
		iFrame.style.zIndex = zindex;
	} else {
		var iFrame = top.document.getElementById(id);
		iFrame.style.display = "none";
	}
}

function visibility(id, flag) {
	if (flag) {
		zindex++;
		var iFrame = top.document.getElementById(id);
		iFrame.style.display = "block";
		iFrame.style.zIndex = zindex;
	} else {
		var iFrame = top.document.getElementById(id);
		iFrame.style.display = "none";
	}
}
