// CONFIG PART

// [POI]
// set when no retailer is found, displaying the country.
function genericCoordinates(ccode){
    var generic = new Array();
    
    switch (ccode) {
        case "en_GB":
            generic[0] = {
                "lat": 57.5,
                "lng": -14.0
            };
            generic[1] = {
                "lat": 50.7,
                "lng": 1.8
            };
            break;
        case "tr_TR":
            generic[0] = {
                "lat": 42.5,
                "lng": 27.5
            };
            generic[1] = {
                "lat": 35.0,
                "lng": 43.8
            };
            break;
        case "de_DE":
            generic[0] = {
                "lat": 54.5,
                "lng": 5.2
            };
            generic[1] = {
                "lat": 47.0,
                "lng": 14.4
            };
            break;
        case "nl_NL":
            generic[0] = {
                "lat": 53.3,
                "lng": 3.8
            };
            generic[1] = {
                "lat": 51.2,
                "lng": 6.5
            };
            break;
        case "fr_FR":
            generic[0] = {
                "lat": 50.0,
                "lng": 4.5
            };
            generic[1] = {
                "lat": 43.0,
                "lng": 6.8
            };
            break;
        case "es_ES":
            generic[0] = {
                "lat": 43.5,
                "lng": -8.7
            };
            generic[1] = {
                "lat": 37.0,
                "lng": 0.7
            };
            break;
        case "de_AT":
            generic[0] = {
                "lat": 50.0,
                "lng": 10.0
            };
            generic[1] = {
                "lat": 46.4,
                "lng": 16.2
            };
            break;
        case "ru_RU":
            generic[0] = {
                "lat": 63.0,
                "lng": 20.0
            };
            generic[1] = {
                "lat": 41.0,
                "lng": 144.0
            };
            break;
        case "fr_BE":
            generic[0] = {
                "lat": 51.2,
                "lng": 3.0
            };
            generic[1] = {
                "lat": 49.6,
                "lng": 6.1
            };
            break;
        case "nl_BE":
            generic[0] = {
                "lat": 51.2,
                "lng": 3.0
            };
            generic[1] = {
                "lat": 49.6,
                "lng": 6.1
            };
            break;
        case "it_IT":
            generic[0] = {
                "lat": 46.0,
                "lng": 6.8
            };
            generic[1] = {
                "lat": 37.6,
                "lng": 18.0
            };
            break;
        case "pl_PL":
            generic[0] = {
                "lat": 54.6,
                "lng": 15.1
            };
            generic[1] = {
                "lat": 49.0,
                "lng": 22.9
            };
            break;
        case "sk_SK":
            generic[0] = {
                "lat": 49.4,
                "lng": 17.7
            };
            generic[1] = {
                "lat": 47.9,
                "lng": 21.9
            };
            break;
        case "cs_CZ":
            generic[0] = {
                "lat": 50.9,
                "lng": 12.9
            };
            generic[1] = {
                "lat": 48.7,
                "lng": 17.8
            };
            break;
        case "de_CH":
            generic[0] = {
                "lat": 47.4,
                "lng": 6.4
            };
            generic[1] = {
                "lat": 46.0,
                "lng": 10.0
            };
            break;
        case "fr_CH":
            generic[0] = {
                "lat": 47.4,
                "lng": 6.4
            };
            generic[1] = {
                "lat": 46.0,
                "lng": 10.0
            };
            break;
        case "it_CH":
            generic[0] = {
                "lat": 47.4,
                "lng": 6.4
            };
            generic[1] = {
                "lat": 46.0,
                "lng": 10.0
            };
            break;
        case "fi_FI":
            generic[0] = {
                "lat": 69.0,
                "lng": 20.6
            };
            generic[1] = {
                "lat": 60.6,
                "lng": 30.8
            };
            break;
        case "pt_PT":
            generic[0] = {
                "lat": 41.5,
                "lng": -9.1
            };
            generic[1] = {
                "lat": 37.3,
                "lng": -7.2
            };
            break;
        case "hu_HU":
            generic[0] = {
                "lat": 48.0,
                "lng": 16.6
            };
            generic[1] = {
                "lat": 46.3,
                "lng": 21.7
            };
            break;
        case "sv_SE":
            generic[0] = {
                "lat": 68.1,
                "lng": 10.4
            };
            generic[1] = {
                "lat": 56.4,
                "lng": 19.7
            };
            break;
    }
    return generic;
}

