$(function(){
	var searchCatID = $('#searchCatID').val();
	var sOption_searchKW = $('#sOption_searchKW').val();
	var sOption_searchFrame = $('#sOption_searchFrame').val();
	var sOption_searchEfficency = $('#sOption_searchEfficency').val();
	var sOption_searchShaft = $('#sOption_searchShaft').val();
	var sOption_searchAMPS = $('#sOption_searchAMPS').val();
	var sOption_searchMotorFrame = $('#sOption_searchMotorFrame').val();
	var sOption_searchFixingHole = $('#sOption_searchFixingHole').val();
	var sOption_searchLength = $('#sOption_searchLength').val();
	
	
	ShowHide(searchCatID);
	getKW(searchCatID,sOption_searchKW);
	getFrame(searchCatID,sOption_searchFrame);
	getMotorFrame(searchCatID,sOption_searchMotorFrame);
	
	$("#searchCatID").change(function(){
		var MCatID = $(this).val();
		ShowHide(MCatID);
		getKW(MCatID,0);
		getFrame(MCatID,0);
		getMotorFrame(MCatID,0);
	})
})
//----------------------------------------------------------------
function ShowHide(MCatID){
	$('.MCatID1, .MCatID2, .MCatID3, .MCatID4').hide();	
	if(MCatID > 0){ $(".MCatID"+MCatID+"").show();}
}
function getKW(MCatID, sOption){
	$.getJSON("AJAX.asp",{MCID: MCatID, ajax: 'true', Funct: 'loadKW', selectedOption: sOption}, function(j){
		var SelectOptions ="";
		if (j != null){
			for (var i = 0; i < j.length; i++) {
				SelectOptions += '<option value="' + j[i].optionValue + '" ';
				if(j[i].optionSelected=="true"){SelectOptions +=" selected='selected' "};
				SelectOptions += '>' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#searchKW").html(SelectOptions);
	});
}
function getFrame(MCatID, sOption){
	$.getJSON("AJAX.asp",{MCID: MCatID, ajax: 'true', Funct: 'loadFrame', selectedOption: sOption}, function(j){
		var SelectOptions ="";
		if (j != null){
			for (var i = 0; i < j.length; i++) {
				SelectOptions += '<option value="' + j[i].optionValue + '" ';
				if(j[i].optionSelected=="true"){SelectOptions +=" selected='selected' "};
				SelectOptions += '>' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#searchFrame").html(SelectOptions);
	});
}
function getMotorFrame(MCatID, sOption){
	$.getJSON("AJAX.asp",{MCID: MCatID, ajax: 'true', Funct: 'loadMotorFrame', selectedOption: sOption}, function(j){
		var SelectOptions ="";
		if (j != null){
			for (var i = 0; i < j.length; i++) {
				SelectOptions += '<option value="' + j[i].optionValue + '" ';
				if(j[i].optionSelected=="true"){SelectOptions +=" selected='selected' "};
				SelectOptions += '>' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#searchMotorFrame").html(SelectOptions);
	});
}

//----------------------------------------------------------------
function ValidationSearch(myform){
	
	if(isNaN(myform.searchKW.value)){
		alert("please enter numeric value for 'KW' ");
		return false;
	}
	if(isNaN(myform.searchShaft.value)){
		alert("please enter numeric value for 'Shaft' ");
		return false;
	}
	if(isNaN(myform.searchAMPS.value)){
		alert("please enter numeric value for 'AMPS' ");
		return false;
	}
	if(isNaN(myform.searchFixingHole.value)){
		alert("please enter numeric value for 'Fixing hole centres' ");
		return false;
	}
	if(isNaN(myform.searchLength.value)){
		alert("please enter numeric value for 'Overall Length' ");
		return false;
	}	
		
	return true;
}

