function flip(rid) {
	current=(document.getElementById(rid).style.display == 'none') ? 'block' : 'none';
    document.getElementById(rid).style.display = current;
}
function flipoff(rid) {
	if (rid == '') return false;
	var obj = MM_findObj(rid);
	if (obj) obj.style.display = 'none';
}
function flipon(rid) {
	if (rid == '') return false;
	var obj = MM_findObj(rid);
	if (obj) obj.style.display = 'block';
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function resizeAndMove(percent) {
	var vwidth = screen.width * percent;
	var vheight = screen.height * percent;
	var posX = (screen.width / 2) - (vwidth / 2);
	var posY = (screen.height / 2) - (vheight / 2);
	
	window.moveTo(posX, posY);
	window.resizeTo(vwidth, vheight);
}

function open_div_alert(url) {
	var usefull = document.getElementById('usefull');
	var html_form = '';
	var html_lien = 'popup.php?static=1&tmpl=alerte&url=' + url;
	var div_width = 500;
	var div_height = 350;
	
	usefull.style.display = 'none';
	usefull.style.width = div_width;
	usefull.style.height = div_height+20;
	
	html_form = '<div align="right"><a href="#null" onclick="close_div_alert();">X fermer</a></div>';
	
	html_form += '<iframe src="' + html_lien + '" ';
	html_form += 'frameborder="0"  id="alerte" scrolling="auto"';
	html_form += 'width="' + div_width + '" height="' + div_height + '">';
	html_form += '</iframe>';
	
	usefull.innerHTML = html_form;
	
	div_usefull_center(div_width, div_height + 10);
	
	usefull.style.display = 'block';

}

function close_div_alert() {
	var usefull = $('usefull');
	usefull.innerHTML = '';
	usefull.style.display = 'none';
}

function getWindowScroll() {
	var T, L, W, H;
	var parent = document.body;              
	
	if (parent != document.body) {
		T = parent.scrollTop;
		L = parent.scrollLeft;
		W = parent.scrollWidth;
		H = parent.scrollHeight;
	} else {
		var w = window;
		with (w.document) {
			if (w.document.documentElement && documentElement.scrollTop) {
				T = documentElement.scrollTop;
				L = documentElement.scrollLeft;
			} else if (w.document.body) {
				T = body.scrollTop;
				L = body.scrollLeft;
			}
			if (w.innerWidth) {
				W = w.innerWidth;
				H = w.innerHeight;
			} else if (w.document.documentElement && documentElement.clientWidth) {
				W = documentElement.clientWidth;
				H = documentElement.clientHeight;
			} else {
				W = body.offsetWidth;
				H = body.offsetHeight
			}
		}
	}
	return { top: T, left: L, width: W, height: H };
}
   
function getPageSize(){
	var parent = document.body;              
	
	var windowWidth, windowHeight;
	var pageHeight, pageWidth;
	
	if (parent != document.body) {
		windowWidth = parent.getWidth();
		windowHeight = parent.getHeight();                                
		pageWidth = parent.scrollWidth;
		pageHeight = parent.scrollHeight;                                
	} else {
		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;
		}


		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;
		}
	}             
	return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
}
  
function div_usefull_center(width, height) {    
	var usefull = $('usefull');
	
    var windowScroll = getWindowScroll();    
    var pageSize = getPageSize();    
    
	var top = (pageSize.windowHeight - height)/2;
    top += windowScroll.top
    
    var left = (pageSize.windowWidth - width)/2;
    left += windowScroll.left
	
    usefull.style.top = top+'px';
	usefull.style.left = left+'px';
}

function resize_zoom ( obj ) {
	document.getElementById("zoom_txtcharge").style.display='none';
	dom_obj_zoom = document.getElementById("zoom_div");
	if ( obj.height + 60 > document.body.clientHeight ) obj.height = document.body.clientHeight - 100;
	obj.style.display='block';
	dom_obj_zoom.style.width = (obj.width + 10) + "px";
	dom_obj_zoom.style.height = (obj.height + 25) + "px";
	//dom_obj_zoom.style.top = (((document.body.clientHeight-obj.height-40)/2)+document.body.scrollTop) + "px";
	dom_obj_zoom.style.top = '50px';
	dom_obj_zoom.style.left = (((document.body.clientWidth-obj.width)/2)+document.body.scrollLeft) + "px";
}

function open_zoom() {
	var tmphtml = "";
	
	// Masque les embed/object
	$A(document.getElementsByTagName('embed')).map(Element.extend).invoke('hide');
	$A(document.getElementsByTagName('object')).map(Element.extend).invoke('hide');

	tmphtml += "<img src='" + document.getElementById('zoom_txtcharge').getElementsByTagName("img")[1].src + "' onload='resize_zoom(this)' id='zoom_img' onclick=\"hide_zoom();\" style='margin: 5px;display:none'>";
	return use_masque(tmphtml);
}

