/**
* 
* Script Version: Javascipt V1.#
* Date Created: March 2008
* Last Update: 					
* Status: alpha
* Copyright Parca/Nemo
* @author Jary Nemo
* @link http://www.parca.com.au
* @version 0.1
* General order form functions
**/

var targetForm;


function dropItem(id){
	setForm();
	targetForm.elements['Identifier'].value = id;
	doAction('drop');
}

function updateItem(id){
	setForm();
	targetForm.elements['Identifier'].value = id;
	targetForm.elements['Qty'].value = document.forms['Items'].elements['QTY_' + id].value;
	doAction('set');
}

function dropOrder(){
	if(confirm('This action will clear the current order. Do you really want to do this?')){
		doAction('drop_all');
	}
}

function emailOrder(){
	setForm();
	
	if(targetForm.elements['PON'].value == ''){
		targetForm.elements['PON'].focus();
		alert('You must enter an Order Number before the order can be emailed.');
		return;	
	}
	
	doAction('email_order');
	
}

function printOrder(){
	setForm();
	targetForm.elements['Print'].value = "Order";
	doAction('update');
}

function printQuote(){
	setForm();
	targetForm.elements['Print'].value = "Quote";
	doAction('update');
}

function doAction(action){
	setForm();
	setAction(action);
	doSend();
}

function setForm(){
	targetForm = document.forms['Order'];
}

function setAction(action){
	targetForm.elements['action'].value = action;
}


function doSend(){
	targetForm.submit()
}

//stop submissions
function doSubmit(){
	return false;
}

function showUpdate(){
	var updateButton = $('update_button');
	updateButton.setStyle("display","block");
}
