
<!--

function bodyOnLoad () {
	blurLinks();
	resizeTextAreas();
	trapRightClickOnImages();
}

var uploadingImage = 0;
var updatingImage = 0;

function bodyOnFocus () {	
	if (uploadingImage != 0) {
		addImageBlockOnFocus();
	}
	if (updatingImage != 0) {
		updateImageOnFocus();
	}
}

function mainTableOnMouseDown () {
	// Hide existing date picker div when clicking on page's body
	var datePicker = document.getElementById('datePicker');
	if (window.closeCalendar && datePicker && datePicker.style.display == 'block')
		closeCalendar();
}

// Adds image blocks when on description page
function addImageBlockOnFocus () {
	array = uploadingImage.split("_");
	containerId = array[0];
	type = array[1];
	addImageBlock (containerId, type);
	// Sets the body onFocus event off
	uploadingImage = 0;
}

// Updates image when on description page
function updateImageOnFocus () {
	imgNode = document.getElementById("img_" + updatingImage);
	nextNode = imgNode.nextSibling;
	clone = imgNode.cloneNode(true);
	container = imgNode.parentNode;
	
	// The following adds a random number to the image path.
	// This prevents the browser to display the cached image.
	var today=new Date()
	var time=today.getSeconds()
	var randomNb = time.valueOf();
	newPath = clone.src.substring(0, clone.src.indexOf(".jpg") + 4);
	newPath = newPath + "?" + randomNb;
	clone.src = newPath;
	
	container.removeChild(imgNode);
	container.insertBefore(clone, nextNode);
	// Sets the body onFocus event off
	updatingImage = 0;
}

// Shows/Hides next node.
function showHideNextNode(balise) {
	while((balise = balise.nextSibling) && balise.nodeType != 1); // 1 == Node.ELEMENT_NODE
	if (balise.style.display == 'block')	{
		balise.style.display = 'none';
	}
	else if (balise.style.display == 'none')	{
		balise.style.display = 'block';
	}
}
// Shows/Hides element by id.
function showHideById(tagId) {
	var tag = document.getElementById(tagId);
	if (tag.style.display != 'none')	{
		tag.style.display = 'none';
	}
	else if (tag.style.display == 'none')	{
		tag.style.display = '';
	}
}

// Toggles class of element by id.
function toggleClass(id,classe1,classe2) {    
	if (document.getElementById(id)) {
		var obj = document.getElementById(id);
		if (obj) {
			if (obj.className != classe1)
				obj.className = classe1;
			else
				obj.className = classe2;
		}
	}
}