// [POI]
// checks if a country has Google route planning based on the locale used in the application so several controls will not be available, e.g. the "Get directions" links
// Currently Turkey and Russia do not have route Google planning 
// returns true when route planning is available, false when not available
// blacklisting: adding a country locale will switch on the blocking of the route planning
// in the application its value will appear in the mysterious variable "R"
function chkRoutePlanning(loc){
    noroutes = new Array("tr_TR","ru_RU");
    if (noroutes.join().indexOf(loc) > -1) 
        return false;
    else 
        return true;
}

// Writes forced translations for the Google maps controls for Map / Satellite / Hybrid
function createLocalMapLegend(){

	G_DEFAULT_MAP_TYPES[0].Zx = MAP_BUTTON_MAP;
	G_DEFAULT_MAP_TYPES[0].Ow = MAP_BUTTON_ALT_MAP;
	G_DEFAULT_MAP_TYPES[1].Zx = MAP_BUTTON_SATELLITE;
	G_DEFAULT_MAP_TYPES[1].Ow = MAP_BUTTON_ALT_SATELLITE;
	G_DEFAULT_MAP_TYPES[2].Zx = MAP_BUTTON_HYBRID;
	G_DEFAULT_MAP_TYPES[2].Ow = MAP_BUTTON_ALT_HYBRID;
}

// END CONFIG PART

// opens the window for the print version of the route calculation
function printDirections(num){
    var loc = locale;
    if (locale == "en_UK") 
        loc = "en_GB";
    //tc_log("/dealer-locator-google/" + tagLocale + "/OpenPrintDirectionsWindow");

    var url = "printdirections_" + loc + ".jsp?";
    url += "ocoords=" + centerTarget;
    url += "&dcoords=" + retailers[num].lat + "," + retailers[num].lng;
    url += "&dn=" + retailers[num].name;
    url += "&ds=" + retailers[num].address;
    url += "&dz=" + retailers[num].postcode;
    url += "&dc=" + retailers[num].city;
    url += "&dp=" + retailers[num].phone;
    url += "&df=" + retailers[num].fax;
    url += "&de=" + retailers[num].email;
    url += "&du=" + retailers[num].url;
    url += "&rvt=" + revert;
    url += "&googleKey=" + googleKey;
    //alert(url);
    
    var printWin = window.open(url, "printwindow", "width=900,height=600,left=100,top=50,resizable=yes,scrollbars=yes,menubar=yes,status=yes");
}

// switches on/off elements of the print directions page	
function togglePrintViews(choice, ix){
    for (var g = 0; g < document.getElementsByName(choice).length; g++) 
        document.getElementsByName(choice)[g].checked = document.getElementById(ix).checked;
    
    
    if (document.getElementById(choice).checked == true) 
        document.getElementById(choice + "Div").style.display = "block";
    else 
        document.getElementById(choice + "Div").style.display = "none";
    
    
}

// loads initial defaults of the print directions page, currently all items are visible
function setInitialPrintView(){
    document.getElementById("oMapView").checked = true;
    document.getElementById("detailsMapView").checked = true;
    document.getElementById("detailInfo").checked = true;
    
    togglePrintViews("oMapView", "_oMapView");
    togglePrintViews("detailsMapView", "_detailsMapView");
    togglePrintViews("detailInfo", "_detailInfo");
}

// mouseovers for the start page and city selection page
function toggleMapProperties(hid, prop){
    var property;
    var propertyLnk;
    var LnkID = hid + "_lnk";
    switch (prop) {
        case 0:
            property = "hidden";
            propertyLnk = "none";
            break;
        case 1:
            property = "visible";
            propertyLnk = "underline";
            break;
    }
    if (document.getElementById(hid).className != "displayImg") 
        document.getElementById(hid).style.visibility = property;
    if (document.getElementById(LnkID)) 
        document.getElementById(LnkID).style.textDecoration = propertyLnk;
}

// closes details / error inline windows
function closeDetailsWindow(id,f){
    if (!id) 
        id = "inlineWindow_moreInfo";
	if(f && f == "f") deactivateInlineWindow(id);
    document.getElementById("mapViewLeftBoxTypeLabel").style.visibility = "visible";
    document.getElementById("mapViewLeftBoxRadiusLabel").style.visibility = "visible";
}


