function unsetCookie()
{
	$.cookie("user", null);	
}
$(document).ready(function(){
	$("#ajax_response").on("hover", "#addWebProject", function(){
		$("#addWebProject").removeClass("selectedMenuItem");
	}); 
});

// get Items
function getItems(loc, id)
{
	$.ajax({
		url: "../includes/getItems.php",
		context: "text/html",
		data: "id=" + id,
		success: function(response) {
			$("#" + loc).html(response);
		}
	});
}

function getProjects(customerID)
{
	
	var form_data = {
		cusNum: customerID,
		is_ajax: 1	
	}
	$.ajax({
		type: "POST",
		url: "/includes/getCusProjects.php",
		context: "text/html",
		data: form_data,
		success: function(response){
			$("#customerProjects_container").html(response);	
		}
	});
}

function deleteRow(rowID)
{
	var row = document.getElementById(rowID);
	row.parentNode.removeChild(row);
}

function addInvoiceEntryRow(tableID) 
{ 
	
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	row.id="input"+rowCount;
	
	var cell6 = row.insertCell(0);
	cell6.className = "hideBorder";
	var element6 = document.createElement("img");
	var specID = "input"+rowCount;
	element6.name = "item"+rowCount;
	element6.id = "item"+rowCount;
	element6.src = "/images/delete.gif";
	element6.setAttribute("onclick","deleteRow('" + specID + "');");
	cell6.appendChild(element6);
	
	var cell1 = row.insertCell(1);
	cell1.id = "items_" + rowCount;
	getItems("items_" + rowCount, "item" + rowCount);
	
	var cell2 = row.insertCell(2);
	var element2 = document.createElement("textarea");
	element2.name = "desc"+rowCount;
	element2.id = "desc"+rowCount;
	cell2.appendChild(element2);
	
	var cell3 = row.insertCell(3);
	var element3 = document.createElement("input");
	element3.type = "text";
	element3.name = "price"+rowCount;
	element3.id = "price"+rowCount;
	element3.setAttribute("onchange", "getLineTotal('price" + rowCount + "', 'qty" + rowCount + "', " + rowCount + ");")
	cell3.appendChild(element3);
	
	var cell4 = row.insertCell(4);
	var element4 = document.createElement("input");
	element4.type = "text";
	element4.name = "qty"+rowCount;
	element4.id = "qty"+rowCount;
	element4.maxLength = "11";
	element4.setAttribute("onchange", "getLineTotal('price" + rowCount + "', 'qty" + rowCount + "', " + rowCount + ");")
	cell4.appendChild(element4);
	
	var cell5 = row.insertCell(5);
	cell5.className = "total";
	cell5.id = rowCount;
} 

function updateTotal()
{
	var subTotal = 0;
	$(".total").each(function(){
		var x = $(this).html();
		x = x.split("$");
		subTotal += parseInt(x[1]);
	});
	// Update Subtotal
	$("#subTotal").html("$" + subTotal);
	
	// Create Tax
	var tax = 0;
	tax = subTotal * 0.07;
	tax = Math.round(tax * Math.pow(10,2))/Math.pow(10,2);
	$("#tax").html(tax);
	
	// Total
	var total = 0;
	var discount = $("#discount").val();
	if(discount == null || discount =="" || discount == " ")
		discount = 0;
	else
		discount = parseInt(discount);
	total = subTotal - discount + tax;
	$("#total").html("$" + total);
}
