﻿var grapeVarieties = new Array(0);
function grapeVariety(CategoryID, ParentCategoryID, Label)
{
  this.CategoryID = CategoryID;
  this.ParentCategoryID = ParentCategoryID;
  this.Label = Label;
}
function addGrapeVariety(CategoryID, ParentCategoryID, Label)
{
  var temp = new grapeVariety(CategoryID, ParentCategoryID, Label);
  
  grapeVarieties.push(temp);
}
function fillGrapeVarieties()
{
  var ddlWineType = document.getElementById('ddlWineType');
  var ddlGrapeVariety = document.getElementById('ddlGrapeVariety');
  ddlGrapeVariety.options.length = 0;
  var count = 0;
  ddlGrapeVariety.options[count] = new Option("All",0);
  for( var i = 0; i < grapeVarieties.length; i++ )
  {
    var temp = grapeVarieties[i];
    if( (ddlWineType.value==0) || (temp.ParentCategoryID==ddlWineType.value) )
    {
      count++;
      ddlGrapeVariety.options[count] = new Option(temp["Label"],temp["CategoryID"]);
    }
  }
}


function selectDLLElement(ddlID,value)
{
  var ddl = document.getElementById(ddlID);
  for(index = 0; index < ddl.options.length; index++)
  {
    if(ddl.options[index].value == value)
       ddl.selectedIndex = index;
  }  
}

function selectGrapeVariety(CategoryID)
{
  selectDLLElement('ddlGrapeVariety',CategoryID);
}


function selectMinBottlePrice(price)
{
  selectDLLElement('ddlMinBottlePrice',price);
}

function selectMaxBottlePrice(price)
{
  selectDLLElement('ddlMaxBottlePrice',price);
}

function minOrMaxBottlePriceChanged(isMinChanged)
{
  var ddlMinBottlePrice = document.getElementById('ddlMinBottlePrice');
  var ddlMaxBottlePrice = document.getElementById('ddlMaxBottlePrice');
  
  var minBottlePrice = ddlMinBottlePrice.options[ddlMinBottlePrice.selectedIndex].value
  var maxBottlePrice = ddlMaxBottlePrice.options[ddlMaxBottlePrice.selectedIndex].value  
 
  if( minBottlePrice > 0 &&  maxBottlePrice > 0 )
  {
    if( minBottlePrice >= maxBottlePrice )
    {
      if( isMinChanged )
      {
        alert('Minimum price must be less than maximum price');
        selectMinBottlePrice(0);
      }
      else
      {
        alert('Maximum price must be greater than minimum price');
        selectMaxBottlePrice(0);
      }
    }
  }
}



