/*-------------------------------------------------------------------------+
 | POD entry handling                                                      |
 +-------------------------------------------------------------------------*/

var monString = new Array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );

function ajaxPleaseWait() {
	htm = '<div style="height: 100px; vertical-align: middle; ' +
	      'text-align: center"><p><br><img src="/images/loading.gif" ' +
	      'border="0"><br>Processing...</p></div>';

	return htm;
}

function flagTestConsignment(id) {
	if (!confirm('Are you sure you want to flag this consignment as a test consignment.  Once flagged as a test consignment, the consignment will not be billed nor paid.\n\nNOTE: This process can not be reversed'))
		return;

	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/setConsignmentTestFlag',
			cd_id: id
		}, showConsignmentExtras, "text");
}


function sentEmailTracking(vinfo) {
	eval(vinfo);

	htm = '';

	htm += emailresponse.status;

	container = document.getElementById('emailentry');

	container.innerHTML = '';
	container.innerHTML = htm;
}

function sendEmailBookin(biid) {
	// TODO: Validation

	someelement = document.getElementById('emailname');
	emailname = someelement.value;

	someelement = document.getElementById('emailcomment');
	emailcomment = someelement.value;

	if (emailname == '') {
		alert("You must enter an email address");
		return false;
	}

	document.getElementById('emailentry').style.display = 'block';
	document.getElementById('emailformdiv').style.display = 'none';

	// please wait
	container = document.getElementById('emailentry');

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	// send the request
	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/emailBookin',
			bi_id: biid,
			email: emailname,
			comment: emailcomment
		}, sentEmailTracking, "text");
}

function sendEmailTracking(cdid) {
	// TODO: Validation

	someelement = document.getElementById('emailname');
	emailname = someelement.value;

	someelement = document.getElementById('emailcomment');
	emailcomment = someelement.value;

	if (emailname == '') {
		alert("You must enter an email address");
		return false;
	}

	document.getElementById('emailentry').style.display = 'block';
	document.getElementById('emailformdiv').style.display = 'none';

	// please wait
	container = document.getElementById('emailentry');

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	// send the request
	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/emailTracking',
			cd_id: cdid,
			email: emailname,
			comment: emailcomment
		}, sentEmailTracking, "text");
}

function showEmailTracking(cdid) {
	document.getElementById('emailentry').style.display = 'none';
	document.getElementById('emailformdiv').style.display = 'block';
}

function hideBookinExtras(vinfo) {

	eval(vinfo);

	specialElement = document.getElementById('specialb' + id);
	if (!isHiddenObjectByElement(specialElement))
		hideObjectByElement(specialElement);

	return;
}

