//Copyright (c), 2003, g3|dev

NS=(document.layers && !document.all)?1:0
NS6=(document.getElementById && !document.all)?1:0
MACOld=(navigator.userAgent.indexOf("Mac")!=-1&&navigator.userAgent.indexOf("5.1")==-1)?1:0;
MZi=((navigator.userAgent.indexOf("rv:1")!=-1||navigator.userAgent.indexOf("Mozilla/5")!=-1)&&navigator.userAgent.indexOf("Nets")==-1)?1:0;

document.imageHandler=new Array(); // para o preload
document.IN_swapArray=new Array(); // para o setSource

var debugInit='<font color="#FFFF00">Debug Layer</font>';

// ---------------------------------------------- //
// ----- Funções de leitura de propriedades ----- //
// ---------------------------------------------- //

// ---------------------------------------------- //
// ---- Função de aquisição do objecto layer ---- //
// ---------------------------------------------- //
// [oLayer_IN] - ID da layer a obter
// ---------------------------------------------- //
function IN_getLayer(oLayer_IN, doc) { //v1.0
	var i,tLayer;if(!doc) doc=document;
	if(!(tLayer=doc[oLayer_IN])&&!(doc.all)&&!NS) tLayer=doc.getElementById(oLayer_IN);
	if(!tLayer&&!(tLayer=doc[oLayer_IN])&&doc.all) tLayer=doc.all[oLayer_IN];
	for(i=0;!tLayer&&doc.layers&&i<doc.layers.length;i++) tLayer=IN_getLayer(oLayer_IN,doc.layers[i].document);
	return tLayer;
}

// ---------------------------------------------- //
// - Função para todos verem qual a layer Parente //
// ---------------------------------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a obter o seu parente
// [alerter] - Variável que a acciona um Alert
//			   com o nome da layer parente
//			   para debug, nao fazer referencia
//             se nao for o caso de debug
// ---------------------------------------------- //
function IN_findParent(oLayer) { //v1.0
	layer=IN_getLayer(oLayer);
	strResult=(NS)?layer.parentLayer.id:layer.parentNode.id;
	if(!strResult)strResult=false;
	return strResult;
}

// ---------------------------------------------- //
// --- Função para o IE ler os valores do Clip -- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a obter os valores
// [which] - 0=top, 1=right, 2=bottom, 3=left
// ---------------------------------------------- //
function IN_ieGetClips(oLayer,which) { //v1.0
		fClip=IN_getLayer(oLayer);
		Clip=fClip.style.clip;		
		iClip=parseInt(Clip.substring(5,Clip.length-1).split(" ")[which]);
		return iClip;
}
// ---------------------------------------------- //
// ---------------------------------------------- //
// ---------------------------------------------- //
// id
// top
// left
// position
// zIndex
// height
// width
// visibility
// bgColor
// color
// fontFamily
// fontSize
// clipTop
// clipLeft
// clipRight
// clipBottom
// parent
// ---------------------------------------------- //
function IN_getLayerProperties(oLayer) {
	var tLayer=IN_getLayer(oLayer);
	this.id=tLayer.id;
	this.top=(NS)?tLayer.top:tLayer.style.pixelTop;
	this.left=(NS)?tLayer.left:tLayer.style.pixelLeft;
	this.position=(NS)?tLayer.Position:tLayer.style.position;
	this.zIndex=(NS)?tLayer.zIndex:tLayer.style.zIndex;
	this.height=(NS)?tLayer.clip.height:tLayer.clientHeight;
	this.width=(NS)?tLayer.clip.width:tLayer.clientWidth;
	this.visibility=(NS)?tLayer.visibility:tLayer.style.visibility;
	this.bgColor=(NS)?tLayer.bgColor:tLayer.style.backgroundColor;
	this.color=(NS)?tLayer.color:tLayer.style.color;
	this.fontFamily=(NS)?tLayer.fontFamily:tLayer.style.fontFamily;
	this.fontSize=(NS)?tLayer.fontSize:tLayer.style.fontSize;
	this.clipTop=(NS)?tLayer.clip.top:IN_ieGetClips(oLayer,0);
	this.clipLeft=(NS)?tLayer.clip.left:IN_ieGetClips(oLayer,3);
	this.clipRight=(NS)?tLayer.clip.right:IN_ieGetClips(oLayer,1);
	this.clipBottom=(NS)?tLayer.clip.bottom:IN_ieGetClips(oLayer,2);
	this.parent=(NS)?tLayer.parentLayer.id:tLayer.parentNode.id;
	this.load=(NS)?tLayer.load.length:false;
	this.src=(NS)?tLayer.src:false;
	//this.frameName=(NS)?tLayer.window.name:"nao saca o nome da frame em que está";
	this.NAME=(NS)?tLayer.NAME:tLayer.NAME;
	//this.content=(NS)?tLayer.document.getSelection:tLayer.innerHTML;
}

