// JavaScript Document
function addPaymentOption(divObjId) {
	divObj = document.getElementById(divObjId);
	
	/*	Dynamically generated. Unfortunately DateInput wasn't working with this method.
	divObj.innerHTML = divObj.innerHTML + '<p>Option ' + (addpaymentoptionstotal + 1) + ':</p>\n<table cellpadding="5" cellspacing="0" border="0" id="paymentOption' + addpaymentoptionstotal + '">\n<tr>\n<td align="left" class="formLabelsSmall" style="font-weight:bold">Type:</td>\n<td align="left" class="productPriceText"><select name="selPayOptionType[' + addpaymentoptionstotal + ']" onchange="changePaymentOptionType(this.options[this.selectedIndex].value, \'paymentOption' + addpaymentoptionstotal + '\', addpaymentoptionstotal)"><option value="1">Pay In Full</option><option value="2">Recurring</option></select></td>\n</tr>\n<tr>\n<td align="left" class="formLabelsSmall" style="font-weight:bold">Price:</td><td align="left" class="productPriceText">$<input type="text" name="txtPayOptionPrice[' + addpaymentoptionstotal + ']" /></td>\n</tr>\n<tr>\n<td align="left" class="formLabelsSmall" style="font-weight: bold">Pay By Date:</td>\n<td align="left" class="productPriceText"><script>' + eval('DateInput(\'hidPayOptionDate\' + addpaymentoptionstotal , true, \'YYYY-MM-DD\')') +'</script></td>\n</tr>\n</table><br />';
	*/
	//	Less Dynamic way --- hidden divs
	hidDivId = 'paymentOptionDiv' + addpaymentoptionstotal;
	if(document.getElementById(hidDivId)) {
		showobj(hidDivId);
	}
	else {
		alert('To add even more Payment Options please save your changes, then Update this product again.');
	}
	
	addpaymentoptionstotal++;
}

function changePaymentOptionType(optionValue, tableId, optionCount) {
	tableObj = document.getElementById(tableId);
	// How many rows in table?
	tableSize = tableObj.rows.length;
	//alert(tableSize);
	// Want to keep  the last row and the first two
	startrow = tableSize - 2;
	endrow = 2;
	for(j = startrow; j >= endrow; j--) {
		tableObj.deleteRow(j);
	}
	
	if(optionValue == 1) {
		tableObj.insertRow(2);
		row1 = tableObj.rows[2];
		row1.insertCell(0);
		row1.insertCell(1);
			cell1 = row1.cells[0];
			cell2 = row1.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Price:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '$<input type="text" name="txtPayOptionPrice[' + optionCount + ']" />';
	}
	else if(optionValue == 2) {
		tableObj.insertRow(2);
		tableObj.insertRow(3);
		tableObj.insertRow(4);
		row1 = tableObj.rows[2];
		row2 = tableObj.rows[3];
		row3 = tableObj.rows[4];
		row1.insertCell(0);
		row1.insertCell(1);
			cell1 = row1.cells[0];
			cell2 = row1.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Up Front Price:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '$<input type="text" name="txtPayOptionUpFrontPrice[' + optionCount + ']" />';
		row2.insertCell(0);
		row2.insertCell(1);
			cell1 = row2.cells[0];
			cell2 = row2.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Recurring Price:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '$<input type="text" name="txtPayOptionRecurringPrice[' + optionCount + ']" />';
		row3.insertCell(0);
		row3.insertCell(1);
			cell1 = row3.cells[0];
			cell2 = row3.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Num. Months<br />Recurring:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '<input type="text" size="4" name="txtPayOptionRecurringMonths[' + optionCount + ']" />';
	}
	else if(optionValue == 3) {
		tableObj.insertRow(2);
		tableObj.insertRow(3);
		tableObj.insertRow(4);
		row1 = tableObj.rows[2];
		row2 = tableObj.rows[3];
		row3 = tableObj.rows[4];
		row1.insertCell(0);
		row1.insertCell(1);
			cell1 = row1.cells[0];
			cell2 = row1.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Down Payment:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '$<input type="text" name="txtPayOptionUpFrontPrice[' + optionCount + ']" />';
		row2.insertCell(0);
		row2.insertCell(1);
			cell1 = row2.cells[0];
			cell2 = row2.cells[1];
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'Balance:';
			cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '$<input type="text" name="txtPayOptionRecurringPrice[' + optionCount + ']" />';
		row3.insertCell(0);
		//row3.insertCell(1);
			cell1 = row3.cells[0];
			//cell2 = row3.cells[1];
			cell1.colSpan = 2;
			cell1.className = 'formLabelsSmall';
			cell1.style.fontWeight = 'bold';
			cell1.align = 'left';
			cell1.innerHTML = 'The Pay By Date is when the Balance will be charged.';
			/*cell2.className = 'productPriceText';
			cell2.align = 'left';
			cell2.innerHTML = '<input type="text" size="4" name="txtPayOptionRecurringMonths[' + optionCount + ']" />';*/
		//alert('Down Payment Option in testmode.');
	}
	else {
		alert('Unknown Payment Option Type');
	}
}