function showConsignmentValidation(vinfo) {

	eval(vinfo);
	doextra = false;

	id = cdsundry.cn_consignment;

	htm = '';

	htm += '<div id="podentry">';

	if (consignment.cd_release != 'V')
		htm += "<h5>This consignment is already validated.<br>Please refresh this list to remove this entry</h5>";
	else
	{
	htm += '<form id="podform' + id + '" name="podform' + id + '">';
	htm += '<input type="hidden" name="fn" value="none">';
	htm += '<input type="hidden" name="cd_id" value="' + id + '">';
	htm += '<table>';

	htm += '<tr><th>Valdation Reason:</th><td colspan="3">' +
		cdsundry.cn_validation_info + '</td></tr>';

	// Let's turn it on for everyone for now

	// Show weight and cubic

	readonly = "";
	// if (consignment.cd_billing_id > 0 || consignment.cd_cancelled == 'Y')
	if (consignment.cd_cancelled == 'Y')
	    	readonly = " readonly";

	// Ok.. suburb stuff here, I guess
	p1 = "<th><label for=\"pickup_subsearch\">Suburb Search:</label></th><td ><input type=\"text\" autocomplete=\"off\" name=\"pickup_subsearch\" id=\"pickup_subsearch\" onkeyup=\"javascript:pickup_suburbSearch.startSearchTimer();\" value=\"" + consignment.cd_pickup_suburb + "/" + consignment.cd_pickup_postcode + "\"><input type=\"button\" value=\"search\" onclick=\"javascript:pickup_suburbSearch.startSearch();\"><div id=\"pickup_searchResults\"></div></td>";
	d1 = "<th><label for=\"delivery_subsearch\">Suburb Search:</label></th><td ><input type=\"text\" autocomplete=\"off\" name=\"delivery_subsearch\" id=\"delivery_subsearch\" onkeyup=\"javascript:delivery_suburbSearch.startSearchTimer();\" value=\"" + consignment.cd_delivery_suburb + "/" + consignment.cd_delivery_postcode + "\"><input type=\"button\" value=\"search\" onclick=\"javascript:delivery_suburbSearch.startSearch();\"><div id=\"delivery_searchResults\"></div></td>";

	p2 = "<th>Suburb:</th><td ><input type=\"text\" id=\"pickup_s_suburb\" name=\"pickup_s_suburb\" class=\"field\" value=\"\" readonly/>&nbsp;&nbsp;Postcode:&nbsp;<input type=\"text\" name=\"pickup_s_postcode\" id=\"pickup_s_postcode\" class=\"field\" size=\"5\" value=\"\" readonly/></td>";
	d2 = "<th>Suburb:</th><td ><input type=\"text\" id=\"delivery_s_suburb\" name=\"delivery_s_suburb\" class=\"field\" value=\"\" readonly/>&nbsp;&nbsp;Postcode:&nbsp;<input type=\"text\" name=\"delivery_s_postcode\" id=\"delivery_s_postcode\" class=\"field\" size=\"5\" value=\"\" readonly/></td>";

	p0 = "<th>Address:</th><td>"
	p0 += consignment.cd_pickup_addr0 + "<br>";
	p0 += consignment.cd_pickup_addr1 + "<br>";
	p0 += consignment.cd_pickup_addr2 + "<br>";
	p0 += consignment.cd_pickup_addr3 + "</td>";

	d0 = "<th>Address:</th><td>"
	d0 += consignment.cd_delivery_addr0 + "<br>";
	d0 += consignment.cd_delivery_addr1 + "<br>";
	d0 += consignment.cd_delivery_addr2 + "<br>";
	d0 += consignment.cd_delivery_addr3 + "</td>";

	htm += "<tr>";
	htm += "<td colspan=\"2\" width=\"50%\"><h5>Pickup</h5></td>";
	htm += "<td colspan=\"2\" width=\"50%\"><h5>Delivery</h5></td>";
	htm += "</tr>";
	htm += "<tr>" + p0 + d0 + "</tr>";
	htm += "<tr>" + p1 + d1 + "</tr>";
	htm += "<tr>" + p2 + d2 + "</tr>";


	htm += "<tr>";
	htm += "<td colspan=\"2\" width=\"50%\"><h5>Cube</h5></td>";
	htm += "<td colspan=\"2\" width=\"50%\"><h5>Weight</h5></td>";
	htm += "</tr>";

	htm += '<tr>';
	htm += '<th>Cubic:</th>';
	htm += '<td >';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension0" value="' + consignment.cd_dimension0 + '"/>';
	htm += ' x ';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension1" value="' + consignment.cd_dimension1 + '"/>';
	htm += ' x ';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension2" value="' + consignment.cd_dimension2 + '"/>';
	htm += 'cm';
	htm += '&nbsp;&nbsp;&nbsp;';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="8" name="cd_volume" value="' + consignment.cd_volume + '"/>';
	htm += 'm<sup>3</sup>';
	htm += '</td>';

	htm += '<th>Weight:</th>';
	htm += '<td>';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="8" name="cd_deadweight" value="' + consignment.cd_deadweight + '"/>kg';
	htm += '&nbsp;&nbsp;&nbsp;Items:&nbsp;<input type="text" style="text-align: right;" ' + readonly + ' size="8" name="cd_items" value="' + consignment.cd_items + '"/>';
	htm += '</td>';
	htm += '</tr>';

	htm += '<tr>';
	htm += '<th>Comments:</th>';
	if (cdsundry.cn_note)
		note = cdsundry.cn_note;
	else
		note = '';

	htm += '<td ><input type="text" size="40" name="comment" value="' + note + '"/></td>';

	htm += '<th colspan="2" ><input style="width: 180px" type="button" name="submitdetail" value="Recheck Validation" onclick="javascript:submitConsignmentValidation(' + id + ', false)">';
	htm += '<input style="width: 180px" type="button" name="submitdetail" value="Force Validation" onclick="javascript:submitConsignmentValidation(' + id + ', true)"></th></tr>';

	
	htm += '</table>';
	htm += '</form>';
	}


	htm += '</div>';


	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = htm;

	if (consignment.cd_release == 'V')
	{
		pickup_suburbSearch.startSearch();
		delivery_suburbSearch.startSearch();
	}
}


