
//*-----------------------------*
//* Globals
//*-----------------------------*

var action;
var numberOfRooms = 0;
var carpetProtectorWanted = "No";
var moveSqFeet = 0;
var pressureWashSqFeet = 0;
var tileSqFeet = 0;
var tileSealerWanted = "No";
var windowRegCount = 0;
var windowFrenchCount = 0;
var sidesOfWindow = "OutSides Only";

var totalCost = 0;



function changeDisplay(dropdown)
{
  action = dropdown.options[dropdown.selectedIndex].value;
  
  function closeAllServices()
  {
    document.getElementById('ServiceEstimator').style.display = "none";
    document.getElementById('EstimatedPriceWrapper').style.display = "block";
    document.getElementById('CarpetCleaning').style.display = "none";
    document.getElementById('MoveInOutCleaning').style.display = "none";
    document.getElementById('PressureWashing').style.display = "none";
    document.getElementById('TileAndGrout').style.display = "none";
    document.getElementById('WindowCleaning').style.display = "none";
    document.getElementById('NoOnlineEstimate').style.display = "none";
  }
  
  if (action == "Carpet Cleaning Residential")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('CarpetCleaning').style.display = "block";
    document.getElementById('ServiceEstimatorCarpetHeader').innerHTML = "Carpet Cleaning Residential Estimate:";
    
    
  }
  else if (action == "Carpet Cleaning Commercial")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('CarpetCleaning').style.display = "block";
    document.getElementById('CarpetCleaningMinNote').style.display = "none";
    document.getElementById('ServiceEstimatorCarpetHeader').innerHTML = "Carpet Cleaning Commercial Estimate:";
  }
  else if (action == "Move-In/Move-Out Cleaning")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('MoveInOutCleaning').style.display = "block";
  }
  else if (action == "Pressure Washing Residential")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('PressureWashing').style.display = "block";
  }
  else if (action == "Pressure Washing Commercial")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "Pressure Washing Commercial Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to a variety of factors/conditions, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else if (action == "New Construction Clean-Up")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "New Construction Clean-Up Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to a variety of factors/conditions, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else if (action == "Roof Cleaning")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "Roof Cleaning Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to a variety of factors/conditions, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else if (action == "Tile and Grout Cleaning")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('TileAndGrout').style.display = "block";
  }
  else if (action == "Upholstery Cleaning")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "Upholstery Cleaning Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to the variety and care of different fabrics, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else if (action == "Water Extraction")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "Water Extraction Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to a variety of factors/conditions, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else if (action == "Window Cleaning Residential")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('WindowCleaning').style.display = "block";
  }
  else if (action == "Window Cleaning Commercial")
  {
    closeAllServices();
    document.getElementById('ServiceEstimator').style.display = "block";
    document.getElementById('NoOnlineEstimate').style.display = "block";
    document.getElementById('ServiceEstimatorNoEstHeader').innerHTML = "Window Cleaning Commercial Estimate:";
    document.getElementById('NoOnlineEstimateNote').style.display = "block";
    document.getElementById('NoOnlineEstimateNote').innerHTML = "Due to a variety of factors/conditions, we will provide you with an estimate after a brief consultation";
    document.getElementById('EstimatedPriceWrapper').style.display = "none";
  }
  else
  {
    closeAllServices();
  }
  
  
  
  //alert(action);
}

