// JavaScript Document

var credit_count = 0;



function addCredit()
{

	//alert('credit add');

	var holder = document.getElementById('creditsHolder');
	var content = holder.innerHTML;
	
	var inputs = document.getElementsByTagName("input");
	var valArray = new Array();
	
	//get the current values
	for (i in inputs)
	{	
		if(inputs[i].type == 'text' && inputs[i].id.indexOf('txtCredit') == 0)
		{
			valArray[i] = inputs[i].value;
		}
	}
	
	//make the new textboxes (current values are deleted)
	holder.innerHTML = content + makeNewCredit();
	
	//copy values into the old text boxes
	for (i in inputs)
	{	
		if(inputs[i].type == 'text' && inputs[i].id.indexOf('txtCredit') == 0)
		{
			if(valArray[i] == null)
			{
				inputs[i].value = "";
			}
			else
			{
				inputs[i].value =  valArray[i];
			}
		}
	}
	
	
}

function makeNewCredit()
{
	credit_count++;
	
	document.getElementById('CreditCount').value = credit_count;
	
	return '<div>\n<table class="padBottom">\n<tr>\n<td colspan="2">\n<input name="data[Credit]['+credit_count+'][credit]"  size="20" value="" type="text" id="txtCredit'+credit_count+'Credit" />	</td></tr>\n<tr>\n<td>Name:</td><td><input name="data[Credit]['+credit_count+'][name]"  size="20" value="" type="text" id="txtCredit'+credit_count+'Name" /></td></tr>\n' +
	'<tr>\n<td>Title:</td><td><input name="data[Credit]['+credit_count+'][title]" size="20" value="" type="text" id="txtCredit'+credit_count+'Title" />	</td></tr>\n</table>\n </div>';
	
}