function drawImage(path){
	obj = document.createElement('p');
	obj.setAttribute('class','center');
	obj.appendChild(document.createTextNode("Loading image..."));
	drawSimple(obj);
	oImgPreload = new Image();
	//oImg = new Image();
	oImg = document.createElement("img");
	oImgPreload.onload = function(){
		oImg.src = path;
		_closedraw();
		drawSimple(oImg);
	}
	oImgPreload.src = path;
}

function drawSimple(html){
	oSelects = document.getElementsByTagName('select');
	for(i=0;i<oSelects.length;i++){
		oSelects[i].style.display = 'none';	
	}
	var arr = getPageSize();
	oBody = document.getElementsByTagName("body")[0];
	oDiv = document.createElement("div");
	oDiv.setAttribute("id","drawling");
	oDiv.appendChild(html);
	oA = document.createElement("a");
	oA.appendChild(document.createTextNode("Fermer"));
	oA.setAttribute("href","javascript:_closedraw()");
	oDiv.appendChild(document.createElement("br"));
	oDiv.appendChild(oA);
	oOverlay = document.createElement("div");
	oOverlay.style.height = arr[1]+'px';
	oOverlay.setAttribute("id","overlay");;
	oBody.appendChild(oOverlay);
	oBody.appendChild(oDiv);
	oDiv.style.top = '50px';
	odivwidth = (navigator.userAgent.indexOf('MSIE')==-1) ? oDiv.offsetWidth : oDiv.clientWidth;
	if(html.nodeName == "IMG"){
		oImg = document.getElementById('drawling').childNodes[0];
		imagewidth = (oImg.width < odivwidth) ? odivwidth : oImg.width;
		oDiv.style.left = ((arr[0]/2)-(imagewidth/2))+'px';
	}else oDiv.style.left = ((arr[0]/2)-(odivwidth/2))+'px';
	window.scrollTo(0,0);
}
function drawError(message){
	_closedraw();
	oSelects = document.getElementsByTagName('select');
	for(i=0;i<oSelects.length;i++){
		oSelects[i].style.display = 'none';	
	}
	var arr = getPageSize();
	aMessage = message.split("\n");
	oBody = document.getElementsByTagName("body")[0];
	oDiv = document.createElement("div");
	oDiv.setAttribute("id","drawling");
	oUl = document.createElement("ul");
	for(i=0;i<aMessage.length;i++){
		if(aMessage[i] != ""){
			oLi = document.createElement("li");
			oLi.appendChild(document.createTextNode(aMessage[i]))
			oUl.appendChild(oLi);
		}
	}
	oDiv.appendChild(oUl);
	oA = document.createElement("a");
	oA.appendChild(document.createTextNode("Fermer"));
	oA.setAttribute("href","javascript:_closedraw()");
	oDiv.appendChild(document.createElement("br"));
	oDiv.appendChild(oA);
	oOverlay = document.createElement("div");
	oOverlay.style.height = arr[1]+'px';
	oOverlay.setAttribute("id","overlay");;
	oBody.appendChild(oOverlay);
	oBody.appendChild(oDiv);
	oDiv.style.top = '100px';
	oDiv.style.left = ((arr[0]/2)-(oDiv.offsetWidth/2))+'px';
	window.scrollTo(0,0);
}
function drawLoad(message,aPos){
	_closedraw();
	oSelects = document.getElementsByTagName('select');
	for(i=0;i<oSelects.length;i++){
		oSelects[i].style.display = 'none';	
	}
	var arr = getPageSize();
	aMessage = message.split("\n");
	oBody = document.getElementsByTagName("body")[0];
	oDiv = document.createElement("div");
	oDiv.setAttribute("id","drawling");
	oSpan = document.createElement("span");
	oSpan.appendChild(document.createTextNode(message));
	oDiv.appendChild(oSpan);
	oOverlay = document.createElement("div");
	oOverlay.style.height = arr[1]+'px';
	oOverlay.setAttribute("id","overlay");;
	oBody.appendChild(oOverlay);
	oBody.appendChild(oDiv);
	oDiv.style.top = aPos[1]+'px';
	oDiv.style.left = ((arr[0]/2)-(oDiv.offsetWidth/2))+'px';
	//window.scrollTo(0,0);
}

function _closedraw(){
	tip = document.getElementById('drawling');
	if(tip!=null){
		if(typeof(tip)=="object") tip.parentNode.removeChild(tip);
		over = document.getElementById('overlay');
		if(typeof(over)=="object") over.parentNode.removeChild(over);
		oSelects = document.getElementsByTagName('select');
		for(i=0;i<oSelects.length;i++){
			oSelects[i].style.display = '';	
		}
	}
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}