function showConsignmentExtras(vinfo) {

	eval(vinfo);
	doextra = false;

	id = cdsundry.cn_consignment;

	htm = '';

	htm += '<div id="podentry">';

	htm += '<form id="podform' + id + '" name="podform' + id + '">';
	htm += '<input type="hidden" name="fn" value="none">';
	htm += '<input type="hidden" name="cd_id" value="' + id + '">';
	htm += '<table>';

	// POD Entry
	if (consignment.cd_agent_pod == 'Y' || alwayspod == 'Y')
	{
		if (consignment.cd_deliver_pod)
			podname = consignment.cd_deliver_pod;
		else
			podname = '';

		htm += '<tr>';
		htm += '<th>POD Name:</th>';
		htm += '<td><input size="30" type="text" name="podname" value="' + podname + '"></td>';
		htm += '<th>&nbsp;</th>';
		htm += '<td>&nbsp;</td>';

		htm += '</tr>';

		htm += '<tr>';
		htm += '<th>POD Date/Time:</th>';
		htm += '<td>';

		if (consignment.podstamp == '')
			v = formatDate(new Date(), 'd MMM yyyy   HH:mm');
		else
			v = consignment.podstamp;
		eval('cX'+id+'=new CalendarPopup("blankDiv")');
		eval('cX'+id+'.todayText = "Now"');
		eval('cX'+id+'.setDisplayType("datetime")');
		htm += '<a href="#" style="text-decoration: none;" name="cA'+id+'" id="cA'+id+'" onclick="cX'+id+'.select(document.getElementById(\'ajDate\'),\'cA'+id+'\', \'d MMM yyyy   HH:mm\');return false"><input readonly size="30" id="ajDate" name="ajDate" value="'+v+'"><img src="/images/dateSelect16.gif" border="0" alt="select"></a>';
		doextra = true;

		/*
		htm += '<select name="ampm"><option>am</option><option selected>pm</option></select></td>';
		*/
		htm += '</td>';

		htm += '<th colspan="2" class="buttonstrip">';
		if (consignment.podstamp != '')
			nv = 'Submit New POD';
		else
			nv = 'Submit POD';
		htm += '<input style="width: 180px" type="button" name="submitpod" value="' + nv + '" onclick="javascript:submitConsignmentPOD(' + id + ')">';
//		htm += '<input type="button" name="cancelpod" value="Cancel POD" onclick="javascript:cancelConsignmentPOD(' + id + ')">';
		htm += '</th>';
		htm += '</tr>';

	}

	// Let's turn it on for everyone for now
	if (generateconnote == 'Y')
	{
		htm += '<tr>';
		htm += '<td colspan="2">&nbsp;</td>';
		htm += '<th class="buttonstrip">';
		htm += '<input style="width: 180px" type="button" name="generateLabels" value="Generate Labels" onclick="javascript:runGenerateLabels(' + id + ')">';
		htm += '</th>';
		htm += '<th class="buttonstrip">';
		htm += '<input style="width: 180px" type="button" name="generateConnote" value="Generate Connote" onclick="javascript:runGenerateConnote(' + id + ')">';
		htm += '</th>';
		htm += '</tr>';
	}

	if (consignment.cd_test == 'Y')
	{
		htm += '<tr><td colspan="4" style="text-align: center"><h5>NOTE: This consignment has been flagged as a test consignment and will not be billed or paid</h5></td></tr>';
	}
	else
	if (adminsession == 'Y')
	{
		htm += '<tr>';
		htm += '<td colspan="2">&nbsp;</td>';
		htm += '<th colspan="2" class="buttonstrip">';
		htm += '<input style="width: 180px" type="button" name="flagtest" value="Flag as Test Consignment" onclick="javascript:flagTestConsignment(' + id + ')">';
		htm += '</th>';
		htm += '</tr>';
	}

	htm += '<tr>';
	htm += '<th>Cost:</th>';
	if (cdsundry.cn_cost)
		cost = cdsundry.cn_cost;
	else
		cost = '';

	htm += '<td><input type="text" name="cost" size="10" value="' + cost + '"/></td>';

	htm += '<th>Status:';

	htm += '<input type="hidden" name="oldservice" value="';
	htm += consignment.cd_pricecode;
	htm += '">';

	htm += '<input type="hidden" name="service" value="';
	htm += consignment.cd_pricecode;
	htm += '">';

	htm += '<input type="hidden" name="agent" value="';
	htm += consignment.cd_agent_id;
	htm += '">';

	htm += '</th>';
	htm += '<td><select name="status"><option value="">No Issues</option>' + optionstring + '</select></td>';
	htm += '</tr>';


	if (changerating == 'Y')
	{
		htm += '<tr>';
		htm += '<th>Service:</td>';
		htm += '<td><select name="serviceSelect" onchange="javascript:document.podform' + id + '.service.value = document.podform' + id + '.serviceSelect.options[document.podform' + id + '.serviceSelect.selectedIndex].value">' + sst + '</select></td>';
		//htm += '<td colspan="2">&nbsp;</td>';
        htm += '<th>Agent:</td>';
        htm += '<td><select name="agentSelect" onchange="javascript:document.podform' + id + '.agent.value = document.podform' + id + '.agentSelect.options[document.podform' + id + '.agentSelect.selectedIndex].value">' + agentoptionstring + '</select></td>';
		htm += '</tr>';
	}


	htm += '<tr>';
	htm += '<th>Comments:</th>';
	if (cdsundry.cn_note)
		note = cdsundry.cn_note;
	else
		note = '';

	htm += '<td><input type="text" size="40" name="comment" value="' + note + '"/></td>';

	htm += '<th colspan="2" ><input style="width: 180px" type="button" name="submitdetail" value="Submit Details" onclick="javascript:submitConsignmentExtras(' + id + ')"></th></tr>';

	// Show weight and cubic

	readonly = "";
//	if (consignment.cd_billing_id > 0 || consignment.cd_cancelled == 'Y' ||
//	    consignment.cd_pickup_pay_notified == 'Y' ||
//	    consignment.cd_deliver_pay_notified == 'Y')
//	if (consignment.cd_billing_id > 0 || consignment.cd_cancelled == 'Y')
	if (consignment.cd_cancelled == 'Y')
	    	readonly = " readonly";

	htm += '<tr>';
	htm += '<th>Cubic:</th>';
	htm += '<td>';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension0" value="' + consignment.cd_dimension0 + '"/>';
	htm += ' x ';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension1" value="' + consignment.cd_dimension1 + '"/>';
	htm += ' x ';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="4" name="cd_dimension2" value="' + consignment.cd_dimension2 + '"/>';
	htm += 'cm';
	htm += '&nbsp;&nbsp;&nbsp;';
	htm += '<input type="text" style="text-align: right;" ' + readonly + ' size="8" name="cd_volume" value="' + consignment.cd_volume + '"/>';
	htm += 'm<sup>3</sup>';
	htm += '</td>';

	htm += '<th>Weight:</th>';
	htm += '<td><input type="text" style="text-align: right;" ' + readonly + ' size="8" name="cd_deadweight" value="' + consignment.cd_deadweight + '"/>kg';
	htm += '</td>';
	htm += '</tr>';

	if (atr != '')
	{
		htm += '<tr><td colspan="4"><table>' + atr + '</table></td></tr>';
	}

	htm += '</table>';
	htm += '</form>';


	htm += '</div>';


	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = htm;

	if (doextra)
	{
		eval('document.getElementById(\'ajDate\').style.background="#ffffff"');
		eval('document.getElementById(\'ajDate\').style.border="1px solid #7f9db9"');
	}

}

