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


// Global function for creating an in-place editor
function createInPlaceEditor(field) {
  new Ajax.InPlaceEditor('store_description', '#', {
    okControl: false,
    cancelControl: false,
    callback: function(form, value) {
      var id = form.id.substring(0,id.indexOf('-inplaceeditor'));
      var i  = id.substring(id.lastIndexOf('_')+1,id.length);
      return 'id=' + i + '&value=' + encodeURIComponent(value) + '&authenticity_token=' + encodeURIComponent(window._token);
    }
  });
}

function change_size(size, id) {
  clearClasses();
  $('#' + id).addClass('selected');
  $('#psize').val(size);
}

function change_product(html_id, product_id, resolution) {
  clearClasses();
  $('#' + html_id).addClass('selected');
  $('#product_type_id').val(product_id);
  $('#upload-field-placeholder').hide();
  $('#image-resolution').html(resolution);
  $('#upload-field').show();
}

function clearClasses() {
  $('.selected').removeClass('selected');
}

function popitup(url) {
	newwindow=window.open(url,'name','height=600,width=400,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function adjust_price(target, base_price) {
  var price;
  var percent = parseInt($('#profit_margin').val()) * 0.01;
  price = (parseInt(base_price) * percent) + base_price;  
  $('#total_price').html(Math.ceil(price));
}
