function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

var player;
connectionSpeed = 0;
function drawCSImageTag( fileLocation, fileSize, imgTagProperties ) {
        start = (new Date()).getTime();
        loc = fileLocation + '?t=' + escape(start);
        document.write('<div style="display:none"><img src="' + loc + '" ' + imgTagProperties + ' onload="connectionSpeed=computeConnectionSpeed(' + start + ',' + fileSize + ');"></div>');
        return;
}
function connectionType(speed) {
        SLOW_MODEM = 50;
        BB_MODEM = 128;
        LEASED = 256;
        if (speed) {
                if (speed <= SLOW_MODEM) {
                        return "28000";
                } else if (speed <= BB_MODEM) {
                        return "100000";
                } else if (speed <= LEASED) {
                        return "200000";
                } else {
                        return "200000";
                }
        } else {
                return "28000";
        }
}
function computeConnectionSpeed( start, fileSize ) {
                // for cookie expires value
          var now = new Date();
          fixDate(now);
          now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //cookie expires in one year (actually, 365 days)
        end = (new Date()).getTime();
        connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
                setCookie("InternetBandwidth", connectSpeed, now);
        return connectSpeed;
}
var connection_Speed = getCookie("InternetBandwidth"); // get connection speed from cookie
if(!connection_Speed) // if cookie  not set , find the connection speed
{
//alert('no cookie');
var rav_no= Math.random()*4;
drawCSImageTag('http://bbmedia.sify.com/images/aspasia.jpg?rav_no',34748,'border=0 height=200 width=200 alt="bway solar AP" transparency=100');   // <img> tag attributes
}
else // if cookie set assign value from cookie
{
//alert('cookie');
connectionSpeed=connection_Speed // from cookie value
}


