// JavaScript Document
var browser_type = navigator.appVersion.split("MSIE");
var browser_version = parseFloat(browser_type[1]);
var browser_flag = 0;

function Fragmenteditor(fragment){
	var sizes = getPageSize();
	var alltags = document.getElementsByTagName('*');
	
	for(var t in alltags) {
		try {
			if(!alltags[t].old_style) alltags[t].old_style = new Object;
			alltags[t].style.position=getStyle(alltags[t],'position');
			alltags[t].style.zIndex = 1;
			if(alltags[t].tagName == 'OBJECT' || alltags[t].tagName == 'EMBED' ) {
				alltags[t].style.display='none';
			}
		}catch(e){}
	}

	var iframe = document.createElement('IFRAME');
	iframe.src = 'fckeditor/editor.php?text='+fragment;
	iframe.id = 'Fragmenteditor_box'
	
	if(browser_version >= 5 && browser_version < 7){
		iframe.style.position = 'relative';
		browser_flag = 1;
	}
	else {
		iframe.style.position = 'absolute';
	}

	var width,height,top,left;
	width  = Math.round(sizes[0] / 1.5);
	height = Math.round(400);
	top = (sizes[1] - height) / 4;
	left = (sizes[0] - width) / 2;
	iframe.style.width = iframe.width = width +'px';
	iframe.style.height = iframe.height = height +'px';	
	
	iframe.style.left = left +'px';
	
	//iframe.style.top = top +'px';
	iframe.style.top = scrollOffset()+100+'px';
	iframe.style.border = 0;
	iframe.style.zIndex = 140;
	
	document.body.insertBefore(iframe, document.body.firstChild);
	
	var opacityDiv = document.createElement('div');
	opacityDiv.id = 'Fragmenteditor_opacityDiv'
	opacityDiv.style.position = 'absolute';
	opacityDiv.style.width = opacityDiv.width = '100%';
	opacityDiv.style.height = opacityDiv.height = sizes[1] + 'px';
	/*opacityDiv.style.height = Math.max(document.body.offsetHeight,screen.availHeight) + 'px';*/
	opacityDiv.style.left = 0;
	opacityDiv.style.top = 0;
	opacityDiv.style.backgroundColor = '#000';
	opacityDiv.style.opacity = 0.75;
	opacityDiv.style.mozOpacity = 0.75;
	opacityDiv.style['filter'] = 'alpha(opacity=75)';
	opacityDiv.style.zIndex = 105;
	opacityDiv.ondblclick = function() { document.location.reload(); };
	document.body.insertBefore(opacityDiv, document.body.firstChild);
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function scrollOffset(){
	var x,y;
	
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}	
	
	return y;
}

