﻿var containerControl = 'ctl00_ContentPlaceHolder1_';

function processGeoAd() {
    var lat = document.getElementById(containerControl + 'txtClientLatitude').value;
    var lng = document.getElementById(containerControl + 'txtClientLongitude').value;
    var distance = document.getElementById(containerControl + 'txtRadius').value;
    if (lat != 0 && lng != 0) {
        searchLocationsNear(lat, lng, distance);
    }
}

function searchLocationsNear(lat, lng, distance) {
    var radius = distance;  //document.getElementById('radiusSelect').value;
    var searchUrl = '/StoreProximity.aspx?lat=' + lat + '&lng=' + lng + '&rad=' + radius;
    var objCtrl = document.getElementById('divStoreSpecificMessage');
    var isConnTypeValid = new Boolean(document.getElementById(containerControl + 'isConnTypeValid').value);
    var html = '';

    //default message for liCol03
    html = objCtrl.innerHTML;

    if (isConnTypeValid == true) {

        CDownloadUrl(searchUrl, function(data, responseCode) {
            if (responseCode == 200) {
                var xml = GXml.parse(data);
                var stores = xml.documentElement.getElementsByTagName('store');
                var totalStoreCount = 62;

                var isSGMValid = new Boolean(document.getElementById(containerControl + 'isSGMValid').value);
                var isSSMValid = new Boolean(document.getElementById(containerControl + 'isSSMValid').value);
                var isSMOMValid = new Boolean(document.getElementById(containerControl + 'isSMOMValid').value);

                var tmpHTML = '';

                if (stores.length == totalStoreCount) { //total number of stores will be totalStoreCount if there's no store found in a given radius
                }
                else {
                    html = '';

                    var companyId = stores[0].getAttribute('companyId');
                    var name = stores[0].getAttribute('name');
                    var introduction = stores[0].getAttribute('introduction');
                    var state = stores[0].getAttribute('state');




                    if (companyId == 222 && isSMOMValid == true) {
                        tmpHTML = "<img alt=\"\" class=\"center\" src=\"/promo/2009-04/no_tax_meridian.jpg\"/>"
                                 + "<p>4 Wheel Parts will pay your sales tax on any purchase. There are 2 ways to get this discount:</p><ul class=\"specs\"><li>Shop at your nearest 4 Wheel Parts store location, or</li><li>Shop online, and choose to pickup the products at the nearest 4 Wheel Parts store.</li></ul><p>If you choose to shop online, you will see an instant rebate in your shopping cart that is equal to the amount of the sales tax. Take advantage of this opportunity to get all the products you’ve been wanting without dealing with the recently increased sales tax.</p>";
                    }
                    else if (isSSMValid == true) {

                        var cids = [44, 50, 223, 205, 24, 40, 47, 209, 17, 22, 32, 202, 212, 221, 55, 213, 48, 207];
                        for (var j = 0; j < cids.length; j++) {
                            if (companyId == cids[j]) {
                                tmpHTML = "<img src=\"http://www.truckjeepsuvparts.com/4wp/2009-04/nosalestax.jpg\" class=\"center\" alt=\"\"/>"
                                                + "<table width=\"600\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\">"
                                                + "<tbody><tr>"
                                                + "<td>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=17\" target=\"_blank\">Chula Vista , CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=22\" target=\"_blank\">El Cajon, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=32\" target=\"_blank\">San Marcos, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=212\" target=\"_blank\">Modesto, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=209\" target=\"_blank\">Temecula, CA</a>"
                                                + "</td>"
                                                + "<td>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=221\" target=\"_blank\">Santa Rosa, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=55\" target=\"_blank\">Riverside, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=202\" target=\"_blank\">Thousand Oaks, CA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=48\" target=\"_blank\">Memphis , TN</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=207\" target=\"_blank\">Nashville , TN</a><br/>"
                                                + "</td>"
                                                + "<td>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=24\" target=\"_blank\">Coppell, TX</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=40\" target=\"_blank\">Fort Worth, TX</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=47\" target=\"_blank\">Plano, TX</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=205\" target=\"_blank\">Dallas , TX</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=213\" target=\"_blank\">West Palm Beach, FL</a>"
                                                + "</td>"
                                                + "<td valign=\"top\">"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=223\" target=\"_blank\">Forest Park, GA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=50\" target=\"_blank\">Marietta, GA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=44\" target=\"_blank\">Norcross, GA</a><br/>"
                                                + "- <a href=\"/stores/store-info.aspx?sNo=222\" target=\"_blank\">Meridian, ID</a>"
                                                + "</td>"
                                                + "</tr>"
                                                + "</tbody></table>"
                                                + "<p>4 Wheel Parts will pay your sales tax on any purchase. There are 2 ways to get this discount:</p><ul class=\"specs\"><li>Shop at your nearest 4 Wheel Parts store location, or</li><li>Shop online, and choose to pickup the products at the nearest 4 Wheel Parts store.</li></ul><p>If you choose to shop online, you will see an instant rebate in your shopping cart that is equal to the amount of the sales tax. Take advantage of this opportunity to get all the products you’ve been wanting without dealing with the recently increased sales tax.</p>";
                                break;
                            }
                        }
                    }

                    html += tmpHTML;



                    html += "</div>";   //ADDED 3.26.09 LC
                }
            }
            else if (responseCode == -1) {
                //alert('Data request timed out. Please try later.');
            } else {
                //alert('Request resulted in error.');
            }
            objCtrl.innerHTML = html;
            displayControl(objCtrl);
        });
    }
    else {
        displayControl(objCtrl);
    }

}

function displayControl(obj) {
    if (obj.innerHTML.length > 0) {
        obj.style.display = 'block';
    }
}



