function loadMenu() {
	document.getElementById('wound_feedback').innerHTML = "<select id=\"wound\" onclick=\"javascript:loadWound();\"><option>-Select One-</option></select>" ;
	document.getElementById('type_feedback').innerHTML = "<select id=\"type\"><option onclick=\"javascript:loadProduct();\">-Select One-</option></select>" ;
	document.getElementById('product_feedback').innerHTML = "<select id=\"product\"><option>-Select One-</option></select>" ;
	loadWound();
}

function loadWound() {
	
	document.getElementById('wound_feedback').innerHTML = "Loading ..." ;
	SearchAjax.loadWound( {callback:cbLoadWound } );
}

function cbLoadWound(param) {

	//Callback function
	if(param == ''){
		document.getElementById('wound_feedback').innerHTML = 'Error';
	}
	else{
		var wound = "";
		wound += "<select id=\"wound\" onchange=\"javascript:loadType(document.formMenu.wound.value);\">";
		myArray = param.split(/,/);
		
		for (i=0; i < myArray.length; i++) {
			wound += "<option value=\"" + myArray[i].substring(0, myArray[i].indexOf('|')) + "\">";
			wound += myArray[i].substring(myArray[i].indexOf('|') + 1, myArray[i].length);
			wound += "</option>";
		}
		wound += "</select>";
		document.getElementById('wound_feedback').innerHTML = wound;
	}
	loadType(document.formMenu.wound.value);
	loadProduct(document.formMenu.wound.value);
}

function loadType(id) {
	document.getElementById('type_feedback').innerHTML = "Loading ..." ;
	SearchAjax.loadType( id, {callback:cbLoadType } );
}

function cbLoadType(param) {

	//Callback function
	if(param == ''){
		document.getElementById('type_feedback').innerHTML = 'Error';
	}
	else{
		var type = "";
		type += "<select id=\"type\" onchange=\"javascript:makeDisable('product', 'type');\">";
		myArray = param.split(/,/);
		
		for (i=0; i < myArray.length; i++) {
			type += "<option value=" + myArray[i].substring(0, myArray[i].indexOf('|')) +">";
			type += myArray[i].substring(myArray[i].indexOf('|') + 1, myArray[i].length);
			type += "</option>";
		}
		type += "</select>";
		document.getElementById('type_feedback').innerHTML = type;
	}
	loadProduct(document.formMenu.wound.value);
	
}

function loadProduct(id) {
	document.getElementById('product_feedback').innerHTML = "Loading ..." ;
	SearchAjax.loadProduct( id, {callback:cbLoadProduct } );
}

function cbLoadProduct(param) {

	//Callback function
	if(param == ''){
		document.getElementById('product_feedback').innerHTML = 'Error';
	}
	else{
		var product = "";
		product += "<select id=\"product\" onchange=\"javascript:makeDisable('type', 'product');\">";
		myArray = param.split(/,/);
		
		for (i=0; i < myArray.length; i++) {
			product += "<option value=" + myArray[i].substring(0, myArray[i].indexOf('|')) +">";
			product += myArray[i].substring(myArray[i].indexOf('|') + 1, myArray[i].length);
			product += "</option>";
		}
		product += "</select>";
		document.getElementById('product_feedback').innerHTML = product;
	}
}

function makeDisable(choice1, choice2) {
	var x = document.getElementById(choice1);
    x.disabled = true;
    if (String(eval("document.formMenu."+choice2+".value")) == 0) {
    	x.disabled = false;
	}
}

function search() {
	if (document.getElementById("product").disabled) {
		if (String(document.formMenu.type.value) == "0") {
			alert("Please select a type.");
			return false;
		}
		document.formMenu.action = document.formMenu.type.value;
	} else {
		if (String(document.formMenu.product.value) == "0") {
			alert("Please select a product or a type.");
			return false;
		}
		document.formMenu.action = document.formMenu.product.value;
	}
	document.formMenu.submit();	
}
