﻿/// <reference path="googlemaps-intellisense.js"/>
function Dealer( dealerID, companyName, street, city, state, postal, latitude, longitude, website, numLocal, groupUsed, locationCount, groupID, phone, fax, distance,  smallLogoUrl, largeLogoUrl, tagline, units, isDeluxe) {
      /// <summary>A dealer structure</summary>  
    this.DealerID = dealerID;
    this.CompanyName = companyName;    
    this.City = city;
    this.State = state;
    this.Street = street;    
    this.Postal = postal;
    this.Latitude = latitude;
    this.Longitude = longitude;
    this.Website = website;
    this.NumLocal = numLocal;
    this.GroupUsed = groupUsed;
    this.LocationCount = locationCount;
    this.GroupID = groupID;
    this.Phone = phone;
    this.Fax = fax;
    this.Distance = distance;
    this.SmallLogoUrl = smallLogoUrl;
    this.LargeLogoUrl = largeLogoUrl;
    this.TagLine = tagline;
    this.Units = units;
    this.IsDeluxe = isDeluxe;
};

Dealer.prototype.GetInfoWindowTabs = function () {

    var contactTab = new GInfoWindowTab( "Contact",  this.GetContactInfo() );    
    var inventoryTab = new GInfoWindowTab( "Inventory", this.GetInventoryInfo());
    
    var tabs =  [contactTab, inventoryTab];
    
    if ( this.IsDeluxe ) {
        var locationTab = new GInfoWindowTab( "Zoom In", this.GetLocationInfo() );
        tabs[2] = locationTab;
    }
     
    return tabs;   
    
};

Dealer.prototype.GetContactInfo = function() {
    var output = "<span class='infoWindowHeader'>" + this.CompanyName + "</span>";
    output += "<div class='infoWindow'><table><tr><td><img style='padding: 0 0 0 0' src='" + this.SmallLogoUrl + "'/>";
    output += "<td>" + this.Street + "<br/>" + this.City + ", " + this.State;
    output += "  " + this.Postal + "<br/>Phone:" + this.Phone;
    output += "<br/>Fax:" + this.Fax + "</td></tr></table>";
    
    if ( this.IsDeluxe ) {
        output += "<span class='dealerTagLine'><em>" +  this.TagLine + "</em></span><br/>";
    }
    
    if ( this.Distance > -1 ) 
        output += "<br/>You are approximately " + this.Distance + " " + this.Units + " from this dealer</div>";
        
    return output;
};

Dealer.prototype.GetLocationInfo = function() {
    var output = "<div id='minimap' class='blowupMap' ></div>";
    
    return output;
};

Dealer.prototype.GetInventoryInfo = function() {
    var output = "<div class='infoWindow'>";
    output += "<table><tr><td><img class='largeLogo' src='" + this.LargeLogoUrl + "' alt='Logo'/></td><td>";
     output += "<a href='http://www.ironsearch.com/IRONSearch/inventory.aspx?dealer_no=" + this.DealerID + "' target='_blank'>";
    output += this.NumLocal + " items in local store</a><br/>";
        
        if ( this.LocationCount > 0 ) {
            output += "<a href='http://www.ironsearch.com/IRONSearch/inventory.aspx?group_id=" + this.GroupID + "' target='_blank'>";
            output += this.GroupUsed + " listings in " + this.LocationCount + " locations</a><br/>";
        }
        //output += "<a href='http://" + this.Website + "' target='_blank'>Visit Website</a></td></tr></table></div>";
        output += "<a href='#' onClick=\"window.open('http://" + this.Website + "');\">Visit Website</a></td></tr></table></div>";
        return output;
};

Dealer.prototype.GetBlowupMapContent = function() {
    var output =  '<div id="minimap" class="blowupMap" ></div>';
    return output;
};

Dealer.prototype.GetGLocation = function() {
    return new GLatLng( this.Latitude, this.Longitude );
};


Dealer.prototype.GetIcon = function () {
    var icon;
    icon = new GIcon( G_DEFAULT_ICON, this.GetIconFile() );
    icon.iconSize = this.GetIconSize();
    
    icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    //icon.iconAnchor = new GPoint(9, 34 );
    //icon.infoWindowAnchor = new GPoint( 9, 2 );
    return icon;
};

Dealer.prototype.GetIconFile = function() {
      
    if ( this.IsDeluxe ) {
        var path = "Images/";
        switch ( this.SmallLogoUrl ) {
            case "http://images.irondealer.com/dealers/816/63/27277/custom/cnh_temp_small.gif":
                return path + "CaseIHNH.gif";
            case "http://www.ironweb.com/images/dealers/agco.gif":
                return "agco.gif";
            case "http://www.ironweb.com/images/dealers/belarus_sml.gif":
                return "http://www.ironweb.com/images/dealers/belarus_sml.gif";
            case "http://www.ironweb.com/images/dealers/bobcat_logo_small.gif":
                return path + "cat.gif";
            case "http://www.ironweb.com/images/dealers/caselogo.gif":
                return path + "case.gif";
            case "http://www.ironweb.com/images/dealers/cat_logo_small.gif":
                return path + "cat.gif";
            case "http://www.ironweb.com/images/dealers/claas_sm.gif":
                return "http://www.ironweb.com/images/dealers/claas_sm.gif";
            case "http://www.ironweb.com/images/dealers/fnh3.gif":
                return path + "nh.gif";
            case "http://www.ironweb.com/images/dealers/gear_small.gif":
                return path + "gear_small.gif";
            case "http://www.ironweb.com/images/dealers/jd.gif":
                return path + "jd.gif";
            case "http://www.ironweb.com/images/dealers/kubota_small.gif":
                return path + "kubota.gif";
            case "http://www.ironweb.com/images/dealers/mflogo-small.gif":
                return path + "mf.gif";
            case "http://www.ironweb.com/images/dealers/vermeer_small.gif":
                return path + "vermeer.gif";
         }
     } else {
        return "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/blank.png"
     }
};

Dealer.prototype.GetIconSize = function() {
      
    if ( this.IsDeluxe ) {
        switch ( this.SmallLogoUrl ) {
            case "http://images.irondealer.com/dealers/816/63/27277/custom/cnh_temp_small.gif":
                return new GSize( 40,24);
            case "http://www.ironweb.com/images/dealers/agco.gif":
                return new GSize(25,21);
            case "http://www.ironweb.com/images/dealers/belarus_sml.gif":
                return new GSize( 20,30);
            case "http://www.ironweb.com/images/dealers/bobcat_logo_small.gif":
                return new GSize(30,17);
            case "http://www.ironweb.com/images/dealers/caselogo.gif":
                return new GSize(40,13);
            case "http://www.ironweb.com/images/dealers/cat_logo_small.gif":
                return new GSize( 30,17);
            case "http://www.ironweb.com/images/dealers/claas_sm.gif":
                return new GSize( 20,30);
            case "http://www.ironweb.com/images/dealers/fnh3.gif":
                return new GSize( 40,12);
            case "http://www.ironweb.com/images/dealers/gear_small.gif":
                return new GSize(25,26);
            case "http://www.ironweb.com/images/dealers/jd.gif":
                return new GSize(25,23);
            case "http://www.ironweb.com/images/dealers/kubota_small.gif":
                return new GSize(20,22);
            case "http://www.ironweb.com/images/dealers/mflogo-small.gif":
                return new GSize(25,17);
            case "http://www.ironweb.com/images/dealers/vermeer_small.gif":
                return new GSize(20,18);
         }
     } else {
        return new GSize( 20,30);
     }
};