
function get_contact_address() {
	var page = $.ajax({url: "/content/get_contact_email", type: "GET", success: function(html ){$('#c_container').append(html)} });
}

function nWYSIWIG(obj) {
	if (document.selection) {
		obj.bound = function(prefix, sufix) {
			this.focus();
			var str = document.selection.createRange().text;
			var sel = document.selection.createRange();
			sel.text = prefix + str + sufix;
			this.focus();
			return false;
		}
		
		obj.insert = function(content) {
			this.focus();
			document.selection.createRange().text = content;
			this.focus();
			return false;
		}
	} else {
		obj.bound = function(prefix, sufix) {
			this.focus();
			startPos = this.selectionStart;
			endPos = this.selectionEnd;
			before = this.value.substr(0, startPos);
			selected = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
			after = this.value.substr(this.selectionEnd, (this.value.length - this.selectionEnd));
			this.value = before + prefix + selected + sufix + after;
			return false;
		}
		
		obj.insert = function(content) {
			this.focus();
			startPos = this.selectionStart;
			endPos = this.selectionEnd;
			before = this.value.substr(0, startPos);
			selected = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
			after = this.value.substr(this.selectionEnd, (this.value.length - this.selectionEnd));
			this.value = before + content + after;
			return false;
		}
	}
	
	obj.bold = function() {
		return obj.bound('[b]', '[/b]');
	}
	
	obj.link = function() {
	  return obj.bound('[link]', '[/link]');
	}
	
	obj.img = function() {
    return obj.bound('[img]', '[/img]')	
	}
  
  obj.quote = function() {
    return obj.bound('[quote]', '[/quote]')
  }
}

var quote_post = function(id) {
  $.ajax({
    type: "GET",
    url: '/post/get_body/' + id,                                 
    success: function(response) {  
      $('#forum_post_body')[0].value = response; 
    }
	});  
$.scrollTo("#forum_post_body");
}

var toggle_promotion = function() {
  if ($('product_promotion_enabled').checked) {
    $('product_promotion_price').enable();
  } else {
    $('product_promotion_price').disable();    
    $('product_promotion_price').value = '';
  }
}
  
var load_side_products = function(product_id, type) {
  if (type === undefined) type = 'similar';
  var container = ( type == 'similar') ? '#sidebar_left' : '#sidebar_right' 
  num = estimate_products_number(type);
  $.ajax({
    type: "GET",
    url: '/products/' + product_id + '/related',
    data: { type: type, number: num },                                 
    success: function(response) {  
      $(container).append(response);
    }
	});
}

var estimate_products_number = function(type) {
  // First element takes 174px, every next 135px
  var content_height = $('#content').height();
  var used_height = (type == 'similar') ? $('#sidebar_left').height() : $('#sidebar_right').height();
  var height = content_height - used_height;
  if (height < 174) return 0;
  num = 1;
  height -= 174;
  return num + Math.floor(height / 135.0)
}
  
if (!window.getComputedStyle) { // FIX FOR IE
    window.getComputedStyle = function(el, pseudo) {
        this.el = el;
        this.getPropertyValue = function(prop) {
            var re = /(\-([a-z]){1})/g;
            if (prop == 'float') prop = 'styleFloat';
            if (re.test(prop)) {
                prop = prop.replace(re, function () {
                    return arguments[2].toUpperCase();
                });
            }
            return el.currentStyle[prop] ? el.currentStyle[prop] : null;
        }
        return this;
    }
}