// JavaScript Document
// requires Ajax.js
// 11.05.2009 iklein1 initial version
/*-global var--------------------------------------------------------------------------------------------------*/
//to store connection speed.
var connectionSpeed = 0;
//bandwidth limit, set from site term value
var	limitBW = 0;
//function writeTestImgTag( fileLocation, fileSize, imgTagProperties ) {
function writeTestImgTag() {
// Draws the image tag required to detect bandwith.
//1. Path to the image for load test
fileLocation = '/cs/ENGInE/img/Logo_fordlogo.jpg';
//2. Size of the image file in bytes
fileSize = 8638;
//3. IMG-Tag properties to be included
imgTagProperties = 'border=2 height=89 alt="ford logo"';
// Store Start time of <img> load.
start = (new Date()).getTime();
// Append the Start time to the image url to ensure the image is not in disk cache.
loc = fileLocation + '?t=' + escape(start);
// Write <img> tag in <div> with display none.
document.write('<div style="display: none"><img src="' + loc + '" ' + imgTagProperties + ' onload="connectionSpeed=computeConnectionSpeed(' + start + ',' + fileSize + ');"></div>');
return;
}
//returns true or false if speed is under bandwith limit
function checkBW(speed) {
if (speed) {
if (speed < limitBW) {
return false;
} else {
return true;
}
} else {
return true;
}
}
// returns the speed in kbps of client connection, based on 
// the loading of a single image called via onload of image drawn 
// by writeTestImgTag() and is not meant to be called in any other way.
function computeConnectionSpeed( start, fileSize ) {
end = (new Date()).getTime();
connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
return connectSpeed;
}
// Function call the page content with AJAX and writes it to the content div. 
// But only if bandwidth detection is requested - (doAction is TRUE) 
function detectBandwidth(doAction){
if (doAction){
document.getElementById("bw").innerHTML = "BW detected: " + connectionSpeed;
onAjaxGet(url + '&adv=' + checkBW(connectionSpeed), function(xhr){document.getElementById('flash_content').innerHTML=xhr.responseText});
return;
}
}
/*-------------------------------------------------------------------------------------------------------------*/
