function addInvoiceItem() {
	var titles = document.invoice_add.elements["title[]"];
	var desc = document.invoice_add.elements["desc[]"];
	var values = document.invoice_add.elements["value[]"];
	
	var len = titles.length;
	
	var thetitles = Array(len);
	var thedesc = Array(len);
	var thevalues = Array(len);
	
	for ( i=0; i<len; i++ ) {
		thetitles[i] = titles[i].value;
		thedesc[i] = desc[i].value;
		thevalues[i] = values[i].value;
	}


	div = document.getElementById('storageItemDiv').innerHTML;
	
	div = div.replace('JSCHANGEVALUE', len);
		
	document.getElementById('invoiceItems').innerHTML += div;
	
	titles = document.invoice_add.elements["title[]"];
	desc = document.invoice_add.elements["desc[]"];
	values = document.invoice_add.elements["value[]"];
	
	for ( i =0; i<len; i++ ) {
		titles[i].value= thetitles[i];
		desc[i].value = thedesc[i];
		values[i].value = thevalues[i];
	}
	
	titles = null;
	desc = null;
	values = null;
	len = null
	thetitles = null;
	thedesc = null;
	thevalues = null;	
}


function validateInvoiceForm(){

	var titles = document.invoice_add.elements["title[]"];
	var desc = document.invoice_add.elements["desc[]"];
	var values = document.invoice_add.elements["value[]"];
		
	var len = values.length;
	
	var filledItems = 0;
	var error = false;
	
	for ( i = 0; i < len; i++ ) {
		testval = values[i].value;
		if (isNaN(testval) || testval.indexOf('x') != -1 || testval.indexOf('b') != -1 || (testval == ""&& titles[i].value!="")) {
			document.getElementById('valueerr_'+i).innerHTML="This is not a number!";
			error = true;
		} else {
			if ( titles[i].value != "" ) {
				filledItems++;
			}
			document.getElementById('valueerr_'+i).innerHTML="";
		}
	}
	
	if ( filledItems == 0 && !error ) {
		document.getElementById('valueerr_0').innerHTML="An invoice must have at least one item!";
		error = true;
	}
	
	if ( document.getElementById('newdom_domain_use').value == 1 ) {
		// opted to add in the domain - lets check the domain information...
		
		if ( document.getElementById('newdom_domain').value != "" ) {
			// so far so good..
			var domain = document.getElementById('newdom_domain').value;
			
			test = domain.match(/^([0-9A-Za-z\-\.]+)\.[a-zA-Z]{2,4}$/);
			
			if ( test == null ) {
				// we're not good
				error = true;
				document.getElementById('domain_error').innerHTML = "Not valid.";
			} else {
				document.getElementById('domain_error').innerHTML = "";
			}
		}
		
		if ( isNaN(document.getElementById('newdom_cost').value) ) {
			error = true;
			document.getElementById('cost_error').innerHTML = "Not valid.";
		} else {
			document.getElementById('cost_error').innerHTML = "";
		}
		
	}
	
	if ( !error ) {
		//document.invoice_add.submit();
		return true;
	} else {
		alert ( "Please check the warnings given.\nThis form will dictate how the invoice will be displayed. Please make sure that it is correct, as there will be no opportunities to change this once the form has been submitted!.");
		return false;
	}

}

function adddomainchangehandler() {
	var start = document.getElementById('newdom_from').value;
	var years = document.getElementById('newdom_length').value;
	
	split = start.split("/");
	
	newexpir = split[0] + "/" + split[1] + "/" + (parseInt(split[2]) + parseInt(years));
	document.getElementById('newdom_expiry').innerHTML = newexpir;
}