var ap_products = new Array();

function makeDescriptionFromSelection(formName) {
	var selectedItem = document.forms[formName].itemSelector.value;
	var nProductIndex = 0;
	for (nProductIndex = 0; nProductIndex < productArraySize; nProductIndex++) {
		if (ap_products[nProductIndex][3] == selectedItem) {
			divName = formName + "DivDescription";
   			BetterInnerHTML(document.getElementById(divName), "<p style='margin: 3px;'>" + selectedItem + "<br /><b>$" + ap_products[nProductIndex][6] + ", </b> <em>" + ap_products[nProductIndex][5] + "</em><br />" + "</p>");
		}
	}
};

function makeQuanityFromSelection(formName) {
	var selectedItem = document.forms[formName].itemSelector.value;
	var nProductIndex = 0;
	for (nProductIndex = 0; nProductIndex < productArraySize; nProductIndex++) {
		if (ap_products[nProductIndex][3] == selectedItem) {
			divName = formName + "DivQuantity";
    			BetterInnerHTML(document.getElementById(divName), "<p style='margin: 3px; text-align: right;'>Quantity: <input type='text' class='text' id='quantity' name='quantity' value='1' size='5' maxlength='10' style='vertical-align: middle;' /></p>");
		}
	}
};

function makeAddToCartFromSelection(formName) {
	var selectedItem = document.forms[formName].itemSelector.value;
	var nProductIndex = 0;
	for (nProductIndex = 0; nProductIndex < productArraySize; nProductIndex++) {
		if (ap_products[nProductIndex][3] == selectedItem) {
			divName = formName + "DivAddToCart";
		    strNewInnerHTML = "<input type='image' src='https://www.paypal.com//en_US/i/btn/x-click-but22.gif' border='0' name='submit' alt='Make payments with PayPal - it is fast, free and secure!' />";
		    // Add the item code as a hidden value
		    strNewInnerHTML += ("<input type='hidden' name='code' value='" +  ap_products[nProductIndex][1] + "' />");
		    // alert(strNewInnerHTML);
		    BetterInnerHTML(document.getElementById(divName), strNewInnerHTML);
		}
	}
};

function makeImageFromSelection(formName) {
	var selectedItem = document.forms[formName].itemSelector.value;
	var nProductIndex = 0;
	for (nProductIndex = 0; nProductIndex < productArraySize; nProductIndex++) {
		if (ap_products[nProductIndex][3] == selectedItem) {
			divName = formName + "DivImage";
			nDex = nProductIndex+1;
			BetterInnerHTML(document.getElementById(divName), "<a rel='lightbox[products]' class='showTip L" + nDex + "' href='./images/" + ap_products[nProductIndex][1] + ".jpg' title='' alt='" + ap_products[nProductIndex][4] + "'><img src='./images/" + ap_products[nProductIndex][1] + "_tn.jpg' alt='' title='' /></a>");
			// BetterInnerHTML(document.getElementById(divName), "<a class='showTip L" + nDex + "' href='#' title='' onclick=\"Slimbox.open(\'./images/" + ap_products[nProductIndex][1] + ".jpg\', '" + ap_products[nProductIndex][4] + "');\" ><img src='./images/" + ap_products[nProductIndex][1] + "_tn.jpg' alt='' title='' /></a>");
		}
	}
};

function makeItemFromSelection(formName) {
    makeDescriptionFromSelection(formName);
    makeQuanityFromSelection(formName);
    makeAddToCartFromSelection(formName);
    makeImageFromSelection(formName);
	Slimbox.scanPage();
}

