//function $(n) {
  //return document.getElementById(n);
//}

$(document).ready(function(){

  $("img.caption").each(function() {
    $(this).replaceWith('<div class="capt"><img src="'+ $(this).attr("src")
      + '" /><div style="width:'+($(this).width()-10)+'px;">'
      +$(this).attr("alt")+'</div></div>');
  });

});


function doLoad() {
  // does nothing
}

function addEvent( obj, type, fn ){  // the add event function
  if (obj.addEventListener) obj.addEventListener( type, fn, false );
  else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() {
      obj["e"+type+fn]( window.event );
    };
    obj.attachEvent( "on"+type, obj[type+fn] );
  }
}

/** MOUSE OVER EFFECTS **/
function preloadImgs() {
  imgs = document.images;
  for(i=0; i<imgs.length; i++) {
    src = imgs[i].src;
    if(imgs[i].className != 'no-hover' && src.indexOf('_off') != -1) {
      document.onImg = new Image();
      document.onImg.src = src.replace('_off', '_on');
      
      addEvent(imgs[i], "mouseover", toggleImg);
      addEvent(imgs[i], "mouseout", toggleImg);
    }
  }
  imgs = document.getElementsByTagName("input");
  for(i=0; i<imgs.length; i++) {
    if(imgs[i].type.toLowerCase() == 'image') {
      src = imgs[i].src;
      if(imgs[i].className != 'no-hover' && src.indexOf('_off') != -1) {
        document.onImg = new Image();
        document.onImg.src = src.replace('_off', '_on');
        
        addEvent(imgs[i], "mouseover", toggleImg);
        addEvent(imgs[i], "mouseout", toggleImg);
      }
    }
  }
}

addEvent(window, "load", preloadImgs);

function toggleImg() {
  src = this.src;
  if(src.indexOf('_off') != -1)
    this.src = src.replace('_off', '_on');
  else if(src.indexOf('_on') != -1)
    this.src = src.replace('_on', '_off');
}


function fixIE() {
  if(document.all) {
    theObjects = document.getElementsByTagName("object");
    for (var i = 0; i < theObjects.length; i++) {
      theObjects[i].outerHTML = theObjects[i].outerHTML;
    }
  }
}
//addEvent(window, "load", fixIE);


function goTo(u) {
  window.location = u;
}

function openPopupWindow(url, width, height, scrolling, name) {
  if (!width) width = 350;
  if (!height) height = 350;
  if (!scrolling) scrolling = "no"; 
  if (!name) name = "win"+Math.round(Math.random()*1000); 
  
  features = "width="+width+","
           + "height="+height+","
           + "toolbar=no,"
           + "location=no,"
           + "status=no,"
           + "menubar=no,"
           + "scrollbars="+scrolling+","
           + "top=50,"//+(window.screen.height-height)/2+","
           + "left=50";//+(window.screen.width-width)/2;
  win = window.open(url,name,features);
  win.focus();
  return win;
}

function viewImg(src) {
  openPopupWindow('/popup.jsp?url='+src, 50, 50);
}

var r;
function validateForm(frm) {
  r = "";
  $(".req", frm).each(function() {
    if(jQuery.trim($(this).val()).length == 0)
      r += "- " +this.title + "\n";
  });
  if(r != "") {
    alert("Please fix the following errors:\n\n"+r);
    return false;
  }
  return true;
}

function doSubmit() {
  if(validateForm(document.dForm)) {
    document.dForm.submit();
  }
}

function doBack() {
  window.history.back();
}
