function ShowImage(url, width, height, img) {
  // Max ridepage dimension is 575
  var imgHeight, imgWidth;
  if (img && img.tagName == 'IMG') {
    imgHeight = img.height;
    imgWidth = img.width;
    if (imgHeight > imgWidth) {
      height = 615;
      width = Math.round((imgWidth/imgHeight) * 600);
    } else {
      width = 600;
      height = Math.round((imgHeight/imgWidth) * 600) + 15;
    }
  }
  window.open(url,"image_win","height=" + height + ",width=" + width + ",statusbar=no,location=no,menubar=no,toolbar=no,resizable=no ");
}

function checktitle() {
  if (document.guestbook_form.title.value.length < 8) {
    alert ('Your vehicle summary must be at least 8 characters.'); 
    return false;
  }
  return true;
}

function checksummary() {
  if (document.summary_form.summary_text.value.length < 8) {
    alert ('Your vehicle summary must be at least 8 characters.'); 
    return false;
  }
  return true;
}

function checkpagetext() {
  if (document.edit_form.text.value.length < 30) {
    alert ('Your page text must be at least 30 characters.'); 
    return false;
  } 
  return true;
}

function show_remaining_chars(element,maxlen) {
  var remaining_text = "Character limit reached";
  if (element.value.length < maxlen ) { remaining_text = maxlen-element.value.length +' characters remaining'; }
  document.getElementById('remaining_chars').firstChild.data = remaining_text;
}

// Adds an input box for user-supplied ride modifications
function add_mod_input(ele) {
  var ele = jQuery(ele);

  var cl = jQuery('<div class="element-wrap"></div>');
  cl.css('display', 'none');
  var mod_id = jQuery("input[type='hidden']", ele.parent().parent()).attr('value');
  var inp = jQuery('<label>Custom Mod</label><input type="text" name="' + mod_id + '_usermod_'
    + (MOD_INPUT_INC++) + '" maxlength="50" class="user_mod"> <a href="#" class="remove_user_mod">Remove</a>');
  cl.append(jQuery('<div class="user_custom_mod_input"></div>').append(inp));
  cl.insertBefore(ele.parent().parent());
  cl.slideDown('fast');

  jQuery('.user_custom_mod_input .remove_user_mod').click(function() {
    var ele = jQuery(this).parent().parent();
    ele.slideUp('fast', function() { ele.remove() } );
    return false;
  });

  return;
}

