﻿//Messages:
var Message71 = "Please enter street";
var Message72 = "Please enter zip code";
var Message73 = "This should be only 5 digits";
var Message74 = "Please select Island";
var Message75 = "Please select miles and fill out street and zip (only 5 digits)";
var Message75a = "Please select Range & Landmark";
var Message76 = "Please select property type";
var Message77 = "Please select property status";
var Message78 = "Please select Min. price";
var Message79 = "Please select Max. price";
var Message7a = "Max. price must be greater than min price";


//Validation functions
function IsEmpty(objTx, Message) {
    if (objTx.value == "") {
        alert(Message);
        objTx.focus();
        return true;
    }
    return false;
}

function IsNotSelected(objSel, Message) {
    if (objSel.selectedIndex < 1) {
        alert(Message);
        return true;
    }

}

function ValidateProximitySearchStepFirst(ddlPropertyType, ddlPropertyStatus, ddlPriceMin, ddlPriceMax, ddlSearchRangeFirst, ddlCenterPoint) {

    var isValid = true;

    if (IsNotSelected(ddlPropertyType, Message76) || IsNotSelected(ddlPropertyStatus, Message77) || IsNotSelected(ddlPriceMin, Message78)) {
        isValid = false;
        return isValid;
    }

    //validate price
    isValid = ValidateDropdownListRange(Message7a, ddlPriceMin, ddlPriceMax, '0');
    if (!isValid) {
        isValid = false;
        return isValid;
    }
    
    if (ddlSearchRangeFirst.selectedIndex < 1 || ddlCenterPoint.selectedIndex < 1)
    {
        alert(Message75a);
         isValid = false;
        return isValid;
    }
    return isValid;  
}


function ValidateProximitySearchStepSecond(ddlIsland, ddlPropertyType, ddlPropertyStatus, ddlPriceMin, ddlPriceMax, ddlSearchRangeSecond, txtSearchZip, txtSearchStreet) 
{


    var isValid = true;

    if (IsNotSelected(ddlPropertyType, Message76) || IsNotSelected(ddlPropertyStatus, Message77) || IsNotSelected(ddlPriceMin, Message78)) {
        isValid = false;
        return isValid;
    }


    //validate price
    isValid = ValidateDropdownListRange(Message7a, ddlPriceMin, ddlPriceMax, '0');
    if (!isValid) {
        return false;
    }
    
   

    if (ddlSearchRangeSecond.selectedIndex < 1) {
    alert(Message75);
    isValid = false;
    return isValid; 
    }
     
        if (IsEmpty(txtSearchStreet, Message71) || IsEmpty(txtSearchZip, Message72))
            return false;

        for (j = 0; j < txtSearchZip.value.length; j++)
            if ((txtSearchZip.value.length != 5) || (txtSearchZip.value.toUpperCase().charCodeAt(j) > 57) || (txtSearchZip.value.toUpperCase().charCodeAt(j) < 48)) {
            alert(Message73);
            txtSearchZip.select();
            return false;
        }
        if (ddlIsland.selectedIndex < 1) {
            alert(Message74);
            return false;
        }
    
    


    return isValid;  
}

