function findAnchors() {
  $$('a').each(function(a){
    var fail = true;
    if (a.href.match(/ingenio.com/) != null) {
      a.setStyle({
        backgroundColor: 'yellow'
      })
    }
    else if (a.href.match(/javascript/) != null) {
      new Ajax.Request(a.href.match(/\'.+\'/).toString().split('\'')[1], {
        method: 'get',
        asynchronous: false,
        onComplete: function(t) {
          if (404 == t.status)
            a.setStyle({
              backgroundColor: 'red'
            })
        }
      })
    }
    else if (a.href.match(/logout/) == null) {
      new Ajax.Request(a.href, {
        asynchronous: false,
        onComplete: function(t) {
          if (404 != t.status)
            fail = false;
        }
      })
      new Ajax.Request(a.href, {
        asynchronous: false,
        method: 'get',
        onComplete: function(t) {
          if (404 != t.status)
            fail = false;
        }
      })
      if (fail)
        a.setStyle({
          backgroundColor: 'red'
        })
    }
  })
}

function complete_request() {

}

function findImages() {
  $$('img').each(function(img){
    if (img.src.match(/ingenio.com/) != null) {
      img.setStyle({
        borderStyle: 'solid',
        borderSize: 'medium',
        borderColor: 'red'
      })
    }
  })
}

function findForms(){
  $$('form').each(function(form){
    if (form.action.match(/ingenio.com/) != null) {
      form.setStyle({
        borderStyle: 'solid',
        borderSize: 'medium',
        borderColor: 'red'
      })
    }
    else {
      new Ajax.Request(form.action, {
        asynchronous: false,
        onComplete: function(t){
          if (404 == t.status)
            form.setStyle({
              borderStyle: 'solid',
              borderSize: 'medium',
              borderColor: 'red'
            })
        }
      })
    }
  })
}

function findAreas(){
  $$('area').each(function(area){
    if (area.href.match(/ingenio.com/) != null) {
      area.setStyle({color: 'red'})
    }
  })
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

document.observe("dom:loaded", function(){
 if (getCookie("highlight") == 1 || getCookie("highlight") == "1")
 {
   findAnchors();
   findImages();
   findForms();
 }
})

