//-----------------------------------------------------------------------------
// SMILE
// @(#) $Header: /home/cvs/src/iir2/web/war/javascripts/page_details.js,v 1.13 2008-02-15 10:00:48 ansam Exp $
// 
// Projet : IIR2
// 
// Description : Fonctions javascript pour la generation du graphe de chargement de page.
// 
// Creation : ??/07/2007
//
// Historique : 
// ??/07/2007 jakac Creation
// 12/02/08 ansam Corrections bug #0005911
//-----------------------------------------------------------------------------
/**
 * @author jakac
 */

var minTime = null;
var maxTime = 0;	
var minSize = null;
var maxSize = 0;	
var scaleMaxTime = 0;
var element_count = 0;

    /**
     * Returns the closest <code>double</code> to the argument. 
     * The result is rounded to the number of given <code>places</code>. 
     * 
     * @param value         - value to be rounded
     * @param places        - number of places after the comma
     * 
     * @return              - rounded <code>double</code> value
     */
    function round(value, places) {
        factor = Math.pow(10, places);     
        
        value = value * factor;
        tmp = Math.round(value);
        
        return tmp / factor;
    }     

function setElementCount(count, sort){
	if (sort == "stime_DESC")
		element_count = count;
	else 
		element_count = 0;
}

function setSizeSelect(size){
	if (size == "2000")
		document.filter.sizefilter.selectedIndex = 1;
	else
		document.filter.sizefilter.selectedIndex = 0;					
}

function setTypeSelect(type){
	if (type == "application"){
		document.filter.typefilter.selectedIndex = 1;
	}
	else if (type == "image"){
		document.filter.typefilter.selectedIndex = 2;				
	}						
	else if (type == "text"){
		document.filter.typefilter.selectedIndex = 3;				
	}
	else{
		document.filter.typefilter.selectedIndex = 0;					
	}
}

function refreshSite(domian_name, ressource_id, result_id, size, type, sort){
	url = "/ressourcesize/" + domian_name + "/" + ressource_id + "/" + result_id + "/?size=" + size + "&type=" + type + "&sort=" + sort;
				
	window.location.assign(url);	
}

function addScaleValues(){
	intervall = parseInt(scaleMaxTime / 10);	
	for (i=0; i<=9; i++){
		var scale_cell = document.getElementById('scale' + i);	
		scale_cell.appendChild(document.createTextNode(parseInt(intervall * parseInt(i + 1)) / parseInt(1000) + 's'));				
	}
}

