(function(){
var l=this,o=l.q=function(A,B){return o.fn.init(A,B);};
o.fn=o.prototype={
	init:function(A,B){
		var i;
		this.EB = null;
		if ((typeof A == 'string') && (i = document.getElementById(A))) { this.EB = i; }
		if (typeof A == 'object') { this.EB = A; }
		return this;
	},
	EB: null
};

o.extend=o.fn.extend=function(){
	var J=arguments[0],I=arguments.length,H=1;
	if (!J) return;
	if (typeof J === 'boolean' && J) J = o.fn;
	for (; H<I; H++) {
		var G = arguments[H];
		for (var F in G) {var L = G[F]; J[F] = L;}
	}
};

o.fn.extend(true,{
	ge:function(id){return document.getElementById(id);},
	posLeft:function(P) {
		var x = 0;
		while (P) {
			x += P.offsetLeft;
			P = P.offsetParent;
		}
		return x;
	},
	posTop:function(P) {
		var x = 0;
		while (P) {
			x += P.offsetTop;
			P = P.offsetParent;
		}
		return x;
	}
});

o.QS=o.prototype.QS={};
o.extend(o.QS,{
	E:null,
	set:function(){
		var L=o.fn.EB,D=document.createElement('div');
		D.className="hidden";
		D.id = 'sr_'+(new Date()).getTime()+Math.random();
		D.setAttribute('qT',null);
		D.setAttribute('qP',L.id);
		D.onmouseover = function(){o.QS.clearTimer(this);};
		D.onmouseout = function(){o.QS.setTimer(this);};
		o.fn.EB.value = "Search through over 300,000 promo codes and coupon codes, e.g. Kohls";
		o.fn.EB.style.color = "#888";
		o.fn.EB.onfocus = function() {
			with(this) {
				value = "";
				style.color = "#000";
				onfocus = null;
			}
		}
		
		L.setAttribute('qD',D.id);
		L.parentNode.appendChild(D);
		L.onkeyup=function(){o.QS.get(this);};
		L.onmouseover = function(){o.QS.clearTimer(o.fn.ge(this.getAttribute('qD')));};
		L.onmouseout = function(){o.QS.setTimer(o.fn.ge(this.getAttribute('qD')));};
	},
	get:function(pt){
		with (o.ajax) {
			if(xh == null)return;
			xh.abort();
			o.QS.E = pt;
			get('/search/qs/'+escape(pt.value)+'/',o.QS.show);
		}
	},
	show:function(data){
		var F=o.fn,Q=o.QS,L=Q.E;
		var D=F.ge(L.getAttribute('qD'));
		D.className = "hidden";
		Q.clearTimer(D);
		
		if (data === false || data.status != 'ok' || typeof data.list == 'undefined' || data.list == '') return;
		D.innerHTML = decodeURIComponent(data.list);
		with (D.style) {
			top = F.posTop(L)+parseInt(L.offsetHeight)+3+'px';
			left = F.posLeft(L)+'px';
		}
		D.className = "sr_list";
	},
	hide:function() {
		var F=o.fn,L=F.EB,D=F.ge(L.getAttribute('qD'));
		D.className = "hidden";
		D.setAttribute('qT',null);
	},
	clearTimer:function(D) {
		var T = D.getAttribute('qT');
		if (T != null) {
			window.clearTimeout(T);
			D.setAttribute('qT',null);
		}
	},
	setTimer:function(D) {
		D.setAttribute('qT',
			window.setTimeout(function(){q(D.getAttribute('qP')).QS.hide();},500));
	}
});

o.ajax = o.prototype.ajax = {};
o.extend(o.ajax, {
	xh:null,
	init:function() {
		var X = null;
		if (window.XMLHttpRequest) {
			X = new XMLHttpRequest();
			if (X.overrideMimeType) X.overrideMimeType('text/xml');
		} else if (window.ActiveXObject) {
			try {
				X = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					X = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		this.xh = X;
	},
	get:function(U,F,OS) {
		var X = this.xh;
		if (X == null) return;
		OS = OS || true;
			
			
		if (U.indexOf('?') < 0) U += '?'; else U += '&';
		U += 'mr='+(new Date()).getTime();
		
		X.onreadystatechange = function() { o.ajax.PR(F); };
		X.open( "GET", U, OS );
		X.send( null );	
	},
	PR:function(F) {
		var X = this.xh;
		if (X.readyState == 4 && X.status == 200) {
			try {  var v = eval("("+X.responseText+")"); }
			catch (e) { v = false; }
			return F(v);
		}
	}
});
o.ajax.init();

})();