// toggles between map view and list view 
function toggleViews(elem){
    if (elem == 'listlnk') {
    
        document.getElementById('listlnk').className = "inactiveLnk";
        document.getElementById('maplnk').className = "MainContentLink02";
        document.getElementById("mainMap").style.display = "none";
        document.getElementById("listResults").style.display = "block";
        document.getElementById("mapResults").style.display = "none";
        if (!lvs) {
            $("#resultTableListView").tablesorter();
        }
        
        lvs = true;
        //tc_log("/dealer-locator-google/" + tagLocale + "/ShowListview");
    }
    
    else 
        if (elem == 'maplnk') {
            //clearMap(map);
            document.getElementById('listlnk').className = "MainContentLink02";
            document.getElementById('maplnk').className = "inactiveLnk";
            document.getElementById("mainMap").style.display = "block";
            initRetailers("iconsonly");
            document.getElementById("mapResults").style.display = "block";
            document.getElementById("listResults").style.display = "none";
        //tc_log("/dealer-locator-google/" + tagLocale + "/ShowMapview");
        }
    if (document.getElementById("BCCityLnk")) 
        switchBC("");
    document.getElementById("directions").innerHTML = "";
    document.getElementById("additionalInfo").innerHTML = "";
    document.getElementById("furtherStepsLinks").style.display = "none";
    document.getElementById("searchDirectionsResultHeadline").style.display = "none";
    document.getElementById("searchResultHeadline").style.display = "block";
    document.getElementById("searchResultPrintLnk").style.display = "inline";
    document.getElementById("searchDirectionsResultPrintLnk").style.display = "none";
    
}

// toggles retailer name on/off in "breadcrump navigation"
function switchBC(name){
    var separator = "";
    if (name && name.length > 0) {
        separator = " > ";
        
        document.getElementById("BCCityLnk").className = "MainContentLink01";
        document.getElementById("BCCityLnk").style.cursor = "pointer";
        
    }
    
    else {
        document.getElementById("BCCityLnk").className = "BCArrow";
        document.getElementById("BCCityLnk").removeAttribute("style");
    }
    var text = separator + name;
    document.getElementById("retailerBC").innerHTML = text;
}

// calculates initial coordinates and zoom level, to be initiated as a new object InitCoords
// 1st argument: an array of coordinates as is part of the retailer array, second one: the GMap2 object
function InitCoords(coords, map){
    this.sX = parseFloat(coords[0].lat);
    this.sY = parseFloat(coords[0].lng);
    this.bX = parseFloat(coords[0].lat);
    this.bY = parseFloat(coords[0].lng);
    
    this.setInits = function(){
        for (var a = 0; a < coords.length; a++) {
            coords[a].iconPnt = new GLatLng(coords[a].lat, coords[a].lng);
            lat = coords[a].lat;
            lng = coords[a].lng;
            if (lat < this.sX) 
                this.sX = lat;
            if (lng < this.sY) 
                this.sY = lng;
            if (lat >= this.bX) 
                this.bX = lat;
            if (lng >= this.bY) 
                this.bY = lng;
            
        }
        
    }
    
    this.setMapCenter = function(){
        var cX = (this.sX + this.bX) / 2;
        var cY = (this.sY + this.bY) / 2;
        //alert("X: " + cX + ", Y: " + cY);
        return new GLatLng(cX, cY);
    }
    
    this.setMapZoom = function(){
        var bounds = new GLatLngBounds();
        for (var t = 0; t < coords.length; t++) {
            var point = new GLatLng(coords[t].lat, coords[t].lng);
            bounds.extend(point);
        }
        return map.getBoundsZoomLevel(bounds) - 1;
        
    }
}