function submitBookinPOD(id) {
	podname = eval('document.podform' + id + '.podname.value');
	// TODO: Time stuff!
	//hour = eval('document.podform' + id + '.hour.value');
	//minute = eval('document.podform' + id + '.minute.value');
	//ampm = eval('document.podform' + id + '.ampm.value');
	//date = eval('document.podform' + id + '.date.value');
	bjDate = eval('document.podform' + id + '.bjDate.value');

	if (podname == '') {
		alert('You must enter a POD name before submitting');
		return false;
	}

	container = document.getElementById('sbdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/setBookinPOD',
			bi_id: id,
			podname: podname,
			cn_status: status,
			bjDate: bjDate
		}, hideBookinExtras, "text");
}

function submitConsignmentPOD(id) {
	podname = eval('document.podform' + id + '.podname.value');
	// TODO: Time stuff!
	//hour = eval('document.podform' + id + '.hour.value');
	//minute = eval('document.podform' + id + '.minute.value');
	//ampm = eval('document.podform' + id + '.ampm.value');
	//date = eval('document.podform' + id + '.date.value');
	ajDate = eval('document.podform' + id + '.ajDate.value');

	if (podname == '') {
		alert('You must enter a POD name before submitting');
		return false;
	}

	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/setConsignmentPOD',
			cd_id: id,
			podname: podname,
			cn_status: status,
			ajDate: ajDate
		}, showConsignmentExtras, "text");
}

