if(typeof gTooltipTimeout=="undefined"){gTooltipTimeout=0}
if(typeof window.XMLHttpRequest=="undefined"){var ms_xhr_ver=false;window.XMLHttpRequest=function(){if(ms_xhr_ver)return new ActiveXObject(ms_xhr_ver);var xhr=false;var versions=["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];var n=versions.length;for(var i=0;i<n;i++){try{if(xhr=new ActiveXObject(versions[i])){ms_xhr_ver=versions[i];break}}catch(e){}}return xhr}}
function fnShowTooltipProxy(_aRef,_contentId,_lockMark){clearTimeout(gTooltipTimeout);if((_aRef.id!=""||typeof _contentId!="undefined")&&document.getElementById(_contentId)!=null){var _tContent=document.getElementById("tooltip-content");_tContent.className="";_tContent.innerHTML="<div id=\"tooltip-tail\"></div><a href=\"javascript:void(0);\" onclick=\"fnCloseTooltip();\" id=\"tooltip-close\"></a>"+document.getElementById(_contentId).innerHTML;var _position=fnGetAbsolutePosition(_aRef);_position.left+=(_aRef.offsetWidth/2)+14;_position.top+=_aRef.offsetHeight/2;fnCloseTooltip();var _tooltip=document.getElementById("tooltip");_tooltip.style.display="block";_tooltip.style.top=_position.top+"px";_tooltip.style.left=_position.left+"px";if(_lockMark){var _img=null;if(_aRef.tagName=="IMG"){img=_aRef}else{var _imgLookup=_aRef.getElementsByTagName("IMG");var _cond1=_imgLookup.length==1;var _cond2=_cond1?(_imgLookup[0].className=="qmark"):true;if(_cond1&&_cond2){img=_imgLookup[0]}}if(_img!=null){_img.src="/images/overlay-qmark-over.gif"}}if(_position.left+_tooltip.clientWidth>(window.innerWidth?window.innerWidth:document.body.clientWidth)){var _aPos=fnGetAbsolutePosition(_aRef);var _left=_aPos.left-_tooltip.offsetWidth;var _className="right";if(_left<0){_className="center";_left=(_aPos.left+(_aRef.offsetWidth/2))-_tooltip.offsetWidth/2;_tooltip.style.top=(_position.top+12)+"px"}document.getElementById("tooltip-content").className=_className;_tooltip.style.left=(_left)+"px"}_aRef.onmouseover=_tooltip.onmouseover=function(){clearTimeout(gTooltipTimeout)};_aRef.onmouseout=_tooltip.onmouseout=function(){gTooltipTimeout=window.setTimeout(fnCloseTooltip,2000)}}}
function JSONError(message){this.message=message||"";this.name="JSONError"}JSONError.prototype=new Error;
JSON=new function(){this.decode=function(){var filter,result,self,tmp;if($$("toString")){switch(arguments.length){case 2:self=arguments[0];filter=arguments[1];break;case 1:if($[typeof arguments[0]](arguments[0])===Function){self=this;filter=arguments[0]}else self=arguments[0];break;default:self=this;break}if(rc.test(self)){try{result=e("(".concat(self,")"));if(filter&&result!==null&&(tmp=$[typeof result](result))&&(tmp===Array||tmp===Object)){for(self in result)result[self]=v(self,result)?filter(self,result[self]):result[self]}}catch(z){}}else{throw new JSONError("bad data");}}return result};this.encode=function(){var self=arguments.length?arguments[0]:this,result,tmp;if(self===null)result="null";else if(self!==undefined&&(tmp=$[typeof self](self))){switch(tmp){case Array:result=[];for(var i=0,j=0,k=self.length;j<k;j++){if(self[j]!==undefined&&(tmp=JSON.encode(self[j])))result[i++]=tmp}result="[".concat(result.join(","),"]");break;case Boolean:result=String(self);break;case Date:result='"'.concat(self.getFullYear(),'-',d(self.getMonth()+1),'-',d(self.getDate()),'T',d(self.getHours()),':',d(self.getMinutes()),':',d(self.getSeconds()),'"');break;case Function:break;case Number:result=isFinite(self)?String(self):"null";break;case String:result='"'.concat(self.replace(rs,s).replace(ru,u),'"');break;default:var i=0,key;result=[];for(key in self){if(self[key]!==undefined&&(tmp=JSON.encode(self[key])))result[i++]='"'.concat(key.replace(rs,s).replace(ru,u),'":',tmp)}result="{".concat(result.join(","),"}");break}}return result};this.toDate=function(){var self=arguments.length?arguments[0]:this,result;if(rd.test(self)){result=new Date;result.setHours(i(self,11,2));result.setMinutes(i(self,14,2));result.setSeconds(i(self,17,2));result.setMonth(i(self,5,2)-1);result.setDate(i(self,8,2));result.setFullYear(i(self,0,4))}else if(rt.test(self))result=new Date(self*1000);return result};var c={"\b":"b","\t":"t","\n":"n","\f":"f","\r":"r",'"':'"',"\\":"\\","/":"/"},d=function(n){return n<10?"0".concat(n):n},e=function(c,f,e){e=eval;delete eval;if(typeof eval==="undefined")eval=e;f=eval(""+c);eval=e;return f},i=function(e,p,l){return 1*e.substr(p,l)},p=["","000","00","0",""],rc=null,rd=/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/,rs=/(\x5c|\x2F|\x22|[\x0c-\x0d]|[\x08-\x0a])/g,rt=/^([0-9]+|[0-9]+[,\.][0-9]{1,3})$/,ru=/([\x00-\x07]|\x0b|[\x0e-\x1f])/g,s=function(i,d){return"\\".concat(c[d])},u=function(i,d){var n=d.charCodeAt(0).toString(16);return"\\u".concat(p[n.length],n)},v=function(k,v){return $[typeof result](result)!==Function&&(v.hasOwnProperty?v.hasOwnProperty(k):v.constructor.prototype[k]!==v[k])},$={"boolean":function(){return Boolean},"function":function(){return Function},"number":function(){return Number},"object":function(o){return o instanceof o.constructor?o.constructor:null},"string":function(){return String},"undefined":function(){return null}},$$=function(m){function $(c,t){t=c[m];delete c[m];try{e(c)}catch(z){c[m]=t;return 1}};return $(Array)&&$(Object)};try{rc=new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$')}catch(z){rc=/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/}};

var gTooltips = {
	EditorsPick: "<strong>This card is selected by our editor as one of his favorites.</strong><br /><br /><strong>If a card is not selected by our Editor, it does NOT mean that it is not a <span style=\"text-decoration: underline;\">great card</span> for what YOU are looking for!</strong><br /><br /><a href=\"/best-credit-cards/\" target=\"_blank\">Learn more</a> about our Editor&#039;s Picks.",
	ShowPhotos: "<strong>This card has an <span style=\"text-decoration:underline;\">Optional Feature</span> of allowing you to place your own picture on the card.</strong><br />For example, some people will place a picture of their friends, child, significant other, etc.<br /><br />You will be able to upload the picture of your choice after you get the card.",
	SearchCritInc: "By checking this checkbox we will ONLY show you the cards that <strong>match the keywords in the search box <span style=\"color:#f00;\">+</span> all the other criteria</strong> that you have specified in the above filters.<br /><br />For example, if on the very first filter you select 'Excellent' Credit and on the search box you enter the word &#039;VISA&#039; then:<ul style=\"margin-left: 0; padding-left: 15px; margin-top:0px; margin-bottom:0px;\"><li><span style=\"text-decoration:underline;\">If the checkbox is checked</span>, we will only show you the VISA cards that are for people with Excellent Credit.</li><li><span style=\"text-decoration:underline;\">If the checkbox is NOT checked</span>, we will show you ALL the VISA cards regardless of your choices on any of the above filters.</li></ul>"
};

function fnCreateHiddenDiv ( _id ) {
	var _el = document.getElementById(_id);
	if (_el == null) {
		_el = document.createElement("div");
		_el.style.display = "none";
		_el.id = _id;
		document.body.appendChild(_el);
	}
	return _el;
}

function fnShowTooltipInQmark ( _ref ) {
	switch (_ref.tagName.toLowerCase()) {
		case "a":
			var _a = _ref;
			var _id = _ref.id.replace("tooltipa-", "");
			var _img = document.getElementById("tooltipi-" + _id);
			if (_img != null) {
				_ref = _img;
			}
		break;
		case "img":
			var _id = _ref.id.replace("tooltipi-", "");
			var _a = document.getElementById("tooltipa-" + _id);
			if (_a == null) {
				return false;
			}
		break;
	}
	var _tcont = fnCreateHiddenDiv("cur-tooltip-content");
	var _term = "";
	var _match = _a.href.match(/\/glossary\/([^\/]+)\/?/);
	if (_match != null) {
		_term = _match[1];
	}
	fnShowGlossaryTooltipAjax(_ref, _term);
	return false;
}

function fnShowAjaxTooltip ( _ref ) { // this function is used by the 3 question mark images in the control
	fnShowGlossaryTooltipAjax(_ref, _ref.href.match(/\/glossary\/([^\/]+)\/?/)[1]);
	return false;
}

function fnShowTooltipInElement ( _el, _content ) {
	var _tt = document.getElementById('tooltip');
	var _ajc = fnCreateHiddenDiv('tooltip-ajax-content');
	_tt.className = '';
	_ajc.innerHTML = _content;
	fnShowTooltip(_el, 'tooltip-ajax-content');
}

function fnShowGlossaryTooltipAjax ( _el, _term ) {
	var _tt  = document.getElementById("tooltip");
	var _ajc = fnCreateHiddenDiv("tooltip-ajax-content");
	_tt.className = "ajax";
	_ajc.innerHTML = "";
	fnShowTooltip(_el, "tooltip-ajax-content");
	var _ajx = new XMLHttpRequest();
	_ajx.onreadystatechange = function () {
		if (_ajx.readyState == 4) {
			if (_ajx.status == 200) {
				_tt.className = "";
				var _data = JSON.decode(_ajx.responseText);
				var _msg = "<div id=\"tooltip-tail\">&nbsp;</div><a href=\"javascript:void(0);\" onclick=\"fnCloseTooltip();\" id=\"tooltip-close\">&nbsp;</a>" + (_data.error ? _data.errormsg : _data.details.replace(/\n/g, "<br />"));
				document.getElementById("tooltip-content").innerHTML = _msg;
			}
		}
	};
	_ajx.open("GET", "/glossary/ajax.jsp?term=" + _term, true);
	_ajx.send(null);
	return false;
}

function fnDoTooltipLinkReplace () {
	var _links = document.getElementsByTagName("a");
	var _tcont = fnCreateHiddenDiv("cur-tooltip-content");
	for ( var _i = 0; _i < _links.length; _i++ ) {
		if (_links[_i].id == "tooltipl-SearchCritInc" ||
		    _links[_i].id == "tooltipl-BalanceTransferFee" ||
			_links[_i].id == "tooltipl-ForeignTransactionFee" ||
			_links[_i].id == "tooltipl-ShowPhotosControls"
		) {
			continue;
		}
		if (_links[_i].className == "tooltip-beacon" || (_links[_i].id != null && _links[_i].id.indexOf("tooltipl-") != -1)) {
			var _link  = _links[_i];
			var _lid   = _link.id.replace("tooltipl-", "");
			_link.onclick = function () {
				_tcont.innerHTML = gTooltips[this.id.replace("tooltipl-", "")];
				fnShowTooltip(this, "cur-tooltip-content");
				return false;
			};
		}
	}
	// ajax tooltips
	/*var _img = document.getElementsByTagName("img");
	for ( var _i = 0; _i < _img.length; _i++ ) {
		if (_img[_i].id.substr(0, 9) == "tooltipi-") {
			_img[_i].onclick = function () {
				fnShowTooltipInQmark(this);
			};
		}
	}*/
}

if (typeof window.fnGetAbsolutePosition == "undefined") {
	eval("function fnGetAbsolutePosition(elRef){var res=new Object();res.left=0;res.top=0;if(elRef!==null){res.left=elRef.offsetLeft;res.top=elRef.offsetTop;var offsetParent=elRef.offsetParent;var parentNode=elRef.parentNode;while(offsetParent!==null){res.left+=offsetParent.offsetLeft;res.top+=offsetParent.offsetTop;if(offsetParent!=document.body&&offsetParent!=document.documentElement){res.left-=offsetParent.scrollLeft;res.top-=offsetParent.scrollTop}if(navigator.userAgent.match(/gecko/i)){while(offsetParent!=parentNode&&parentNode!==null){res.left-=parentNode.scrollLeft;res.top-=parentNode.scrollTop;parentNode=parentNode.parentNode}}parentNode=offsetParent.parentNode;offsetParent=offsetParent.offsetParent}}return res}");
}
if (typeof window.fnCloseTooltip == "undefined") {
	eval("function fnCloseTooltip(){clearTimeout(gTooltipTimeout);var _tooltips=[\"tooltip\",\"tooltipsmall\"];for(var _i=0;_i<_tooltips.length;_i++){var _tooltip=document.getElementById(_tooltips[_i]);if(_tooltip!=null){_tooltip.style.display=\"none\"}}var _qmarks=document.getElementsByTagName(\"img\");for(_i=0;_i<_qmarks.length;_i++){if(_qmarks[_i].className==\"qmark\"){_qmarks[_i].src=\"/images/overlay-qmark.gif\"}}}");
}
if (typeof window.fnShowTooltip == "undefined") {
	window.fnShowTooltip = fnShowTooltipProxy;
}
