//   ************************************************************************//
//   * Module Name		: Index.js											*//
//   * Release			: 1.0												*//
//   * Date				: 20/10/2006										*//
//   * Project			: AGSE_TT											*//
//   * Author			: aCOSwt											*//
//   * Description		: Index.html management scripts						*//
//   * History			: 1.0 : First Site Version							*//
//   * Language			: JavaScript										*//
//   * Compatibility	: FireFox 2 - IE 7 - Opera 9 - Konqueror 3			*//
//   ************************************************************************//

//******************************* Global References *************************//

var	Solde, Active;
	
//*************************** Inscript HTML page init ***********************//

function initInscript(){

	var	i, j, newtr, newtd, newdata;
	
	initPage(1,3,8);
	Solde=0;
	Active=new Array();
	for(i=1;i<_IB.length;i++){
		newtr=document.createElement("tr");
		newtr.id=i;
		_IB[i][5]=0;
		for(j=1;j<4;j++){
			newtd=document.createElement("td");
			newtd.innerHTML=_IB[i][j]+((j==3)?" &#8364;":"");
			switch(j){
				case 1: if(_IB[i][3]=="0")
						j=4;
					else
						newtd.style.width="260px";
					break;
				case 2: newtd.style.width="290px";
					break;
				case 3: newtd.style.textAlign="right";
					break;}
			newtr.appendChild(newtd);
			newtr.onmouseover=function(){this.style.backgroundColor="#F6E600";};
			newtr.onmouseout=function(){offselective(this);};
			newtr.onclick=function(){togglesel(this);};}
		document.getElementById("INSCR_"+_IB[i][0]).appendChild(newtr);
		Active[parseInt(_IB[i][0])]=0;}}

//**************************** Take selection into account *******************//

function togglesel(idtr){

	var	intidtr, oldidactive;
	
	intidtr=parseInt(idtr.id);
	if(_IB[intidtr][5]){
		_IB[intidtr][5]=0;
		Solde-=_IB[intidtr][3];
		idtr.style.backgroundColor="transparent";
		if(_IB[intidtr][4])
			Active[parseInt(_IB[intidtr][0])]=0;}
	else{
		_IB[intidtr][5]=1;
		Solde+=_IB[intidtr][3];
		idtr.style.backgroundColor="#F6E600";
		oldidactive=Active[parseInt(_IB[intidtr][0])];
		if(_IB[intidtr][4]){
			if(oldidactive){
				document.getElementById(oldidactive).style.backgroundColor="transparent";
				_IB[oldidactive][5]=0;
				Solde-=_IB[oldidactive][3];}
			Active[parseInt(_IB[intidtr][0])]=idtr.id;}}
	document.getElementById("SOLDE").innerHTML="&#8364; "+Math.round(Solde*100)/100;}

//***************************** TR Off if not already selected ****************//

function offselective(idtr){

	if(!_IB[parseInt(idtr.id)][5])
		idtr.style.backgroundColor="transparent";}

//****************************** Print preparation ****************************//

function prepimp(){

	var	i;

	for(i=1;i<_IB.length;i++)
		if(InscriptBase[i][5]==0)
			document.getElementById(i).style.display="none";
	window.print();
	for(i=1;i<_IB.length;i++)
		if(_IB[i][5]==0)
			document.getElementById(i).style.display="";}