function IN_alertLayerProperties(oLayer) {
	var str="";
	tPrps=IN_getLayer(oLayer)//new IN_getLayerProperties(oLayer);//
	for(i in tPrps){
		str=str+"\'"+i+"\': "+tPrps[i]+"---";
	}
	str=str+tPrps.document.getSelection
	alert(str);
}

function IN_getDocumentProperties() {
	this.altura=(NS)?window.innerHeight:document.body.offsetHeight-4;
	this.largura=(NS)?window.innerWidth:document.body.offsetWidth-4;
	this.pixelVisivelTopo=(NS)?window.pageYOffset:document.body.scrollTop;
	this.pixelVisivelEsquerda=(NS)?window.pageXOffset:document.body.scrollLeft;
	this.locationHref=document.location.href;
}

function IN_getWindowProperties() {
	this.name=window.name;
	this.location=window.location;
	this.historyLength=window.history.length;
	this.windowTopLength=window.top.length;
	this.window=window?true:false;
}

// ---------------------------------------------- //
// ---------------------------------------------- //


// ---------------------------------------------- //
// ----- Funções de escrita de propriedades ----- //
// ---------------------------------------------- //

// ---------------------------------------------- //
// ----- Funções de Movimento ------------------- //
// ---------------------------------------------- //
// esta função só move na horizontal
// [oLayer] - ID da layer a ser movida
// [iTo] - Coordenada Final
// [iSpeed] - Velocidade do contador,
//			  quanto menor mais rápido
// [iPixel] - quantos pixeis cada vez que
//			  corre a função em conjunto com
//			  o iSpeed define a velocidade do
//			  movimento
// [checker] - é necessária a sua referencia
//			   no principio para funcionamento
//			   da função
// ---------------------------------------------- //
var IN_moverTimeout;
function IN_moveBy(oLayer,iTo,iSpeed,iPixel,checker) { //v1.0
	clearTimeout(IN_moverTimeout);iArgs=IN_moveBy.arguments.length;
	if(iArgs>=5){nLayer=IN_getLayer(oLayer);document.IN_layer=nLayer;}strDir="right";leftAux=(NS)?document.IN_layer.left:document.IN_layer.style.pixelLeft;if(leftAux>iTo){iPixel=-iPixel;strDir="left";}
	with(document.IN_layer) {iLeft=(NS)?left:style.pixelLeft;if(((strDir=='right') && ((parseInt(iLeft)+iPixel)<=iTo)) || ((strDir=='left') && ((parseInt(iLeft)+iPixel)>=iTo))){if(NS){left=iLeft+iPixel;}else{style.pixelLeft=iLeft+iPixel;}IN_moverTimeout=setTimeout("IN_moveBy('"+oLayer+"',"+iTo+","+iSpeed+","+Math.abs(iPixel)+")",iSpeed);}else{IN_stopMover();}}
}
function IN_stopMover() { //v1.0
	clearTimeout(IN_moverTimeout);
}

