﻿
//shows and hides form fields by selected property types (except condo)
function SetDisplayFromPropertyType(cbPropertyTypeSingleFamily, cbPropertyTypeCondo, cbPropertyTypeMultiFamily, cbPropertyTypeVacantLand, cbPropertyTypeTownhouse, pnlHomeFeatures, pnlCondoFeatures, pnlLandArea, pnlYearBuilt, lbNeighborhoodsSelected, divBedrooms, divBathrooms)
{
    //hide home features if single family isn't selected
    if (!cbPropertyTypeSingleFamily.checked)
    {
        pnlHomeFeatures.style.display = "none";
    }
    else
    {
        pnlHomeFeatures.style.display = "";
    }

 /*
    //hide land area if none of SF, Multi, townhouse, or Land is checked
    if (!cbPropertyTypeSingleFamily.checked && !cbPropertyTypeMultiFamily.checked && !cbPropertyTypeTownhouse.checked && !cbPropertyTypeVacantLand.checked)
    {
        pnlLandArea.style.display = "none";
    }
    else
    {
        pnlLandArea.style.display = "";
    }
*/

    var hasSelectedPropertyTypes = cbPropertyTypeCondo.checked || cbPropertyTypeSingleFamily.checked || cbPropertyTypeTownhouse.checked || cbPropertyTypeMultiFamily.checked || cbPropertyTypeVacantLand.checked;

    //alert(hasSelectedPropertyTypes);


    //year built is applicable to everything but vacant land
    if (hasSelectedPropertyTypes && !(cbPropertyTypeCondo.checked || cbPropertyTypeSingleFamily.checked || cbPropertyTypeTownhouse.checked || cbPropertyTypeMultiFamily.checked)) {
        pnlYearBuilt.style.display = "none";
    }
    else 
    {
        pnlYearBuilt.style.display = "";
    }

    //beds and baths show for everything but multifamily and vacant land
    if (hasSelectedPropertyTypes && !(cbPropertyTypeCondo.checked || cbPropertyTypeSingleFamily.checked || cbPropertyTypeTownhouse.checked)) {

        divBathrooms.style.display = "none";
        divBedrooms.style.display = "none";
    }
    else 
    {

        divBathrooms.style.display = "";
        divBedrooms.style.display = "";
    }
    
}

//shows and hides condo fields
function SetCondoDisplay(cbPropertyTypeCondo, lbNeighborhoodsSelected, divNeighborhoodsRequiredForCondoMsg, pnlCondoFeatures)
{
    //if condo is selected but no neighborhoods are selected, we show neighborhoods required message
    if (cbPropertyTypeCondo.checked && lbNeighborhoodsSelected.length == 0)
    {
        divNeighborhoodsRequiredForCondoMsg.style.display = "";
    }
    else
    {
        divNeighborhoodsRequiredForCondoMsg.style.display = "none";
    }

    //hide condo features if condo isn't selected or if no neighborhoods are selected
    if (!cbPropertyTypeCondo.checked || lbNeighborhoodsSelected.length == 0)
    {
        pnlCondoFeatures.style.display = "none";
    }
    else
    {
        pnlCondoFeatures.style.display = "";
    }
}

