﻿function cityCheck() {
    if (document.locations.menu.value = "--") {
        alert("Please select a city or state");
        return false
    } else {
        return true
    }
}

var viewRegion = function(setTo) {
    // Regional Info

    // Old style HTML for the Regional Pest Report Pre new HTML from HTML Slicers
    var canadaHtmlOld =
        '<li><a href="/ants">Ants</a>,&nbsp</li>' +
        '<li><a href="/other/spiders">Spiders</a>,&nbsp;</li>' +
        '<li><a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;</li>' +
        '<li><a href="/flies/images/black-fly-illustration">Black Flies</a>,&nbsp;</li>' +
        '<li><a href="/other/bed-bugs">Bed Bugs</a>,&nbsp;</li>' +
        '<li><a href="/cockroaches/german-cockroach">German Cockroaches</a></li>';

    var southeastHtmlOld =
        '<li><a href="/cockroaches/american-cockroach">American Cockroach</a>,&nbsp;</li>' +
        '<li><a href="/cockroaches/oriental-cockroach">Oriental Cockroach</a>,&nbsp;</li>' +
        '<li><a href="/ants">Ants</a>,&nbsp;</li>' +
        '<li><a href="/other/crickets">Crickets</a>,&nbsp;</li>' +
        '<li><a href="/rodents">Rodents</a>,&nbsp;</li>';

    var northeastHtmlOld =
        '<li><a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;</li>' +
        '<li><a href="/other/spiders">Spiders</a>,&nbsp;</li>' +
        '<li><a href="/ants">Ants</a>,&nbsp;</li>' +
        '<li><a href="/rodents/deer-mice">Mice</a>,&nbsp;</li>' +
        '<li>Wildlife,&nbsp;</li>' +
        '<li>indoor Fly Activity</li>';

    var midwestHtmlOld =
        '<li><a href="/rodents/deer-mice">Mice</a>,&nbsp;</li>' +
        '<li><a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;</li>' +
        '<li><a href="/other/fleas">Fleas</a>,&nbsp;</li>' +
        '<li><a href="/other/bed-bugs">Bed Bugs</a>,&nbsp;</li>' +
        '<li><a href="/flies">Flies</a>,&nbsp;</li>' +
        '<li><a href="/other/bees">Bees</a>,&nbsp;</li>' +
        '<li><a href="/other/wasps">Wasps</a></li>';

    var southwestHtmlOld = '<li><a href="/other/crickets">Crickets</a></li>';

    var westHtmlOld = '<li><a href="/rodents">Rodents</a></li>';

    var floridaHtmlOld =
        '<li><a href="/ants/fire-ant">Fire Ants</a>,&nbsp;</li>' +
        '<li><a href="/ants/pavement-ant">Pavement Ants</a>,&nbsp;</li>' +
        '<li><a href="/ants/argentine-ant">Argentine Ants</a>,&nbsp;</li>';

    // New HTML will use only this in the futures. For now we need both.
    var canadaHtmlNew =
        '<a href="/ants">Ants</a>,&nbsp;' +
        '<a href="/other/spiders">Spiders</a>,&nbsp;' +
        '<a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;' +
        '<a href="/flies/images/black-fly-illustration">Black Flies</a>,&nbsp;' +
        '<a href="/other/bed-bugs">Bed Bugs</a>,&nbsp;' +
        '<a href="/cockroaches/german-cockroach">German Cockroaches</a>';

    var southeastHtmlNew =
        '<a href="/cockroaches/american-cockroach">American Cockroach</a>,&nbsp;' +
        '<a href="/cockroaches/oriental-cockroach">Oriental Cockroach</a>,&nbsp;' +
        '<a href="/ants">Ants</a>,&nbsp;' +
        '<a href="/other/crickets">Crickets</a>,&nbsp;' +
        '<a href="/rodents">Rodents</a>';

    var northeastHtmlNew =
        '<a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;' +
        '<a href="/other/spiders">Spiders</a>,&nbsp;' +
        '<a href="/ants">Ants</a>,&nbsp;' +
        '<a href="/rodents/deer-mice">Mice</a>,&nbsp;<br/>' +
        'Wildlife,&nbsp;' +
        'Indoor Fly Activity';

    var midwestHtmlNew =
        '<a href="/rodents/deer-mice">Mice</a>,&nbsp;' +
        '<a href="/other/mosquitoes">Mosquitoes</a>,&nbsp;' +
        '<a href="/other/fleas">Fleas</a>,&nbsp;' +
        '<a href="/other/bed-bugs">Bed Bugs</a>,&nbsp;' +
        '<a href="/flies">Flies</a>,&nbsp;' +
        '<a href="/other/bees">Bees</a>,&nbsp;' +
        '<a href="/other/wasps">Wasps</a>';

    var southwestHtmlNew = '<a href="/other/crickets">Crickets</a>&nbsp;';

    var westHtmlNew = '<a href="/rodents">Rodents</a>';

    var floridaHtmlNew =
        '<a href="/ants/fire-ant">Fire Ants</a>,&nbsp;' +
        '<a href="/ants/pavement-ant">Pavement Ants</a>,&nbsp;' +
        '<a href="/ants/argentine-ant">Argentine Ants</a>';

    var isNewRegionSelect = (document.getElementById("region"));

    // Create the region information psuedo objects
    var canada = [
        'Canada&mdash;Fall season',
        'The current pest threat is ants, spiders, and flies particularly mosquitoes and black flies.  German cockroaches, bed bugs, stored product pests in commercial accounts are year around issues.',
        (isNewRegionSelect) ? canadaHtmlNew : canadaHtmlOld,
        'YT, BC, NT, AB, SK, MB, NU, ON, QC, NB, NS, PE, NL',
        'Orkin Pest Control in Canada'
        ];

    var southeast = [
        'Southeast&mdash;Fall season',
        'With the temperature still hovering around 80-90 degrees in some areas, most insects are still fairly active during this time.  Although the rain has stopped "drowning them out" of their natural environment and into yours, they still make it inside quite regularly during this time. Why? Most individuals begin to leave their windows and doors open during this time of year to enjoy the cooler weather. Unfortunately, American Roaches, Argentine Ants, Big Headed Ants and various other bugs just travel right in and get established. ',
        (isNewRegionSelect) ? southeastHtmlNew : southeastHtmlOld,
        'AL, AR, GA, KY, LA, MS, NC, SC, TN, VA, WV',
        'Orkin Pest Control in the Southeast'];

    var northeast = [
        'Northeast&mdash;Fall season',
        ' Mosquito activity will heighten.  Spiders constructing egg sacs as well as ants and mice are moving inside.  Potential wildlife harborage. Commercial accounts will want to be aware for possible small fly activity. House fly activity can be expected.',
        (isNewRegionSelect) ? northeastHtmlNew : northeastHtmlOld,
        'CT, DE, MA, MD, ME, NH, NJ, NY, PA, RI, VT',
        'Orkin Pest Control in the Northeast'];

    var midwest = [
        'Midwest&mdash;Fall season',
        'Be aware of rodents; mainly mice are moving inside.  Some mosquito populations survive into October.  Fleas and bedbugs will be moving inside.  Non threatening pest- boxelders and cluster flies are also abundant.  Bees and wasps are on the move.',
        (isNewRegionSelect) ? midwestHtmlNew : midwestHtmlOld,
        'IA, IL, IN, KS, MI, MN, MO, ND, NE, OH, SD, WI',
        'Orkin Pest Control in the Midwest'];

    var southwest = [
        'Southwest&mdash;Fall season',
        'The current pest threat is American & Oriental Cockroaches, ants, crickets, rodents.',
        (isNewRegionSelect) ? southwestHtmlNew : southwestHtmlOld,
        'AZ, NM, OK, TX',
        'Orkin Pest Control in the Southwest'];

    var west = [
        'West&mdash;Fall season',
        'Argentine ants (CA), Carpenter ants (Pac NW), spiders, rodents will be abundant.',
        (isNewRegionSelect) ? westHtmlNew : westHtmlOld,
        'AK, CA, CO, HI, ID, MT, NV, OR, UT, WA, WY',
        'Orkin Pest Control in the West'];

    var florida = [
        'Florida&mdash;Fall season',
        'As the heavy bug season winds down, be on the lookout for ants trying to make their way inside.  Fall almost mimics summer as far as temperature goes in most areas, so a lot of the things you fight during the summer are still present in the fall.',
        (isNewRegionSelect) ? floridaHtmlNew : floridaHtmlOld,
        'FL',
        'Orkin Pest Control in the Florida'];

    //Vars
    var regionSelect = (isNewRegionSelect) ?  document.getElementById('region') : document.getElementById('regionSelect');

    var regionTitle = document.getElementById('regionTitle');
    var regionMap = (isNewRegionSelect) ? document.getElementById('map') : document.getElementById('regionMap');
    var regionThreat = document.getElementById('regionThreat');
    var regionAlert = document.getElementById('regionAlert');

    selectedRegion = (setTo) ? setTo : regionSelect.options[regionSelect.selectedIndex].value;

    if (selectedRegion !== '--') {
        regionTitle.innerHTML = eval(selectedRegion)[0];
        regionMap.src = '/images/misc/regions/' + selectedRegion + '_154x102.gif';
        regionMap.alt = eval(selectedRegion)[4];
        regionThreat.innerHTML = eval(selectedRegion)[1];
        regionAlert.innerHTML = eval(selectedRegion)[2];

        Set_Cookie('orkinRegion', selectedRegion, 365);
    }
}

//Set Initial Region
if (Get_Cookie('orkinRegion') == null) {
    viewRegion('southeast');
}
else {
    viewRegion(Get_Cookie('orkinRegion'));
}

function Set_Cookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function Get_Cookie(check_name) {
    //console.log('Get_Cookie');
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}
