<!--//
var year;
var manufacturerId;
var modelId;

function getContainer(comboBox) {
	name = comboBox.options[comboBox.selectedIndex].text;
	document.frm_container.cargo_type_name.value = name;
}

function getManufacturers(comboBox) {
	year = comboBox.options[comboBox.selectedIndex].value;
	if (year == 0) {
		document.location.href='items.php?num_items=1';
	} else {
		document.getElementById('fra_control').src = 'load_manufacturers.php?auto_year=' + year;
	}
}

function loadManufacturers(manufacturers) {
	populateComboBox(document.frm_auto.auto_manufacturer_id, manufacturers);
	populateComboBox(document.frm_auto.auto_model_id, []);
}

function getModels(comboBox) {
	manufacturerId = comboBox.options[comboBox.selectedIndex].value;
	document.getElementById('fra_control').src = 'load_models.php?auto_year=' + year + '&auto_manufacturer_id=' + manufacturerId;
}

function loadModels(models) {
	populateComboBox(document.frm_auto.auto_model_id, models);
}

function getDestinationPorts(comboBox) {
	origPortId = comboBox.options[comboBox.selectedIndex].value;
	document.getElementById('fra_control').src = 'load_destination_ports.php?orig_port_id=' + origPortId;
	document.getElementById('orig_name').value = comboBox.options[comboBox.selectedIndex].text;
}

function setDestinationPort(comboBox) {
	document.getElementById('dest_name').value = comboBox.options[comboBox.selectedIndex].text;
}

function loadDestinationPorts(destinationPorts) {
	populateComboBox(document.frm_route.dest_port_id, destinationPorts);
}

function populateComboBox(comboBox, newOptions) {
	while (comboBox.options.length > 0) {
		if (document.all) {
			comboBox.options.remove(0);
		} else {
			comboBox.options[0] = null;
		}
	}
	comboBox.options[0] = new Option('<Select One>','');
	for (var i = 0; i < newOptions.length; i++) {
		comboBox.options[i + 1] = new Option(newOptions[i][1],newOptions[i][0]);
	}
}

function toggleInsurance(checkBox) {
	document.getElementById('txt_insured_value').style.display = (checkBox.checked) ? 'inline' : 'none';
	document.getElementById('txt_insured_value').value = '';
}

// Validates all fields in the specified form
function validate(form) {
	var input = null;
	var ok = true;
	var elements = form.getElementsByTagName('input');
	for (var i = 0; i < elements.length; i++) {
		var input = elements.item(i);
		if ((input.required == 'true' || input.required == '1' || input.required == 1) && input.style.display != 'none' && input.value.length == 0) {
			window.alert('Please complete field "' + input.title + '"');
			return false;
		}
 	}
	elements = form.getElementsByTagName('select');
	for (var i = 0; i < elements.length; i++) {
		var input = elements.item(i);
		if ((input.required == 'true' || input.required == '1' || input.required == 1) && input.style.display != 'none' &&
				(input.options.length == 0 || !input.options[input.selectedIndex].value)) {
			window.alert('Please complete field "' + input.title + '"');
			return false;
		}
	}
	return true;
}

function positionWindow() {
	if (window.location.href.indexOf('.php') == -1 || window.location.href.indexOf('index.php') != -1) {
		//window.resizeTo(600, 480); 
		window.moveTo(0, 0);
	}
}
//-->