// page browser for details view (<< XX of YY retailers >>) 
function Pager(){

    this.len = retailers.length;
    this.pagerStep = 0;
    this.pT = 1;
    this.pagerTotal = document.getElementById("pagerTotal");
    this.pagerPrevious = document.getElementById("pagerTotal");
    this.pagerNext = document.getElementById("pagerTotal");
    this.dsF = UI_Pager_Dealerships;
    this.dsfSx = "[XX]";
    this.dsfSy = "[YY]";
    this.footerArr;
    this.x;
    this.y;
    
    
    this.setInits = function(){
        this.analyzeFooter();
        this.outOf();
        document.getElementById("pagerPrevious").innerHTML = "<< " + UI_Pager_PreviousStep;
        document.getElementById("pagerNext").innerHTML = UI_Pager_NextStep + " >>";
        this.getStyles();
    }
    
    this.analyzeFooter = function(){
        xx = this.dsF.indexOf(this.dsfSx);
        yy = this.dsF.indexOf(this.dsfSy);
        
        if (xx > yy) {
            this.x = yy;
            this.xP = 3;
            this.xString = this.dsfSy;
            this.y = xx;
            this.yP = 1;
            this.yString = this.dsfSx;
            
        }
        else {
            this.x = xx;
            this.xP = 1;
            this.xString = this.dsfSx;
            this.y = yy;
            this.yP = 3;
            this.yString = this.dsfSy;
            
        }
        xE = this.xString.length;
        yE = this.yString.length;
        
        this.footerArr = new Array(this.dsF.substring(0, this.x), this.xString, this.dsF.substring(this.x + xE, this.y), this.yString, this.dsF.substring(this.y + yE));
    }
    
    this.outOf = function(){
    
        UI_Pager_Dealerships = UI_Pager_Dealerships.replace(/\[XX\]/, this.pT);
        UI_Pager_Dealerships = UI_Pager_Dealerships.replace(/\[YY\]/, this.len);
        UI_Pager_Dealerships = UI_Pager_Dealerships.replace(/0-9/, this.pT);
        UI_Pager_Dealerships = UI_Pager_Dealerships.replace(/0-9/, this.len);
        this.footerArr[this.xP] = this.pT;
        this.footerArr[this.yP] = this.len;
        document.getElementById("pagerTotal").innerHTML = this.footerArr.join("");
    }
    
    
    this.setPagerNo = function(no){
        if (!no) 
            no = 0;
        
        this.pagerStep = currentRetID + no;
        this.pT = this.pagerStep + 1;
        this.outOf();
        this.getStyles();
        
        
    }
    
    this.getStyles = function(){
        if (this.len <= 1) {
            document.getElementById("pagerPrevious").className = "inactivePagerLink";
            document.getElementById("pagerPrevious").style.cursor = "text";
            document.getElementById("pagerNext").className = "inactivePagerLink";
            document.getElementById("pagerNext").style.cursor = "text";
        }
        else 
            if (this.pagerStep == 0) {
            
                document.getElementById("pagerPrevious").className = "inactivePagerLink";
                document.getElementById("pagerPrevious").style.cursor = "text";
                document.getElementById("pagerNext").className = "MainContentLink02";
                document.getElementById("pagerNext").style.cursor = "pointer";
            }
            else 
                if (this.pagerStep == this.len - 1) {
                    document.getElementById("pagerPrevious").className = "MainContentLink02";
                    document.getElementById("pagerPrevious").style.cursor = "pointer";
                    document.getElementById("pagerNext").className = "inactivePagerLink";
                    document.getElementById("pagerNext").style.cursor = "text";
                }
                
                else {
                    document.getElementById("pagerPrevious").className = "MainContentLink02";
                    document.getElementById("pagerNext").className = "MainContentLink02";
                    document.getElementById("pagerPrevious").style.cursor = "pointer";
                    document.getElementById("pagerNext").style.cursor = "pointer";
                }
        
        
    }
    
    this.browse = function(step){
        this.setPagerNo();
        
        if (step == "back" && this.pagerStep > 0) {
            //getRetailerDetails(this.pagerStep-1,true);
            currentRetID -= 1;
            getRetailerDetails(currentRetID, true);
            
        }
        
        else 
            if (step == "next" && this.pagerStep < this.len - 1) {
                //getRetailerDetails(this.pagerStep+1,true);
                currentRetID += 1;
                getRetailerDetails(currentRetID, true);
            }
        
        this.getStyles();
    }
    
}

