/* RP (c) 2007 Nordsites.com */

function fix_ratio(name,ratio) {		
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src;			
		if (imgName.substring(imgName.length - name.length, imgName.length) == name) {				
			if( img.naturalHeight ) { 
				//firefox
				h = img.naturalHeight;
				w = img.naturalWidth;
			} else {
				//IE
				lgi = new Image();
				lgi.src = img.src;
				h = lgi.height;
				w = lgi.width
			}
			img.style.width = Math.round( w * ratio) + "px";
			img.style.height = Math.round( h * ratio) + "px";								
		}
	}		
}
	
function clip_img(name,dim) {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src;		

		if (imgName.substring(imgName.length - name.length, imgName.length) == name) {
			if( img.naturalHeight ) { 
				//firefox
				h = img.naturalHeight;
				w = img.naturalWidth;
			} else {
				//IE
				lgi = new Image();
				lgi.src = img.src;
				h = lgi.height;
				w = lgi.width
			}
			//find the min of width and height
			if(h < w) {
				new_h = dim;
				new_w = Math.round(dim * w / h);
				l = - Math.round((new_w-dim)/2);
				t = 0;
			} else {
				new_w = dim;
				new_h = Math.round(dim * h /w);
				t = - Math.round((new_h-dim)/2);
				l = 0;
			}
			img.style.width = new_w + "px";
			img.style.height = new_h + "px";
			img.style.top = t + "px";
			img.style.left = l + "px";
		}
		//force refresh
		//img.src = img.src + "?random=" + Math.random();
	}
}

function clip_img_by_id(id, dim) {
	var img = document.getElementById(id);

	if( img.naturalHeight ) { 
		//firefox
		h = img.naturalHeight;
		w = img.naturalWidth;
	} else {
		//IE
		lgi = new Image();
		lgi.src = img.src;
		h = lgi.height;
		w = lgi.width
	}
	//find the min of width and height
	if(h < w) {
		new_h = dim;
		new_w = Math.round(dim * w / h);
		l = - Math.round((new_w-dim)/2);
		t = 0;
	} else {
		new_w = dim;
		new_h = Math.round(dim * h /w);
		t = - Math.round((new_h-dim)/2);
		l = 0;
	}
	img.style.width = new_w + "px";
	img.style.height = new_h + "px";
	img.style.top = t + "px";
	img.style.left = l + "px";
}

function fenetr()
{
  window.open('','help','width=600,height=550,resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no');
}

function fenetre()
{
  window.open('','act','width=500,height=380,resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no');
}

function fenetretradeoff()
{
  window.open('','tradeoff','width=640,height=380,resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no');
}


function fenetrephoto()
{
  window.open('','photo','width=600,height=470,resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no');
}

//
// ouvre un popup
//
var popUpWin=0;
function popup(URLStr, width, height) {
	if(popUpWin) {
		if(!popUpWin.closed)
			popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height);  
}
	

//
// Gestion de la photo perso
//
function do_submit(etape, action) {
	document.forms['photo'].action.value = action;
	document.forms['photo'].submit();
}
/*
//ne pas l'utiliser, elle merde sous IE5
function check_ajouter() {
	if (document.photo.the_file.value.length<1) {
		document.photo.ajouter.disabled=true;
	}
	else {
		document.photo.ajouter.disabled=false;
	}
}

function open_preview() {
	window.open('','preview','width=500,height=500,resizable=no,scrollbars=no,'+'menubar=no,toolbar=no,location=no,directories=no');
	return true;
}
*/
