function ChatSettings(domain, width, height) {
    this.domain = domain;
    this.windowDims = { width: width, height: height };
    this.chatTypeMap = {
        sel:   { id: 5, isDefault: false },
        insp:  { id: 3, isDefault: false },
        purch: { id: 5, isDefault: false },
        prot:  { id: 4, isDefault: true  }
    };
    this.mapQueue = function(type) {
        var queue = this.chatTypeMap[type];
        
        if (queue == null)
            queue = this.defaultQueue;

        return queue.id;
    }
    this.createUrl = function(type) {
	    var url = "https://" 
	        + this.domain
	        + ":444"
	        + "/SightMaxAgentInterface"
	        + "/PreChatSurvey.aspx?"
	        + "siteID=3"
	        + "&queueID=" 
	        + this.mapQueue(type);
        if (type=="prot")
        {
	        url += '&fullname=' + escape(fullname);
	        url += '&email=' + escape(email);
	        url += '&state=' + escape(state);
	        url += '&vehicle=' + escape(vehicle);
	        url += '&mileage=' + escape(mileage);
	        url += '&leadid=' + escape(leadid);
	        url += '&autosubmit=true';
        }
        return url;
    }
    this.createWindowOptions = function() {
	    var str = "left=" + ((screen.availWidth - this.windowDims.width) / 2) + ",top=" + ((screen.availHeight - this.windowDims.height) / 3)
		    + ",width=" + this.windowDims.width  + ",height=" + this.windowDims.height
		    + ",toolbar=0,location=0,directories=0,menubar=0,status=0,scrollbars=0,resizable=0,replace=0";
        return str;
    }
    this.start = function(type) {
	    var win = window.open(this.createUrl(type), 'chatWindow', this.createWindowOptions());

	    if (win == null)
		    alert('Your browser is blocking pop-up windows.  You must enable popups in order to chat.');
	    else
		    win.focus();
    }
    // Initialize
    for (var key in this.chatTypeMap) {
        if (this.chatTypeMap[key].isDefault) {
            this.defaultQueue = this.chatTypeMap[key];
            break;
        }
    }
}

var _chat = new ChatSettings("chat.carchex.com", 490, 404);

function startChat(type) {
    _chat.start(type);
    return false;
}

var fullname = '';
var email = '';
var state = '';
var vehicle = '';
var mileage = '';
var leadid = '';