// replots the data received from the GDirections object to adapt the directions display to the layout
function customPanel(map, mapname, dirn, div, opt){
    var html = "";
    
    // ===== local functions =====
    
    // === waypoint banner ===
    function waypoint(point, type, address){
        var target = '"' + mapname + ".showMapBlowup(new GLatLng(" + point.toUrlValue(6) + "))" + '"';
        html += '<table style="border:none; margin: 10px 0px; background-color: rgb(229, 240, 244); border-collapse: collapse; color: rgb(0, 0, 0);">';
        
        html += '  <tr>';
        html += '    <td style="padding:10px; vertical-align: middle; width: 20px;">';
        html += '      <img src="' + IMG_DirBase + type + '.gif">'
        html += '    </td>';
        html += '    <td style="vertical-align: middle; padding:10px;width: 100%;cursor: pointer;" onclick=' + target + '>';
        html += address;
        html += '    </td>';
        if (type == "play" && opt != "print") {
            html += '    <td style="vertical-align: middle; width: 100%; text-align:right;vertical-align:bottom; padding:10px;">';
            html += '		<a class="MainContentLink03" id="editDirections" style="cursor:pointer;" onclick="openInfoBubble(true);revert=false;">' + UI_GEdit + '</a>';
            html += '    </td>';
        }
        html += '  </tr>';
        html += '</table>';
    }
    
    function getAddressHeader(){
        var header = '	<strong>' + retailers[currentRetID].name + '</strong><br />';
        header += retailers[currentRetID].address + '<br />';
        header += retailers[currentRetID].postcode + ' ' + retailers[currentRetID].city + '<br />';
        header += retailers[currentRetID].phone;
        return header;
    }
    // === route distance ===
    function routeDistance(dist){
        html += '<div style="text-align:right; padding-bottom: 0.3em;">' + dist + '</div>';
    }
    
    // === step detail ===
    function detail(point, num, description, dist){
        var target = '"' + mapname + ".showMapBlowup(new GLatLng(" + point.toUrlValue(6) + "))" + '"';
        html += '<table style="margin: 0px; padding: 0px; border-collapse: collapse;">';
        html += '  <tr style="cursor: pointer;" onclick=' + target + '>';
        html += '    <td style="border-top: 1px solid rgb(229, 240, 244); margin: 0px; padding: 0.3em 3px; vertical-align: top; text-align:right;">';
        html += '      <a class="MainContentLink01" href="javascript:void(0)"> ' + num + '. </a>';
        html += '    </td>';
        html += '    <td style="border-top: 1px solid rgb(229, 240, 244); margin: 0px; padding: 0.4em 3px; vertical-align: top; width: 100%;">';
        html += description;
        html += '    </td>';
        html += '    <td style="border-top: 1px solid rgb(229, 240, 244); margin: 0px; padding: 0.3em 3px 0.3em 0.5em; vertical-align: top; text-align:right; color:#c4c4c4;">';
        html += dist;
        html += '    </td>';
        html += '  </tr>';
        html += '</table>';
    }
    
    // === Copyright tag ===
    function copyright(){
    
        html += '<div style="font-size: 0.86em; color:#c4c4c4;padding-left:4px;">' + UI_GDisclaimer + "<br /><br />" + dirn.getCopyrightsHtml() + "</div>";
    }
    
    
    // === read through the GRoutes and GSteps ===
    
    for (var i = 0; i < dirn.getNumRoutes(); i++) {
        if (i == 0) {
            var type = "play";
        }
        else {
            var type = "pause";
        }
        var route = dirn.getRoute(i);
        var geocode = route.getStartGeocode();
        var point = route.getStep(0).getLatLng();
        // === Waypoint at the start of each GRoute
        if (revert == true) 
            waypoint(point, "play", getAddressHeader());
        else 
            waypoint(point, "play", geocode.address);
        if (UI_EstimatedDuration) 
            estimated = UI_EstimatedDuration.replace(/X/, parseInt(route.getDuration().seconds / 60));
        else 
            estimated = "(" + route.getDuration().html + ")";
        //routeDistance(route.getDistance().html + " (about " + route.getDuration().html + ")");
        routeDistance(route.getDistance().html + " " + estimated);
        for (var j = 0; j < route.getNumSteps(); j++) {
            var step = route.getStep(j);
            // === detail lines for each step ===
            detail(step.getLatLng(), j + 1, step.getDescriptionHtml(), step.getDistance().html);
        }
    }
    
    // === the final destination waypoint ===   
    var geocode = route.getEndGeocode();
    var point = route.getEndLatLng();
    if (revert == false) 
        waypoint(point, "stop", getAddressHeader());
    else 
        waypoint(point, "stop", geocode.address);
    
    // === the copyright text ===
    copyright();
    
    // === drop the whole thing into the target div
    div.innerHTML = html;
    
} // ============ end of customPanel function ===========
// clears all overlays
function clearMap(map){
    map.clearOverlays();
}