function cancelConsignment(id) {
	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/cancelConsignment',
			cd_id: id
		}, showConsignmentExtras, "text");
}

function uncancelConsignment(id) {
	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/reviveConsignment',
			cd_id: id
		}, showConsignmentExtras, "text");
}

function cancelConsignmentPOD(id) {
	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/cancelConsignmentPOD',
			cd_id: id
		}, showConsignmentExtras, "text");
}

function submitConsignmentValidation(id, force) {
	comment = eval('document.podform' + id + '.comment.value');
	cd_deadweight = eval('document.podform' + id + '.cd_deadweight.value');
	cd_items = eval('document.podform' + id + '.cd_items.value');
	cd_dimension0 = eval('document.podform' + id + '.cd_dimension0.value');
	cd_dimension1 = eval('document.podform' + id + '.cd_dimension1.value');
	cd_dimension2 = eval('document.podform' + id + '.cd_dimension2.value');
	cd_volume = eval('document.podform' + id + '.cd_volume.value');

	cd_pickup_suburb = eval('document.podform' + id + '.pickup_s_suburb.value');
	cd_pickup_postcode = eval('document.podform' + id + '.pickup_s_postcode.value');
	cd_delivery_suburb = eval('document.podform' + id + '.delivery_s_suburb.value');
	cd_delivery_postcode = eval('document.podform' + id + '.delivery_s_postcode.value');

	if (cd_pickup_suburb == '')
	{
		alert("No valid pickup suburb selected");
		eval('document.podform' + id + '.pickup_subsearch.focus()');
		return;
	}

	if (cd_delivery_suburb == '')
	{
		alert("No valid delivery suburb selected");
		eval('document.podform' + id + '.delivery_subsearch.focus()');
		return;
	}

	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/setConsignmentValidation',
			cd_id: id,
			cn_note: comment,
			cd_pickup_suburb: cd_pickup_suburb,
			cd_pickup_postcode: cd_pickup_postcode,
			cd_delivery_suburb: cd_delivery_suburb,
			cd_delivery_postcode: cd_delivery_postcode,
			cd_deadweight: cd_deadweight,
			cd_items: cd_items,
			cd_dimension0: cd_dimension0,
			cd_dimension1: cd_dimension1,
			cd_dimension2: cd_dimension2,
			cd_volume: cd_volume,
			force: force
		}, showConsignmentValidation, "text");
}

