﻿var geocoder = null;
function ResetRadComboBox() {
    $find(ServerVariables.RadTextBoxLastNameId).set_value("");
    $find(ServerVariables.RadTextBoxCompanyNameId).set_value("");
    //$find(ServerVariables.RadComboBoxServicesOfferedId).clearSelection();
    $find(ServerVariables.RadComboBoxCountryId).clearSelection();
    $find(ServerVariables.RadComboBoxStatesOrProvincesId).clearSelection();
    $find(ServerVariables.RadTextBoxZipId).set_value("");
    $find(ServerVariables.RadComboBoxProximityId).set_value("10");
}
function ClientValidateRequireAtLeastOneField(source, arguments) {
    var LastName = $find(ServerVariables.RadTextBoxLastNameId).get_value();
    var Zip = $find(ServerVariables.RadTextBoxZipId).get_value();
    var Country = $find(ServerVariables.RadComboBoxCountryId).get_value();
    var StateOrProvince = $find(ServerVariables.RadComboBoxStatesOrProvincesId).get_value();
    var CAIS = document.getElementById(ServerVariables.CheckBoxCAISId).checked;
    var CGIA = document.getElementById(ServerVariables.CheckBoxCGIAId).checked;
    var CIC = document.getElementById(ServerVariables.CheckBoxCICId).checked;
    var CID = document.getElementById(ServerVariables.CheckBoxCIDId).checked;
    var CIDDM = document.getElementById(ServerVariables.CheckBoxCIDDMId).checked;
    var CIDSP = document.getElementById(ServerVariables.CheckBoxCIDSPId).checked;
    var CIDSU = document.getElementById(ServerVariables.CheckBoxCIDSUId).checked;
    var CIDC = document.getElementById(ServerVariables.CheckBoxCIDCId).checked;
    var CIDGC = document.getElementById(ServerVariables.CheckBoxCIDGCId).checked;
    var CIDR = document.getElementById(ServerVariables.CheckBoxCIDRId).checked;
    var CLIA = document.getElementById(ServerVariables.CheckBoxCLIAId).checked;
    var CLIM = document.getElementById(ServerVariables.CheckBoxCLIMId).checked;
    var CLWM = document.getElementById(ServerVariables.CheckBoxCLWMId).checked;
    if ((LastName == "") && (Zip == "") && ((Country == "") || (Country == "United States")) && (StateOrProvince == "") &&
        (CAIS == false) && (CGIA == false) && (CIC == false) && (CID == false) && (CIDDM == false) && (CIDSP == false) && (CIDSU == false) && (CIDC == false) && (CIDGC == false) && (CIDR == false) && (CLIA == false) && (CLIM == false) && (CLWM == false)) {
        arguments.IsValid = false;
    }
    else
        arguments.IsValid = true;
}
function FindACertifiedProfessional() {
    jQuery('html, body').animate({
        scrollTop: jQuery("#result").offset().top
    }, 1500);
    jQuery(':input[type="submit"]:[value="Search"]').attr("disabled", "true").attr("readonly", "true");
    jQuery('#result').html('<img src="/images/loading.gif" alt="Loading..." />');
    var CertificationDesignation = "";
    if (document.getElementById(ServerVariables.CheckBoxCAISId).checked) {
        CertificationDesignation += ",List_CAIS";
    }
    if (document.getElementById(ServerVariables.CheckBoxCGIAId).checked) {
        CertificationDesignation += ",List_CGIA";
    }
    if (document.getElementById(ServerVariables.CheckBoxCICId).checked) {
        CertificationDesignation += ",List_CIC";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDId).checked) {
        CertificationDesignation += ",List_CID";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDDMId).checked) {
        CertificationDesignation += ",List_CIDDM";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDSPId).checked) {
        CertificationDesignation += ",List_CIDSP";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDSUId).checked) {
        CertificationDesignation += ",List_CIDSU";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDCId).checked) {
        CertificationDesignation += ",List_CIDC";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDGCId).checked) {
        CertificationDesignation += ",List_CIDGC";
    }
    if (document.getElementById(ServerVariables.CheckBoxCIDRId).checked) {
        CertificationDesignation += ",List_CIDR";
    }
    if (document.getElementById(ServerVariables.CheckBoxCLIAId).checked) {
        CertificationDesignation += ",List_CLIA";
    }
    if (document.getElementById(ServerVariables.CheckBoxCLIMId).checked) {
        CertificationDesignation += ",List_CLIM";
    }
    if (document.getElementById(ServerVariables.CheckBoxAvail_For_HireId).checked) {
        CertificationDesignation += ",Avail_For_Hire";
    }
    if (document.getElementById(ServerVariables.CheckBoxEPA_WSPId).checked) {
        CertificationDesignation += ",EPA_WSP";
    }
    if (document.getElementById(ServerVariables.CheckBoxUSDA_TSPId).checked) {
        CertificationDesignation += ",USDA_TSP";
    }
    if (document.getElementById(ServerVariables.CheckBoxCLWMId).checked) {
        CertificationDesignation += ",List_CWCML";
    }
    if (CertificationDesignation != "") {
        CertificationDesignation = CertificationDesignation.substring(1, CertificationDesignation.length);
    }
    var MemberRecord = "False";
    if (document.getElementById(ServerVariables.CheckBoxMEMBER_RECORDId).checked) {
        MemberRecord = "True";
    }
    var data = {
        LastName: $find(ServerVariables.RadTextBoxLastNameId).get_value(),
        CompanyName: $find(ServerVariables.RadTextBoxCompanyNameId).get_value(),
        CertificationDesignation: CertificationDesignation,
        MemberRecord: MemberRecord,
        //ServicesOffered: $find(ServerVariables.RadComboBoxServicesOfferedId).get_value(),
        Country: $find(ServerVariables.RadComboBoxCountryId).get_value(),
        StateOrProvince: $find(ServerVariables.RadComboBoxStatesOrProvincesId).get_value(),
        Zip: $find(ServerVariables.RadTextBoxZipId).get_value(),
        Proximity: $find(ServerVariables.RadComboBoxProximityId).get_value(),
        Longitude: 0,
        Latitude: 0
    };
    if (data.Zip != "") {
        geocoder.getLocations(data.Zip, function(response) {
            if (response && response.Status.code == 200) {
                var place = response.Placemark[0];
                data.Longitude = place.Point.coordinates[0];
                data.Latitude = place.Point.coordinates[1];
            }
            jQuery.post(
                "/IA/FindACertifiedProfessional.ashx",
                jQuery.param(data),
                function(response) {
                    jQuery('#result').html(response);
                }
            );
        });
    }
    else {
        jQuery.post(
            "/IA/FindACertifiedProfessional.ashx",
            jQuery.param(data),
            function(response) {
                jQuery('#result').html(response);
            }
        );
    }
}
function slide_trigger_onclick() {
    if (jQuery('.slide_target').is(':visible')) {
        jQuery('.slide_target').hide();
        jQuery('.slide_trigger').html('(Show Options)');
    }
    else {
        jQuery('.slide_target').show();
        jQuery('.slide_trigger').html('(Hide Options)');
    }
}
jQuery(document).ready(function() {
    geocoder = new GClientGeocoder();
    jQuery('.slide_target').hide();
    jQuery('.slide_trigger').css('text-decoration', 'none');
    jQuery(':input[type="submit"]:[value="Search"]').ajaxComplete(function(e, xhr, settings) {
        jQuery(this).removeAttr("disabled").removeAttr("readonly");
    });
});
function radComboBoxStatesOrProvinces_onClientSelectedIndexChanging(combo, eventArqs) {
    var item = eventArqs.get_item();
    var combobox = $find(ServerVariables.RadComboBoxStatesOrProvincesId);

    combobox.set_text("Loading...");
    // This will fire the ItemsRequested event of the
    // state/province combobox passing the country description as a parameter.
    var country = item.get_text();
    combobox.requestItems(country.toString(), false);
	combobox.clearSelection();
	combobox._applyEmptyMessage();
}
function radComboBoxStatesOrProvinces_onClientItemsRequesting(sender, eventArgs) {
    var context = eventArgs.get_context();
    context["Country"] = eventArgs.get_text();
}
function pageLoad() {
	var combo = $find(ServerVariables.RadComboBoxStatesOrProvincesId);
	// Invoke the webMethod passing the country as e.Text.
	combo.requestItems($find(ServerVariables.RadComboBoxCountryId).get_text(), false);
}
function radComboBoxStatesOrProvinces_onClientLoad(combo, eventArgs){
	// No custom text allowed.
	var inputArea = combo.get_inputDomElement();
	inputArea.onkeydown = function(){return false;};
}