function addElementLine(itemIndex, url, name, type, size, extern, barWidth, barHeight, barX, barColor, responseTime){
	var elements_table = document.getElementById('elements_table');
	
	var row = elements_table.insertRow(parseInt(itemIndex) + parseInt(3));
	row.style.width = '100%';	
	row.style.borderBottom = "1px solid #FFFFFF";

	// type cell
    var type_cell  = row.insertCell(0);			
	type_cell.id = 'element' + itemIndex + '_type';		
	type_cell.style.width = '5%';
	type_cell.style.textAlign = 'center';	
	type_cell.style.borderRight = "1px solid #FFFFFF";	
	type_cell.style.borderBottom = "1px solid #FFFFFF";	

	var type_image = document.createElement('img');	
	type_image.id = 'element' + itemIndex + '_type_image'
	type_image.src = getImageForType(type);
	type_cell.appendChild(type_image);
	
	// name cell
    var name_cell  = row.insertCell(1);			
	name_cell.id = 'element' + itemIndex + '_name';
	name_cell.style.width = '25%';	
	name_cell.style.borderRight = "1px solid #FFFFFF";		
	name_cell.style.borderBottom = "1px solid #FFFFFF";		
				
	var link = document.createElement('a');		
	link.id = 'element' + itemIndex + '_link';
	link.setAttribute("href", url);
	link.style.textDecoration = 'none';
	nameColor = "#000000";
	if (extern){
		nameColor = "#FF0000";		
	}		
	
	link.style.color = nameColor;
	if (name == ""){
		
		name = url;
		if (name.length > 30){
			name = name.substring(0, 27) + "..";
		}				
		
	}
	
	link.appendChild(document.createTextNode(name));				
	name_cell.appendChild(link);
	
	// size cell
    var size_cell  = row.insertCell(2);				
	size_cell.id = 'element' + itemIndex + '_size';
	size_cell.style.width = '8%';	
	size_cell.style.borderRight = "1px solid #FFFFFF";		
	size_cell.style.borderBottom = "1px solid #FFFFFF";		
	size_cell.style.fontSize = "80%";
	size_cell.style.textAlign = 'right';
	
	size_rounded = round(parseFloat(size) / parseFloat(1000), 1);
	size_cell.appendChild(document.createTextNode(size_rounded + ' KO'));		
	
	// time cell
    var time_cell  = row.insertCell(3);		
	time_cell.colSpan = 10;
	time_cell.id = 'element' + itemIndex + '_time';	
	time_cell.style.width = '65%';
	time_cell.style.background = 'transparent url(/img/static/img_ressourcesize/iir2_bkg_grph_totd.gif) repeat-x scroll 0%';
	if (itemIndex%2 == 0){
		time_cell.style.background = 'transparent url(/img/static/img_ressourcesize/iir2_bkg_grph_totc.gif) repeat-x scroll 0%';
	}			
	
	// download time bar
	var downloadDiv = document.createElement('div');			
	downloadDiv.id = 'element' + itemIndex + '_bar';	
	downloadDiv.title = 'Temps de reponse: ' + (parseFloat(responseTime) / parseFloat(1000)) + ' s';	
	downloadDiv.style.height = "10px";
	downloadDiv.style.width = barWidth + "%";	
	downloadDiv.style.background = barColor;		
	downloadDiv.style.position = "relative";
	downloadDiv.style.left = barX + "%";
	downloadDiv.style.top = '1px';
	downloadDiv.style.fontSize = "6";
	
	time_cell.appendChild(downloadDiv);				
}

function getImageForType(type){
	TYPE_IMG_TEXT = "/img/static/img_ressourcesize/txt.gif";
	TYPE_IMG_IMAGE = "/img/static/img_ressourcesize/img.gif";
	TYPE_IMG_AUDIO = "/img/static/img_ressourcesize/audio.png";
	TYPE_IMG_VIDEO = "/img/static/img_ressourcesize/video.gif";
	TYPE_IMG_APP = "/img/static/img_ressourcesize/exe.gif";
	TYPE_IMG_MULTIPART = "/img/static/img_ressourcesize/multipart.png";
	TYPE_IMG_MSG = "/img/static/img_ressourcesize/message.gif";		
	
	if (type == "text" || type == "text-css" || type == "text-html"){		
		return TYPE_IMG_TEXT;
	}
	else if (type == "image"){
		return TYPE_IMG_IMAGE;				
	}
	else if (type == "application" || type == "application-swf" || type == "application-js"){
		return TYPE_IMG_APP;				
	}
	else if (type == "audio"){
		return TYPE_IMG_AUDIO;				
	}
	else if (type == "video"){
		return TYPE_IMG_VIDEO;				
	}
	else if (type == "multipart"){
		return TYPE_IMG_MULTIPART;				
	}
	else if (type == "message"){
		return TYPE_IMG_MSG;				
	}			
}

/**
 * Adds the onmouseover and onmouseout events to each row of the chart
 * 
 * @param {Object} componentCount
 */
