if(!window.console){var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];window.console={};for(var i=0;i<names.length;++i)window.console[names[i]]=function(){}}
Date.dayNames=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];Date.abbrDayNames=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];Date.monthNames=['January','February','March','April','May','June','July','August','September','October','November','December'];Date.abbrMonthNames=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];Date.firstDayOfWeek=1;Date.format='dd/mm/yyyy';Date.fullYearStart='20';
(function(){function add(name,method){if(!Date.prototype[name]){Date.prototype[name]=method}}add("isLeapYear",function(){var y=this.getFullYear();return(y%4==0&&y%100!=0)||y%400==0});add("amPM",function(){return(this.getHours()>11)?"pm":"am"});add("getregHours",function(){return(this.getHours()>12)?this.getHours()-12:this.getHours()});add("isWeekend",function(){return this.getDay()==0||this.getDay()==6});add("isWeekDay",function(){return!this.isWeekend()});add("getDaysInMonth",function(){return[31,(this.isLeapYear()?29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()]});add("getDayName",function(abbreviated){return abbreviated?Date.abbrDayNames[this.getDay()]:Date.dayNames[this.getDay()]});add("getMonthName",function(abbreviated){return abbreviated?Date.abbrMonthNames[this.getMonth()]:Date.monthNames[this.getMonth()]});add("getDayOfYear",function(){var tmpdtm=new Date("1/1/"+this.getFullYear());return Math.floor((this.getTime()-tmpdtm.getTime())/86400000)});add("getWeekOfYear",function(){return Math.ceil(this.getDayOfYear()/7)});add("setDayOfYear",function(day){this.setMonth(0);this.setDate(day);return this});add("addYears",function(num){this.setFullYear(this.getFullYear()+num);return this});add("addMonths",function(num){var tmpdtm=this.getDate();this.setMonth(this.getMonth()+num);if(tmpdtm>this.getDate()){this.addDays(-this.getDate())}return this});add("addDays",function(num){this.setTime(this.getTime()+(num*86400000));return this});add("addHours",function(num){this.setHours(this.getHours()+num);return this});add("addMinutes",function(num){this.setMinutes(this.getMinutes()+num);return this});add("addSeconds",function(num){this.setSeconds(this.getSeconds()+num);return this});add("zeroTime",function(){this.setMilliseconds(0);this.setSeconds(0);this.setMinutes(0);this.setHours(0);return this});add("asString",function(format){var r=format||Date.format;return r.split('yyyy').join(this.getFullYear()).split('yy').join((this.getFullYear()+'').substring(2)).split('mmmm').join(this.getMonthName(false)).split('mmm').join(this.getMonthName(true)).split('mm').join(_zeroPad(this.getMonth()+1)).split('dd').join(_zeroPad(this.getDate())).split('hh').join(_zeroPad(this.getHours())).split('min').join(_zeroPad(this.getMinutes())).split('ss').join(_zeroPad(this.getSeconds()))});Date.fromString=function(s,format){var f=format||Date.format,d=new Date('01/01/1977'),mLength=0,iM=f.indexOf('mmmm'),i=0;if(iM>-1){for(i=0;i<Date.monthNames.length;i++){var mStr=s.substr(iM,Date.monthNames[i].length);if(Date.monthNames[i]==mStr){mLength=Date.monthNames[i].length-4;break}}d.setMonth(i)}else{iM=f.indexOf('mmm');if(iM>-1){var mStr=s.substr(iM,3);for(i=0;i<Date.abbrMonthNames.length;i++){if(Date.abbrMonthNames[i]==mStr){break}}d.setMonth(i)}else{d.setMonth(Number(s.substr(f.indexOf('mm'),2))-1)}}var iY=f.indexOf('yyyy');if(iY>-1){if(iM<iY){iY+=mLength}d.setFullYear(Number(s.substr(iY,4)))}else{if(iM<iY){iY+=mLength}d.setFullYear(Number(Date.fullYearStart+s.substr(f.indexOf('yy'),2)))}var iD=f.indexOf('dd');if(iM<iD){iD+=mLength}d.setDate(Number(s.substr(iD,2)));if(isNaN(d.getTime())){return false}return d};var _zeroPad=function(num){var s='0'+num;return s.substring(s.length-2)}})();
Date.format="mmm, dd";
function pad2(number){return((number<10)?'0':'')+number;}
function valZip(strValue){var objRegExp=/(^\d{5}$)/;return objRegExp.test(strValue)}

jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'',domain=options.domain?'; domain='+(options.domain):'',secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

var JSON;if(!JSON){JSON={}}(function(){"use strict";function f(n){return n<10?'0'+n:n}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z':null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key)}if(typeof rep==='function'){value=rep.call(holder,key,value)}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null'}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null'}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' '}}else if(typeof space==='string'){indent=space}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}return str('',{'':value})}}if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j}throw new SyntaxError('JSON.parse');}}}());

var Location={_zip:null,_cd:null,_state_cd:null,_PPID:null,_callback:null,encodeCookie:function(data){var str=JSON.stringify(data);var enc='ddd'+sjcl.encrypt('democrats',str);return enc},decodeCookie:function(cookie){var str=(cookie&&cookie.indexOf('ddd')==0)?sjcl.decrypt('democrats',cookie.substring(3)):cookie;var data={};try{data=eval('('+str+')')}catch(e){}return data},getSpudLoc:function(callback){jQuery.getJSON('http://my.barackobama.com/page/spud?type=getm&field=state_cd,zip&jsonp=?',callback)},getLoggedData:function(){var data=this.decodeCookie(jQuery.cookie('demLocation'));if(data){return data}else{return{}}},setLoggedData:function(data){jQuery.cookie('demLocation',this.encodeCookie(data),{path:'/',domain:'.democrats.org',expire:7})},clearLoggedData:function(){this.setLoggedData({'zip':null,'state_cd':null,'cd':null,'PPID':null});this._zip=null;this._state_cd=null;this._cd=null;this._PPID=null},getLocationFromZip:function(zip,callback){this._callback=callback;var jsonp=jQuery('<script><'+'/script>');jsonp.attr('type','text/javascript');jsonp.attr('src','http://gerald.dnc.org/zips/lookup.jsonp?query='+zip+'&key=8b5890523882cadbcd40d05a550b14e281aa5d7a&callback=Location.getLocationFromZipCallback');jQuery('body').append(jsonp)},getLocationFromZipCallback:function(data){if(data.postal_code){var state=(data.region)?data.region:this.getState();var cd=data.congressional_district;if(cd==null){cd=''}if(cd&&cd<10){cd='0'+cd}if(cd){cd=state+cd}this._callback({'zip':data.postal_code,'state_cd':state,'cd':cd})}else{this._callback({'zip':null,'state_cd':null,'cd':null})}},getLocationFromAddr:function(addr,zip,callback){var self=this;var key='ABQIAAAA8mFtHl1c7dgkU6Mihvp0yRTczGIe8T4HNdmIza5zrtFSZ14sxRQPJ0qpsuywOZIOYpf2FF8_NEpwVQ';jQuery.ajax({dataType:'jsonp',url:'http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false&key='+key+'&q='+escape(addr+' '+zip),cache:false,success:function(data){if(data.Status.code==200&&data.Placemark[0].AddressDetails.Country.AdministrativeArea!==undefined){var queryString;var ad=data.Placemark[0].AddressDetails.Country.AdministrativeArea;var sub=(ad.SubAdministrativeArea)?ad.SubAdministrativeArea:ad;queryString='street='+escape(sub.Locality&&sub.Locality.Thoroughfare&&sub.Locality.Thoroughfare.ThoroughfareName?sub.Locality.Thoroughfare.ThoroughfareName:'');queryString+='&locality='+escape(sub.Locality&&sub.Locality.LocalityName?sub.Locality.LocalityName:'');queryString+='&region='+escape(ad&&ad.AdministrativeAreaName?ad.AdministrativeAreaName:'');queryString+='&postal_code='+escape(sub.Locality&&sub.Locality.PostalCode&&sub.Locality.PostalCode.PostalCodeNumber?sub.Locality.PostalCode.PostalCodeNumber:'');queryString+='&longitude='+escape(data.Placemark[0].Point.coordinates[0]);queryString+='&latitude='+escape(data.Placemark[0].Point.coordinates[1]);queryString+='&country='+escape(data.Placemark[0].AddressDetails.Country.CountryNameCode);queryString+='&precision='+escape(data.Placemark[0].AddressDetails.Accuracy);jQuery.getJSON('http://gerald.dnc.org/location/lookup.jsonp?'+queryString+'&key=8b5890523882cadbcd40d05a550b14e281aa5d7a&callback=?',function(data){if(data.seats){var state=(data.region)?data.region:self.getState();var cd=data.congressional_district;if(cd&&cd<10){cd='0'+cd}if(cd){cd=state+cd}callback({'zip':zip,'state_cd':state,'cd':cd})}else{callback({'zip':null,'state_cd':null,'cd':null})}})}else{callback({'zip':null,'state_cd':null,'cd':null})}}})},updateLoggedData:function(data,callback){var loggedData=this.getLoggedData();if(data.state_cd||data.state_cd==''){loggedData.state_cd=data.state_cd;this._state_cd=data.state_cd}if(data.zip||data.zip==''){loggedData.zip=data.zip;this._zip=data.zip}if(data.cd||data.cd==''){loggedData.cd=data.cd;this._cd=data.cd}if(data.PPID||data.PPID==''){loggedData.PPID=data.PPID;this._PPID=data.PPID}this.setLoggedData(loggedData);if(callback){callback(data)}},updateFromZip:function(zip,callback){var self=this;this.getLocationFromZip(zip,function(data){self.updateLoggedData(data,callback)})},updateFromAddr:function(addr,zip,callback){var self=this;this.getLocationFromAddr(addr,zip,function(data){self.updateLoggedData(data,callback)})},logFromSpud:function(){var self=this;var loggedData=this.getLoggedData();if(!loggedData.zip){this.getSpudLoc(function(data){self.logFromSpudData(data)})}},logFromSpudData:function(data){if(data.zip){this.updateFromZip(data.zip)}},getData:function(){var data=this.getLoggedData();if(this._zip){data.zip=this._zip}if(this._cd){data.cd=this._cd}if(this._state_cd){data.state_cd=this._state_cd}return data},getZip:function(){if(this._zip){return this._zip}else{return this.getLoggedData().zip}},getCD:function(){if(this._cd){return this._cd}else{return this.getLoggedData().cd}},getState:function(){if(this._state_cd){return this._state_cd}else{return this.getLoggedData().state_cd}},getPPID:function(){if(this._PPID){return this._PPID}else{return this.getLoggedData().PPID}},setZip:function(zip,callback){this.updateFromZip(zip,callback)},setCD:function(cd){this.updateLoggedData({'cd':cd})},setState:function(state){this.updateLoggedData({'state_cd':state})},setAddr:function(addr,zip,callback){this.updateFromAddr(addr,zip,callback)},setPPID:function(vanID){this.updateLoggedData({'PPID':vanID})},setDynamicZip:function(zip){if(zip){this._zip=zip}},setDynamicState:function(state){if(state){this._state_cd=state}},setDynamicCD:function(cd){if(cd){this._cd=cd}},updateFromDynamicZip:function(){var self=this;if(this._zip){this.getLocationFromZip(this._zip,function(data){if(data.state_cd){self._state_cd=data.state_cd}if(data.cd){self._cd=data.cd}})}},getGeoCodeState:function(){if(google.loader.ClientLocation&&google.loader.ClientLocation.address.country_code=="US"&&google.loader.ClientLocation.address.region){if(!this.getState()){this.setState(google.loader.ClientLocation.address.region.toUpperCase())}return google.loader.ClientLocation.address.region.toUpperCase()}}};
jQuery(document).ready(function(){Location.logFromSpud();Location.setDynamicZip(jQuery.url.param('loczip'));Location.setDynamicState(jQuery.url.param('locstate'));Location.setDynamicCD(jQuery.url.param('loccd'));Location.getGeoCodeState()});
