// php analogs
function escapearg(s){
  if(s == undefined || !s) return '';
  return s.replace('\\','\\\\').
           replace('*','\\*').
           replace('.','\\.').
           replace('/','\\/');
}
function htmlspecialchars(s){
  if(s == undefined || !s) return '';
  return s.replace('&','&amp;').
           replace('<','&lt;').
           replace('>','&gt;');
}
function ltrim(s){
  if(s == undefined || !s) return '';
  return s.replace(/^\s+/g,'');
}

function addProduct(product_id, running, moduletype, myOptionID, myOptionValue){
	if(myOptionID != "") {
		$("#spanQuickField").append('<input type="hidden" name="option[' + myOptionID + ']" value="' + myOptionValue + '" />');
	}

	$("#quick_product_id").val(product_id);
	$("#quick_redirect").val(htmlspecialchars(window.location.href));

	if(running!="") { running = '_' + running; }
	if(moduletype!="") { moduletype = '_' + moduletype; }

	//$('#add_to_cart' + moduletype + running).removeAttr('onclick');

//	$('#add_to_cart' + moduletype + running).click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#quick_product :input'),
			error: function(){
				alert('Error loading XML document');
			},
			success: function (html) {
				$('#module_cart .middle').html(html);
			},	
			complete: function () {

				var image = $('#image' + moduletype + running).offset();
				var cart  = $('#module_cart').offset();

	
				$('#image' + moduletype + running).before('<img src="' + $('#image' + moduletype + running).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
	
				params = {
					top : cart.top + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),  
					heigth : $('#module_cart').height()
				};		
	
				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});		
			}
		});
//	});			
}
