// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

  // Load an event onto the page load queue.
  // from: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
  //
  // To add an event:
  //
  // addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
  // addLoadEvent(function() {
  //   /* more code to run on page load */
  // });
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }

  }
}

  // Set focus to the first field on the page.
  //
function setFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i = 0; i < field.length; i++) {
      if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea")
      || (field.elements[i].type.toString().charAt(0) == "s")) {
        document.forms[0].elements[i].focus();
        break;
      }
    }
  }
}

function openEditorWindow(urltext, titletext, windowwidth, windowheight) {
  var win = new Window( 'editor_window', {
    className: "mac_os_x",
    width: windowwidth,
    height: windowheight,
    zIndex: 100,
    resizable: true,
    title: titletext,
    url: urltext,
    draggable:true,
    wiredDrag: true,
    destroyOnClose: true
  });
  win.showCenter();
}

var productPhotoChangeCount = 1;

function onProductPhotoChange() {
  productPhotoChangeCount = productPhotoChangeCount + 1;
  $("gallery_asset_field").insert(
"          <br />"+
"          <table class=\"gallery_asset_form\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" summary=\"GalleryItem Photo\">\n"+
"            <tr><th>File:</th><td><input id=\"photo_"+productPhotoChangeCount+"_data\" name=\"photo["+productPhotoChangeCount+"][data]\" size=\"45\" type=\"file\" /></td></tr>\n"+
"            <tr><th>Name:</th><td><input id=\"photo_"+productPhotoChangeCount+"_name\" name=\"photo["+productPhotoChangeCount+"][name]\" size=\"45\" /></td></tr>\n"+
"            <tr><th>Alt: </th><td><input id=\"photo_"+productPhotoChangeCount+"_alt\"  name=\"photo["+productPhotoChangeCount+"][alt]\" size=\"45\" /></td></tr>\n"+
"            <tr><th>Desc:</th><td><input id=\"photo_"+productPhotoChangeCount+"_description\" name=\"photo["+productPhotoChangeCount+"][description]\" size=\"45\" /></td></tr>\n"+
"          </table>\n");
  $("photo_"+productPhotoChangeCount+"_data").observe('change', onProductPhotoChange);
  this.stopObserving('change', onProductPhotoChange);
}