function addEventsToInfoButton(index){
	idImgInfo = 'element' + index + '_type';
	idBar = 'element' + index + '_bar';
	idLink = 'element' + index + '_link';

//	document.getElementById(idImgInfo).onmouseover = new Function('createBorder("' + idBar + '"); return true;');	
//	document.getElementById(idImgInfo).onmouseout = new Function('removeBorder("' + idBar + '"); return true;');			

	document.getElementById(idImgInfo).onmouseover = new Function('onMouseOverFunc("' + idBar + '", "' + idLink + '"); return true;');	
	document.getElementById(idImgInfo).onmouseout = new Function('onMouseOutFunc("' + idBar + '", "' + idLink + '"); return true;');			

}


/**
 * Adds tooltip to table rows
 * 
 * @param {Object} size
 * @param {Object} startTime
 * @param {Object} responseTime
 * @param {Object} type
 * @param {Object} url
 * @param {Object} name
 * @param {Object} barWidth
 * @param {Object} barHeight
 * @param {Object} barX
 * @param {Object} barColor
 * @param {Object} extern
 * @param {Object} componentIndex
 */
function addInfoToolTip(size, startTime, responseTime, type, url, name, barWidth, barHeight, barX, barColor, extern, componentIndex){

	// get the document elements: image cell, name cell, bar cell and the bar div
	idName = "element" + componentIndex + "_name";
	elName = document.getElementById(idName);			
	
	idRow = "element" + componentIndex + "_time";
	elRow = document.getElementById(idRow);
		
	idBar = "element" + componentIndex + "_bar";
	elBar = document.getElementById(idBar);					
	
	idType = "element" + componentIndex + "_type";
	elImgType = document.getElementById(idType);					

	idIndex = "element" + componentIndex + "_no";
	elIndex = document.getElementById(idIndex);						
	
	idSize = "element" + componentIndex + "_size";
	elSize = document.getElementById(idSize);							
	
	endTime = parseInt(startTime) + parseInt(responseTime);
	barEndPrc = (parseFloat(barX) + parseFloat(barWidth)) / 100;
	
	offsetXForBar = 0;
	newOffset = 0;
	diff = 0;
			
	if (navigator.appName != 'Microsoft Internet Explorer'){
		offsetXForBar = offsetXForBar + parseFloat(5);
		diff = parseFloat(5);
	}	
	
	// diff = parseFloat(getX(elBar)) - parseFloat(getX(elRow)) + diff;

	//	newOffset = parseFloat(elBar.offsetWidth) + parseFloat(elInfo.offsetWidth) + parseFloat(diff);
	newOffset = parseFloat(elImgType.offsetWidth);
	newOffset = parseFloat(getX(elImgType));
//	newOffset = 0;
	
	// get the tooltip with custom offset	
//	toolTipInfo = getFixedToolTip(name, url, type, size, startTime, endTime, responseTime, barColor, extern, newOffset, 0, componentIndex);	
	toolTipInfo = createToolTip(name, url, type, size, startTime, endTime, responseTime, barColor, extern, newOffset, 0, componentIndex);	

	elImgType.title = toolTipInfo;
//	elImgType.title = "header=[wdfgdg] body=[qsgqsgsd] fixedrelx=[0] fixedrely=[0]";
}

/**
 * Returns the absolute X coordinate of given element
 * 
 * @param {Object} oElement
 */