// Replaces special characters in a string with basic ones
function removeSpecialChars (string) {
	string = string.replace(/ /g, '_');
	string = string.replace(/'/g, '-');
	string = string.replace(/[àâä]/gi,"a");
	string = string.replace(/[éèêë]/gi,"e");
	string = string.replace(/[îï]/gi,"i");
	string = string.replace(/[ôö]/gi,"o");
	string = string.replace(/[ùûü]/gi,"u");
	string = string.replace(/[ç]/gi,"c");
	return string;
}

// Popup window
function openWindow(name, url, width, height, scrollbar, statusbar, toolbar, menubar, resizable, left, top) {
	if (typeof width == 'undefined' ) width = screen.availWidth;
	if (typeof height == 'undefined' ) height = screen.availHeight;
	if (typeof scrollbar == 'undefined' ) scrollbar = 1;
	if (typeof statusbar == 'undefined' ) statusbar = 0;
	if (typeof toolbar == 'undefined' ) toolbar = 0;
	if (typeof menubar == 'undefined' ) menubar = 0;
	if (typeof resizable == 'undefined' ) resizable = 1;
  var toolbar_str = toolbar ? 'yes' : 'no';
  var menubar_str = menubar ? 'yes' : 'no';
  var statusbar_str = statusbar ? 'yes' : 'no';
  var scrollbar_str = scrollbar ? 'yes' : 'no';
  var resizable_str = resizable ? 'yes' : 'no';
	
	// Center the window if no left and top coordinates supplied
	var xy = getCenteredXY (width, height);
	if (typeof left == 'undefined' ) left = xy[0];
	if (typeof top == 'undefined' ) top = xy[1];

  cookie_str = document.cookie;
  cookie_str.toString();

  pos_start  = cookie_str.indexOf(name);
  pos_end    = cookie_str.indexOf('=', pos_start);

  cookie_name = cookie_str.substring(pos_start, pos_end);

  pos_start  = cookie_str.indexOf(name);
  pos_start  = cookie_str.indexOf('=', pos_start);
  pos_end    = cookie_str.indexOf(';', pos_start);
  
  if (pos_end <= 0) pos_end = cookie_str.length;
  cookie_val = cookie_str.substring(pos_start + 1, pos_end);
  if (cookie_name == name && cookie_val  == "done")
	return;

  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

function getScreenRes () {
	var x = screen.availWidth;
	var y = screen.availHeight;
	var res = new Array (x, y);
	return res;	
}
function getCenteredXY (width, height) {
	if (typeof height == 'undefined' ) height = screen.availHeight;
	var res = getScreenRes ();
	var x = (res[0] - width) / 2;
	var y = (res[1] - (height+60)) / 2;
	var pos = new Array (x, y);
	return pos;
}


// Fades the element in or out
function fadeEffect (id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

// Changes the opacity of the given element
function changeOpacity(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "Alpha(Opacity=" + opacity + ")";
}
	
	
// Resizes a textarea to fit its text content. 
function resizeTextArea (textarea) {
	var i = 0;
	var lineCount = 2;	
	if (navigator.userAgent.indexOf("Firefox") != -1)
		lineCount = 1;
	var cols = textarea.cols;
	// trim trailing return char if exists
	var linesArray = textarea.innerHTML.replace(/\s+$/g,"").split("\n");
	if (navigator.userAgent.indexOf("Firefox") != -1)
	var linesArray = textarea.value.replace(/\s+$/g,"").split("\n");
	var newLines = linesArray.length;
	
	var factor = 1;
	if (navigator.userAgent.indexOf("Firefox") != -1)
		factor = 12;
	
	for (i = 0 ; i < newLines ; i++) {
		lineCount += 1;
		lineCount += Math.floor(linesArray[i].length / (cols + factor));
	}
	textarea.setAttribute('rows', lineCount);
}

// Resizes all textareas on the page and set them to resize on keyup events.
function resizeTextAreas () {
	var array = document.getElementsByTagName('textarea');
	for (i = 0 ; i < array.length ; i++) {
		textarea = array[i];
		if (textarea.title == '') { // Automatic resize won't be enabled if the textarea tag has a title attribute
			resizeTextArea (textarea);
			textarea.setAttribute("onkeyup", "resizeTextArea(this);");
			textarea.onkeyup = function() { resizeTextArea(this); }; // For IE
		}
		// The following prevents an issue with Firefox and innerHTML where
		// the text of all inputs and textareas on the page is set back to default
		// whenever you modify the innerHTML attribute of any other element.
		textarea.setAttribute("onchange", "currentToDefaultValue(this);");
	}
}

// InnerHTML "bug fix" for Firefox. When the contents of a textarea or other form element is modified, 
// get its current value and set it as its defaut attribute. Otherwise the changes will be erased as soon as
// the innerHTML of a parent element is modified.
function currentToDefaultValue (object) {
	if (navigator.userAgent.indexOf('Firefox') == -1)
		return;
	
	// Textarea
	if(object.tagName == "TEXTAREA")
		object.innerHTML = object.value;
		
	else if (object.tagName == 'INPUT') {
		// Textfield
		if (object.type == 'text') {
			object.setAttribute('value', object.value);
		}
		// Checkbox
		else if(object.type == 'checkbox') {
			if (object.checked)
				object.setAttribute('checked', 'checked');
			else
				object.removeAttribute('checked');
		}
		// Radio buttons
		else if(object.type == 'radio') {
			if (object.checked)
				object.setAttribute('checked', 'checked');
			else
				object.removeAttribute('checked');
		}
	}
}

// Creates and displays a popup div asking the visitor to wait while the page reloads
function waitingMessage () {
	var div = document.createElement('div');
	div.setAttribute('id', 'divWaitingMessage');
	div.setAttribute('style', 'width: 200px;\
															text-align: center;\
															position: fixed;\
															background-color: #FFFBA6;\
															padding: 30px;\
															font-size: 1.2em;\
															border: 2px solid #73685B;');
	// Center popup
	var height = div.offsetHeight;
	var width = div.offsetWidth;
	var parent = document.getElementById('tdContent');
	var pHeight = parent.offsetHeight;
	var pWidth = parent.offsetWidth;
	var sTop = parent.scrollTop;
	var sLeft = parent.scrollLeft;
	var posY = (pHeight/2)-(height/2)+sTop;
	var posX = (pWidth/2)-(width/2)+sLeft;
	div.style.top = posY+"px";
	div.style.left = posX+"px";
	
	div.innerHTML = '<p>Please wait...<br />Retrieving currency exchange rates online.</p><p>It may take up to 30s.</p><p style="text-decoration:blink;">......</p>'; 
	document.body.appendChild(div);
}

// Centers an element into it's parent element
function centerPopup(id) {
	var element = document.getElementById(id);
	var height = element.offsetHeight;
	var width = element.offsetWidth;
	var myParent = element.parentNode;
	var pHeight = myParent.offsetHeight;
	var pWidth = myParent.offsetWidth;
	var sTop = myParent.scrollTop;
	var sLeft = myParent.scrollLeft;
	var posY = (pHeight/2)-(height/2)+sTop;
	var posX = (pWidth/2)-(width/2)+sLeft;
	document.getElementById(id).style.top = posY+"px";
	document.getElementById(id).style.left = posX+"px";
}

	
// Prevents drawing of the dotted line when you click on a link.
function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("A");
	theAreas = document.getElementsByTagName("AREA");
	for(i=0; i<theLinks.length; i++) {theLinks[i].onfocus = unblur;}
	for(i=0; i<theAreas.length; i++) {theAreas[i].onfocus = unblur;}
  }
function unblur() {
	this.blur();
} 


//  ********************* General Cookie handling *********************
//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@netw.com>
//  The following functions are released to the public domain.
function getCookieVal (offset) {  
   var endstr = document.cookie.indexOf (";", offset);  
   if (endstr == -1)    
      endstr = document.cookie.length;  
   return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
   var arg = name + "=";  
   var alen = arg.length;  
   var clen = document.cookie.length;  
   var i = 0;  
   while (i < clen) {    
      var j = i + alen;    
      if (document.cookie.substring(i, j) == arg)      
         return getCookieVal (j);    
      i = document.cookie.indexOf(' ', i) + 1;    
      if (i == 0) break;   
   }  
   return null;
}
function SetCookie (name, value) {  
   var argv = SetCookie.arguments;  
   var argc = SetCookie.arguments.length;  
   var expires = (argc > 2) ? argv[2] : null;  
   var path = (argc > 3) ? argv[3] : null;  
   var domain = (argc > 4) ? argv[4] : null;  
   var secure = (argc > 5) ? argv[5] : false;  
   document.cookie = name + "=" + escape (value) + 
      ((expires == null) ? "" : ("; expires=" + expires)) + 
      ((path == null) ? "" : ("; path=" + path)) +  
      ((domain == null) ? "" : ("; domain=" + domain)) +    
      ((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
   var exp = new Date();  
   exp.setTime (exp.getTime() - 1);  
   // This cookie is history  
   var value = GetCookie (name);  
   document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
}

// "Protects" images
function trapRightClickOnImages() {
	/*
	if(document.images)	{
		for(i=0 ; i < document.images.length ; i++)	{
			document.images[i].onmousedown = rightClick;
			document.images[i].onmouseup = rightClick;
		}
	}
	*/
}	
function rightClick(e) {
	var msg = "Images are property of Just Provence";
	if (navigator.appName == 'Netscape' && e.which == 3) {
		alert(msg);
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
		return false;
	}
	else return true;
}


// js version for PHP function mktime()
function mktime() {    
	var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
	d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
	
	var dateManip = {
		0: function(tt){ return d.setHours(tt); },
		1: function(tt){ return d.setMinutes(tt); },
		2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
		3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
		4: function(tt){ return d.setDate(tt+mb); },
		5: function(tt){ return d.setYear(tt+ma); }
	};
	
	for( i = 0; i < argc; i++ ){
		no = parseInt(argv[i]*1);
		if(no && isNaN(no)){
			return false;
		} else if(no){
			// arg is number, let's manipulate date object
			if(!dateManip[i](no)){
				// failed
				return false;
			}
		}
	}	
	return Math.floor(d.getTime()/1000);
}


function getDaysInMonth(iMonth, iYear) {
	return 32 - new Date(iYear, iMonth, 32).getDate();
}


-->

