
function getProducts(objComboCategory)
{
	var objCategoryCombo = objComboCategory;
	var objProductCombo = document.getElementById("cmbProduct");
	
	if(objCategoryCombo.value != '')
	{
		$.ajax({
						type: "POST",
						url: "get_data.php",
						data: "action=get_products&prod_cat_name=" + objCategoryCombo.value,
						error: function(errorResponse){alert(errorResponse.statusText);},
						success: function(xmlReponseResult) {

						var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "cmbProduct";
						objNewCmbModel.id = "cmbProduct";
						objNewCmbModel.onchange = function() { getDisease (this); }
							
						objNewCmbModel.options[0] = new Option('Select Product', '');

						if(xmlReponseResult.getElementsByTagName('proId').item(0).firstChild.nodeValue != 'NO_RECORDS')
						{
							for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('proId').length; cnt++)
							{
								var productID = xmlReponseResult.getElementsByTagName('proId').item(cnt).firstChild.nodeValue;
								var productName = xmlReponseResult.getElementsByTagName('proName').item(cnt).firstChild.nodeValue;
									/* To display values in drop down */
									objNewCmbModel.options[cnt+1] = new Option(productName,productID);
									/* To check the db value with the dropdown value to display the option selected */
									/* For loop ends here */										
							}
						 }
							objProductCombo.parentNode.replaceChild(objNewCmbModel, objProductCombo);
					}
				});
	}
}

function getDisease(objComboProduct)
{
	var objProductCombo = objComboProduct;
	var objDiseaseCombo = document.getElementById("cmbDisease");
	
	if(objProductCombo.value != '')
	{
			$.ajax({
							type: "POST",
							url: "get_data.php",
							data: "action=get_disease&productID=" + objProductCombo.value,
							error: function(errorResponse){alert(errorResponse.statusText);},
							success: function(xmlReponseResult) 
							{
								
								var objNewCmbModel = document.createElement('SELECT');
								objNewCmbModel.name = "cmbDisease";
								objNewCmbModel.id = "cmbDisease";
							
								objNewCmbModel.options[0] = new Option('Select Disease', '');

								if(xmlReponseResult.getElementsByTagName('disId').item(0).firstChild.nodeValue != 'NO_RECORDS')
								{
									for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('disId').length; cnt++)
									{
										var diseaseId = xmlReponseResult.getElementsByTagName('disId').item(cnt).firstChild.nodeValue;
										var diseaseName = xmlReponseResult.getElementsByTagName('disName').item(cnt).firstChild.nodeValue;

											objNewCmbModel.options[cnt+1] = new Option(diseaseName, diseaseName);
									}
								}
								objDiseaseCombo.parentNode.replaceChild(objNewCmbModel, objDiseaseCombo);
							}
					});
	}
}

function getResult(objForm)
{
	if(objForm.cmbCategory.value != '' && objForm.cmbProduct.value =='' && objForm.cmbDisease.value =='')
	{
		//alert(HTTP_JS_SERVER+'categoryProduct.php?catName='+objForm.cmbCategory.value);
		location.href = HTTP_JS_SERVER+'categoryProduct.php?catName='+objForm.cmbCategory.value;
	}
	else if(objForm.cmbCategory.value != '' && objForm.cmbProduct.value !='' && objForm.cmbDisease.value =='')
	{
		//alert(HTTP_JS_SERVER+'productDetail.php?productName='+objForm.cmbProduct.value);
		location.href = HTTP_JS_SERVER+'productDetail.php?productID='+objForm.cmbProduct.value;
	}
	else if(objForm.cmbCategory.value != '' && objForm.cmbProduct.value !='' && objForm.cmbDisease.value !='')
	{
		location.href = HTTP_JS_SERVER+'diseaseInfo.php?disName='+objForm.cmbDisease.value;
	}
	else
	{
		alert('Select Product Category');
	}
}