// Part of "Lookup" by Independence Ave <http://IndependenceAve.org>
// To use Lookup on your own site please visit our website.
// Copyright 2005 Shawn Brown <http://shawnbrown.com/contact>

//var LOOKUP_ROOT = "http://independenceave.org/lookup/";
//var LOOKUP_MEMBER_FOLDER = 'http://independenceave.org/congress/member/';
var LOOKUP_ROOT = "http://independenceave.org/lookup/";
var LOOKUP_MEMBER_FOLDER = 'http://independenceave.org/congress/member/';

var EXPIRES = 1440; // this in minutes? 1440 min == 24 hours
var Lookup = {
a:{
pop:function(h,t,a){
return[
'<a href="',h,'"',
'onclick="javascript:window.open(this.href);return false"',
(a?a:''),'>',(t?t:h),'</a>'
].join("")
},
email:function(h,t){
var lc=h.toLowerCase();
if(lc.indexOf("http://")==0)return Lookup.a.pop(h,(t?t:"via&nbsp;web&nbsp;form"),(t?'title="via web form"':""));
if(lc.indexOf("mailto:")==0)return Lookup.a.pop(h,(t?t:h.substring(7,h.length)),"");
if(h)return Lookup.a.pop("mailto:"+h,(t?t:h),"");
return Lookup.a.pop("http://www.house.gov/writerep/",(t?t:"via&nbsp;&#8220;Write&nbsp;Your&nbsp;Representative&#8221;"),(t?"title='via \"Write Your Representative\"'":""))
},
map:function(i,t){
var h="&#104;&#116;&#116;&#112;&#58;&#47;&#47;&#119;&#119;&#119;&#46;&#110;&#97;&#116;&#105;&#111;&#110;&#97;&#108;&#97;&#116;&#108;&#97;&#115;&#46;&#103;&#111;&#118;&#47;&#112;&#114;&#105;&#110;&#116;&#97;&#98;&#108;&#101;&#47;&#105;&#109;&#97;&#103;&#101;&#115;&#47;&#112;&#114;&#101;&#118;&#105;&#101;&#119;&#47;&#99;&#111;&#110;&#103;&#100;&#105;&#115;&#116;&#47;";
var s=i.substring(0,2).toUpperCase();
i=i.substring(2,4);
if(i=="00")i="01";
h+=s+i+"&#95;&#49;&#48;&#57;&#46;&#103;&#105;&#102;";
return['<a href="',h,'" onclick="javascript:',
'window.open(this.href, \'\', \'height=450,scrollbars=yes,resizable=yes\');',
'return false">',t?t:'see&nbsp;map','</a>'].join("")
},
mem:function(n,i){
i=i.toLowerCase();
return[
'<a href="',
LOOKUP_MEMBER_FOLDER,
i.substring(0,2),'/',i.substring(2,4),
'" onclick="javascript:this.blur();Lookup.obj.req(\'',i,'\');return false"',
'title="Phone, FAX, address, etc.">',n,'</a>'
].join("")
}
},
cdata:{
ord:function(n){
n=n.replace(/^[0]+/,"");
if(!n)return "";
var len=n.length;
var dgt=parseInt(n.substring(len-2,len));
switch(dgt){
case 13:
case 12:
case 11:return n+"th"
}
dgt=parseInt(n.substring(len-1,len));
switch(dgt){
case 0:
case 9:
case 8:
case 7:
case 6:
case 5:
case 4:return n+"th";
case 3:return n+"rd";
case 2:return n+"nd";
case 1:return n+"st"
}
return n
},
rank:function(x){
x=x.substring(2,4).toUpperCase();
return x=="S1"?"Senior":x=="S2"?"Junior":""
}
},
table:{
center:function(x){
return['<div style="text-align:center"><table style="text-align:left;margin-left:auto;margin-right:auto;border-collapse:collapse">',x,'</table></div>'].join("")
}
},
fn:{
main:function(m){
m=document.getElementById(m);
this.write=function(x){
m.innerHTML=x
};
this.show=function(){m.style.visibility="visible"};
m.style.visibility="hidden"
},
supp:function(){
if(document.URL.indexOf("http")!=0)return false;
if(Lookup.fn.getCookie("s")){
Lookup.fn.setCookie("s","1",EXPIRES);
return true
}
Lookup.fn.delCookie("r");
Lookup.fn.setCookie("x","1");
if(!Lookup.fn.getCookie("x"))return false;
Lookup.fn.delCookie("x");
if(!document.createElement||!document.getElementById)return false;
if(typeof document.body.innerHTML!="string")return false;
Lookup.fn.setCookie("s","1",EXPIRES);
return true
},
setCookie:function(n,v,t){
if(t){
var d=new Date();
d.setTime(d.getTime()+(t*60000));
t=";expires="+d.toGMTString()
}else{
t=""
}
v=v.toString().replace(/\n/gm,"%0A").replace(/\f/gm,"%0C").replace(/\r/gm,"%0D").replace(/;/g,"%3B").replace(/=/g,"%3D");
if((v=n+'='+v+t+';path=/').length<=3072){
document.cookie=v;
return true
}
Lookup.fn.delCookie(n);
return false
},
getCookie:function(n){
var v=new RegExp("\\b"+n+"=([^;]*)");
v=document.cookie.match(v);
return v?unescape(v[1]):null
},
delCookie:function(n){
Lookup.fn.setCookie(n,"",-1)
}
},
JSReq:'JSReq:{var JSR=document.getElementById("JSRNode");if(JSR&&typeof JSR.readyState=="undefined"){JSR.readyState="loaded";JSR.onreadystatechange()}}',
obj:{}
}
if (Lookup.fn.supp()) {
document.write('<div id="lookup">&nbsp;</div>');
Lookup.obj.main = new Lookup.fn.main("lookup");
//document.write('<script src="http://lookup.independenceave.org/lgd.p?v=008" type="text/javascript"></script>')
document.write('<script src="'+LOOKUP_ROOT+'lookup_client.js?v=008" type="text/javascript"></script>')
} else {
document.write(
[
'<div id="lookup">',
'<p style="text-align:center">',
'Please visit ',
'<a href="http://independenceave.org/"',
'onclick="javascript:',
'window.open(this.href+\'?ref='+ window.location.hostname +'\');',
'return false">',
'Independence&nbsp;Ave</a> ',
'to find your elected representatives.',
'</p>',
'</div>'
].join("")
)
}

