// JavaScript Document

		// http://www.mredkj.com/tutorials/tableaddrow.html
		// Last updated 2006-02-21
			
	// used in caseadmin.jsp
	function addNextRow(tbl) {			
		  // var tbl = document.getElementById('partsTable');
		  var lastRow = tbl.rows.length - 1;
		  // if there's no header row in the table, then iteration = lastRow + 1
		  var iteration = lastRow;
		  var row = tbl.insertRow(iteration);
				  
		  // right cell
		  var cell0 = row.insertCell(0);
		  var el = document.createElement('input');
		  el.type = 'text';
		  el.name = 'quantity' + iteration;
		  el.id = 'quantity' + iteration;
		  el.value = '1';
		  el.size = 5;
		  cell0.appendChild(el);
		  
		  // right cell
		  var cell1 = row.insertCell(1);
		  el = document.createElement('input');
		  el.type = 'text';
		  el.name = 'part' + iteration;
		  el.id = 'part' + iteration;
		  el.size = 30;
		  cell1.appendChild(el);
		  
		  // right cell
		  var cell2 = row.insertCell(2);
		  el = document.createElement('input');
		  el.type = 'text';
		  el.name = 'unitPrice' + iteration;
		  el.id = 'unitPrice' + iteration;
		  el.size = 10;
		  cell2.appendChild(el);
		  
		  // right cell
		  var cell3 = row.insertCell(3);
		  el = document.createElement('input');
		  el.type = 'text';
		  el.name = 'cost' + iteration;
		  el.id = 'cost' + iteration;
		  el.size = 10;
		  cell3.appendChild(el);			  
	}	
			
	// used in createcase.jsp			
	function clearLast() {	
	
		document.SubmitCaseForm.doNotCall.checked = false;	
	}	
	
	function clearChecks() {		
		if (document.SubmitCaseForm.doNotCall.checked) {		
			document.SubmitCaseForm.callWhenSubmitted.checked = false;
			document.SubmitCaseForm.callWhenReceived.checked = false;
			document.SubmitCaseForm.callWithEstimates.checked = false;		
		}
	}

	// used in caseadmin.jsp
	function onPrintInvoice() {
		var invoiceNumber = document.getElementsByName('invoiceNumber')[0];
		var invoiceDate = document.getElementsByName('invoiceDate')[0];
		var forward = true;
				
		if (!invoiceNumber) {
			invoiceNumber = document.forms[1].invoiceNumber;
		}
				
		if (!invoiceDate) {
			invoiceDate = document.forms[1].invoiceDate;
		}		
				
				
		if (invoiceNumber.value == '') {
			window.alert('Please provide the invoice number');
			forward = false;
		} 
		
		if (forward && invoiceDate.value == '') {
			window.alert('Please provide the invoice date');
			forward = false;				
		}			
					
		if (forward) {
			/** // var url = "https://www.800tech.com/pages/invoice.jsp";
				var url = "/pages/invoice.jsp?";
				url += "invoiceno=" + invoiceNumber.value + "&invoicedate=" + invoiceDate.value; 
			*/
			document.location = "/pages/invoice.jsp";			
		}
	}
	  
	function saveWarranty(caseNumber) {
	  		var key1 = document.getElementById('warrantyKey1');
			var key2 = document.getElementById('warrantyKey2');
			var value1 = document.getElementById('warrantyValue1');
			var value2 = document.getElementById('warrantyValue2');
			
			var params = "?referer=" + escape(document.location) + "&";
	  		params += "caseNumber=" + caseNumber + "&warrantyKey1=" + key1.value + "&warrantyValue1=" + value1.value + "&warrantyKey2=" + key2.value + "&warrantyValue2=" + value2.value;
	  		document.location = "/warranty.jsp" + params;
	}
	  	  
	function saveNeededParts(caseNumber) {	  	
	  	var quantity = "";
	  	var part = "";
	  	var unitPrice = "";
	  	var cost = "";
	  	
	  	var params = "?referer=" + escape(document.location) + "&";
	  	params += "caseNumber=" + caseNumber;
	  	
	  	var maxParts = 6; // Maximum of six (6)  Parts ;)
	  	
	  	for (var index = 1; index <= maxParts; index++) {
	  		quantity = document.getElementById('quantity' + index);
			part = document.getElementById('part' + index);
			unitPrice = document.getElementById('unitPrice' + index);
	  		cost = document.getElementById('cost' + index);	  	  
	  		
	  		
	  		if (quantity == null || quantity == undefined) {
	  			continue;
	  			
	  		} else {	  			
	  			params += "&quantity" + index + "=" + quantity.value;
				params += "&part" + index + "=" + part.value;
				params += "&unitPrice" + index + "=" + unitPrice.value;
	  			params += "&cost" + index + "=" + cost.value;	  		
	  		}
	  	}	  	
	  	
	  	document.location  = "/neededParts.jsp" + params;
    }	  


	// used in processPayment.jsp
	function toggleHide(componentName) {
		var component = document.getElementById(componentName);
		if (component) {
			if (component.style.display == "block") {
				component.style.display = "none";
				
			} else if (component.style.display == "none") {
				component.style.display = "block";				
			} 
		} 
		
		if (document.all) {			
			if (component.visibility == "visible") {
				component.visibility = "hidden";
				
			} else if (component.visibility == "hidden") {
				component.visibility = "visible";				
			} 
		}
	}
