//Copyright © 2004 PAULGRANT.ON.CA INC.
//http://www.paulgrant.on.ca

//Interface

function MagKingCalculator3(iAffId, iSubAffId, iMerchantId, sCoupons)
{
	var sString = " "
	+ "<FORM NAME='frmMagKingCalc2' ACTION='http://www.depotnet.com/store/DataTransferBot.php' METHOD='post' TARGET='_magking'>"
	+ "<TABLE BORDER='0'><TR><TD ALIGN='center' VALIGN='top'>"
	+ "<SELECT NAME='products' SIZE='9' CLASS='fontTextInput' STYLE='width:190px'>";

	for(var i = 0; i < aProducts.length; i++)
	{
		var aProd = aProducts[ i ];
		if(!aProd)
			continue;

		sString += "<OPTION VALUE=\"" + aProd[ 0 ] + "\" TITLE=\"" + aProd[ 1 ] + "\">" + aProd[ 2 ] + "</OPTION>";
	}

	sString += "</SELECT></TD></TR>"
	+ "<TR><TD ALIGN='center' VALIGN='middle'>"
	+ "<A HREF='#' onClick='AddProduct2();'><IMG SRC='http://www.magking.com/images/down.gif' BORDER='0'></A>"
	+ "<A HREF='#' onClick='RemoveProduct2();'><IMG SRC='http://www.magking.com/images/up.gif' BORDER='0'></A>"
	+ "</TD></TR>"
	+ "<TR><TD ALIGN='center' VALIGN='top'>"
	+ "<SELECT NAME='selections[]' MULTIPLE SIZE='9' CLASS='fontTextInput' STYLE='width:190px'></SELECT><BR>"
	+ "<INPUT TYPE='image' SRC='http://www.magking.com/images/quote.gif' onClick='DoSubmit2();'>"
	+ "</TD></TR></TABLE>"
	+ "<input type='hidden' name='cls' value='Y'>"
	+ "<INPUT TYPE='hidden' NAME='aid' VALUE='" + iAffId 		+ "'>"
	+ "<INPUT TYPE='hidden' NAME='sid' VALUE='" + iSubAffId		+ "'>"
	+ "<INPUT TYPE='hidden' NAME='mid' VALUE='" + iMerchantId	+ "'>"
	+ "<INPUT TYPE='hidden' NAME='coupons' VALUE='" + sCoupons	+ "'>"
	+ "<INPUT TYPE='hidden' NAME='url' VALUE='http://www.magking.com/MagicDiscount.php'>"
	+ "</FORM>";

	document.write(sString);
}

//Functionality

function AddProduct2()
{
	var iIdx = document.frmMagKingCalc2.products.selectedIndex;

	var iSel 	= document.frmMagKingCalc2.elements['selections[]'].length;
	var iVal 	= document.frmMagKingCalc2.products.options[ iIdx ].value;
	var sText	= document.frmMagKingCalc2.products.options[ iIdx ].text;
	var sTitle	= document.frmMagKingCalc2.products.options[ iIdx ].title;

	for(var i = 0; i < iSel; i++)
	{
		if(document.frmMagKingCalc2.elements['selections[]'].options[ i ].value == iVal)
			return false;
	}

	iSel = document.frmMagKingCalc2.elements['selections[]'].options.length;
	document.frmMagKingCalc2.elements['selections[]'].options.length++;

	document.frmMagKingCalc2.elements['selections[]'].options[ iSel ].value		= iVal;
	document.frmMagKingCalc2.elements['selections[]'].options[ iSel ].text		= sText;
	document.frmMagKingCalc2.elements['selections[]'].options[ iSel ].title		= sTitle;
	document.frmMagKingCalc2.elements['selections[]'].options[ iSel ].selected	= true;
}

function RemoveProduct2()
{
	var iIdx = document.frmMagKingCalc2.elements['selections[]'].selectedIndex;

	document.frmMagKingCalc2.elements['selections[]'].options[ iIdx ] = null;
}

function DoSubmit2()
{
	var oSel = document.frmMagKingCalc2.elements['selections[]'];
	if(!oSel)
		return;

	for(var i = 0; i < oSel.length; i++)
	{
		oSel.options[ i ].selected = true;
	}
}

//End
