// JavaScript Document

// update the brand dropdown list based on the selected criteria
function brandList() {

	// collect relevant data from form
	var manufacturer = $("manufacturer").value;
	
	// call helper to update the floorplan dropdown list
	new Ajax.Updater($("brandwrap"), "helpers/helpers.inventory/helper.inventory.brands.php", { method:"post", parameters: { manufacturer:manufacturer }});
}

// check for missing required information
function formCheck(form, message) {
	
	// get an array of all the form elements
	var elements = $(form).getElements();
	
	// assume all required fields have been completed
	var completed = true;
	
	// loop through the array
	elements.each(function(item) {
		
		// check to see if field is required
		if(item.title == "required") {
			
			// check to see if the field has been completed
			if(item.value == "") {
				
				// set completed flag to false
				completed = false;
				
				// get the id of the table cell containing the empty field
				var parents = $(item.id).ancestors();
				
				// highlight the label cell
				var sibling = $(parents[0]).previousSiblings();
				$(sibling[0]).addClassName("missing");
			}
		}
	});
	
	// do not submit form if a required field has been left blank
	if(completed == false) {
	
		// display warning message
		if(message == true) {
			
			// display warning message
			$("formwarning").setStyle({ display:"block" });
			$("formwarning").update("Oops! One or more required fields was left blank!");
		}

		return false;
	}
}

// check for missing form fields
/*function formCheck(form) {
	
	// get an array of all the form elements
	var elements = $(form).getElements();
	
	// assume all required fields have been completed
	var completed = true;
	
	// run through the array
	elements.each(function(item) {
		
		// check to see if field is required
		if(item.title == "required") {
			
			// check to see if the field has been completed
			if(item.value == "") {
				
				// set completed flag to false
				completed = false;
				
				// get the id of the table cell containing the empty field
				var parents = $(item.id).ancestors();
				
				// highlight the label cell
				var sibling = $(parents[0]).previousSiblings();
				$(sibling[0]).addClassName("missing");
			}
		}
	});
	
	// do not submit form if a required field has been left blank
	if(completed == false) {
	
		// display warning message
		$("formwarning").setStyle({ display:"block" });
		$("formwarning").update("Oops! One or more required fields was left blank!");

		return false;
	}
}*/

// open a new sized window
function openWin(url, width, height, scrollbars) {
	
	// open new window
	window.open(url, "", "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars);
}

// enable mouseover effect
function mouseOver(id) {

	// set the background color to the highlight color
	$(id).setStyle({ backgroundColor:"#ff3", cursor:"pointer" });
}

// revert back to original display
function mouseOut(id) {
	
	// return the background color to its original color
	$(id).setStyle({ backgroundColor:"transparent" });
}
