/*--------------------------------------------------------------+
/*	Traitement pour grossissement de la popup de preview		|
/*-------------------------------------------------------------*/

inter = '';		/* variable globale utilisée pour l'interval */
speed = 8;		/* vitesse de grossissement de la popup vitesse augmente quand speed diminue */
frequency = 10;	/* frequence de rafraichissement de la popup pdt le changement en ms */
L_txt_close = 'Clic to close this preview';
/**
 * Affiche la popup au milieu de l'ecran a la taille passé en paramétre
 */
function showImage (event, finalWidth, finalHeight, image)
{
    if (document.getElementById('preview_block').firstChild) {
    	for (var i=0; i < document.getElementById('preview_block').childNodes.length; i++)
    	{
        	document.getElementById('preview_block').removeChild(document.getElementById('preview_block').childNodes[i]);
    	}
    }
    var mouseX = 0;
    var mouseY = 0;
    var vScroll = 0;
    var hScroll = 0;
    var inWidth = getWindowWidth();
    var inHeight = getWindowHeight();
    if (document.all) 
    {
        mouseX = window.event.clientX + document.documentElement.scrollLeft;
        mouseY = window.event.clientY + document.documentElement.scrollTop;
        vScroll = document.documentElement.scrollTop;
        hScroll = document.documentElement.scrollLeft;
    }
    else 
    {
        mouseX = event.clientX + window.scrollX;
        mouseY = event.clientY + window.scrollY;
        vScroll = window.scrollY;
        hScroll = window.scrollX;
    }
    
	var div = document.createElement('div');
	div.style.height = '0';
	div.style.width = '0';
	div.className = 'preview';
	div.style.position = 'absolute';
	div.style.top = mouseY+'px';
	div.style.left = mouseX+'px';
	div.style.zIndex = '1000';
	div.setAttribute('id', 'image');
	div.onclick = new Function ("document.getElementById('preview_block').removeChild(document.getElementById('preview_block').firstChild);window.clearInterval(inter);"); 
    
    var finalLeft = (inWidth - finalWidth) / 2;
    var finalTop  = (inHeight - finalHeight) / 2;
	finalTop += vScroll;
    var stepLeft = (finalLeft - mouseX)  / speed;
    var stepTop  = (finalTop - mouseY) / speed;
    var stepWidth = finalWidth / speed;
    var stepHeight = finalHeight / speed;
	
	document.getElementById('preview_block').appendChild(div);
	
	inter = window.setInterval('moveAndResize('+stepLeft+','+stepTop+','+stepWidth+','+stepHeight+','+finalHeight+',"'+image+'")', frequency);

	return false;
}

function moveAndResize (stepLeft, stepTop, stepWidth, stepHeight, finalHeight, image)
{
	if (!document.getElementById('preview_block') || !document.getElementById('preview_block').firstChild)
	{
		window.clearInterval(inter);
		return false;
	}

	var div = document.getElementById('preview_block').firstChild;
	var height = div.style.height.match(/[0-9\.]*/);
	var width  = div.style.width.match(/[0-9\.]*/);
	var top = div.style.top.match(/[0-9\.]*/);
	var left = div.style.left.match(/[0-9\.]*/);
	
	height = Number(height);
	width = Number(width);
	top = Number(top);
	left = Number(left);
	
	height += stepHeight;
	width  += stepWidth;
	top += stepTop;
	left += stepLeft;

	
	div.style.height = height + 'px';
	div.style.width = width + 'px';
	div.style.top = top + 'px';
	div.style.left = left + 'px';
	if (height >= finalHeight)
	{
		window.clearInterval(inter);
		var img = document.createElement('img');
		img.setAttribute('src', '/rsc/img/skin/'+image);
		img.setAttribute('alt', L_txt_close);
		img.setAttribute('title', L_txt_close);
		img.setAttribute('width', '840');
		img.setAttribute('height', '600');
		img.style.cursor = 'pointer';
        div.appendChild(img);
        var p = document.createElement('p');
        p.appendChild(document.createTextNode(L_txt_close));
        p.style.cursor = 'pointer';
        div.appendChild (p);
	}
}


/**
 * Fonction qui retourne la taille interieure de la fenetre
 * Necessaire a cause d'IE
 */
function getWindowHeight() {

  var pageHeight =  window.innerHeight;
  pageHeight = (pageHeight)? pageHeight :document.documentElement.clientHeight;
  pageHeight = (pageHeight)? pageHeight: document.body.clientHeight;
  
  return pageHeight;

}
function getWindowWidth() {

  var pageWidth =  window.innerWidth;
  pageWidth = (pageWidth)? pageWidth :document.documentElement.clientWidth;
  pageWidth = (pageWidth)? pageWidth: document.body.clientWidth;
  
  return pageWidth;

}

/**
 * Desactive le bouton submit des qu'on a soumis le formulaire,
 * cela permet d'eviter la validation multiple d'un formulaire
 *
 * @param string btn_id : id de l'element a desactiver
*/
function disable_submit (btn_id)
{
	var btn = document.getElementById(btn_id);
	btn.setAttribute('disabled', 'disabled');
	btn.className = 'button_disabled';
}