// ---------------------------------------------- //
// ----- Função de Clip ------------------------- //
// ---------------------------------------------- //
// esta função só funciona na vertical
// [oLayer] - ID da layer a ser Clipada
// [iLastClip] - Valor Final do clip bottom
// [iPixel] - quantos pixeis cada vez que
//			  corre a função em conjunto com
//			  o iSpeed define a velocidade do
//			  movimento
// [iSpeed] - Velocidade do contador,
//			  quanto menor mais rápido
// [iNowClip] - não fazer referencia no
//				chamamento da função
// ---------------------------------------------- //
var IN_clipperTimeout;
function IN_setClipHeight(oLayer,iLastClip,iPixel,iSpeed,iNowClip) { //v1.0
	clearTimeout(IN_clipperTimeout);iDir=1;iArgs=IN_setClipHeight.arguments.length;nLayer=IN_getLayer(oLayer);document.IN_clipLayer=nLayer;
	if(iArgs<5){if(NS){nowClip=document.IN_clipLayer.clip.bottom;}else{clipAux=document.IN_clipLayer.style.clip;nowClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[2]);widthClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[1]);}
	}else{nowClip=iNowClip;if(!NS){clipAux=document.IN_clipLayer.style.clip;widthClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[1]);}}	
	if(nowClip>iLastClip){nextClip=parseInt(nowClip-iPixel);iDir=2;}else{nextClip=parseInt(nowClip+iPixel);iDir=1;}
	if(NS){document.IN_clipLayer.clip.bottom=nextClip;}else{document.IN_clipLayer.style.clip='rect(0px '+widthClip+'px '+nextClip+'px 0px)';}
	if((nextClip<=iLastClip && iDir==1)||(nextClip>=iLastClip && iDir==2)){IN_clipperTimeout=setTimeout("IN_setClipHeight('"+oLayer+"',"+iLastClip+","+parseInt(Math.abs(iPixel))+","+iSpeed+","+nextClip+")",iSpeed);
	}else{IN_stopClipper();if(NS){document.IN_clipLayer.clip.bottom=iLastClip;}else{document.IN_clipLayer.style.clip='rect(0px '+widthClip+'px '+iLastClip+'px 0px)';}}
}
function IN_stopClipper() { //v1.0
	clearTimeout(IN_clipperTimeout);
}

var IN_clipperTimeoutWidth;
function IN_setClipWidth(oLayer,iLastClip,iPixel,iSpeed,iNowClip) { //v1.0
	clearTimeout(IN_clipperTimeoutWidth);iDir=1;iArgs=IN_setClipWidth.arguments.length;nLayer=IN_getLayer(oLayer);document.IN_clipLayerWidth=nLayer;
	if(iArgs<5){if(NS){nowClip=document.IN_clipLayerWidth.clip.right;}else{clipAux=document.IN_clipLayerWidth.style.clip;nowClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[1]);widthClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[2]);}
	}else{nowClip=iNowClip;if(!NS){clipAux=document.IN_clipLayerWidth.style.clip;widthClip=parseInt(clipAux.substring(5,clipAux.length-1).split(" ")[2]);}}	
	if(nowClip>iLastClip){nextClip=parseInt(nowClip-iPixel);iDir=2;}else{nextClip=parseInt(nowClip+iPixel);iDir=1;}
	if(NS){document.IN_clipLayerWidth.clip.right=nextClip;}else{document.IN_clipLayerWidth.style.clip='rect(0px '+nextClip+'px '+widthClip+'px 0px)';}
	if((nextClip<=iLastClip && iDir==1)||(nextClip>=iLastClip && iDir==2)){IN_clipperTimeoutWidth=setTimeout("IN_setClipWidth('"+oLayer+"',"+iLastClip+","+parseInt(Math.abs(iPixel))+","+iSpeed+","+nextClip+")",iSpeed);
	}else{IN_stopClipperWidth();if(NS){document.IN_clipLayerWidth.clip.right=iLastClip;}else{document.IN_clipLayerWidth.style.clip='rect(0px '+iLastClip+'px '+widthClip+'px 0px)';}}
}
function IN_stopClipperWidth() { //v1.0
	clearTimeout(IN_clipperTimeoutWidth);
}