function getX(oElement){
   	var iReturnValue = 0; 
	while(oElement) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

/**
 * Returns the absolute Y coordinate of given element
 * 
 * @param {Object} oElement
 */
function getY(oElement){
	var iReturnValue = 0;
	while( oElement ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	
	return iReturnValue;
}

/**
 * Counts the percentage.
 * 
 * @param {Object} totalTime
 * @param {Object} time
 */
function getPercentage(total, part){
	return part / total * 100;	
}		

/**
 * Sets the global variables minTime and maxTime 
 * (only if current minTime is > than startTime 
 * or current maxTime is < than endTime (startTime + responseTime)).
 * 
 * @param {Object} startTime
 * @param {Object} responseTime
 */
function setMinAndMaxTime(startTime, responseTime){	
	if (minTime == null || startTime < minTime){
		minTime = startTime;
	}
	if (startTime + responseTime > maxTime){
		maxTime = startTime + responseTime;
	}		
			
}

/**
 * Sets the global variables minSize and maxSize 
 * (only if current minSize is > than size 
 * or current maxSize is < than size.
 * 
 * @param {Object} size
 */
function setMinAndMaxSize(size){	
	if (minSize == null || size < minSize){
		minSize = size;
	}
	if (size > maxSize){
		maxSize = size;
	}	
}

/**
 * Counts the component loading bitrate
 * 
 * @param size  size of the component (in bytes)
 * @param time	component loading time (in ms) 
 */
function countBitRate(size, responseTime){
	sizeKBit = (parseFloat(size) * parseFloat(8)) / parseFloat(1000);
    timeSec = parseFloat(responseTime) / parseFloat(1000);
    	
    return parseFloat(sizeKBit) / parseFloat(timeSec);
}	

/**
 * Parse the components URL.
 * Returns the name of the file.
 * 
 * @param {Object} url
 */
function getNameFromUrl(url){
	startIndex = parseInt(url.lastIndexOf("/")) + parseInt(1);
	name = url.substring(startIndex, url.length);	
	
	index = name.indexOf("?");
	
	if (index >= 0){
		name = name.substring(0, index);
	}
	
	if (name.length > 30){
		name = name.substring(0, 27) + "..";
	}
			
	return name;
}

/**
 * For the component type: text and application, depending on file extension,
 * creates new types: text-css, text-html, application-js, application-swf. 
 * Retuirns new type.
 * 
 * @param {Object} type
 * @param {Object} url
 */
function getCustomType(type, url){
	if (type == "text"){
		if (url.indexOf(".css") >= 0){
			return "text-css";
		}
		else if (url.indexOf(".htm") >= 0){
			return "text-html";
		}	
		else{
			return type;
		}					
	}	
	else if (type == "application"){
		if (url.indexOf(".js") >= 0){
			return "application-js";
		}
		else if (url.indexOf(".swf") >= 0){
			return "application-swf";			
		}	
		else{
			return type;
		}					
	}
	else{
		return type;
	}
}

/**
 * Returns the color for each component type.
 * 
 * @param {Object} type
 */
function getColor(type){
	TYPE_COLOR_TEXT = "#1E90FF";
	TYPE_COLOR_TEXT_CSS = "#4169E1";
	TYPE_COLOR_TEXT_HTML = "#00BFFF";
	TYPE_COLOR_IMAGE = "#32CD32";
	TYPE_COLOR_AUDIO = "#A9A9A9";
	TYPE_COLOR_VIDEO = "#FF6347";
	TYPE_COLOR_APP = "#C71585";
	TYPE_COLOR_APP_JS = "#FF1493";
	TYPE_COLOR_APP_SWF = "#FF69B4";
	TYPE_COLOR_MULTIPART = "#FFD700";
	TYPE_COLOR_MSG = "#D2691E";		
	
	if (type == "text-css"){		
		return TYPE_COLOR_TEXT_CSS;
	}
	else if (type == "text-html"){
		return TYPE_COLOR_TEXT_HTML;		
	}
	else if (type == "text"){
		return TYPE_COLOR_TEXT;		
	}	
	else if (type == "image"){
		return TYPE_COLOR_IMAGE;				
	}
	else if (type == "application-js"){
		return TYPE_COLOR_APP_JS;				
	}
	else if (type == "application-swf"){
		return TYPE_COLOR_APP_SWF;				
	}	
	else if (type == "application"){
		return TYPE_COLOR_APP;				
	}
	else if (type == "audio"){
		return TYPE_COLOR_AUDIO;				
	}
	else if (type == "video"){
		return TYPE_COLOR_VIDEO;				
	}
	else if (type == "multipart"){
		return TYPE_COLOR_MULTIPART;				
	}
	else if (type == "message"){
		return TYPE_COLOR_MSG;				
	}	
}

/**
 * Returns the max value on the scale of the chart
 * 
 * @param {Object} time
 */
function getChartScale(time){
//	var out = document.getElementById('output');			
//	out.appendChild(document.createTextNode('0 - time = ' + time + "</br>"));
		
	scaleMax = 0;
	tmp = 0;
	
	// 1 - devide by 100
	tmp = parseFloat(time) / parseFloat(100.0);
//	out.appendChild(document.createTextNode('1 - tmp = ' + tmp + "</br>"));	
	
	// 2 - add 0.5 (to get always "round up" in the next step)
	tmp = parseFloat(tmp) + parseFloat(0.5);
//	out.appendChild(document.createTextNode('2 - tmp = ' + tmp + "</br>"));		
	
	// 3 - do "round up"
	tmp = Math.round(tmp);
//	out.appendChild(document.createTextNode('3 - tmp = ' + tmp + "</br>"));		
	
	/*
	// 4 - devide by 10
	tmp = parseFloat(tmp) / parseFloat(10.0);
	out.appendChild(document.createTextNode('4 - tmp = ' + tmp + "</br>"));		
	
	// 5 - add 0.5 (to get always "round up" in the next step)
	tmp = parseFloat(tmp) + parseFloat(0.5);
	out.appendChild(document.createTextNode('5 - tmp = ' + tmp + "</br>"));		
	
	// 6 - do "round up"
	tmp = Math.round(tmp);
	out.appendChild(document.createTextNode('6 - tmp = ' + tmp + "</br>"));		
	
	// 7 - devide by 10
	tmp = parseFloat(tmp) / parseFloat(10.0);
	out.appendChild(document.createTextNode('7 - tmp = ' + tmp + "</br>"));			
	
	// 8 - count scale max time
	tmp = parseFloat(tmp) * parseFloat(10.0);
	out.appendChild(document.createTextNode('8 - tmp = ' + tmp + "</br>"));		
	
	// 9 - * 1000 to get value in ms
	scaleMax = parseFloat(tmp) * parseFloat(1000.0);
	*/
	
	// 4 - devide by 100
	tmp = parseFloat(tmp) / parseFloat(100.0);
//	out.appendChild(document.createTextNode('7 - tmp = ' + tmp + "</br>"));			
	
	// 5 - * 10000 to get value in ms
	scaleMax = parseFloat(tmp) * parseFloat(10000.0);
	
	return scaleMax;
}	

/**
 * Returns the max value on the scale of the chart
 * 
 * @param {Object} time
 */
function getChartScale_old(time){
	temp = 0;
	scaleMax = 0;
	
	if (time >= 1 && time < 10){
		temp = parseFloat(time) + parseFloat(0.5);
		scaleMax = Math.round(temp);
	}
	else if (time >= 10 && time < 100){
		temp = parseFloat(time / 10) + parseFloat(0.5);
		scaleMax = Math.round(temp) * 10;
	}
	else if (time >= 100 && time < 1000){
		temp = parseFloat(time / 100) + parseFloat(0.5);
		scaleMax = Math.round(temp) * 100;
	}
	else if (time >= 1000 && time < 10000){
		temp = parseFloat(time / 1000) + parseFloat(0.5);		
		scaleMax = Math.round(temp) * 1000;
	}
	else if (time >= 10000 && time < 100000){
		temp = parseFloat(time / 10000) + parseFloat(0.5);
		scaleMax = Math.round(temp) * 10000;
	}
	else if (time >= 100000 && time < 1000000){
		temp = parseFloat(time / 100000) + parseFloat(0.5);
		scaleMax = Math.round(temp) * 100000;
	}
	else{
		scaleMax = parseFloat(time / 10);
	}
	
	return scaleMax;
}

/**
 * Creates the border round the element.
 * Used during mouseOver event.
 * 
 * @param {Object} idBar	id of the element
 */
function createBorder(idBar){
	element = document.getElementById(idBar);
	
	oldHeight = element.style.height;		
	oldHeight = oldHeight.toString().substring(0, oldHeight.toString().length - 2);
			
	if (navigator.appName != 'Microsoft Internet Explorer'){
		element.style.height = parseInt(oldHeight) - parseInt(4) + 'px';
	}
	
	element.style.border = "2px solid black";
}

/**
 * Removes the border round the element.
 * Used during mouseOut event.
 * 
 * @param {Object} idBar	id of the element
 */
function removeBorder(idBar){
	element = document.getElementById(idBar);
	
	oldHeight = element.style.height;	
	oldHeight = oldHeight.toString().substring(0, oldHeight.toString().length - 2);			
	
	element.style.border = "0px solid black"; 		

	if (navigator.appName != 'Microsoft Internet Explorer'){
		element.style.height = parseInt(oldHeight) + parseInt(4) + 'px';
	}				
}

/**
 * Underlines the name element.
 * Used during mouseOver event.
 * 
 * @param {Object} idLink	id of the url element
 */
function underLineName(idLink){
	element = document.getElementById(idLink);				
	element.style.textDecoration = 'underline';
}

/**
 * Removes underline of the name element.
 * Used during mouseOut event.
 * 
 * @param {Object} idLink	id of the url element
 */
function removeUnderLineName(idLink){
	element = document.getElementById(idLink);				
	element.style.textDecoration = 'none';
}

function onMouseOverFunc(idBar, idLink){
	createBorder(idBar);
	underLineName(idLink);
}

function onMouseOutFunc(idBar, idLink){
	removeBorder(idBar);
	removeUnderLineName(idLink);
}

function createToolTip(name, url, customType, size, startTime, endTime, responseTime, color, isExtern){
	if (isExtern){
		name = name + ' <font color=red> - EXTERN FILE </color>';
	}
	
	tip = 'tooltip';	
	bitRate = countBitRate(size, responseTime);	
	
	if (customType == "image"){		
		tip = 'header=[' + name + '] body=[' + 
				'<table style="text-align: left"> ' + 
					'<tbody>' + 
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td></tr>' + 							
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td style="text-align: center; vertical-align: middle; width: 170px;"> Type d\'élément: ' + customType + ' &nbsp </td></tr>' + 
						'<tr>' + 
							'<td> Taille: </td>' + 
							'<td>' + size + ' &nbsp </td>' + 
							'<td> bytes </td>' + 
							'<td rowspan="6" colspan="1" style="text-align: center; vertical-align: middle; width: 170px;"> ' + 
								'<img style="border: 1px solid #000000" src="' + url + '" width="150" height="60"></td></tr>' + 														
						'<tr>' + 
							'<td> Débit moyen: </td>' + 
							'<td>' + Math.round(bitRate) + ' &nbsp </td>' + 
							'<td> kbit/s </td></tr>' + 
						'<tr>' + 
							'<td> Début de téléchargement: &nbsp </td>' + 
							'<td>' + startTime + ' &nbsp </td>' + 	
							'<td> ms </td></tr>' + 								
						'<tr>' + 
							'<td> Fin de téléchargement: </td>' + 
							'<td>' + endTime + ' &nbsp </td>' + 
							'<td> ms </td></tr>' + 							
						'<tr>' + 
							'<td> Temps de chargement: </td>' + 
							'<td>' + responseTime + ' &nbsp </td>' +
							'<td> ms </td></tr>' +							
						'<tr>' + 
							'<td> &nbsp</td>' + 
							'<td> &nbsp</td></tr>' + 							
					'</tbody>' + 
				'</table>]'; 
	}
	else if (customType == "application-swf"){
		tip = 'header=[' + name + '] body=[' + 
				'<table style="text-align: left"> ' + 
					'<tbody>' + 
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td></tr>' + 							
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td style="text-align: center; vertical-align: middle; width: 170px;"> Type d\'élément: ' + customType + ' &nbsp </td></tr>' + 
						'<tr>' + 
							'<td> Taille: </td>' + 
							'<td>' + size + ' &nbsp </td>' + 
							'<td> bytes </td>' + 
							'<td rowspan="6" colspan="1" style="text-align: center; vertical-align: middle; width: 170px;"> ' + 
								'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' + 
								'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="150" height="60" id="flashmovie">' + 
								'<param name="movie" value="' + url + '" />' + 
								'<param name="quality" value="high" /> ' + 
								'<param name="bgcolor" value="#000000" /> ' + 
								'<embed style="border: 1px solid #000000" src="' + url + '" quality="high" bgcolor="#000000" width="150" height="60" name="flashmovie" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed> </object> </td></tr>' + 				
						'<tr>' + 
							'<td> Débit moyen: </td>' + 
							'<td>' + Math.round(bitRate) + ' &nbsp </td>' + 
							'<td> kbit/s </td></tr>' + 
						'<tr>' + 
							'<td> Début de téléchargement: &nbsp </td>' + 
							'<td>' + startTime + ' &nbsp </td>' + 	
							'<td> ms </td></tr>' + 								
						'<tr>' + 
							'<td> Fin de téléchargement: </td>' + 
							'<td>' + endTime + ' &nbsp </td>' + 
							'<td> ms </td></tr>' + 							
						'<tr>' + 
							'<td> Temps de chargement: </td>' + 
							'<td>' + responseTime + ' &nbsp </td>' +
							'<td> ms </td></tr>' +							
						'<tr>' + 
							'<td> &nbsp</td>' + 
							'<td> &nbsp</td></tr>' + 							
					'</tbody>' + 
				'</table>]'; 		
	}
	else{
		if (name == ""){
			name = url;
			
			if (name.length > 30){
				name = name.substring(0, 27) + "..";
			}			
		}
		
		tip = 'header=[' + name + '] body=[' + 
				'<table style="text-align: left"> ' + 
					'<tbody>' + 
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td></tr>' + 							
						'<tr>' + 
							'<td> &nbsp </td>' + 
							'<td> &nbsp </td>' + 							
							'<td> &nbsp </td>' + 
							'<td style="text-align: center; vertical-align: middle; width: 170px;"> Type d\'élément: ' + customType + ' &nbsp </td></tr>' + 
						'<tr>' + 
							'<td> Taille: </td>' + 
							'<td>' + size + ' &nbsp </td>' + 
							'<td> bytes </td>' + 
							'<td rowspan="6" colspan="1" style="text-align: center; vertical-align: middle; width: 170px;">' + 
								'<img style="border: 1px solid #000000" src="/img/no_image.jpg" width="150" height="60"></td></tr>' + 
						'<tr>' + 
							'<td> Débit moyen: </td>' + 
							'<td>' + Math.round(bitRate) + ' &nbsp </td>' + 
							'<td> kbit/s </td></tr>' + 
						'<tr>' + 
							'<td> Début de téléchargement: &nbsp </td>' + 
							'<td>' + startTime + ' &nbsp </td>' + 	
							'<td> ms </td></tr>' + 								
						'<tr>' + 
							'<td> Fin de téléchargement: </td>' + 
							'<td>' + endTime + ' &nbsp </td>' + 
							'<td> ms </td></tr>' + 							
						'<tr>' + 
							'<td> Temps de chargement: </td>' + 
							'<td>' + responseTime + ' &nbsp </td>' +
							'<td> ms </td></tr>' +							
						'<tr>' + 
							'<td> &nbsp</td>' + 
							'<td> &nbsp</td></tr>' + 							
					'</tbody>' + 
				'</table>]'; 		
	}		
	
	return tip;
}

/**
 * Checks home server name
 * 
 * @param {Object} server
 */
function checkHomeServerName(homeServer, url){
	pattern='^http://[^/]*'+homeServer;	
	if (url.match(pattern)!=null)
		return 0;
	else
		return 1;
}

