// check all the non-GiftGen anchor links on the current page
// and if 200 or 500 returned, then change to GREEN 
// otherwise set to orange, unless 404 then RED

// #########################################################
// ## Enure you are using IE, and you have 'cross domain  ##
// ## data access' enabled in custom security settings    ##
// #########################################################


var LastLinkChecked=0;

// check the next anchor link on the current page
function fnCheckNextLink(anchorID) {
//alert("anchorID="+anchorID);
if (anchorID==0) {
  alert("Enure you are using IE, and you have 'cross domain data access' allowed in custom security settings");
  }
nextAnchorID=anchorID+1;
//alert("starting at link "+nextAnchorID);
var arr = document.getElementsByTagName("a");
var linknum=0;
for (i = 0; i < arr.length; i++) {
  if ((arr[i].href!="")&&(arr[i].href.substring(0,18)!="http://www.giftgen")) {
    //alert("href="+arr[i].href);
    linknum=linknum+1;
    if (linknum==(nextAnchorID)) break;
    }
  }
//alert("anchor"+nextAnchorID);
nextAnchorElement=arr[i];
doHeadCheck(nextAnchorElement,nextAnchorID)
}

// Check url'S hEADER
function doHeadCheck(anchorElement,anchorID) {
var url=anchorElement.href;

try {
  http.open("HEAD", url);
  http.onreadystatechange=function () { handleHeadResponse(anchorElement,anchorID);};
  http.send(null);
  }
catch(error)
  {
  alert("anchor"+anchorID+"\nurl:"+url+"\nError:"+error+"\nEnure you are using IE, and you have 'cross domain data access' allowed in custom security settings");
  anchorElement.innerHTML=anchorElement.innerHTML+" (Problem Communicating)";
  anchorElement.style.color="#dd33dd";
  anchorElement.style.fontWeight="bold";
  }
}

function handleHeadResponse(anchorElement,anchorID) {
  if (http.readyState==4) {
    anchorElement.innerHTML=anchorElement.innerHTML+" ["+http.status+"]";
    anchorElement.style.color="green";
    if ((http.status!=200)&&(http.status!=500)) {
      anchorElement.style.fontWeight="bold";
      anchorElement.style.color="#ff9933";
      }
    if (http.status==404) {
      anchorElement.style.color="red";
      }
    LastLinkChecked=anchorID;
    document.getElementById("LastLinkChecked").value=LastLinkChecked;
    if (anchorID!=99999) {
      fnCheckNextLink(anchorID);
      }
    //http.close();
    }
}


// Check url'S CONTENT
function doContentCheck(anchorElement,anchorID) {
var url=anchorElement.href;

try {
  http.open("HEAD", url);
  http.onreadystatechange=function () { handleContentResponse(anchorElement,anchorID);};
  http.send(null);
  }
catch(error)
  {
  alert("anchor"+anchorID+"\nurl:"+url+"\nError:"+error+"\nEnure you are using IE, and you have 'cross domain data access' allowed in custom security settings");
  anchorElement.innerHTML=anchorElement.innerHTML+" (Problem Communicating)";
  anchorElement.style.color="#dd33dd";
  anchorElement.style.fontWeight="bold";
  }
}

function handleContentResponse(anchorElement,anchorID) {
  if (http.readyState==4) {
    anchorElement.innerHTML=anchorElement.innerHTML+" ["+http.status+"]";
    anchorElement.style.color="green";
    if ((http.status!=200)&&(http.status!=500)) {
      anchorElement.style.fontWeight="bold";
      anchorElement.style.color="#ff9933";
      }
    if (http.status==404) {
      anchorElement.style.color="red";
      }
    LastLinkChecked=anchorID;
    document.getElementById("LastLinkChecked").value=LastLinkChecked;
    if (anchorID!=99999) {
      fnCheckNextLink(anchorID);
      }
    //http.close();
    }
}

function GetXmlHttpObject() {
  var xmlhttp;
  if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
    xmlhttp = new XMLHttpRequest();
    //if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml');
  } else if (window.ActiveXObject) { // IE
      try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
      }
  }
  if (!xmlhttp) {
    alert('Cannot create an XMLHTTP instance');
    return false;
  }
  return xmlhttp;
}

var http = GetXmlHttpObject();