// ---------------------------------------------- //
// - Função de Mostrar Layer e esconder restantes //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser mostrada
//			  se 'all' mostra todas as que se
//			  encontram no array de controle
// ---------------------------------------------- //
function IN_hideShowLayers(oLayer_IN) { //v1.0
	var i,lArray;lArray=new Array('teste','teste1');
	if(oLayer_IN=='all'){for (i=0;i<lArray.length;i++){IN_layer1=IN_getLayer(lArray[i]);if(NS){IN_layer1.visibility='show';for(j=0;j<IN_layer1.document.layers.length;j++) {IN_layer1.document.layers[j].visibility='show';}}else{IN_layer1.style.visibility='visible';for(j=0;j<IN_layer1.childNodes.length;j++) {if(IN_layer1.childNodes[j]) {IN_layer1.childNodes[j].style.visibility='visible';}}}}
	}else{IN_oLayer=IN_getLayer(oLayer_IN);for (i=0;i<lArray.length;i++){IN_layer2=IN_getLayer(lArray[i]);if(NS){IN_layer2.visibility='hide';for(j=0;j<IN_layer2.document.layers.length;j++) {IN_layer2.document.layers[j].visibility='hide';}}else{IN_layer2.style.visibility='hidden';for(j=0;j<IN_layer2.childNodes.length;j++) {if(IN_layer2.childNodes[j]) {IN_layer2.childNodes[j].style.visibility='hidden';}}}}
		if(IN_oLayer){if(NS){IN_oLayer.visibility='show';for(j=0;j<IN_oLayer.document.layers.length;j++) {IN_oLayer.document.layers[j].visibility='show';}}else{IN_oLayer.style.visibility='visible';for(j=0;j<IN_oLayer.childNodes.length;j++) {if(IN_oLayer.childNodes[j]) {IN_oLayer.childNodes[j].style.visibility='visible';}}}}
	}
}

// ---------------------------------------------- //
// - Função de controlo de visibilidade --------- //
// ------ de uma layer -------------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser alterada
// [strStatus] - visible,hidden
// ---------------------------------------------- //
function IN_setVisibility(oLayer_IN,strStatus) { //v1.0
	oLayer=IN_getLayer(oLayer_IN);if(NS){oLayer.visibility=strStatus;}else{oLayer.style.visibility=strStatus;}
}

// ---------------------------------------------- //
// - Função de controlo de posição -------------- //
// ------ de uma layer -------------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser alterada
// [coordX] - coordenada no Eixo X
// [coordX] - coordenada no Eixo X
// [keepInside] - true ou false,
//				  define se a layer se mantem
//				  sempre dentro da parente ou se pode
//				  receber valores que façam com
//				  k esta desapareça
// ---------------------------------------------- //
function IN_setPositionLayer(oLayer,coordX,coordY,keepInside) { //v1.0
	var IN_oLayer,oParent,IN_oParent,thisClipTop,thisClipLeft,thisClipRight,thisClipBottom,parentClipTop,parentClipLeft,parentClipRight,parentClipBottom
	IN_oLayer=IN_getLayer(oLayer);oParent=IN_findParent(oLayer);if(keepInside){IN_oParent=IN_getLayer(oParent);}
	thisClipTop=(NS)?IN_oLayer.clip.top:IN_ieGetClips(oLayer,3);thisClipLeft=(NS)?IN_oLayer.clip.left:IN_ieGetClips(oLayer,0);thisClipRight=(NS)?IN_oLayer.clip.right:IN_ieGetClips(oLayer,1);thisClipBottom=(NS)?IN_oLayer.clip.bottom:IN_ieGetClips(oLayer,2);
	if(IN_oParent)parentClipTop=(NS)?IN_oParent.clip.top:IN_ieGetClips(oParent,3);if(IN_oParent)parentClipLeft=(NS)?IN_oParent.clip.left:IN_ieGetClips(oParent,0);if(IN_oParent)parentClipRight=(NS)?IN_oParent.clip.right:IN_ieGetClips(oParent,1);if(IN_oParent)parentClipBottom=(NS)?IN_oParent.clip.bottom:IN_ieGetClips(oParent,2);
	coordX=parseInt(coordX);coordY=parseInt(coordY);
	if(NS){
		if(!isNaN(coordX)){if(coordX>parentClipRight-thisClipRight && keepInside){IN_oLayer.left=parentClipRight-thisClipRight;} else if (coordX<parentClipLeft && keepInside) {IN_oLayer.left=parentClipLeft;} else {IN_oLayer.left=coordX;}}
		if(!isNaN(coordY)){if(coordY>parentClipBottom-thisClipBottom && keepInside){IN_oLayer.top=parentClipBottom-thisClipBottom;} else if (coordY<parentClipTop && keepInside) {IN_oLayer.top=parentClipTop;} else {IN_oLayer.top=coordY;}}
	}else{
		if(!isNaN(coordX)){if(coordX>parentClipRight-thisClipRight && keepInside){IN_oLayer.style.left=parentClipRight-thisClipRight;} else if (coordX<parentClipLeft && keepInside) {IN_oLayer.style.left=parentClipLeft;} else {IN_oLayer.style.left=coordX;}}
		if(!isNaN(coordY)){if(coordY>parentClipBottom-thisClipBottom && keepInside){IN_oLayer.style.top=parentClipBottom-thisClipBottom;} else if (coordY<parentClipTop && keepInside) {IN_oLayer.style.top=parentClipTop;} else {IN_oLayer.style.top=coordY;}}
	}
}

