// Maps Google's returned name → PetRelocation Location page spelling var PR_COUNTRY_MAP = { "Turkey": "Türkiye", "Democratic Republic of the Congo": "Congo Kinshasa", "Republic of the Congo": "Congo", "Ivory Coast": "Cote D'Ivoire", "South Korea": "South Korea", // Google returns this — matches your list "North Korea": "North Korea", // Google returns this — matches your list "North Macedonia": "North Macedonia", // matches "Palestinian Territories": "Palestinian Territory", "Réunion": "Reunion", "Guadeloupe": "Guadaloupe", // your spelling has one 'u' after 'd' "Eswatini": "Swaziland", "Timor-Leste": "Timor-Leste", // matches "Vatican City": "Vatican City", // matches "Macau": "Macau", // matches "Hong Kong": "Hong Kong", // matches "Micronesia": "Federated States Of Micronesia", "U.S. Virgin Islands": "Virgin Islands, US", "British Virgin Islands": "Virgin Islands, British", "Saint Martin": "Saint Martin (French)", "Sint Maarten": "Sint Maarten (Dutch)", "Wallis & Futuna": "Wallis and Futuna", "Heard & McDonald Islands": "Heard and McDonald Islands", "South Georgia & South Sandwich Islands": "South Georgia and the South Sandwich Isl", "Bonaire": "Bonaire, Saint Eustatius and Saba", "Caribbean Netherlands": "Bonaire, Saint Eustatius and Saba", "United States": "United States", // matches "United Kingdom": "United Kingdom", // matches "Australia": "Australia", // matches }; // US state abbreviation → full name (Google sometimes returns abbreviations) var US_STATE_MAP = { "AL": "Alabama", "AK": "Alaska", "AZ": "Arizona", "AR": "Arkansas", "CA": "California", "CO": "Colorado", "CT": "Connecticut", "DE": "Delaware", "DC": "District Of Columbia", "FL": "Florida", "GA": "Georgia", "HI": "Hawaii", "ID": "Idaho", "IL": "Illinois", "IN": "Indiana", "IA": "Iowa", "KS": "Kansas", "KY": "Kentucky", "LA": "Louisiana", "ME": "Maine", "MD": "Maryland", "MA": "Massachusetts", "MI": "Michigan", "MN": "Minnesota", "MS": "Mississippi", "MO": "Missouri", "MT": "Montana", "NE": "Nebraska", "NV": "Nevada", "NH": "New Hampshire", "NJ": "New Jersey", "NM": "New Mexico", "NY": "New York", "NC": "North Carolina", "ND": "North Dakota", "OH": "Ohio", "OK": "Oklahoma", "OR": "Oregon", "PA": "Pennsylvania", "RI": "Rhode Island", "SC": "South Carolina", "SD": "South Dakota", "TN": "Tennessee", "TX": "Texas", "UT": "Utah", "VT": "Vermont", "VA": "Virginia", "WA": "Washington", "WV": "West Virginia", "WI": "Wisconsin", "WY": "Wyoming" }; function normalizeCountry(name) { return PR_COUNTRY_MAP[name] || name; } function normalizeState(name, countryCode) { // If Google returns a 2-letter abbreviation for a US state, expand it if (countryCode === 'US' && name && name.length === 2) { return US_STATE_MAP[name.toUpperCase()] || name; } return name; } /* move to top? function initAutocomplete() { setupLocationAutocomplete( 'pickup_autocomplete', // visible input ID '00Ni0000000Z3fI', // Pickup City SF field '00Ni0000002or0b', // Pickup State SF field '00Ni0000000Z3b5', // Pickup Country SF field 'pickup_hawaii_row' // Hawaii island field container ID ); setupLocationAutocomplete( 'delivery_autocomplete', '00Ni0000000Z0wi', // Delivery City SF field '00Ni0000002oqzO', // Delivery State SF field '00Ni0000000Z3fN', // Delivery Country SF field 'delivery_hawaii_row' ); // Auto-populate GCLID captureGCLID(); } function setupLocationAutocomplete(inputId, cityFieldId, stateFieldId, countryFieldId, hawaiiRowId) { var input = document.getElementById(inputId); var autocomplete = new google.maps.places.Autocomplete(input, { types: ['geocode'] // accepts cities, states, countries, regions }); autocomplete.addListener('place_changed', function () { var place = autocomplete.getPlace(); if (!place || !place.address_components) return; var city = ''; var state = ''; var country = ''; var countryCode = ''; place.address_components.forEach(function (component) { var types = component.types; if (types.includes('locality') || types.includes('postal_town')) { city = component.long_name; } else if (types.includes('administrative_area_level_1')) { state = component.long_name; // full name preferred } else if (types.includes('country')) { country = component.long_name; countryCode = component.short_name; } }); // Normalize to PetRelocation spellings country = normalizeCountry(country); state = normalizeState(state, countryCode); // Write to hidden SF fields document.getElementById(cityFieldId).value = city; document.getElementById(stateFieldId).value = state; document.getElementById(countryFieldId).value = country; // Handle Hawaii island field visibility var hawaiiRow = document.getElementById(hawaiiRowId); if (hawaiiRow) { var isHawaii = (country === 'United States' && state === 'Hawaii'); hawaiiRow.style.display = isHawaii ? 'block' : 'none'; if (!isHawaii) { // Clear Hawaii island selection if no longer applicable var hawaiiSelect = hawaiiRow.querySelector('select'); if (hawaiiSelect) hawaiiSelect.value = ''; } } }); } */ // SF hidden field IDs for species and breed per pet number var PET_FIELD_IDS = { 1: { species: '00Ni0000002orLM', breed: '00Ni0000002p2Rs' }, 2: { species: '00Ni0000002orLR', breed: '00Ni0000002oyJv' }, 3: { species: '00Ni0000002orLW', breed: '00Ni0000002p2WK' }, 4: { species: '00Ni0000002omDq', breed: '00Ni0000002p2WU' }, 5: { species: '00Ni0000002orLv', breed: '00Ni0000002p2RK' } }; var CAT_BREEDS = [ "Abyssinian","American Bobtail","American Curl","American Shorthair (purebred)", "American Wirehair (purebred)","Arabian Mau","Ashera","Balinese","Bengal","Birman", "Bombay","Brazilian Shorthair","British Longhair","British Shorthair","Burmese", "Burmilla","Canadian Hairless (Sphynx)","Chartreux","Chausie","Chinchilla Cat", "Colorpoint Shorthair","Cornish Rex","Devon Rex","Domestic Longhair","Domestic Mediumhair", "Domestic Shorthair","Egyptian Mau","European Burmese","European Longhair", "European Shorthair","Exotic","Havana Brown","Himalayan","Japanese Bobtail","Javanese", "Kashmir","Korat","Kurilian Bobtail","LaPerm","Maine Coon","Manx","Mixed Breed Feline", "Mixed Feline","Munchkin","Napoleon","Nebelung","Norwegian Forest Cat","Ocicat", "Oriental Shorthair","Persian","Peterbald","Pixie-Bob","Ragamuffin","Ragdoll", "Russian Blue","Safari","Savannah","Scottish Fold","Scottish Straight","Selkirk Rex", "Serengeti","Shirazi","Siamese","Siberian","Singapura","Snowshoe","Somali","Sphynx", "Tiffany","Tonkinese","Toyger","Turkish Angora","Turkish Van","York Chocolate" ]; var DOG_BREEDS = [ "Affenpinscher","Afghan Hound","Africanis","Airedale Terrier","Akbash","Akita", "Alapaha Blue Blood Bulldog","Alaskan Klee Kai","Alaskan Malamute","American Bulldog", "American Bully","American Cocker Spaniel","American Eskimo Dog","American Foxhound", "American Hairless Terrier","American Mastiff","American Pit Bull Terrier", "American Staffordshire Terrier","American Water Spaniel","Anatolian Shepherd Dog", "Argentine Dogo","Australian Bulldog","Australian Cattle Dog","Australian Kelpie", "Australian Shepherd","Australian Terrier","Azawakh","Basenji","Basset Hound","Beagle", "Bearded Collie","Belgian Malinois","Belgian Sheepdog","Belgian Tervuren", "Bernese Mountain Dog","Bichon Frise","Bloodhound","Blue Heeler","Boerboel", "Border Collie","Border Terrier","Borzoi","Boston Terrier","Boxer","Briard", "British Bulldog","Brittany","Brussels Griffon","Bull Terrier","Bullmastiff", "Cairn Terrier","Cane Corso","Cardigan Welsh Corgi","Cavalier King Charles Spaniel", "Chesapeake Bay Retriever","Chihuahua","Chinese Crested","Chinese Shar-Pei","Chow Chow", "Cocker Spaniel","Collie","Dachshund","Dalmatian","Doberman Pinscher","English Bulldog", "English Cocker Spaniel","English Setter","English Springer Spaniel","French Bulldog", "German Shepherd","German Shorthaired Pointer","Giant Schnauzer","Golden Retriever", "Goldendoodle","Great Dane","Great Pyrenees","Greyhound","Havanese","Ibizan Hound", "Irish Setter","Irish Water Spaniel","Irish Wolfhound","Italian Greyhound", "Jack Russell Terrier","Labradoodle","Labrador Retriever","Leonberger","Lhasa Apso", "Maltese","Maltipoo","Mastiff","Miniature Dachshund","Miniature Pinscher", "Miniature Poodle","Miniature Schnauzer","Mixed Breed Canine","Mixed Canine", "Neapolitan Mastiff","Newfoundland","Norwegian Elkhound", "Nova Scotia Duck Tolling Retriever","Old English Sheepdog","Papillon","Pekingese", "Pembroke Welsh Corgi","Pomeranian","Portuguese Water Dog","Pug","Puggle", "Rat Terrier","Rhodesian Ridgeback","Rottweiler","Saint Bernard","Samoyed", "Scottish Terrier","Shetland Sheepdog","Shiba Inu","Shih Tzu","Siberian Husky", "Soft Coated Wheaten Terrier","Staffordshire Bull Terrier","Standard Poodle", "Standard Schnauzer","Tibetan Mastiff","Tibetan Spaniel","Vizsla","Weimaraner", "Welsh Springer Spaniel","West Highland White Terrier","Whippet","Wire Fox Terrier", "Wirehaired Pointing Griffon","Xoloitzcuintli","Yorkshire Terrier" ]; function onSpeciesChange(petNum) { var ids = PET_FIELD_IDS[petNum]; var speciesSelect = document.getElementById('pet_' + petNum + '_species_select'); var species = speciesSelect.value; // Write to hidden SF field document.getElementById(ids.species).value = species; var breedRow = document.getElementById('pet_' + petNum + '_breed_row'); var breedSelect = document.getElementById('pet_' + petNum + '_breed_select'); var breedHidden = document.getElementById(ids.breed); var mixedRow = document.getElementById('pet_' + petNum + '_mixed_row'); var mixedCheckbox = mixedRow ? mixedRow.querySelector('input[type="checkbox"]') : null; // Reset breed breedHidden.value = ''; breedSelect.innerHTML = ''; if (species === 'Cat' || species === 'Dog') { var list = species === 'Cat' ? CAT_BREEDS : DOG_BREEDS; list.forEach(function(b) { var opt = document.createElement('option'); opt.value = b; opt.textContent = b; breedSelect.appendChild(opt); }); breedRow.style.display = 'block'; breedSelect.setAttribute('required', ''); // NEW: breed required for Cat/Dog if (mixedRow) mixedRow.style.display = 'block'; // NEW: show Mixed Breed } else { breedRow.style.display = 'none'; breedSelect.removeAttribute('required'); // NEW: drop required when hidden if (mixedRow) { mixedRow.style.display = 'none'; // NEW: hide Mixed Breed if (mixedCheckbox) mixedCheckbox.checked = false; // NEW: clear stale value } } } function onSpeciesChange_v1(petNum) { var ids = PET_FIELD_IDS[petNum]; var speciesSelect = document.getElementById('pet_' + petNum + '_species_select'); var species = speciesSelect.value; // Write to hidden SF field document.getElementById(ids.species).value = species; var breedRow = document.getElementById('pet_' + petNum + '_breed_row'); var breedSelect = document.getElementById('pet_' + petNum + '_breed_select'); var breedHidden = document.getElementById(ids.breed); // Reset breed breedHidden.value = ''; breedSelect.innerHTML = ''; if (species === 'Cat' || species === 'Dog') { var list = species === 'Cat' ? CAT_BREEDS : DOG_BREEDS; list.forEach(function(b) { var opt = document.createElement('option'); opt.value = b; opt.textContent = b; breedSelect.appendChild(opt); }); breedRow.style.display = 'block'; } else { breedRow.style.display = 'none'; } } function onBreedChange(petNum) { var ids = PET_FIELD_IDS[petNum]; var val = document.getElementById('pet_' + petNum + '_breed_select').value; document.getElementById(ids.breed).value = val; } function togglePetSections() { var num = parseInt(document.getElementById('num_pets').value) || 1; for (var i = 2; i <= 5; i++) { var section = document.getElementById('pet_section_' + i); if (!section) continue; if (i <= num) { section.style.display = 'block'; // Restore required on name and weight section.querySelector('[data-required="true"]') && section.querySelectorAll('[data-required="true"]') .forEach(function(el) { el.setAttribute('required', ''); }); } else { section.style.display = 'none'; clearPetSection(i); } } } function clearPetSection(petNum) { var section = document.getElementById('pet_section_' + petNum); if (!section) return; section.querySelectorAll('input, select, textarea').forEach(function(el) { el.value = ''; el.removeAttribute('required'); if (el.type === 'checkbox') el.checked = false; }); // Reset breed row + mixed row visibility var breedRow = document.getElementById('pet_' + petNum + '_breed_row'); if (breedRow) breedRow.style.display = 'none'; var mixedRow = document.getElementById('pet_' + petNum + '_mixed_row'); if (mixedRow) mixedRow.style.display = 'none'; // v1 // Reset breed row visibility //var breedRow = document.getElementById('pet_' + petNum + '_breed_row'); //if (breedRow) breedRow.style.display = 'none'; } // Add onsubmit="return validateForm()" to the
tag function validateForm() { var errors = []; // Breed required when species is Cat or Dog (visible pet sections only) for (var p = 1; p <= 5; p++) { var section = document.getElementById('pet_section_' + p); if (!section || section.style.display === 'none') continue; var sp = document.getElementById('pet_' + p + '_species_select'); if (!sp) continue; if (sp.value === 'Cat' || sp.value === 'Dog') { var bs = document.getElementById('pet_' + p + '_breed_select'); if (bs && !bs.value) { errors.push('Pet ' + p + ' Breed is required.'); } } } // Validate location hidden fields are populated var locationChecks = [ { id: '00Ni0000000Z3b5', label: 'Pickup Country' }, { id: '00Ni0000000Z3fN', label: 'Delivery Country' } ]; locationChecks.forEach(function(check) { if (!document.getElementById(check.id).value.trim()) { errors.push(check.label + ': please select a location from the suggestions.'); } }); // Validate at least Pet 1 name and species are filled if (!document.getElementById('00Ni0000002oqsm').value.trim()) { errors.push('Pet 1 Name is required.'); } if (!document.getElementById('00Ni0000002orLM').value.trim()) { errors.push('Pet 1 Species is required.'); } if (errors.length > 0) { alert(errors.join('\n')); return false; } return true; }