function calculateCost()
{
  if (action == "Carpet Cleaning Residential" || "Carpet Cleaning Commercial")
  {
    numberOfRooms = document.getElementById('ctl00_ContentPlaceHolder1_DLCarptetRoomCount').options[document.getElementById('ctl00_ContentPlaceHolder1_DLCarptetRoomCount').selectedIndex].value;
    if (numberOfRooms == "(Number Of Rooms)")
    {
      numberOfRooms = 0;
    }
    carpetProtectorWanted = document.getElementById('ctl00_ContentPlaceHolder1_DLCarpetProtector').options[document.getElementById('ctl00_ContentPlaceHolder1_DLCarpetProtector').selectedIndex].value;
  }
  
  if (action == "Move-In/Move-Out Cleaning")
  {
    if (document.getElementById('ctl00_ContentPlaceHolder1_TxtMoveSqFeet').value == "" || document.getElementById('ctl00_ContentPlaceHolder1_TxtMoveSqFeet').value == "0")
    {
      moveSqFeet = 0;
    }
    else
    {
      moveSqFeet = document.getElementById('ctl00_ContentPlaceHolder1_TxtMoveSqFeet').value;
    }
  }
  
  if (action == "Pressure Washing Residential")
  {
    if (document.getElementById('ctl00_ContentPlaceHolder1_TxtPressureWashResSqFeet').value == "" || document.getElementById('ctl00_ContentPlaceHolder1_TxtPressureWashResSqFeet').value == "0")
    {
      pressureWashSqFeet = 0;
    }
    else
    {
      pressureWashSqFeet = document.getElementById('ctl00_ContentPlaceHolder1_TxtPressureWashResSqFeet').value;
    }
  }
  
  if (action == "Tile and Grout Cleaning")
  {
    if (document.getElementById('ctl00_ContentPlaceHolder1_TxtTileSqFeet').value == "" || document.getElementById('ctl00_ContentPlaceHolder1_TxtTileSqFeet').value == "0")
    {
      tileSqFeet = 0;
    }
    else
    {
      tileSqFeet = document.getElementById('ctl00_ContentPlaceHolder1_TxtTileSqFeet').value;
    }
    
    tileSealerWanted = document.getElementById('ctl00_ContentPlaceHolder1_DLTileSealerApplied').options[document.getElementById('ctl00_ContentPlaceHolder1_DLTileSealerApplied').selectedIndex].value;
  }
  
  if (action == "Window Cleaning Residential")
  {
    windowRegCount = document.getElementById('ctl00_ContentPlaceHolder1_DLRegResWindowCount').options[document.getElementById('ctl00_ContentPlaceHolder1_DLRegResWindowCount').selectedIndex].value;
    windowFrenchCount = document.getElementById('ctl00_ContentPlaceHolder1_DLFrenchResWindowCount').options[document.getElementById('ctl00_ContentPlaceHolder1_DLFrenchResWindowCount').selectedIndex].value;
    
    if (windowRegCount == "(Number of Windows)")
    {
      windowRegCount = 0;
    }
    
    if (windowFrenchCount == "(Number of Windows)")
    {
      windowFrenchCount = 0;
    }
    
    sidesOfWindow = document.getElementById('ctl00_ContentPlaceHolder1_DLSidesOfResWindow').options[document.getElementById('ctl00_ContentPlaceHolder1_DLSidesOfResWindow').selectedIndex].value;
  }
  
  totalCost = getCost();
  
  // Cost Minimum
  if (action == "Carpet Cleaning Residential")
  {
    if (totalCost < 100)
    {
      document.getElementById('CarpetCleaningMinNote').style.display = "block";
    }
    else
    {
      document.getElementById('CarpetCleaningMinNote').style.display = "none";
    }
  }
  
  function formatCurrency(num)
  {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
  }
  
  totalCost = formatCurrency(totalCost);
  document.getElementById('ctl00_ContentPlaceHolder1_Cost_Estimate').value = totalCost;
  document.getElementById('ServiceEstimatorPrice').innerHTML = totalCost;
}

function getCost()
{
  // Carpet Cleaning Rates
  var CarpetCleaningRmRate       = 45;     // $45.00 per room
  var CarpetProtectionRmRate     = 10;     // $10.00 per room
  var MoveSqFootRate             = .20;    // $.20 per Sq Foot
  var PressureWashSqFootRate     = .10;    // $.10 per Sq Foot
  var TileAndGroutCleaningRate   = .60;    // $.60 per Sq Foot
  var TileAndGroutSealerRate     = .40;    // $.40 per Sq Foot
  var ResRegWindowCleaningRate   = 5;      // $5.00 per window
  var ResFrenchPaneCleaningRate  = .50;    // $.50 per window pane
  
  // Calculate Carpet Cleaning
  if (action == "Carpet Cleaning Residential" || "Carpet Cleaning Commercial")
  {
    if (carpetProtectorWanted == "Yes")
    {
      cost = (CarpetCleaningRmRate * numberOfRooms) + (CarpetProtectionRmRate * numberOfRooms);
    }
    else
    {
      cost = (CarpetCleaningRmRate * numberOfRooms);
    }
  }
  
  // Move In/Out Cleaning
  if (action == "Move-In/Move-Out Cleaning")
  {
    cost = (MoveSqFootRate * moveSqFeet);
  }
  
  // Residential Pressure Washing
  if (action == "Pressure Washing Residential")
  {
    cost = (PressureWashSqFootRate * pressureWashSqFeet);
  }
  
  // Tile & Grout Cleaning
  if (action == "Tile and Grout Cleaning")
  {
    if (tileSealerWanted == "Yes")
    {
      cost = (TileAndGroutCleaningRate * tileSqFeet) + (TileAndGroutSealerRate * tileSqFeet);
    }
    else
    {
      cost = (TileAndGroutCleaningRate * tileSqFeet);
    }
  }
  
  // Tile & Grout Cleaning
  if (action == "Window Cleaning Residential")
  {
    cost = (ResRegWindowCleaningRate * windowRegCount) + (ResFrenchPaneCleaningRate * windowFrenchCount);
    
    if (sidesOfWindow == "Inside and Outside")
    {
      cost = cost * 2; // Double the rate for cleaning both sides
    }
  }
  
  return cost;
}


