//Modes used by validator
var saveVoyageMode = 'save';
var editVoyageMode = 'edit';
 
function editUser(userID){
	frm = document.forms[0];
	frm.action = 'user.do';		
	frm.mode.value = 'editUser';
	frm.userID.value = userID;
	frm.submit();
}
function deleteUser(userID, message){
	if (confirm(message)){
		frm = document.forms[0];
		frm.action = 'user.do';		
		frm.mode.value = 'deleteUser';
		frm.userID.value = userID;
		frm.submit();
	}
}

function editProduct(id){
	frm = document.forms[0];
	setFormProperty(frm, 'productForm.productID', id);
	frm.mode.value = 'editProduct';
	frm.action = 'product.do';
	frm.submit();
}
function deleteProduct(id, message){
	frm = document.forms[0];
	if (confirm(message)){
		setFormProperty(frm, 'productForm.productID', id);
		frm.mode.value = 'deleteProduct';
		frm.action = 'product.do';
		frm.submit();
	}
}
function editProductMem(id){
	frm = document.forms[0];
	setFormProperty(frm, 'productForm.listIndex', id);
	frm.mode.value = 'editProduct';
	frm.action = 'product.do';
	frm.submit();
}
function deleteProductMem(id, message){
	frm = document.forms[0];
	if (confirm(message)){
		setFormProperty(frm, 'productForm.listIndex', id);
		frm.mode.value = 'deleteProduct';
		frm.action = 'product.do';
		frm.submit();
	}
}
function newUser(usertype){
	frm = document.forms[0];
	frm.action = 'user.do';	
	frm.mode.value = 'newUser';
	frm.userTypeID.value = usertype;
	frm.submit();
}


function clearNote(frm){
	setFormProperty(frm, "note,note","");
}
function setFormProperty(frm, name, value){
	for(i = 0;i < frm.elements.length;i++){

		if (frm.elements[i].name==name){
			frm.elements[i].value=value;
		}
	}
}
function toggleLayer(target, toggleIndicator) {
  
  targetLayer = (document.getElementById) ?
    document.getElementById(target).style : eval ("document." + target);
  targetLayer.display = (targetLayer.display == "none") ? "" : "none";
  
  toggleIndicator = (document.getElementById) ?
    document.getElementById(toggleIndicator) : eval ("document." + toggleIndicator);
  if (targetLayer.display == "none") {
    toggleIndicator.src = "images/open_icon_lg.gif"; 
  } else {
    toggleIndicator.src = "images/close_icon_lg.gif";
  }
 }
 
 function printPage(){
 	pw = window.open('', '', 'width=770,height=400,scrollbars=yes');
 	pw.document.open();
 	pw.document.write('<html><head>');
 	pw.document.write('<link rel="stylesheet" href="res/print.css" type="text/css">');
 	pw.document.write('</head><body>');
 	printDiv = document.getElementById('printArea');
 	pw.document.write(printDiv.innerHTML);
 	pw.document.write('<body></html>');
 	pw.document.close();
 	tables = pw.document.getElementsByTagName('table');
 	for(i=0;i<tables.length;i++){
 		//need to do check that parent element is not a table cell
 		tables[i].style.width=650;
 	}

 	pw.print();
 	
 }
 
 function printOrder(frm){
 	oldMode = frm.mode.value;
 	frm.mode.value='printOrder';
 	frm.target='_blank';
 	frm.submit();
 	frm.target='_self';
 	frm.mode.value=oldMode;
 }
 
 function deleteDocument(index){
 	frm = document.forms[0];
 	frm.documentIndex.value=index;
 	frm.action='email.do';
 	frm.submit();
 }
 function onTabHeaderOver(a, b, c)
 {
 	// TODO :IMplement this functionality for Tab Mouse Overs
 }
 function deleteContainer(index){
	 	frm = document.forms[0];
	 	frm.action = frm.action + '&deleteContainer=yes&containerID=' + index;
	 	frm.submit();
 } 
 
 function newDependant(frm, companyTypeName){
	bCancel=true;
 	frm.mode.value='new'+companyTypeName;
 	frm.action='dependant.do';
 }
 function checkDateInFuture(field){
 	today = new Date();
 	today.setMinutes(0);
 	today.setHours(0);
 	today.setSeconds(0);
 	today.setMilliseconds(0);
 	
 	if (trim(field.value) == ''){
 		return;
 	}
 	
 	bits = field.value.split("/");
 	if (bits.length != 3){
 		field.value = '';
 		alert('dd/mm/yyyy');
 		return;
 	}
 	for(i = 0; i < bits.length;i++){
 		if (isNaN(bits[i])){
 			field.value = '';
 			alert('dd/mm/yyyy');
 			return;
 		}
 	}
 	test = new Date(parseInt(bits[2]), parseInt(bits[1]) - 1, parseInt(bits[0]), 0,0,0,0);

 	if (test - today < 0){
 		alert('Date can not be in the past');
 		field.value='';
 	}
 	return;
 }
 
 function validateLocalCartageHemiForm(frm)
 {
	var isOK = confirm('Requested delivery date is different to the estimated delivery date. Press OK to confirm.');
	if (isOK){
		var rdd = document.getElementById('requestedDelivery').value;
		document.getElementById('estimatedDelivery').value = rdd;
	}
 }
 
 function validateLocalCartageCarrierForm(frm)
 {		 
	var choice=confirm("Please enter the reason for amendment");
	if (choice == true)
	{
		var w = 300;
		var h = 200;
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
		var settings = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no';				
	
		var noteWin = window.open('/hemitrack/form/AddOrderNote.jsp?mode=amendmentReason','Notewindow',settings); 
		
		return false;
	} else return true; 
 }
 
 




			

				
		
