
function autoFit() {
	/*
	alert("This web page containg " + document.frames.length + " iframe element");
	alert(document.frames[0].document.body.scrollHeight);
	*/
	
	// document.frames[0].resizeTo(document.frames[0].document.body.scrollWidth, document.frames[0].document.body.scrollHeight)
	/*
	var thisIndex = new Number;
	for(thisIndex=0;thisIndex<=document.frames.lenght;thisIndex++) {
		alert(document.frames[thisIndex].document.body.scrollheight);
		document.frames[thisIndex].resizeTo(document.frames[thisIndex].document.body.scrollWidth, document.frames[thisIndex].document.body.scrollHeight)
	}
	*/
}

function autoFit2(layerName) {
	var iObj = eval('IFRAME_' + layerName);
	try {
		if(iObj.document.domain==document.domain) {
			iObj.resizeTo(iObj.document.body.scrollWidth, iObj.document.body.scrollHeight);
		}
	} catch (iExp) {
		// ...
	}
}

var reloadCounter = new Number;
function restartRequest(iCount) {
	reloadCounter = iCount;
	setTimeout("reloadPage()", 1000);
} 

function reloadPage() {
	document.location.reload();
}

function quickEditWebpart(iWebpart) {
	var regExp = /WEBPART_/g;
	var iElement = iWebpart.replace(regExp,'');
	window.open('layout/handleWebpart.asp?PAGE=' + iPageName + '&OBJ=' + iElement);
}

function quickEditArea(iArea) {
	window.open('layout/editArea.asp?AREA=' + iArea + '&PAGE=' + iPageName);
}

var parentElement = new String;

function showHTMLcode(webpartName) {
	var iCode = window.open('about:blank');
	iCode.document.body.innerText = document.getElementById(webpartName).innerHTML;
}

function supportTextshowLayerArea(selectedElement, xPos, yPos) {	
	// ...	
}

function supportTextshowLayer(childElement, xPos, yPos) {
	// ...
	var regExp = /CHILD_/g;
	parentElement = childElement.replace(regExp, '');

	try {
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML = '<img style=\"cursor: hand;\" onClick=javascript:supportTextHideLayer(\"' + childElement + '\") src=layout\\imag\\hidepane.gif align=center border=1><br>';
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML += 'Technical information: <br>Nome fisico: <b>' + parentElement + '</b>';
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML += '<br>Posizione: (left,top): ' + xPos + ',' + yPos;
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML += '<br>Dimensione: (WxH): ' + (eval(parentElement).getBoundingClientRect().right - eval(parentElement).getBoundingClientRect().left) + ',' + (eval(parentElement).getBoundingClientRect().bottom - eval(parentElement).getBoundingClientRect().top);
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML += '<br>Peso del testo (escluse immagini): ' + eval(parentElement).innerText.length + ' bytes';
		SUPPORT_TEXT_LAYER_CONTENT.innerHTML += '<br><a style=\"font-weight: bold;\" href=javascript:quickEditWebpart(\"' + parentElement + '\") >Configura questa webpart</a> | <a style=\"font-weight: bold;\" href=javascript:showHTMLcode(\"' + parentElement + '\")>Visualizza codice HTML</a>';
	
		SUPPORT_TEXT_LAYER.style.left = xPos + 10;
		SUPPORT_TEXT_LAYER.style.top = yPos + 10;
		SUPPORT_TEXT_LAYER.style.display = '';
	} catch (e) {
		// ...
	}	
}

function supportTextHideLayer(childElement) {
	SUPPORT_TEXT_LAYER_CONTENT.innerHTML = '';
	SUPPORT_TEXT_LAYER.style.display = 'none';
	eval(parentElement).style.border='solid 1pt #ffcc00';
}

function supportTextHideLayer2(childElement) {
	// ...
}

