function checkProducts(lmi, surfer) {
	var params;
	var invalid;
	var surf = '';
	var links = new Array();

	if (surfer) {
	  surf = 'Surfer';
	  var loader = $('bulkLoaderSurfer' + lmi);
	  var lister = 'bulkListSurfer' + lmi;
	} else {
	  var loader = $('bulkLoader' + lmi);
	  var lister = 'bulkList' + lmi;
	}

	Element.show('loading' + surf  + lmi);

	if (loader.value.length > 0) {
  	var getProducts = loader.value.split('\n');

  	if (getProducts.length > 500) {
  	  alert('You can add a maximum of 10 links.');
  	} else {

    	loader.value = "Processing...";

    	for (var n=0; n < getProducts.length; n++) {
    	  var asin = extractASIN(getProducts[n]);
    	  if (links.indexOf(asin) == -1) {
    	    links.push(asin);
      		if (asin && (asin.toString().length == 10 || asin.toString().length == 13)) {
      			params = 'source=Amazon&item_data=' + escape(asin);
      		  var myAjax = new Ajax.Request( '/utility/module/plexconnect', {method: 'get', parameters: params, onComplete: function (originalRequest) {
      		    var response = originalRequest.responseText;
            	if (response.indexOf('|') != 0) {
            		alert(response);
            		invalid = true;
      			    Element.hide('loading' + surf  + lmi);
            	} else {
            		var html = '';
            		var item = new Array();
            		var numProducts = eval('numProducts' + surf + lmi) + 1;

            		item_array = response.split('||');
            		item = new Object();
            		item['data']= item_array[1];
            		item['title'] = item_array[2];
            		item['description'] = item_array[3];
            		item['link'] = item_array[4];
            		item['thumbnail'] = item_array[5];

            		/*
            		if (item['description'].length > 150) {
            		  item['description'] = item['description'].substring(0,146) + '...';
            		}
            		*/

            		var display_link = item['link'];
            		if (display_link.length > 70) {
            			var display_link = item['link'].substring(0, 70) + '...';
            		}

            		if (surfer) {
            		  html = '<div class="plexo_item"><div class="plexo_rank"></div><div class="plexo_image"><a target="_new" href="' + item['link'] + '"><img src="' + item['thumbnail'] + '" alt="' + item['title'] + '" border="0" /></a></div><div class="plexo_list-item-editor"><input type="hidden" name="plexus_items[' + numProducts + '][item_data]" value="' + item['data'] + '" /><input type="hidden" name="plexus_items[' + numProducts + '][link]" value="' + item['link'] + '" /><input type="hidden" name="plexus_items[' + numProducts + '][thumbnail]" value="' + item['thumbnail'] + '" /><input type="text" name="plexus_items[' + numProducts + '][title]" value="' + item['title'] + '" size="40" /> <br /> <span class="points">' + display_link + '</span><p><textarea name="plexus_items[' + numProducts + '][description]" rows="3" cols="50">' + item['description'] + '</textarea><br /><span class="note">maximum of 500 characters</span></p></div><div class="plexo-edit"><a href="#" onclick="Element.remove(this.parentNode.parentNode); return false;" class="delete">Delete</a></div></div><div class="break"></div>';
            		} else {
            		  html = '<div class="plexo_item"><div class="plexo_rank"></div><div class="plexo_list-item-editor"><div class="plexo_image"><a target="_new" href="' + item['link'] + '"><img src="' + item['thumbnail'] + '" alt="' + item['title'] + '" border="0" /></a></div><input type="hidden" name="modules[id' + lmi + '][plexus_items][' + numProducts + '][item_data]" value="' + item['data'] + '" /><input type="hidden" name="modules[id' + lmi + '][plexus_items][' + numProducts + '][link]" value="' + item['link'] + '" /><input type="hidden" name="modules[id' + lmi + '][plexus_items][' + numProducts + '][thumbnail]" value="' + item['thumbnail'] + '" /><input type="text" name="modules[id' + lmi + '][plexus_items][' + numProducts + '][title]" value="' + item['title'] + '" size="40" /> <br /> <span class="points">' + display_link + '</span><p><textarea name="modules[id' + lmi + '][plexus_items][' + numProducts + '][description]" rows="3" cols="50">' + item['description'] + '</textarea><br /><span class="note">maximum of 500 characters</span></p></div><div class="plexo-edit"><a href="#" onclick="Element.remove(this.parentNode.parentNode); return false;" class="delete">Delete</a></div></div><div class="break"></div>';
            		}

            		window.eval('numProducts' + surf + lmi + '++');
            		new Insertion.Bottom(lister, html);
            		Element.hide('loading' + surf  + lmi);
            	}}});
      		} else {
      			alert("Whoops! We're having trouble identifying an Amazon product based on the link " + getProducts[n] + ". For best results, please enter just the Amazon ASIN (or product ID) number instead of the whole link. Sorry for the hassle!");
      			invalid = true;
      			Element.hide('loading' + surf  + lmi);
      		}
    	  } else {
    	    alert("Golly! It looks like you submitted " + getProducts[n] + " more than once. Please check your entries and remove duplicate items.and try again. Thanks.");
      		invalid = true;
      		Element.hide('loading' + surf  + lmi);
    	  }
    	}
    	loader.value = "";
		  showItems(lmi, surfer, invalid);
  	}
	} else {
	  showItems(lmi, surfer);
	}
}

function extractASIN(linkURL) {
	var reASINURLCatcher = /http:\/\/.*amazon.com\/.*\/[0-9A-Za-z]{10,13}/;
	var reASINIDCatcher = /[0-9A-Z]{10}/;
	var ASINID = linkURL.match(reASINURLCatcher);
	if (!ASINID || ASINID == "") {
		anyURLCatcher = /http:\/\/.*/;
		if (linkURL.match(anyURLCatcher)) {
			return null;
		} else {
	        return linkURL.match(reASINIDCatcher);
		}
	} else {
	    ASINID = ASINID.toString();
	    return ASINID.match(reASINIDCatcher);
	}
}