$(document).ready(function()
{
	$("#nav a").click(function(event)
	{
		$(this).blur();
	});
	
	$("#preferred").click(function(event)
	{
		if($(this).attr("checked"))
		{
			$("#supplier-name").show("normal");
			$("#preferred_supplier").show("normal");
		}
		else
		{
			$("#supplier-name").hide("normal");
			$("#preferred_supplier").hide("normal");
		}
	});
	
	$("input.print").click(function(event)
	{
		event.preventDefault();
		print();
	});
	
	defaultCustomerDetails = Array();
	customerInputs = $("#customer-details input");		
	for(var x = 0; x < customerInputs.length; x++)
	{
		defaultCustomerDetails[customerInputs[x].name] = customerInputs[x].value;
	}
	customerTextareas = $("#customer-details textarea");		
	for(var x = 0; x < customerTextareas.length; x++)
	{
		defaultCustomerDetails[customerTextareas[x].name] = customerTextareas[x].value;
	}	
	
	
	$("#customer-details input").focus(function(event)
	{
		if(defaultCustomerDetails[$(this).attr("name")] == $(this).attr("value"))
		{
			$(this).attr("value","");
		}
	});
	$("#customer-details input").blur(function(event)
	{
		if($(this).attr("value") == "")
		{
			$(this).attr("value",defaultCustomerDetails[$(this).attr("name")]);
		}
	});	
	
	$("#customer-details textarea").focus(function(event)
	{
		if(defaultCustomerDetails[$(this).attr("name")] == $(this).attr("value"))
		{
			$(this).attr("value","");
		}
	});	
	$("#customer-details textarea").blur(function(event)
	{
		if($(this).attr("value") == "")
		{
			$(this).attr("value",defaultCustomerDetails[$(this).attr("name")]);
		}
	});	
	
	/* FREIGHT CALC */
	


	/*
	function formatFreightItem(row)
	{
		return row[0]+' '+row[1];
	}
		
	function formatFreightResult(row)
	{
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	$("#productcode-freight-quickadd").autocomplete('/resource/enquiry/freightlookup',
	{
		minChars: 0,
		width: 300,
		matchContains: false,
		formatItem: formatFreightItem,		
		formatResult: formatFreightResult
	});

	
	$('#productcode-freight-quickadd').result(function(event, data, formatted)
	{
		if(!data)
		{
			$("#productcode-freight-quickadd").val("")		
		}
		else
		{
			$("#productcode-freight-quickadd").val(data[1])		
		}
	});
	*/
});