// ---------------------------------------------- //
// - Função de controlo de escrita -------------- //
// ------ dentro de uma layer ------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser alterada
// [strText] - Texto ou código a ser escrito
// ---------------------------------------------- //
function IN_writeLayer(oLayer_IN,strText) { //v1.0
	oLayer=IN_getLayer(oLayer_IN);if(NS){oLayer.document.open();oLayer.document.write(strText);oLayer.document.close();}else{oLayer.innerHTML=strText;}
}

// ---------------------------------------------- //
// ---------------------------------------------- //
// ---------------------------------------------- //


// ---------------------------------------------- //
// - Função de controlo de visibilidade --------- //
// ------ de uma layer -------------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser alterada
// [strStatus] - visible,hidden
// ---------------------------------------------- //
function IN_setVisibility(oLayer_IN,strStatus) { //v1.0
	oLayer=IN_getLayer(oLayer_IN);if(NS){oLayer.visibility=strStatus;}else{oLayer.style.visibility=strStatus;}
}



function IN_getImage(oImage_IN, doc) { //v1.0
	var i,tImage;if(!doc) doc=document;
	if(!(tImage=doc.images[oImage_IN])&&!(doc.all)&&doc.getElementById) tImage=doc.getElementById[oImage_IN];
	if(!(tImage=doc.images[oImage_IN])&&doc.all) tImage=doc.all[oImage_IN];
	for(i=0;!tImage&&doc.images&&i<doc.layers.length;i++) tImage=IN_getImage(oImage_IN,doc.layers[i].document);return tImage;
}

function IN_setImageSource(oImage_IN,strNewSrc) { //v1.0
	tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=strNewSrc;}
}

function IN_setImageSource2(oImage_IN,l) { //v1.0
	strNewSrc=document.imageHandler[l].src;
	tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=strNewSrc;}
}

function IN_setImageSourceOriginal(oImage_IN) { //v1.0
	tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=document.IN_swapArray[oImage_IN];}
}

function IN_preloadImages() {
	for(i=0;i<IN_preloadImages.arguments.length;i++) {
		document.imageHandler[IN_preloadImages.arguments[i]]=new Image();
		document.imageHandler[IN_preloadImages.arguments[i]].src=IN_preloadImages.arguments[i];
	}
}

// ---------------------------------------------- //
// ---------------------------------------------- //
// ---------------------------------------------- //


function IN_submitPagingForm(sFormName_IN, sField_IN, iTotalPages_IN, iAddPage_IN){
	var oFormField = eval("document." + sFormName_IN + "." + sField_IN);
	oFormField.value = parseInt(parseInt(oFormField.value)+iAddPage_IN);
	if(oFormField){
		if(oFormField.value>iTotalPages_IN){
			oFormField.value=iTotalPages_IN;
		}else if(oFormField.value<1){
			oFormField.value=1;
		}
	}
	var oForm = eval("document." + sFormName_IN);
	oForm.submit();
}