function hide_zoom() {
	document.getElementById('zoom_div').style.display='none';
	document.getElementById('zoom_masque').style.display='none'; 
	
	// Affiche les embed/object
	$A(document.getElementsByTagName('embed')).map(Element.extend).invoke('show');
	$A(document.getElementsByTagName('object')).map(Element.extend).invoke('show');
	
	return false;
}

function use_masque(add_html) {
	var dom_obj_masque , dom_obj_zoom;

	if ( ! ( dom_obj_masque = document.getElementById("zoom_masque") ) ) {
		dom_obj_masque = document.createElement("DIV");
		dom_obj_masque.id = "zoom_masque";
		document.body.appendChild( dom_obj_masque );
	}
	
	if ( ! ( dom_obj_zoom = document.getElementById("zoom_div") ) ) {
		dom_obj_zoom = document.createElement("DIV");
		dom_obj_zoom.id = "zoom_div";
		document.body.appendChild( dom_obj_zoom );
	}
	
	dom_obj_masque.className = 'couleur1';
	dom_obj_masque.style.cssText="position:absolute;z-index:99;top:0px;left:0px;"
		+ "display:block;filter:alpha(opacity:70);";
	dom_obj_masque.style.opacity = 0.7;
	dom_obj_masque.style.height = document.body.scrollHeight + "px";
	dom_obj_masque.style.width = document.body.scrollWidth + "px";
	
	dom_obj_zoom.style.width = "400px";
	dom_obj_zoom.style.height = "400px";
	//dom_obj_zoom.style.top = (((document.body.clientHeight-400)/2)+document.body.scrollTop) + "px";
	dom_obj_zoom.style.top = '50px';
	dom_obj_zoom.style.left = (((document.body.clientWidth-400)/2)+document.body.scrollLeft) + "px";
	
	dom_obj_zoom.style.display="block";
	dom_obj_zoom.style.padding = '2px';
	dom_obj_zoom.style.background = '#FFFFFF';
	dom_obj_zoom.style.zIndex = 101;
	dom_obj_zoom.style.position = 'absolute';
	//dom_obj_zoom.style.filter = 'alpha(opacity:100)';
	dom_obj_zoom.style.opacity = 1;
	dom_obj_zoom.style.border="1px solid #000000";
	
	//var tmphtml = "<div style='width:100%;text-align:center' id='zoom_txtcharge'>Chargement en cours</div>";
	var tmphtml = "";
	
	tmphtml += "<a href=\"#null\" onclick=\"hide_zoom();\" style='float:right;cursor:pointer'>" +
		"<img src='" + document.getElementById('zoom_txtcharge').getElementsByTagName("img")[0].src + "'  id='zoom_close' onclick=\"hide_zoom();\">" + 
		"</a><div style='clear: both; margin-bottom: 5px;'></div>";
		
	tmphtml += add_html;
	
	dom_obj_zoom.innerHTML = tmphtml;
}

function sendtofriend_open(action, url, from, email) {
	
	var tmphtml = "";
	
	new Ajax.Request(action, {
	  method: 'post',
	  onSuccess: function(transport) {
		tmphtml = '<div id="masque_content">' + transport.responseText + '</div>';
		use_masque(tmphtml);
		
		var obj = $('masque_content');
		resize_zoom(obj);
		
	  }
	});

}

function sendtofriend_send(action) {
	var datas = new Array();
	datas = collate_form_datas('frmsendfriend');
	
	new Ajax.Request(action, {
	  method: 'post',
	  parameters: { datas: datas }, 
	  onSuccess: function(transport) {
		tmphtml = '<div id="masque_content">' + transport.responseText + '</div>';
		use_masque(tmphtml);
		
		var obj = $('masque_content');
		resize_zoom(obj);
		
	  }
	});
	
	return false;
}

function collate_form_datas(id_from) {
	var elts = new Array();
	var datas = '';
	
	elts = $(id_from).getElements();
	var nbelts = elts.length;
	
	for(i=0; i<nbelts; i++) {
		if (elts[i].id)
			datas += '&' + elts[i].id +'='+elts[i].value;
	}
	return datas;
}

/* 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
*/
function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i];
		  var imgName = img.src.toUpperCase();
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : "";
			 var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			 var imgStyle = "display:inline-block;" + img.style.cssText ;
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" ;
			 img.outerHTML = strNewHTML;
			 i = i-1;
		  }
	   }
	}
};

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
if ((version >= 5.5) && (version < 7))
	window.attachEvent("onload", correctPNG);