function showWebparts() {

	window.scrollTo(0,0);
	// highlight webpart items...
	for(var thisIndex=0;thisIndex<document.all.length;thisIndex++) {
		if(document.all[thisIndex].tagName=='DIV' && document.all[thisIndex].className=='web_part') {
			document.all[thisIndex].style.border='solid 1pt #ffcc00';
			document.body.innerHTML+='<DIV ID=CHILD_' + document.all[thisIndex].id + ' onMouseOver=javascript:supportTextshowLayer(\"CHILD_' + document.all[thisIndex].id + '\",' + document.all[thisIndex].getBoundingClientRect().left + ',' + document.all[thisIndex].getBoundingClientRect().top + ') onMouseOut=javascript:supportTextHideLayer2(\"CHILD_' + document.all[thisIndex].id + '\") onclick=javascript:quickEditWebpart(\"' + document.all[thisIndex].id + '\") style=\"filter: alpha(opacity: 50); cursor: hand; color: white; font: 7pt verdana; height: 12pt; width: 14pt; background: black; position: absolute; left: ' + document.all[thisIndex].getBoundingClientRect().left + 'px; top: ' + document.all[thisIndex].getBoundingClientRect().top + 'px;\" >&nbsp;webpart&nbsp;</DIV>';
		}
	}
	PORTAL_LINK_WEBPART.disabled = true;
	PORTAL_LINK_WEBPART.href = 'javascript:document.location.reload()';
}

function showAreas() {
	window.scrollTo(0,0);
	for(var thisIndex=0;thisIndex<document.all.length;thisIndex++) {
		// if(document.all[thisIndex].tagName=='DIV' && document.all[thisIndex].className=='COLUMN_AREA') {
		if(document.all[thisIndex].className=='COLUMN_AREA') {
			document.all[thisIndex].style.border='solid 1pt #ffcc66';
			var thisAreaName = document.all[thisIndex].id;
			
			var originalAreaName = thisAreaName.substring(5);
			document.body.innerHTML+='<DIV onMouseOver=javascript:supportTextshowLayerArea(\"' + 
				originalAreaName + '\",' + 
				document.all[thisIndex].getBoundingClientRect().left + ',' + 
				document.all[thisIndex].getBoundingClientRect().top + ') onclick=javascript:quickEditArea(\"' + originalAreaName + '\") style=\"filter: alpha(opacity: 50); cursor: hand; color: white; font: 7pt verdana; height: 12pt; width: 14pt; background: black; position: absolute; left: ' + document.all[thisIndex].getBoundingClientRect().left + 'px; top: ' + document.all[thisIndex].getBoundingClientRect().top + 'px;\" >&nbsp;' + originalAreaName + '&nbsp;</DIV>';		}
	}
	PORTAL_LINK_AREA.disabled = true;
	PORTAL_LINK_AREA.href = 'javascript:document.location.reload()';

}

function changeStyle() {
	// alert(document.styleSheets[0].id);
	document.styleSheets[0].disabled = true;
	
	document.createStyleSheet('lib\\accessibleStyle.txt');
}


var isWin = false;
var isIE7 = false;
var isMAc = false;
var isWin2k = false;
var isWinSP2 = false;
var isOther = false;
var isSafari = false;
var isSafari2 = false;
var isOpera = false;
var isNN = false;
var isIE = false;

var agent = new String;

function detect() {
	// simplify things
	agent 	= navigator.userAgent.toLowerCase();
	
	// detect platform
	this.isMac		= (agent.indexOf('mac') != -1);
	this.isWin		= (agent.indexOf('win') != -1);
	this.isIE7 		= (agent.indexOf('msie 7.') != -1);

	this.isWin2k	= (this.isWin && (
			agent.indexOf('nt 5') != -1));
	this.isWinSP2	= (this.isWin && (
			agent.indexOf('xp') != -1 || 
			agent.indexOf('sv1') != -1));
	this.isOther	= (
			agent.indexOf('unix') != -1 || 
			agent.indexOf('sunos') != -1 || 
			agent.indexOf('bsd') != -1 ||
			agent.indexOf('x11') != -1 || 
			agent.indexOf('linux') != -1);
	
	// detect browser
	this.isSafari	= (agent.indexOf('safari') != -1);
	this.isSafari2 = (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));
	this.isOpera	= (agent.indexOf('opera') != -1);
	this.isNN		= (agent.indexOf('netscape') != -1);
	this.isIE		= (agent.indexOf('msie') != -1);
}	

	detect();


	

