
function getXMLHttpObject() {
  var xmlhttp=false;
  // http://www.jibbering.com/2002/4/httprequest.html
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
     xmlhttp = false;
    }
   }
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }
  if (!xmlhttp && window.createRequest) {
    try {
      xmlhttp = window.createRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }
  return xmlhttp;
}

var oXMLHttp = getXMLHttpObject();
function getResponseHeaders(sMethod, sURL, responseHandler, async) {
  sMethod = sMethod.toUpperCase();
  sMethod = (sMethod=='GET' || sMethod=='POST' || sMethod=='HEAD') ? sMethod : 'HEAD';
  async = (async) ? async : false;
  oXMLHttp.open(sMethod, sURL, async);
  responseHandler = (responseHandler) ? responseHandler : readyStateHandler;
  oXMLHttp.onreadystatechange= responseHandler;
  oXMLHttp.send(null)
}

//getResponseHeaders('HEAD', 'http://db.brevduen.dk/slipdata.php3');
//getResponseHeaders('HEAD', 'http://www.permadi.com/tutorial/images/header_js.dgif');
// javascript:void(getResponseHeaders('HEAD', 'http://db.brevduen.dk/slipdata.php3', function() {alert()}, false))
function readyStateHandler() {
  if (oXMLHttp.readyState==4) {
    alert('status: '+oXMLHttp.status+'\n'+oXMLHttp.getAllResponseHeaders())
  }
};

/*-------------------------------------------*/

function doesURLExits(sURL)
{
  
}


var oCurrentImage;
var sURLOver;
var sURLOriginal;
function setMouseOverOnAllImages(sMouseOverPostfix, sPathMustInclude)
{
  var aImages = document.getElementsByTagName('img');
  for(var i=0; i<aImages.length; i++)
  {
    oCurrentImage = aImages[i];
    sURLOriginal = oCurrentImage.src;
    var bOkay = true;
    if (sPathMustInclude) {
      bOkay = (sURLOriginal.indexOf(sPathMustInclude)>-1)
    }
    if (bOkay) {
    sURLOver = getMouseOverURL(sURLOriginal, sMouseOverPostfix);
      getResponseHeaders('HEAD', sURLOver, function() {
        if (oXMLHttp.readyState==4) {
          if (oXMLHttp.status=='200' || oXMLHttp.status=='0')
          {
            oCurrentImage.mo = sURLOver;
            oCurrentImage.original = sURLOriginal;
            oCurrentImage.onmouseover = function() {
              this.src = this.mo;
            }
            oCurrentImage.onmouseout = function() {
              this.src = this.original;
            }
          }
        }
      }, false);
    }
  }
}

function getMouseOverURL(sURLOriginal, sMouseOverPostfix)
{
  var iLen = sURLOriginal.length;
  var iLastDot = sURLOriginal.lastIndexOf('.');
  var sExtention = '';
  if (iLastDot==-1)
  {
    // Apparently no extention on this URL - ok
    iLastDot = iLen;
  } else{
    sExtention = sURLOriginal.substr(iLastDot, iLen-iLastDot);
  }
  return sURLOriginal.substr(0, iLastDot)+sMouseOverPostfix+sExtention;
}

