function getWidth(width)
{
	if(typeof(width)=='string')
	{
		var idx = width.lastIndexOf("%");
		if(idx>0) width = (screen.availWidth>0?screen.availWidth:screen.width) * width.substring(0,idx) / 100;
	}
	return width;
}

function getHeight(height)
{
	if(typeof(height)=='string')
	{
		var idx = height.lastIndexOf("%");
		if(idx>0) height = (screen.availHeight>0?screen.availHeight:(screen.height-20)) * height.substring(0,idx) / 100;
	}
	return height;
}

function getLeft(width)
{
	var left = ((screen.availWidth>0?screen.availWidth:screen.width) - width) / 2;
	return left;
}

function getTop(height)
{
	var top = ((screen.availHeight>0?screen.availHeight:(screen.height-20)) - height) / 2;
	return top;
}

function popup_memo(url,code,width,height)
{
	if(code!="")
	{
		width = getWidth(width);
		height = getHeight(height);
		var left = getLeft(width);
		var top = getTop(height);
		getContext().memoswindowurl = url+"&code="+code;
		getContext().memoswindow = window.open(getContext().memoswindowurl,"Memos","scrollbars=1,toolbar=0,resizable=1"+(width>0?(",width="+width):"")+(height>0?(",height="+height):""));
		if(is.ie) getContext().memoswindow.focus();
	}
	else
		close_memo();
	return false;
}

function close_memo()
{
	if(typeof(getContext().memoswindow)!="undefined")
		with(getContext())
			if(!memoswindow.closed)
				memoswindow.close();
}

function popup_img(url,code,width,height)
{
	if(code!="")
	{
		var left=-1,top=-1,sb=0;
		width = getWidth(width);
		height = getHeight(height);
		if(width==-1) {width=screen.availWidth;left=0;sb=1}
		else left = getLeft(width);
		if(height==-1) {height=screen.availHeight;top=0;sb=1}
		else top = getTop(height);
		getContext().imageswindowurl = url+"&code="+code+"&width="+width+"&height="+height+"&win=true";
		getContext().imageswindow = window.open(getContext().imageswindowurl,"Images","scrollbars="+sb+",toolbar=0,resizable=1,dependent=1,alwaysRaised=1,left="+left+",top="+top+",width="+width+",height="+height+",outerWidth="+width+",outerHeight="+height);
		if(is.ie) getContext().imageswindow.focus();
	}
	else
		close_img();
	return false;
}

function close_img()
{
	if(typeof(getContext().imageswindow)!="undefined")
		with(getContext())
			if(!imageswindow.closed)
				imageswindow.close();
}

function popup_obj(url,width,height)
{
	width = getWidth(width);
	height = getHeight(height);
	var left = getLeft(width);
	var top = getTop(height);
	getContext().objectswindow = window.open(url,"Objects","toolbar=0,resizable=1,dependent=1,alwaysRaised=1,left="+left+",top="+top+",width="+width+",height="+height+",outerWidth="+width+",outerHeight="+height);
	if(is.ie) getContext().objectswindow.focus();
	return false;
}

function close_obj()
{
	if(typeof(getContext().objectswindow)!="undefined")
		with(getContext())
			if(!objectswindow.closed)
				objectswindow.close();
}

function popup_spec(url,width,height)
{
	width = getWidth(width);
	height = getHeight(height);
	var left = getLeft(width);
	var top = getTop(height);
	getContext().specswindow = window.open(url,"Specs","scrollbars=1,toolbar=0,status=1,resizable=1,dependent=1,alwaysRaised=1,left="+left+",top="+top+",width="+width+",height="+height+",outerWidth="+width+",outerHeight="+height);
	if(is.ie) getContext().specswindow.focus();
	return false;
}

function close_spec()
{
	if(typeof(getContext().specswindow)!="undefined")
		with(getContext())
			if(!specswindow.closed)
				specswindow.close();
}

function popup_cad(url,width,height)
{
	width = getWidth(width);
	height = getHeight(height);
	var left = getLeft(width);
	var top = getTop(height);
	getContext().cadwindow = window.open(url,"CADs","toolbar=0,status=1,resizable=1,dependent=1,alwaysRaised=1,left="+left+",top="+top+",width="+width+",height="+height+",outerWidth="+width+",outerHeight="+height);
	if(is.ie) getContext().cadwindow.focus();
	return false;
}

function close_cad()
{
	if(typeof(getContext().cadwindow)!="undefined")
		with(getContext())
			if(!cadwindow.closed)
				cadwindow.close();
}

function close_windows()
{
	// bug IE : doc.xxxxwindow.close() en rafale bloque le navigateur
	var doc = getContext();
	if(typeof(doc.memoswindow)!="undefined" && !doc.memoswindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.memoswindow.close();
		else
			window.open('','Memos').close();
	}
	if(typeof(doc.imageswindow)!="undefined" && !doc.imageswindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.imageswindow.close();
		else
			window.open('','Images').close();
	}
	if(typeof(doc.objectswindow)!="undefined" && !doc.objectswindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.objectswindow.close();
		else
			window.open('','Objects').close();
	}
	if(typeof(doc.specswindow)!="undefined" && !doc.specswindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.specswindow.close();
		else
			window.open('','Specs').close();
	}
	if(typeof(doc.cadwindow)!="undefined" && !doc.cadwindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.cadwindow.close();
		else
			window.open('','CADs').close();
	}
	if(typeof(doc.complistwindow)!="undefined" && !doc.complistwindow.closed)
	{
		if(is.ie&&!is.ie6up)
			doc.complistwindow.close();
		else
			window.open('','complist').close();
	}
}

function img_assist(code,url)
{
	var elt;
	if((elt=getElementById(document,'assist_'+code))!=null)
	{
		if(is.khtml)
		{
			if(elt.style.display == 'none')
			{
				elt.style.display = '';
				elt.src = url + "&selparameter=" + code;
			}
			else
			{
				if(elt.style.height != "0px")
					elt.style.height = "0px";
				else
					elt.style.height = "";
			}
		}
		else
		{
			var visible = elt.style.display!='none';
			elt.style.display = visible?'none':'';
			elt.src = !visible?(url + "&selparameter=" + code):'about:blank';
		}
	}
	return false;
}

function show_parts(url)
{
	var elt;
	if((elt=getElementById(document,'Parts'))!=null)
	{
		var visible = elt.style.display!='';
		elt.style.display=!visible?'none':''
		if(visible)
			elt.src = url;
		else
			elt.src = 'about:blank';
	}
	return false;
}