//shows and hides form fields from the selected island
function SetDisplayFromIsland(ddlIsland, divHomeFeaturesOhanaDwelling, divHomeFeaturesOhanaAttached, divHomeFeaturesOhanaDetached, divFrontage, divPropertyTypeTownhouse, divPropertyTypeMultiFamily, ddlHomeFeaturesPropertyCondition, ddlCondoFeaturesPropertyCondition, divCondoFeaturesSecurity, divCondoFeaturesParking, divViewGolfCourse, divViewDiamondHead, divViewMarinaCanal, divViewCity, cbPropertyTypeMultiFamily, cbPropertyTypeTownhouse, divDistressedProperties, openHouseControlForOahu,waterFrontControl,schoolSearchControlForOahu) {

    var val = ddlIsland.options[ddlIsland.selectedIndex].value;

/*
    if (val)
    {
        txt = txt.toLowerCase();
    }
*/

    if (val == "1")//oahu
    {
        divHomeFeaturesOhanaAttached.style.display = "none";
        divHomeFeaturesOhanaDetached.style.display = "none";
        divHomeFeaturesOhanaDwelling.style.display = "";
        divFrontage.style.display = "";
        ddlHomeFeaturesPropertyCondition.style.display = "";
        ddlCondoFeaturesPropertyCondition.style.display = "";
        divPropertyTypeTownhouse.style.display = "";
        divPropertyTypeMultiFamily.style.display = "";
        divCondoFeaturesSecurity.style.display = "";
        divCondoFeaturesParking.style.display = "";
        divViewGolfCourse.style.display = "";
        divViewDiamondHead.style.display = "";
        divViewMarinaCanal.style.display = "";
        divViewCity.style.display = "";
        divDistressedProperties.style.display = "";
        openHouseControlForOahu.style.display = "block";
        waterFrontControl.style.display = "none";
        schoolSearchControlForOahu.style.display = "block";
    }
    else if (val == "2" || val == "5" || val == "6")//maui, molokai, lanai
    {
        divHomeFeaturesOhanaAttached.style.display = "";
        divHomeFeaturesOhanaDetached.style.display = "";
        divHomeFeaturesOhanaDwelling.style.display = "none";
        divFrontage.style.display = "none";
        ddlHomeFeaturesPropertyCondition.style.display = "none";
        ddlCondoFeaturesPropertyCondition.style.display = "none";

        divPropertyTypeTownhouse.style.display = "none";
        cbPropertyTypeTownhouse.checked = false;
        FireOnClickEvent(cbPropertyTypeTownhouse); //handle property type selection display
        
        divPropertyTypeMultiFamily.style.display = "";
        divCondoFeaturesSecurity.style.display = "";
        divCondoFeaturesParking.style.display = "";
        divViewGolfCourse.style.display = "";
        divViewDiamondHead.style.display = "none";
        divViewMarinaCanal.style.display = "none";
        divViewCity.style.display = "none";
        divDistressedProperties.style.display = "";
        openHouseControlForOahu.style.display = "none";
        waterFrontControl.style.display = "block";
        schoolSearchControlForOahu.style.display = "none";
    }
    else if (val == "3" || val == "4") //hawaii and kauai
    {
        divFrontage.style.display = "";
        divHomeFeaturesOhanaAttached.style.display = "none";
        divHomeFeaturesOhanaDetached.style.display = "none";
        divHomeFeaturesOhanaDwelling.style.display = "";
        ddlHomeFeaturesPropertyCondition.style.display = "none";
        ddlCondoFeaturesPropertyCondition.style.display = "none";

        divPropertyTypeTownhouse.style.display = "none";
        cbPropertyTypeTownhouse.checked = false;
        divPropertyTypeMultiFamily.style.display = "none";
        cbPropertyTypeMultiFamily.checked = false;
        FireOnClickEvent(cbPropertyTypeTownhouse); //handle property type selection display
        
        divCondoFeaturesSecurity.style.display = "none";
        divCondoFeaturesParking.style.display = "none";
        divViewGolfCourse.style.display = "none";
        divViewDiamondHead.style.display = "none";
        divViewMarinaCanal.style.display = "none";
        divViewCity.style.display = "none";
        divDistressedProperties.style.display = "none";
        openHouseControlForOahu.style.display = "none";
        waterFrontControl.style.display = "none";
        schoolSearchControlForOahu.style.display = "none";
    }
}

//validates the form
function ValidateForm(ddlIsland, ddlRegion, lbNeighborhoodsSelected, ddlPriceMin, ddlPriceMax, ddlInteriorAreaMin, ddlInteriorAreaMax, ddlLandAreaMin, ddlLandAreaMax, cbTenureFeeSimple, cbTenureLeasehold, cbPropertyTypeSingleFamily, cbPropertyTypeCondo, cbPropertyTypeTownhouse, cbPropertyTypeMultiFamily, cbPropertyTypeVacantLand, cbStatusActive, cbStatusPending, cbStatusSold, ddlPriceReducedAmount, ddlPriceReducedTime)
{

    var isValid = true;
    
    //validate island
    isValid = ValidateDropdownList('Please select island', '0', ddlIsland);
    if (!isValid)
    {
        return false;
    }
   
    //validate region
    isValid = ValidateDropdownList('Please select region', '0', ddlRegion);
    if (!isValid)
    {
        return false;
    }

    /*
    //validate selected neighborhoods
    isValid = ValidateListbox('Please select at least one neighborhood', lbNeighborhoodsSelected);
    if (!isValid)
    {
        return false;
    }
    */
    
    //validate tenure
    isValid = ValidateCheckboxGroup('Please select at least one tenure', cbTenureFeeSimple, cbTenureLeasehold);
    if (!isValid)
    {
        return false;
    }

    //validate status
    isValid = ValidateCheckboxGroup('Please select at least one status', cbStatusActive, cbStatusPending, cbStatusSold);
    if (!isValid)
    {
        return false;
    }

    //validate property type
    isValid = ValidateCheckboxGroup('Please select at least one property type', cbPropertyTypeSingleFamily, cbPropertyTypeCondo, cbPropertyTypeTownhouse, cbPropertyTypeMultiFamily, cbPropertyTypeVacantLand);
    if (!isValid)
    {
        return false;
    }
    
    //validate price
    isValid = ValidateDropdownListRange('Price Min cannot be larger than Price Max', ddlPriceMin, ddlPriceMax, '0');
    if (!isValid)
    {
        return false;
    }

    //validate interior area
    isValid = ValidateDropdownListRange('Interior Square ft. Min cannot be larger than Square ft.Max', ddlInteriorAreaMin, ddlInteriorAreaMax, '0');
    if (!isValid)
    {
        return false;
    }


    //don't validate land area if anything but condo is selected
    
    if (cbPropertyTypeSingleFamily.checked || cbPropertyTypeMultiFamily.checked || cbPropertyTypeTownhouse.checked || cbPropertyTypeVacantLand.checked)
    {
        isValid = ValidateDropdownListRange('Land Area Min cannot be larger than Land Area Max', ddlLandAreaMin, ddlLandAreaMax, '0');
        if (!isValid)
        {
            return false;
        }
    }
     if (ddlPriceReducedTime.value == '0' && ddlPriceReducedAmount.value != 'Any') 
    {
        alert('Please select Timeframe for Price Reduction');   
         isValid= false;
        
    }
  
    return isValid;

}



