//Copyright (c), 2004, Innovagency

var debugInit='<font color="#FFFF00">Debug Layer</font>';

var sTrOlder = '';
var sValueOlder = '';

document.imageHandler=new Array(); // para o preload
document.IN_swapArray=new Array(); // para o setSource

// ---------------------------------------------- //
// ---- Detecção de layers nos NS's ------------- //
// ---------------------------------------------- //
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;
OP=((navigator.userAgent.indexOf("Opera")!=-1)||(navigator.userAgent.indexOf("Opera/5")!=-1))

// ---------------------------------------------- //
// ----- 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 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;}
}

function IN_writeLayerTOP(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 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;
}

// ---------------------------------------------- //
// - 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;}
}

function IN_setVisibilityTOP(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 Rollover de imagens --------------- //
// ---------------------------------------------- //
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];
	}
}

// ---------------------------------------------- //
// -- Função de alterar a cor ------------------- //
// ------ de um TD ------------------------------ //
// ---------------------------------------------- //
function IN_changeTrColor(sTrColorId_IN,sBgColor_IN){
	if(!NS){
		if(sTrOlder!=sTrColorId_IN){
			if(NS6){
				document.getElementById('tr'+sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			}else{
				document.all('tr'+sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			}
		}
	}
}

function IN_changeTrColorFullID(sTrColorId_IN,sBgColor_IN){
	if(!NS){
		if(sTrOlder!=sTrColorId_IN){
			if(NS6){
				document.getElementById(sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			}else{
				document.all(sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			}
		}
	}
}

function IN_SelectTrColor(sTrColorId_IN,sBgColor_IN){
	if(!NS){
		if(NS6){
			if(sTrOlder!=''){
				document.getElementById('tr'+sTrOlder).style.backgroundColor = '';
			}
			document.getElementById('tr'+sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			sTrOlder=sTrColorId_IN;
		}else{
			if(sTrOlder!=''){
				document.all('tr'+sTrOlder).style.backgroundColor = '';
				document.all('span'+sTrOlder).innerHTML = sValueOlder;
			}
			sValueOlder = document.all('span'+sTrColorId_IN).innerHTML
			document.all('span'+sTrColorId_IN).innerHTML = document.all('span'+sTrColorId_IN).innerHTML;
			document.all('tr'+sTrColorId_IN).style.backgroundColor = sBgColor_IN;
			sTrOlder=sTrColorId_IN;
		}	
	}
}

function IN_changeTdColor(sTdId_IN,sBgColor_IN){	
	
	if(!NS){
		if(NS6){
			document.getElementById(sTdId_IN).style.backgroundColor = "#" + sBgColor_IN;
		}else{
			document.all(sTdId_IN).style.backgroundColor = "#" + sBgColor_IN;
		}	
	}

}

function IN_resetTdColor(sTdPrefix_IN, iMinId_IN, iMaxId_IN, sBgcolor_IN) {
	var i;

	if(!NS){
		if(NS6){
			for(i=iMinId_IN; i<=iMaxId_IN; i++) {
				document.getElementById(sTdPrefix_IN+i).style.backgroundColor = "#" + sBgcolor_IN;
			}
		}else{
			for(i=iMinId_IN; i<=iMaxId_IN; i++) {
				document.all(sTdPrefix_IN+i).style.backgroundColor = "#" + sBgcolor_IN;
			}
		}	
	}
}


//******************************


function changeLblClass( lblID_IN , className_IN )
{
	if ( document.all )
	{
		document.all[ lblID_IN ].className = className_IN;
	}
	else
	{
		document.getElementById( lblID_IN ).className = className_IN;
	}
}


