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] );
  }
}


function checkImgs() {
  c = document.getElementById("content");
  if(c) {
    imgs = c.getElementsByTagName("img");
    for(i=0; i<imgs.length; i++) {
      if(imgs[i].style.position != 'absolute') {
        w = parseInt(imgs[i].width);
        if(w > 350) {
          imgs[i].style.display = "block";
          if(w > 400)
            imgs[i].width = 400;
        } else if(w > 200) {
          imgs[i].width = 200;
        }
      }
    }
  }
}
addEvent(window, "load", checkImgs);


var firstEl;

function validateForm(frm) {
  errs = "";
  firstEl = null;
  els = frm.elements;
  for(i=0; i<els.length; i++) {
    if(els[i].id == "req")
      errs += checkVal(els[i]);
  }
  if(errs != "") {
    alert("Please make the following changes:\n\n" + errs);
    if(firstEl)
      firstEl.focus();
    return false;
  }
  return true;
}

function checkVal(el) {
  if(el) {
    if(((el.tagName == "INPUT" || el.tagName == "TEXTAREA") && el.value == "")
       || (el.tagName == "SELECT" && el.options[el.selectedIndex].value == "")) {
      if(firstEl == null)
        firstEl = el;
      return "- " + el.title + "\n";
    }
  }
  return "";
}

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

function preloadImg(img) {
  src = img.src;
  document.onImg = new Image();
  document.onImg.src = src.replace('_off', '_on');
}
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;
  window.open(url,name,features);
}

var _firstSaveAttempt = true;
var _frm;
function doSave(frm) {
  _frm = frm
  if(_firstSaveAttempt) {
    for(i=0; i<frm.elements.length; i++) {
      if(frm.elements[i].tagName == "SELECT")
        frm.elements[i].style.visibility = 'hidden';
    }
    document.getElementById('saveAlert').style.display = 'block';
    setTimeout("_doSave();", 1000);
    return false;
  } else {
    return true;
  }
}

function _doSave() {
  if(_frm) {
    _firstSaveAttempt = false;
    _frm.submit();
  }
}

function editImage(fieldName, imageName) {
  openPopupWindow("/forms/images.jsp?fieldName="+fieldName+"&imageName="+imageName,  500, 420, "no", "imgWin");
}

function showVideo(u, w, h, t) {
  if(!t) t = "Video";
  u = u+"?w="+w+"&h="+h+"&t="+t;
  openPopupWindow(u, w+20, h+20, 'no', 'vidWin'); 
}

function showQT(u, w, h, t) {
  if(!t) t = "Video";
  u = "/qt.jsp?u="+u+"&w="+w+"&h="+h+"&t="+t;
  openPopupWindow(u, w+20, h+20, 'no', 'vidWin'); 
}


function changeImg(el, img) {
  document.getElementById(img).src = el.value;
}

function requestW9() {
  openPopupWindow('/w9/index.jsp', 310, 225, 'no', 'w9Win');
}
