// Make sure the LeadPopupVar instance is valid before
// trying to open the popup.
function ShowLeadPopup(vehId, dlrId)
{
    if(LeadPopupVar)
    {
        LeadPopupVar.Open(vehId, dlrId);
    }
    
    return false;
}

function LeadPopup()
{
	this.Init = function(id)
	{
	    this._clientId = id;
	    
	    // Add handlers so we can call functions associated with this object.
        $addHandlers($get("aLPClose"), {click:this.Close}, this);

	    // Create a delegates that will be used by the leadForm object.
        this._delClose = Function.createDelegate(this, this.Close);
        
        // Setup a method to cleanup
        var delDispose = Function.createDelegate(this, this.Dispose);
        Sys.Application.add_unload(delDispose);
	}
	
    // Clean up after ourself
	this.Dispose = function()
	{
        $clearHandlers($get("aLPClose"));
        
        this._delClose = null;
	}

    this.Open = function(vehId, dlrId)
    {
        // Set the vehicle & dealer Id's on the LeadForm.
	    leadFormVar._vehId = vehId;
	    leadFormVar._dlrId = dlrId;

        // Set what to call when the lead is successfully sent to the server.
        leadFormVar._onSuccess = this._delClose;

        // Show grey background and open lead div as a popup.
        showAlertBackground()
        showDIV('divLeadPopup');
        
        setPopupDivPosition('divLeadPopup');
        
        leadFormVar.Focus();

        return false;
    }
    
    this.Close = function()
    {
        hideAlertBackground();
        hideDIV('divLeadPopup');

        return false;
    }
}