Receive Instant Quote
Main Services
Secondary Services
Send SMS message to customer
Send Email to customer
Property Details
var componentForm = { street_number: 'short_name', route: 'long_name', locality: 'long_name', administrative_area_level_1: 'short_name', postal_code: 'long_name', postal_code_suffix: 'short_name' };
//var baseUrl = 'https://localhost:44397'; var baseUrl = 'https://inspectortech.homeinspectionsoftware.co';
$(document).ready(function () { fnBuildServicesLists(); });
function initAutocomplete() { // Create the autocomplete object, restricting the search predictions to // geographical location types. autocomplete = new google.maps.places.Autocomplete( document.getElementById('autocomplete'), { types: ['geocode'] });
// Avoid paying for data that you don't need by restricting the set of // place fields that are returned to just the address components. autocomplete.setFields(['address_component']);
// When the user selects an address from the drop-down, populate the // address fields in the form. autocomplete.addListener('place_changed', fillInAddress); }
function fillInAddress() { // Enable this if wanting some kind of loading notification. fnToggleFieldsLoading();
// Get the place details from the autocomplete object. var place = autocomplete.getPlace();
var street_number; var route; var locality; var administrative_area_level_1; var postal_code; var postal_code_suffix;
// Get each component of the address from the place details,
// and then fill-in the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
switch (addressType) {
case 'street_number':
street_number = val;
break;
case 'route':
route = val;
break;
case 'locality':
locality = val;
break;
case 'administrative_area_level_1':
administrative_area_level_1 = val;
break;
case 'postal_code':
postal_code = val;
break;
case 'postal_code_suffix':
postal_code_suffix = val;
break;
default:
}
}
}
document.getElementById('userAddress1').value = street_number + ' ' + route;
document.getElementById('userCity').value = locality;
document.getElementById('userState').value = administrative_area_level_1;
if (postal_code_suffix)
document.getElementById('userZip').value = postal_code + '-' + postal_code_suffix;
else
document.getElementById('userZip').value = postal_code;
// Fill in address field for POSTing.
document.getElementById('quoteFullAdress').value = document.getElementById('autocomplete').value;
zillowAPI();
}
function fnCalculateTotalPrice(quoteService) {
var currentYear = new Date().getFullYear();
var houseYear = quoteService.year === "0" ? currentYear : quoteService.year;
houseYear = houseYear === "" ? currentYear : houseYear;
// Temporarily multiply fees to avoid floating point rounding (converts 12.34 to 1234).
var adjustedOldPrice = Number(100 * quoteService.oldPrice).toFixed(0);
var adjustedNewPrice = Number(100 * quoteService.newPrice).toFixed(0);
var distanceFee = Number(quoteService.distance) * Number(quoteService.perMile);
var sizeFee = Number(quoteService.size) * Number(quoteService.perSize);
var ageFee = (currentYear - Number(houseYear)) * Number(quoteService.perAge);
adjustedNewPrice = +adjustedNewPrice + (100 * distanceFee) + (100 * sizeFee) + (100 * ageFee);
if (quoteService.addition === 1)
return Number((+adjustedOldPrice + +adjustedNewPrice) / 100).toFixed(2);
else
return Number((+adjustedOldPrice - +adjustedNewPrice) / 100).toFixed(2);
}
// new version of price function that will load both service lists and manually add price of all elements each time.
function loadValues2() {
var price = 0;
var mainServicesList = document.getElementsByClassName('MainServices');
var secondaryServicesList = document.getElementsByClassName('SecondaryServices');
var size = document.getElementById('quoteSqFt').value;
var year = document.getElementById('quoteBuilt').value;
var distance = document.getElementById('quoteDistance').value;
var quoteService = {
oldPrice: price,
newPrice: 0,
// get zillow variables
size: size,
year: year,
distance: distance,
// get price multipliers
perAge: 0,
perMile: 0,
perSize: 0,
// mark for addition or subtraction
addition: 1
}
if (mainServicesList.length == 0 && secondaryServicesList.length == 0) {
$('#tbTotal').val(0);
}
else {
for (i = 0; i < mainServicesList.length; i++) {
if (mainServicesList[i].checked) {
var quoteService = {
oldPrice: price,
newPrice: +mainServicesList[i].value.split(':')[1],
// get zillow variables
size: size,
year: year,
distance: distance,
// get price multipliers
perAge: +mainServicesList[i].value.split(':')[2],
perMile: +mainServicesList[i].value.split(':')[3],
perSize: +mainServicesList[i].value.split(':')[4],
// mark for addition or subtraction
addition: 1
}
}
// Add or subtract fees and divide back down to show cents (1234 to 12.34).
$('#tbTotal').val(fnCalculateTotalPrice(quoteService));
price = $('#tbTotal').val();
}
for (i = 0; i < secondaryServicesList.length; i++) {
if (secondaryServicesList[i].checked) {
var quoteService = {
oldPrice: price,
newPrice: +secondaryServicesList[i].value.split(':')[1],
// get zillow variables
size: size,
year: year,
distance: distance,
// get price multipliers
perAge: +secondaryServicesList[i].value.split(':')[2],
perMile: +secondaryServicesList[i].value.split(':')[3],
perSize: +secondaryServicesList[i].value.split(':')[4],
// mark for addition or subtraction
addition: 1
}
}
// Add or subtract fees and divide back down to show cents (1234 to 12.34).
$('#tbTotal').val(fnCalculateTotalPrice(quoteService));
price = $('#tbTotal').val();
}
}
try {
// this section is throwing an error.
editor
.edit($(this).closest('tr'), false)
.set('active', $(this).prop('checked') ? 1 : 0)
.submit();
}
catch {
}
}
// Bias the autocomplete object to the users geographical location,
// as supplied by the browsers //navigator.geolocation// object.
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle(
{ center: geolocation, radius: position.coords.accuracy });
autocomplete.setBounds(circle.getBounds());
});
}
}
function zillowAPI() {
var url = baseUrl + '/api/ZillowComment';
var address1 = document.getElementById('userAddress1').value;
var city = document.getElementById('userCity').value;
var state = document.getElementById('userState').value;
var userName = 'admin';
var finalUrl = url + '?' +
'address=' + address1 +
'&city=' + city +
'&state=' + state +
'&userName=' + userName;
var request = new XMLHttpRequest();
request.open('GET', finalUrl);
request.onload = function () {
var data = JSON.parse(this.response);
document.getElementById('quoteSqFt').value = data.squarefeet;
document.getElementById('quotePrice').value = data.value;
document.getElementById('quoteBeds').value = data.bedrooms;
document.getElementById('quoteBaths').value = data.bathrooms;
document.getElementById('quoteBuilt').value = data.yearbuilt;
document.getElementById('quoteDistance').value = data.distance;
// set HFs
document.getElementById('hfQuoteSqFt').value = data.squarefeet;
document.getElementById('hfQuotePrice').value = data.value;
document.getElementById('hfQuoteBeds').value = data.bedrooms;
document.getElementById('hfQuoteBaths').value = data.bathrooms;
document.getElementById('hfQuoteBuilt').value = data.yearbuilt;
document.getElementById('hfQuoteDistance').value = data.distance;
loadValues2();
fnToggleFieldsLoading();
}
request.send();
}
// Toggles visiblity of fields on/off. For use by zillow loading function.
function fnToggleFieldsLoading() {
var toggleSpeed = 'fast';
$('#quoteSqFt').toggle(toggleSpeed);
$('#quoteSqFtLoading').toggle(toggleSpeed);
$('#quoteBuilt').toggle(toggleSpeed);
$('#quoteBuiltLoading').toggle(toggleSpeed);
$('#quotePrice').toggle(toggleSpeed);
$('#quotePriceLoading').toggle(toggleSpeed);
$('#quoteBeds').toggle(toggleSpeed);
$('#quoteBedsLoading').toggle(toggleSpeed);
$('#quoteBaths').toggle(toggleSpeed);
$('#quoteBathsLoading').toggle(toggleSpeed);
$('#quoteDistance').toggle(toggleSpeed);
$('#quoteDistanceLoading').toggle(toggleSpeed);
}
// Gets list of main/secondary services available for quote.
function fnBuildServicesLists() {
$.getJSON(baseUrl + '/api/GetServices', function (data) {
for (let i = 0; i < data.length; i++) {
if (data[i].Main == "True") {
// Add as main service
var divMainServices = document.getElementById('divMainServices');
divMainServices.innerHTML += '' + data[i].Name + '
';
}
else {
// Add as secondary service
var divSecondaryServices = document.getElementById('divSecondaryServices');
divSecondaryServices.innerHTML += '' + data[i].Name + '
';
}
}
});
}
// Checks validity of form by comparing email and phone. Also reports whole form validity. function SubmitScheduleForm(status) { var form = document.getElementById('quoteScheduleForm'); var email = document.getElementById("frmEmail"); var phone = document.getElementById("frmPhone");
var validPhoneFields = true; email.setCustomValidity(""); phone.setCustomValidity("");
if (phone.value == "" && email.value == "") { phone.setCustomValidity("Please fill out phone phone or email."); email.setCustomValidity("Please fill out phone phone or email."); phone.focus(); validPhoneFields = false; }
form.reportValidity();
if (validPhoneFields === false || form.checkValidity() === false) { return; }
document.getElementById('frmStatus').value = status; ajaxSendEmailOrSMS('CreateQuoteComplex'); }
// Submits quote. function ajaxSendEmailOrSMS(controllerFunction) {
$.ajax({ cache: false, type: "POST", url: baseUrl + '/api/' + controllerFunction + '/', data: $('form#quoteScheduleForm').serialize(), async: true, success: function (data) { if (document.getElementById('frmStatus').value == 'Send Quote' || document.getElementById('frmStatus').value == 'Save Job') { // window.location.href = "/"; var toggleSpeed = 'fast'; $('#pnlQuote').toggle(toggleSpeed); $('#pnlSuccessful').toggle(toggleSpeed); } //else if (document.getElementById('frmStatus').value == 'Book Job') // window.location.href = "/Appointments/EditAppointment/" + data; //alert("Message sent."); //$("#btnMessageReset").click(); }, error: function () { alert("Couldn't send"); } }); }
function reloadPage() { window.location.href=window.location.href; }
No responses yet