var insurance = {
	com: {
		setup : function(o){
			o = o || {};
			var me = this;
			this.notifyUrl = o.notifyUrl || null;
			this.id = o.id;
			this.tId = o.insured || "qt_insured";
			this.zId = o.zip || "qt_zip";
			this.zeId = o.zip_error || "qt_zip_error";
			this.teId = o.insured_error || "qt_insured_error";
			this.debug = o.debug || false;
			this.hostPath = o.url || "www.insurance.com/partner-landing.aspx";
			var click = function(e){ if  (e &&e.preventDefault) e.preventDefault(); else if (window.event && window.event.returnValue) window.eventReturnValue = false; me.check(); return false; };
			var b = this.g(o.button || "qt_go");
			if (b.addEventListener){ b.addEventListener("click", click, false); }
			else { b.attachEvent("onclick", click); }
		},
		g : function(id){ return document.getElementById(id); },
		getZip : function(){ return this.g(this.zId).value; },
		getTriage : function() { return this.g(this.tId + "_y").checked ? "Y" : (this.g(this.tId + "_n").checked ? "N" : ""); },
		check : function(){
			var zip = this.getZip();
			var triage = this.getTriage();
			this.reset();
			if (!zip.match(/^\d{5}$/)){ this.error(this.zeId, "Invalid zip code"); return; }
			if (triage.length == 0){ this.error(this.teId, "Answer required"); return; }
			if (this.notifyUrl!=null){ this.notify(zip, triage); }
			else { this.go(zip, triage); }
		},
		notify : function(zip, triage){
			var r = this.newRequest(); if (r == null){ return this.go(zip, triage); } var me = this;
			r.onreadystatechange = function(){ if (r.readyState==4){ if (me.debug){alert(r.responseText);} me.go(zip, triage); me = null; r = null; } };
			r.open("POST", this.notifyUrl, true); r.setRequestHeader("content-type", "application/x-www-form-urlencoded"); r.send("zip="+zip+"&triage="+triage);
		},
		go : function(zip, triage){ document.location.href = "http://" + this.hostPath +"?cp=" + this.id + "&zip=" + zip + "&insured=" + triage; },
		reset : function(){ this.g(this.zeId).style.display = "none"; this.g(this.teId).style.display = "none"; },
		error : function(type, message){ with (this.g(type)){ innerHTML = message; style.display = "block"; } },
		newRequest : function() {
			if (window.ActiveXObject){ 
				var ids = ['MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
				for (var i=0;i < ids.length; i++) { try { return new ActiveXObject(ids[i]); } catch (e) {} }
			}
			try { return new XMLHttpRequest(); } catch (e) { }
			return null;
		}
	}
};