function submitConsignmentExtras(id) {
	cost = eval('document.podform' + id + '.cost.value');
	comment = eval('document.podform' + id + '.comment.value');
	status = eval('document.podform' + id + '.status.value');
	cd_deadweight = eval('document.podform' + id + '.cd_deadweight.value');
	cd_dimension0 = eval('document.podform' + id + '.cd_dimension0.value');
	cd_dimension1 = eval('document.podform' + id + '.cd_dimension1.value');
	cd_dimension2 = eval('document.podform' + id + '.cd_dimension2.value');
	cd_volume = eval('document.podform' + id + '.cd_volume.value');

	old_pricecode = eval('document.podform' + id + '.oldservice.value');
	cd_pricecode = eval('document.podform' + id + '.service.value');

    agent = eval('document.podform' + id + '.agent.value');

	container = document.getElementById('sdiv' + id);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/setConsignmentStatus',
			cd_id: id,
			cn_status: status,
			cn_cost: cost,
			cn_note: comment,
			cd_deadweight: cd_deadweight,
			cd_dimension0: cd_dimension0,
			cd_dimension1: cd_dimension1,
			cd_dimension2: cd_dimension2,
			cd_volume: cd_volume,
			old_pricecode: old_pricecode,
			cd_pricecode: cd_pricecode,
			cd_agent:agent
		}, showConsignmentExtras, "text");
}

function releaseReturn(id) {

	var classlist = getElementsByClass('enterpod');
	var len = classlist.length;

	specialElement = document.getElementById('special' + id);
	if (!isHiddenObjectByElement(specialElement)) {
		hideObjectByElement(specialElement);
		return;
	}

	for (i = 0; i < len; i++)
		hideObjectByElement(classlist[i]);
	
	displayObjectByElement(specialElement);

	cname = 'sdiv' + id;
	container = document.getElementById(cname);

	container.innerHTML = '';
	htm = '';

	htm += '<div id="podentry">';

	htm += '<table>';

	htm += '<tr>';

	htm += '<td align="right" style="text-align: right"><input type="button" name="editret" value="Edit Consignment" style="width: 180px" onclick="javascript:editReturn(' + id + ')">&nbsp;&nbsp;';
	htm += '<input type="button" style="width: 180px;" name="deleteret" value="Delete Consignment" onclick="javascript:deleteReturn(' + id + ')">&nbsp;&nbsp;';
	htm += '<input type="button" style="width: 180px;" name="bookret" value="Book Now" onclick="javascript:bookReturn(' + id + ')"></td>';

	htm += '</tr>';

	htm += '</table>';
	htm += '</form>';

	htm += '</div>';

	container.innerHTML = htm;
}