// sets the id of the currently displayed retailer
function setID(n){
    currentRetID = n;
}


// should set the default value of the google bubble search text field depending on the search mode
// currently in use, but not working (does not throw an error, though)
function setNewTarget() {
	if(searchMode == "byAddress") document.getElementById("source").value = searchAddress;
			else document.getElementById("source").value = UI_StartAddress;

}

// wrapper function for more information links: depending of context it either opens the Google info bubble or the inline details window
function getMoreInfo(no, inline){
    setID(no);
    if (inline)  {
		getRetailerDetails();
		ext_log_tracker(alias_showfulldetails);
	}
		
	else {
		openInfoBubble();
		ext_log_tracker(alias_showinfo);
	}
}

// wrapper function for GetDirections-Link: depending from search mode it either gets the direction immediately or points to the Google info bubble to enter user address data
function wrapDirections(no){
    if (no) 
        setID(no);
    if (searchMode == "byAddress") {
        getDirections(no);
		ext_log_tracker(alias_getdirections);
    }
    else 
        openInfoBubble(no);
		ext_log_tracker(alias_requestdirections);
		
    
}

// displays the loading... animation
function loadingBar(elem){
    document.getElementById(elem).style.display = "block";
    document.getElementById(elem).innerHTML = "<img src=\"" + IMG_Load + "\" />";
}


// opens the Google info bubble with more information 
function openInfoBubble(ed){
    map.closeInfoWindow();
        if (!R) 
            document.getElementById("editBox").style.display = "none";
        else {
			document.getElementById("editBox").style.display = "block";		
			document.getElementById("BubbleInfoDistance").innerHTML = retailers[currentRetID].distanceRoadString;
		} 
        
   if (retailers[currentRetID].phone.length > 0) 
        document.getElementById("BubbleInfoPhone").style.display = "block";
    else 
        document.getElementById("BubbleInfoPhone").style.display = "none";
    document.getElementById("BubbleInfoName").innerHTML = retailers[currentRetID].name;
    document.getElementById("BubbleInfoAddress").innerHTML = retailers[currentRetID].address + "<br />" + retailers[currentRetID].postcode + " " + retailers[currentRetID].city;
    document.getElementById("BubbleInfoPhone").innerHTML = UI_GPhoneLegend + " " + retailers[currentRetID].phone;
    document.getElementById("BubbleInfoType").innerHTML = retailers[currentRetID].type.replace(/,\s/, "<br />");
    
    if (document.getElementById("BubbleInfoActions")) {
        if (retailers[currentRetID].dealership) {
            if (retailers[currentRetID].hhrCampaign) {
                document.getElementById("BubbleInfoActions").innerHTML = "<br /><a onclick=\"ext_log_tracker(alias_testdrive);\"  class=\"MainContentLink03\" href=\"http://contact.chevroleteurope.com/crm-forms/crm-forms.htm?_flowId=testdrive&locale=de_DE\">" + testdriveCopy + "</a>";
            }
            else {
                document.getElementById("BubbleInfoActions").innerHTML = "<br /><a onclick=\"ext_log_tracker(alias_testdrive);\"  class=\"MainContentLink03\" href=\"http://contact.chevroleteurope.com/crm-forms/crm-forms.htm?_flowId=testdrive&locale=de_DE\">" + testdriveCopy + "</a>";
            }
            
        }
        else {
            document.getElementById("BubbleInfoActions").innerHTML = "&nbsp;";
        }
        
    }
    setNewTarget();
    html = document.getElementById("InfoWindow").innerHTML;
    map.openInfoWindowHtml(retailers[currentRetID].iconPnt, html);
    map.panTo(retailers[currentRetID].iconPnt);
}

