var site = {};

var adresseImagesCommunes='http://www.stat.ucl.ac.be/commun/images/';

/* FUNCTIONS */


var $header = {toString: function(){
	var sTitle = "Statistical Analysis and modeling for complex substantive questions with complex data";
	var sSubtitle = "Interuniversity Attraction Pole, Phase V (2002-2006)";
	var sSubtitlen = "Interuniversity Attraction Pole, Phase VI (2007-2011)";
	site.adjustFonts();
	var s = "";
	s += site.head(sTitle,sSubtitle,sSubtitlen);
	s += site.topmenu();
	return s;
}};


var $footer = {toString: function(){
return("<div id='footer'><p>2004 <a href='http://www.stat.ucl.ac.be' title='UCL / Institut de statistique'>UCL/STAT</a>&nbsp;&nbsp;::&nbsp;&nbsp;<a href='mailto:iap@stat.ucl.ac.be' title='Contact the IAP webmaster'>Contact</a></p></div>");


}};

site.head = function(title, subtitle, subtitlen){
	return("<div id='head'><div class='title'>"+title +" </div><div class='subtitle'><b> "+subtitle+"</b><BR><img src='/images/new2.gif'> <a href='./PhaseVI/index.html'> "+subtitlen+"</a> </div></div>");
}



site.topmenu = function(){
	var s="";

	s+= "<div id='topmenu'>"

	s+="	<table class='page'>"
	s+="	<tr>"
	s+="		<td class='left'> <a href='./index.html'>Home - IAP network</a>   </td>"
	s+="		<td class='right'>"
	s+="			<a href='./description.html'>Description</a> |"
	s+="			<a href='./people.html'>People</a> |"
	s+="				<a href='./research.html'>Research activities</a> |"
	s+="			<a href='./publication.html'>Publications</a> |"
	s+="			<a href='./evaluation.html'>Ex-Post Evaluation</a> |"
	s+="			<a href='./archive.html'>Archives</a> |"
	s+="			<a href='./contact.html'>Contact</a>"
	s+="		</td>"
	s+="	</tr>"
	s+="	</table>"
	s+="</div>"
	return(s);
}


site.adjustFonts = function(){
	try {
		if (window.navigator.userAgent.match("Linux")) {
			document.body.style.font = "menu";
		}
	}
	catch(error){
	}
}


function LienFichier(nomfic,description)
	{
	x=nomfic.length +1;
	extension=nomfic.substring(x-4,x);
	document.write('<div class="download">&nbsp;<a HREF='+nomfic+'>'+description+'</a>&nbsp;<a HREF='+nomfic+'><img src="'+adresseImagesCommunes+'dwld-'+extension+'.gif" border=0 /></a></div>');
	}

function Lien(cible,description)
	{
	document.write('<div class="lien">[&nbsp;<a HREF='+cible+'>'+description+'</a>&nbsp;<a HREF='+cible+'><img src="'+adresseImagesCommunes+'link3.gif" border=0 /></a>&nbsp;]</div>');
	}




function LoadTXTfile(URLfic){

	// create ActiveWidgets data model - text-based table
	var table = new Active.Text.Table;
	// provide data URL - plain text comma-separated file
	table.setURL(URLfic);
	var Datalen = 0;
	var myData =[];
	var TestmyData =[];
	var myColumns =[];
	var CloneColumns =[];
	var CloneData = [];
	var ColSelected =[];
	var NumColSel = 0;
	var Xsentence ="";
	var maxcol = 30;
	var lastcol = 0;
	var ColLength = [];

	var obj = new Active.Controls.Grid;
	obj.setStatusProperty("code", "loading");
	var defaultResponse = table.response;
	table.response = function(data){
	defaultResponse.call(table, data);
	Datalen=table.getCount();


	// load second CSV line (max 30 cols) to calculate last not empty field
	var x=1;
	var y=0;
	Xsentence = 'TestmyData.push([table.getText( ' + x + ', ' + y + ')';
	y=1;
	for(y=1; y< maxcol; y++) { Xsentence += ', table.getText( ' + x + ', ' + y + ')'; }
   //>
	Xsentence += '])';
	eval(Xsentence);

	// calculate ths CSV file last data column
	for(var x=0; x< maxcol; x++) {  //>

		if(TestmyData[0][x]!=table.getText(0, x))
			{
			//alert("*** "+TestmyData[0][x]);

			//alert("*** "+table.getText(0, x));

			lastcol = x+1;

			}
		}

	TestmyData = [];

	NumColSel = lastcol;
	for(var x=0; x< lastcol; x++) { ColSelected.push([x]); } //>
	LoadData();
	function LoadData() {
		// load first CSV line into array myColumns (note: remove next line -- if myColumns load as array
		// take header size also
		for(var x=0; x< lastcol; x++) {  //>
			myColumns.push([table.getText( 0, x)]);
			// alert("*** "+ myColumns[x]);
			ColLength.push((myColumns[x])[0].length);
			}

		CloneColumns = myColumns ;

		// load CSV data lines 2 to bottom into array myData
		var x=1; // x=0 -- if myColumns load as array or in a separate CSV file
		var y=0;

		while( x< Datalen) { //>
			Xsentence = 'myData.push([table.getText( ' + x + ', ' + y + ')';
			var tmpsize = table.getText(x,y).length;
			if (tmpsize> ColLength[y]) ColLength[y]= tmpsize

			y=1;
			for(y=1; y< lastcol; y++) {  //>
				Xsentence += ', table.getText( ' + x + ', ' + y + ')';
    //alert(table.getText(x,y));
        var tmpsize = table.getText(x,y).length;
				if (tmpsize> ColLength[y]) ColLength[y]= tmpsize
				}
			Xsentence += '])';
			eval(Xsentence);
			//alert("myData[x,y]: "+myData[x,y]);
		y=0;
		x++; }

		// clone the arrays and use tem as default
		CloneColumns = myColumns ;
		CloneData = myData ;

		// load data javascript objects
		obj.setRowProperty("count", Datalen-1);
		obj.setColumnProperty("count", NumColSel);
		obj.setDataProperty("text", function(i, j){return CloneData[i][j]});
		obj.setColumnProperty("text", function(i){return CloneColumns[i]});

		// write good CSS to "auto-size" the grid
		var objid=obj.getId();

		var stylesheet = document.styleSheets[document.styleSheets.length-1];
		var TableWidth=0;
		for(var x=0; x <lastcol;x++){
			var colWidth = 25+(ColLength[x]*7);

			stylesheet.addRule("#"+objid+ " .active-column-"+x,"width:"+colWidth+"px");

			TableWidth += colWidth;
		}
		//TableWidth += 1;

		stylesheet.addRule("#"+objid, "width:"+TableWidth+"px");
		var TableHeight=(20+(Datalen-1)*18);

		stylesheet.addRule("#"+objid, "height:"+TableHeight+"px");
	}
	// let the browser paint the grid
	window.setTimeout(function(){
	obj.setStatusProperty("code", "");
	obj.refresh();
	}, 0);
	}
	// start asyncronous data retrieval
	table.request();
	// writes obj / One could also imagine returning directly obj for more operations on it...
	obj.setRowHeaderWidth("0px");
	document.write(obj);
}








