function ObjectFrame (doc_, objectUrl_) {
	//
	var objectUrl = objectUrl_;
	var doc = doc_;
	
	this.getHtml = function() { 
	/*	
		doc.write('<TABLE border="0" width="' + (getWindowWidth()-155) + '" height="' + (getWindowHeight()-200) + '" cellpadding="0" cellspacing="0">');
		doc.write('<TBODY>');
		doc.write('<TR>');
		doc.write('<TD valign="top">');
		doc.write('<iframe src="' + objectUrl + '" scrolling="no" width="100%" height="100%"  marginwidth="10" marginheight="10" frameborder="0"></iframe></TD>');
		doc.write('</TR>');
		doc.write('</TBODY>');
		doc.write('</BODY>');
*/

		doc.write('<iframe src="' + objectUrl + '" width="' + (getWindowWidth()-155) + '" height="' + (getWindowHeight()-200) + '"  align="top" marginwidth="0" marginheight="0" frameborder="0"></iframe></TD>');
		return;
	}
}


function TableFormatter (doc_ ) { 
	var doc = doc_;
	var ligneCount = 0;
	
	this.getTR = function( enabled, href, thumnail, objectId, objectCommonName) { 
		ligneCount++;
		if ( ( ligneCount % 2 ) != 0 ) {
			doc.write('<TR class="odd">');
		} else {
			doc.write('<TR class="even">');
		}
		if ( enabled ){
			doc.write('<TD width="100" align="center"><A href="' + href + '"><IMG border="0" src="' + thumnail + '"></A></TD>');
			doc.write('<TD width="25" class="objectNumber"><A href="' + href + '">' + objectId + '</A></TD><TD width="200" class="objectCommonName"><A href="' + href + '">' + objectCommonName + '</A></TD>');
		} else {
			doc.write('<TD width="100" align="center"><IMG border="0" src="' + thumnail + '"></TD>');
			doc.write('<TD width="25" class="objectNumberDisabled">' + objectId + '</TD><TD width="200" class="objectCommonNameDisabled">' + objectCommonName + '</TD>');
		}
		doc.write('</TR>');

		return;
	}

	this.getTR_start = function() { 
		ligneCount++;
		if ( ( ligneCount % 2 ) != 0 ) {
			doc.write('<TR class="odd">');
		} else {
			doc.write('<TR class="even">');
		}
		return;
	}

	this.getTR_end = function() { 
		doc.write('</TR>');
		return;
	}


}


/*
BEGIN Image gallery
*/
function GalleryItem( src , width , height ) {
	var _src = src;
	var _width = width;
	var _height = height;
	
	this.getSrc = function(){ 
		return _src; 
	}
	this.getHeight = function(){ 
		return _height; 
	}
	this.getWidth = function(){	
		return _width; 
	}
	
}

function Gallery( galleryPath , image_detail_path) {
	var _galleryPath = galleryPath ;
	var _image_detail_path = image_detail_path;
	
	var _images = new Array;
	var _size = 0;
	var _selected = 0;
	
	this.addItem = function(anItem) { 
		_images[_size] = anItem ; 
		_size++;
	}
	this.getSize = function() { 
		return _size; 
	}
	this.itemAt = function(i) { 
		return _images[i]; 
	}
	this.setSelected = function(i) { 
		_selected = i; 
	}
	this.getSelectedItem = function() { 
		return _images[_selected]; 
	}
	this.getSelectedItemSrc = function() { 
		return ( galleryPath + _images[_selected].getSrc() ); 
	}
	this.getSelectedItemWidth= function() { 
		return _images[_selected].getWidth(); 
	}
	this.getSelectedItemHeight = function() { 
		return _images[_selected].getHeight(); 
	}
	this.hasMoreItems = function () { 
		return (_selected < _size); 
	}
	this.next = function () { 
		_selected++;
		if (_selected >= _size) {
			_selected = 0;
		}
	}
	this.previous = function () { 
		_selected--;
		if (_selected < 0) {
			_selected = _size - 1;
		}
	}
	
	//
	this.viewImage = function(i) {
		this.setSelected(i);
		var selItem = this.getSelectedItem();
		
		if ( _images.length == 1 ) {
			OpenNamedWindow('obs1',
				_image_detail_path, 
				Math.max( selItem.getWidth() + 50 , 200) , selItem.getHeight() + 25);
		} else {
			OpenNamedWindow('obs',
				_image_detail_path, 
				Math.max( selItem.getWidth() + 150 , 790) , selItem.getHeight() + 200);
		}
	}
	
	
}



/*
END image gallery
*/