// replace or reset predefined text in text form elements (input, textarea)
function jwf2RepC(obj, szV, id, bMode){

    if (!obj) {
        return true;
    }
    if (0 == bMode && szV == obj.value) {
        obj.value = ""; /* return SS(id); */
    }
    else 
        if (1 == bMode && "" == obj.value) {
            if (szV.length) {
                obj.value = szV;
            } /* return SS(0); */
        }
    return true;
}


// this finally displays the retailer array after manipulation in map view and list view
function OutputRetailerList(){

    for (var b = 0; b < retailers.length; b++) {
        document.getElementById("resultTableMapView_" + b).style.display = "";
        document.getElementById("resultTableListView_" + b).style.display = "";
        document.getElementById("resultTableMapViewName_" + b).innerHTML = retailers[b].name;
        document.getElementById("resultTableMapViewType_" + b).innerHTML = retailers[b].type;
        document.getElementById("resultTableListViewName_" + b).innerHTML = retailers[b].name;
        document.getElementById("resultTableListViewType_" + b).innerHTML = retailers[b].type.replace(/,\s/, "<br />");
		map.addOverlay(createStartIcons(b));
        
        if (document.getElementById("resultTableListViewActions_" + b)) {
            if (retailers[b].dealership) {
                if (retailers[b].hhrCampaign) {
                    document.getElementById("resultTableListViewActions_" + b).innerHTML = "<a onclick=\"ext_log_tracker(alias_testdrive);\" href=\"http://contact.chevroleteurope.com/crm-forms/crm-forms.htm?_flowId=testdrive&locale=de_DE\">" + testdriveCopy + "</a>";
                }
                else {
                    document.getElementById("resultTableListViewActions_" + b).innerHTML = "<a onclick=\"ext_log_tracker(alias_testdrive);\"  href=\"http://contact.chevroleteurope.com/crm-forms/crm-forms.htm?_flowId=testdrive&locale=de_DE\">" + testdriveCopy + "</a>";
                }
                
            }
            else {
                document.getElementById("resultTableListViewActions_" + b).innerHTML = "&nbsp;";
            }
        }
        
        if (searchMode == "byName") {
            document.getElementById("resultTableListViewDist_" + b).innerHTML = "";
            document.getElementById("resultTableMapViewDist_" + b).innerHTML = "";
            
        }
        else {
            if (R) {
                document.getElementById("resultTableListViewDist_" + b).innerHTML = retailers[b].distanceRoadNum;
                document.getElementById("resultTableMapViewDist_" + b).innerHTML = retailers[b].distanceRoadString;
                //alert(retailers[b].distanceRoadString);
            }
            else {
                document.getElementById("resultTableListViewDist_" + b).innerHTML = retailers[b].distance;
                document.getElementById("resultTableMapViewDist_" + b).innerHTML = retailers[b].distance;
                //alert(retailers[b].distance);
            }
        }
        document.getElementById("resultTableListViewAddress_" + b).innerHTML = retailers[b].address + "<br />";
        document.getElementById("resultTableListViewAddress_" + b).innerHTML += retailers[b].postcode + " " + retailers[b].city + "<br />";
        
    }
    
}


// [POI]
// this class does manipulations of the retailer array after receiving it from the server and before making the browser output:
// a) sorts the retailer array again after the road distance calculation
// b) reduces the number of retailers found when exceeding the search radius (experimental! not in use yet!)
function ArrangeRetailers(){
    function numsort(a, b){
        return a["distanceRoadNum"] - b["distanceRoadNum"];
    }
    retailers.sort(numsort);
	
//begin block retailer reduction
/*if(document.getElementById("searchRadius") && document.getElementById("searchRadius").value > 0)  {
		var maxR = parseInt(document.getElementById("searchRadius").value);
		var anum = retailers.length;
		var diff = 0;
		for(var h=0;h<anum;h++) {
			if(parseInt(retailers[h].distanceRoadNum) > maxR) {
			var removed = retailers.splice(h,retailers.length - h);
			if(retailers.length == 0) retailers[0] = removed[0];
			break;
			}
		}
	}*/
// end block retailer reduction
}


// should set a randomized number, to be used for firing batch route calculation requests towards Google on an irregular basis
// NOT IN USE
function randomize(min, max){
	/*if (this.min > this.max) {
		return (-1);
	}
	if (min == max) {
		return (min);
	}*/
	
	var r = parseInt(Math.random() * (max + 1));
	return (r + min <= max ? r + min : r);
}