function editBookinExtras(id) {

	var classlist = getElementsByClass('enterpod');
	var len = classlist.length;

	specialElement = document.getElementById('specialb' + id);
	if (!isHiddenObjectByElement(specialElement)) {
		hideObjectByElement(specialElement);
		return;
	}

	for (i = 0; i < len; i++)
		hideObjectByElement(classlist[i]);
	
	displayObjectByElement(specialElement);

	cname = 'sbdiv' + id;
	container = document.getElementById(cname);

	container.innerHTML = '';
	htm = '';

	htm += '<div id="podentry">';

	htm += '<form id="podform' + id + '" name="podform' + id + '">';
	htm += '<input type="hidden" name="fn" value="none">';
	htm += '<input type="hidden" name="bi_id" value="' + id + '">';
	htm += '<table>';

	htm += '<tr>';
	htm += '<th>POD Name:</th>';
	htm += '<td><input type="text" name="podname"></td>';
	htm += '<th>&nbsp;</th>';
	htm += '<td>&nbsp;</td>';

	htm += '</tr>';

	htm += '<tr>';
	htm += '<th>POD Date/Time:</th>';
	htm += '<td>';

//	if (consignment.podstamp == '')
		v = formatDate(new Date(), 'd MMM yyyy   HH:mm');
//	else
//		v = consignment.podstamp;

	eval('cX'+id+'=new CalendarPopup("blankDiv")');
	eval('cX'+id+'.todayText = "Now"');
	eval('cX'+id+'.setDisplayType("datetime")');
	htm += '<a href="#" style="text-decoration: none;" name="cA'+id+'" id="cA'+id+'" onclick="cX'+id+'.select(document.getElementById(\'bjDate\'),\'cA'+id+'\', \'d MMM yyyy   HH:mm\');return false"><input readonly size="30" id="bjDate" name="bjDate" value="'+v+'"><img src="/images/dateSelect16.gif" border="0" alt="select"></a>';
	htm += '</td>';

	/*
	today = new Date();

	htm += '<select name="date">';
	for (i = 0; i < 366; i++)
	{
		year = today.getFullYear();
		mon = (today.getMonth() + 1);
		day = today.getDate();

		str = year.toString() + (mon < 10 ? '0' : '') +
			mon.toString() + (day < 10 ? '0' : '') +
			day.toString();

		display = day.toString() + ' ' + monString[mon - 1] +
			' ' + year.toString();
		today.setDate(today.getDate() - 1);
		htm += '<option value="' + str + '">' + display + 
			'</option>';
	}
	htm += '</select>';

	htm += '<select name="hour"><option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="00" selected>12</option></select>';
	htm += '<select name="minute">';
	for (i = 0; i < 10; i++)
		htm += '<option>0' + i + '</option>';
	for (i = 10; i < 60; i++)
		htm += '<option>' + i + '</option>';
	htm += '</select>';


	htm += '<select name="ampm"><option>am</option><option selected>pm</option></select></td>';
	*/
	htm += '<th colspan="2" class="buttonstrip">';
	htm += '<input style="width: 180px" type="button" name="submitpod" value="Submit POD" onclick="javascript:submitBookinPOD(' + id + ')">';
	htm += '</th>';
	htm += '</tr>';

	htm += '</table>';
	htm += '</form>';

	htm += '</div>';

	container.innerHTML = htm;

	eval('document.getElementById(\'bjDate\').style.background="#ffffff"');
	eval('document.getElementById(\'bjDate\').style.border="1px solid #7f9db9"');

}


function editConsignmentExtras(id) {
	var classlist = getElementsByClass('enterpod');
	var len = classlist.length;

	specialElement = document.getElementById('special' + id);
	if (!isHiddenObjectByElement(specialElement)) {
		hideObjectByElement(specialElement);
		return;
	}

	for (i = 0; i < len; i++)
		hideObjectByElement(classlist[i]);
	
	displayObjectByElement(specialElement);

	cname = 'sdiv' + id;
	container = document.getElementById(cname);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	// First, we need to fill it with a 'please wait' box

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/getConsignmentStatus',
			cd_id: id
		}, showConsignmentExtras, "text");
}

