function formatItem(row) {
	return row[0] + " (" + row[1] + ")";
}

function lookupAjax(){
	var oSuggest = $("#keyword")[0].autocompleter;
	return false;
}

$(document).ready(function() {
	$("#keyword").autocomplete(
		"/lib/ajax/autocomplete.cfm",
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			formatItem:formatItem,
			autoFill:true
		}
	);
	
	$(".addNote").click(function() {
			var tmpId = $(this).attr("id");
			var tmpImage = document.getElementById(tmpId).src;
			var pathArray = tmpImage.split( '/' );
			var curImg = pathArray[4];
		
			if (curImg != 'pix.gif')
				var url = "/lib/ajax/notepad.cfm?addNote=1&lid=" + tmpId;
			else
				var url = "/lib/ajax/notepad.cfm?remNote=1&lid=" + tmpId;
			
			$.post(url, function(data){				 
		  $("#noteCount").html(data);
		  return false;
		});
	});
	
	$(".remNote").click(function() {
		var tmpId = $(this).attr("id");
		var url = "/lib/ajax/notepad.cfm?remNote=1&lid=" + tmpId;
		$.post(url, function(data){
		  $("#noteCount").html(data);
		});
	});
});

function swapImage(id){
	if (document.getElementById(id).className == 'remNote') {
		document.getElementById(id).src = '/images/pix.gif';
		document.getElementById(id).className = 'addNote';
	} else {
		document.getElementById(id).src = '/images/note-remove.png';
		document.getElementById(id).className = 'remNote';
	}
	return false;
}

function swapListImage(img,alt) {
  	document.getElementById('image').src = img;
  	document.getElementById('caption').innerHTML = alt;
  }

function enableSubmit(v1,v2){
	if (v1 == '1')
		document.getElementById(v2).disabled = false;
	else
		document.getElementById(v2).disabled = true;	
}

function setDate(field1,field2,i){
	var Date1 = new Date(Date.parse(document.getElementById(field1).value));
	var Date2 = new Date(Date1);
	// Adjusting the date by the amout specified
	Date2.setDate(Date2.getDate() + i);
	
	// Setting date parts
	m = new String(Date2.getMonth() + 1);
	d = new String(Date2.getDate());
	y = new String(Date2.getFullYear());

	// Add leading zeros to month and date if required
	if ( d.length == 1 ) d = "0" + d; 	
	if ( m.length == 1 ) m = "0" + m;
	// Formatting Date
	var date3 = m + '/' + d + '/' + y;
	
	// Setting new filed to the new date
	document.getElementById(field2).value = date3;
	return false;
}
