//This code is protected by copyright. Any not allowed by copyright laws use of this content (distribution, translation, alteration, copying) requires an explicit approval of its authors.
var itemsToSend = new Array();

function sendToCart(){
	var _multi = "";			
	for (var i=0;i<itemsToSend.length;i++){			
		var _itm = itemsToSend[i];
		_multi += _itm.id+","+_itm.qty+";";	
	}		
	$("multiAdds").value = _multi;
	$("frmMultiAdds").submit();
}

function setItemsToSend(event){
	event = event || window.event; // IE doesn't pass event as argument.
	var inpQty = event.target || event.srcElement; // IE doesn't use .target
	inpQty.value = trim(inpQty.value);
	if (inpQty.value != ""){
		flag = false;
		var i = 0;
		while (!flag && i<itemsToSend.length){
			if (itemsToSend[i].id==inpQty.id.replace("qtyAdd_","")){
				itemsToSend[i]={id:inpQty.id.replace("qtyAdd_",""),qty:inpQty.value};
				flag=true;
			}
			i++;
		}
		if (!flag) itemsToSend[itemsToSend.length]={id: inpQty.id.replace("qtyAdd_",""), qty:inpQty.value };
	}else{
		for(var i=0;i<itemsToSend.length;i++){
			if (itemsToSend[i].id==inpQty.id.replace("qtyAdd_","")) 
				itemsToSend.splice(i,1);
		}
	}
}
// Copied form prototype.js
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;
    elements.push(element);
  }
  return elements;
}
// Removes leading whitespaces
function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}
// Removes ending whitespaces
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}
// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