function editConsignmentValidation(id) {
	var classlist = getElementsByClass('enterpod');
	var len = classlist.length;

	specialElement = document.getElementById('special' + id);
	if (!isHiddenObjectByElement(specialElement)) {
		hideObjectByElement(specialElement);
		return;
	}

	for (i = 0; i < len; i++)
		hideObjectByElement(classlist[i]);
	
	displayObjectByElement(specialElement);

	cname = 'sdiv' + id;
	container = document.getElementById(cname);

	container.innerHTML = '';
	container.innerHTML = ajaxPleaseWait();

	// First, we need to fill it with a 'please wait' box

	hubAJAX.unique = true;
	hubAJAX.execute("POST", "index.php",
		{
			fn: 'ajax/getConsignmentStatus',
			cd_id: id
		}, showConsignmentValidation, "text");
}

function cents(amount) {
	amount -= 0;
	amount = (Math.round(amount * 100)) / 100;
	return (amount == Math.floor(amount)) ? amount + '.00' :
		(amount * 10 == Math.floor(amount * 10)) ? amount + '0' :
		amount;
}

function generateEditTrackerHTML(cid, tarr) {
	h = '';

	h += '<form id="retForm" name="retForm">';
	h += '<input type="hidden" name="fn" value="none">';
	h += '<input type="hidden" name="page" value="showConsignment">';
	h += '<input type="hidden" name="cd_id" value="' + cid + '">';
	h += '<input type="hidden" name="con" value="' + cid + '">';

	if (tarr.length == 0)
	{
		h += '<input type="text" name="retF_0" id="retF_0" value="">';
		h += '&nbsp;<a href="javascript:runEditTrackers_add(' + cid + ')">add</a>';

		h += '<br>';

	}
	else
	{
		for (t = 0; t < tarr.length; t++) {
			h += '<input type="text" name="retF_' + t + '" id="retF_' + t + '" value="' + tarr[t] + '">';
			h += '&nbsp;<a href="javascript:runEditTrackers_del(' + cid + ',' + t + ')">del</a>';
			if (t == tarr.length - 1)
				h += '&nbsp;<a href="javascript:runEditTrackers_add(' + cid + ')">add</a>';

			h += '<br>';
		}
	}

	h += '<input type="button" onclick="javascript:runEditTrackers_save(' + cid + ')" value="Save Changes">';
	h += '<form>';

	return h;
}

function runEditTrackers_save(cid) {
	if (!confirm(
		"Please note this update function may take some\n" +
		"time to complete processing.  Please do not   \n" +
		"refresh the screen or move away from the page \n" +
		"while you are waiting.                        \n" +
		"\n" +
		"The consignment status may take up some time  \n" +
		"(up to 15 minutes) to complete update after   \n" +
		"this change has been completed.               \n" +
		"\n" +
		"Do you wish to proceed                        "))
			return;

	document.retForm.fn.value = "update/editTrackers";
	document.retForm.submit();
}

function runEditTrackers_add(cid) {
	var tarr = new Array();
	var tpos = 0;

	for (i = 0; i < 100; i++) {
		if ((f = document.getElementById('retF_' + i)) == false || f == null)
			break;

		if (f.value == '')
			continue;

		tarr[tpos++] = f.value;
	}

	tarr[tpos++] = "";

	document.getElementById('couponedit').innerHTML = generateEditTrackerHTML(cid, tarr);
}

function runEditTrackers_del(cid, dno) {
	var tarr = new Array();
	var tpos = 0;

	for (i = 0; i < 100; i++) {
		if (i == dno)
			continue;

		if ((f = document.getElementById('retF_' + i)) == false || f == null)
			break;

		if (f.value == '')
			continue;

		tarr[tpos++] = f.value;
	}

	document.getElementById('couponedit').innerHTML = generateEditTrackerHTML(cid, tarr);
}

function runEditTrackers(cid, tarr) {
	document.getElementById('couponeditbutton').innerHTML = '';
	document.getElementById('couponedit').innerHTML = generateEditTrackerHTML(cid, tarr);
}