function DataReader(dataPageName_, frameName_) {
	//first we get the browser type
	var doc = document;
	var dataPageName = dataPageName_;
	var appVer=parseInt(navigator.appVersion);
	var browserVersion;
	var frameName = frameName_ ;
	var bTrace = true;

	if (document.all && appVer >= 4)
  		browserVersion = 1; 
	else if (document.getElementById && appVer > 4) 
  		browserVersion = 2; 
	else if (document.layers && appVer >= 4) 
  		browserVersion = 3;
  		
  		
	this.loadData = function(){
	    // tente de créer l'IFrame si elle n'existe pas déjà
    	if (doc.frames[frameName] == null) {
			try {
				this.createIframeURLInvoker(doc,frameName);
		        //if (bTrace) alert("DataReader.getValue :  IFrame '"+ frameName + "' created.");
			} catch (e) {
				if (bTrace) alert("DataReader.getValue :  Error creating IFrame : " + e.message);
			}
		} else {
			if (bTrace) alert("DataReader.getValue :  IFrame already exists");
		}
	}
  	
  	this.getValue = function(id) {
	
//		alert("enter " + id);
	
	
	
		var value;
		var counter = 0;
		if ( browserVersion == 1 ) {
			//ie
			//value = document.bgiframedata.document.formdata.elements[id].value;
			while (counter < 3) {
				try {
					value = document.frames[frameName].document.formdata.elements[id].value;	
					return value;
				} catch (e) {
					//alert("cacth: " + e.message);
				}
				counter++;
			}
		} else if ( browserVersion == 2 ){
			//ns
			var iframedata = document.getElementById(frameName).contentDocument;
			value = iframedata.getElementById(id).value;
			return value;
		}
	}	
	
	
	this.createIframeURLInvoker = function () {
	    if (doc.readyState=="complete") throw "DataReader.createIframeURLInvoker : document is completed. Can't write IFrame.";
		doc.write('<iframe name="' + frameName
	      + '" height="200" width="200" frameborder="0" hspace="0" vspace="0">'
    	  + '</iframe>\n');
    	  
    	var oFrame = doc.frames[frameName];
    	oFrame.location.href = dataPageName;
		//alert("frame name: " + oFrame.name);
//   		setTimeout("var oFrame = doc.frames['"+frameName+"']; oFrame.location.href = '"+dataPageName+"'; alert()" , 1000); 

  }

	
	
		
}





/*
PageQuery class. used to get query string parameters
*/
function PageQuery(q) {
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else 
		this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { 
		return this.keyValuePairs; 
	}
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s) {	
				return this.keyValuePairs[j].split("=")[1];
			}
		}
		return "";
	}

	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}

	this.getLength = function() { 
		return this.keyValuePairs.length;
	} 
}


function Request(){
	var page = new PageQuery(window.location.search); 
	
	this.getParameter = function(s) {
		return unescape(page.getValue(s)); 
	}

}

function displayItem(key){
	if(queryString(key)=='false') {
		document.write("you didn't enter a ?name=value querystring item.");
	}else{
		document.write(queryString(key));
	}
}


/*
Find an object
*/
function findObject(imgName)
{
  var appVer=parseInt(navigator.appVersion);
  var isNC=false,isN6=false,isIE=false;
  if (document.all && appVer >= 4) isIE=true; else
    if (document.getElementById && appVer > 4) isN6=true; else
      if (document.layers && appVer >= 4) isNC=true;
  if (isNC||isN6||isIE)
  {
    if (document.images)
    {
      var img = document.images[imgName];
      if (!img) {
      	img = _ImgFind(document, imgName);
      }
      return img;
    }
  }
}

/*
Hide an object
*/
function _HideObj(lId)
{

  var ob;ob=new Array;
  var appVer=parseInt(navigator.appVersion);
  var isNC=false,isN6=false,isIE=false;
  if (document.all && appVer >= 4) isIE=true; else
    if (document.getElementById && appVer > 4) isN6=true; else
      if (document.layers && appVer >= 4) isNC=true;
  if (isNC)
  {
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) ob[lId].visibility = "hide";
  }
  if (isN6)
  {
    ob[lId] = document.getElementById(lId);
    ob[lId].style.visibility = "hidden";
  }
  if (isIE)
  {
    w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
    ob[lId].visibility = "hidden";
  }
}


/*
Show en object
*/
function _ShowObj(lId)
{
  var ob;ob=new Array;
  var appVer=parseInt(navigator.appVersion);
  var isNC=false,isN6=false,isIE=false;
  if (document.all && appVer >= 4) isIE=true; else
    if (document.getElementById && appVer > 4) isN6=true; else
      if (document.layers && appVer >= 4) isNC=true;
  if (isNC)
  {
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) ob[lId].visibility = "show";
  }
  if (isN6)
  {
    ob[lId] = document.getElementById(lId);
    ob[lId].style.visibility = "visible";
  }
  if (isIE)
  {
    w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
    ob[lId].visibility = "visible";
  }
}

function _FindObj(doc, lId)
{
  for (var i=0; i < doc.layers.length; i++)
  {
    var w_str = "doc.layers[i].document." + lId;
    var obj;obj=new Array;
    obj[lId] = eval(w_str);
    if (!obj[lId]) obj[lId] = _FindObj(doc.layers[i], lId);
    if (obj[lId]) return obj[lId];
  }
 
  return null;
}


/*
swap images
*/
function _ImgSwap(imgName, imgSrc)
{
  var appVer=parseInt(navigator.appVersion);
  var isNC=false,isN6=false,isIE=false;
  if (document.all && appVer >= 4) isIE=true; else
    if (document.getElementById && appVer > 4) isN6=true; else
      if (document.layers && appVer >= 4) isNC=true;
  if (isNC||isN6||isIE)
  {
    if (document.images)
    {
      var img = document.images[imgName];
      if (!img) img = _ImgFind(document, imgName);
      if (img) img.src = imgSrc;
    }
  }
}

function _ImgFind(doc, imgName)
{
  for (var i=0; i < doc.layers.length; i++)
  {
    var img = doc.layers[i].document.images[imgName];
    if (!img) img = _ImgFind(doc.layers[i], imgName);
    if (img) return img;
  }
  return null;
}



function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}

function getWindowWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myWidth;
}






//image protection
var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = 'This image is protected by copyright.\nWe request you not to copy it.';
var x,y,x1,y1,copyAttempt;

function init()
{

//do nothing
return;

	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}


