/*
 * Begin JSON for jQuery (minified)
 * Copywrite (c) Mark Gibson, http://jollytoad.googlepages.com/json.js
 */
(function($){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'array':function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a[a.length]=v;b=true;}}}
a[a.length]=']';return a.join('');},'boolean':function(x){return String(x);},'null':function(x){return"null";},'number':function(x){return isFinite(x)?String(x):'null';},'object':function(x){if(x){if(x instanceof Array){return s.array(x);}
var a=['{'],b,f,i,v;for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a.push(s.string(i),':',v);b=true;}}}
a[a.length]='}';return a.join('');}
return'null';},'string':function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
return'"'+x+'"';}};$.toJSON=function(v){var f=isNaN(v)?s[typeof v]:s['number'];if(f)return f(v);};$.parseJSON=function(v,safe){if(safe===undefined)safe=$.parseJSON.safe;if(safe&&!/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
return undefined;return eval('('+v+')');};$.parseJSON.safe=false;})(jQuery);
/*
 * End JSON for jQuery
 */

/*
 * Begin Cookie plugin for jQuery (minified)
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de), http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
 */
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:'';var domain=options.domain?'; domain='+options.domain:'';var 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;}};
/*
 * End Cookie plugin for jQuery
 */
/*
 * Begin Cookie Jar plugin for jQuery (minified)
 * Copyright (c) 2007 James Dempster (letssurf@gmail.com), http://www.jdempster.com/category/jquery/cookieJar/
 */
(function($){$.cookieJar=function(name,options){if(!$.parseJSON)return false;if(!$.toJSON)return false;if(!$.cookie)return false;return new function(){function log(s){if(typeof console!='undefined'&&typeof console.log!='undefined'){console.log('cookiejar:'+self.cookieName+' '+s);}else{}};function save(){if(self.options.debug)log('save '+$.toJSON(self.cookieObject));return $.cookie(self.cookieName,$.toJSON(self.cookieObject),self.options.cookie);};function load(){var cookieJSON=$.cookie(self.cookieName);if(typeof cookieJSON=='string'){if(self.options.debug)log('load '+cookieJSON);self.cookieObject=$.parseJSON(cookieJSON,true);}else{if(self.options.debug)log('load new');self.cookieObject={};save();}}
this.set=function(name,value){if(self.options.debug)log('set '+name+' = '+value);self.cookieObject[name]=value;return save();};this.get=function(name){if(!self.options.cacheCookie){load();}
if(self.options.debug)log('get '+name+' = '+self.cookieObject[name]);return self.cookieObject[name];};this.remove=function(name){if(self.options.debug)log('remove '+name);if(typeof name!='undefined'){delete(self.cookieObject[name]);}else{self.setFromObject({});}
return save();};this.setFromObject=function(object){if(typeof object=='object'){if(self.options.debug)log('setFromObject');self.cookieObject=object;return save();}};this.toObject=function(){if(self.options.debug)log('toObject');return self.cookieObject;};this.toString=function(){if(self.options.debug)log('toString = '+$.toJSON(self.cookieObject));return $.toJSON(self.cookieObject);};this.destroy=function(){if(self.options.debug)log('destroy');self.cookieObject={};return $.cookie(self.cookieName,null,self.options.cookie);};this.construct=function(name,options){self.options=$.extend({cookie:{expires:365,path:'/'},cacheCookie:true,cookiePrefix:'rrCookie_',debug:false},options);self.cookieName=self.options.cookiePrefix+name;load();return self;};var self=this;self.construct(name,options);};};})(jQuery);
/*
 * End Cookie Jar plugin for jQuery
 */

/*
 * Begin jqModal for jQuery (minified)
 * Copyright (c) 2007,2008 Brice Burgess (bhb@iceburg.net), http://dev.iceburg.net/jquery/jqmodal/
 */
(function($){$.fn.jqm=function(o){var p={overlay:50,overlayClass:'jqmOverlay',closeClass:'jqmClose',trigger:'.jqModal',ajax:F,ajaxText:'',target:F,modal:F,toTop:F,onShow:F,onHide:F,onLoad:F};return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};if(p.trigger)$(this).jqmAddTrigger(p.trigger);});};$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};$.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};$.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};$.jqm={hash:{},open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);if(c.modal){if(!A[0])L('bind');A.push(s);}
else if(c.overlay>0)h.w.jqmAddClose(o);else o=F;h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in{Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}
if(c.ajax){var r=c.target||h.w,u=c.ajax,r=(typeof r=='string')?$(r,h.w):$(r),u=(u.substr(0,1)=='@')?$(t).attr(u.substring(1)):u;r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
else if(cc)h.w.jqmAddClose($(cc,h.w));if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);(c.onShow)?c.onShow(h):h.w.show();e(h);return F;},close:function(s){var h=H[s];if(!h.a)return F;h.a=F;if(A[0]){A.pop();if(!A[0])L('unbind');}
if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();}return F;},params:{}};var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version=="6.0"),F=false,i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i);f(h);},f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return!r;},hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function(){if(!this[c]){this[c]=[];$(this).click(function(){for(var i in{jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};})(jQuery);
/*
 * End jqModel for jQuery
 */


/* The above code is used under the terms of the MIT License and the copyright of its respective authors.
 * The terms of the MIT License are as follows:
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * The information and software code below,
 * located at http://www.ringrevenue.com/number_loader.js ,
 * are confidential and are the sole property of RingRevenue.
 * Your application or use of this information in any way is subject to
 * RingRevenue’s Terms of Service, which are located at
 * http://www.ringrevenue.com/terms_of_service. In accordance with those terms, your
 * use of this information and code may be terminated by RingRevenue at any time
 * for any reason.  The rights granted to you under those terms are expressly
 * non-exclusive. You may not sell, assign, sublicense, or otherwise transfer or
 * agree to transfer all or any portion of those rights without RingRevenue’s
 * prior written consent.  You agree not to copy, republish, frame, download,
 * transmit, modify, rent, lease, loan, sell, assign, distribute, license,
 * sublicense, reverse engineer, or create derivative works based on the
 * information and/or software code on this page except as expressly authorized
 * in RingRevenue’s Terms of Service.  Your use and continued use of this
 * information and/or code constitute your acceptance of RingRevenue’s Terms of Service.
 *
 * Copyright (c) 2009 RingRevenue (r)
 */



var rr_nlObject;function rr_getNumber()
{rr_nlObject.getNumber();}
function setPayPerCallTarget(selector,advertiser_id,promo_numberid_name,separator,leadingOne,buttonMode,debug)
{separator=separator==null?'-':separator;leadingOne=leadingOne==null?true:leadingOne;buttonMode=buttonMode==null?true:buttonMode;debug=debug==null?false:debug;rr_nlObject=new numberLoader(selector,advertiser_id,promo_numberid_name,separator,leadingOne,buttonMode,debug);jQuery(rr_getNumber);}
function numberLoader(selector,advertiser_id,promo_numberid_name,separator,leadingOne,buttonMode,debugMode)
{var selector=selector;var advertiser_id=advertiser_id;var promo_numberid_name=promo_numberid_name;var separator=separator;var leadingOne=leadingOne;var buttonMode=buttonMode;var debugMode=debugMode;var testMode=false;var originalContent=null;var self=this;this.getCookieJar=function(name)
{if(!jQuery.cookie('rrCookie_'+name))
{return null;}
return jQuery.cookieJar(name);}
this.initializeModal=function(cssUrl)
{var cssref=document.createElement("link");cssref.setAttribute("rel","stylesheet");cssref.setAttribute("type","text/css");cssref.setAttribute("href",cssUrl);document.getElementsByTagName("head")[0].appendChild(cssref);if(jQuery('.jqmWindow').length==0)
{jQuery('body').append('<div id="modalWindow" class="jqmWindow" style="display:none"><div id="jqmTitle"><button class="jqmClose" onfocus="this.blur();">x</button><span id="jqmTitleText">Default title</span></div><iframe id="jqmContent" src=""></iframe></div>');}}
this.loadInIframeModal=function(hash)
{var $trigger=jQuery(hash.t);var $modal=jQuery(hash.w);var myUrl=hash.c.ctcUrl;var myTitle='Call Now';var $modalContent=jQuery("iframe",$modal);$modalContent.html('').attr('src',myUrl);jQuery('#jqmTitleText').text(myTitle);var boxHeight=335;var boxWidth=430;var boxTop=Math.max(0,Math.floor(parseInt(jQuery(window).height()-boxHeight)/2));var boxLeft=Math.max(0,Math.floor(parseInt(jQuery(window).width()-boxWidth)/2));$modal.css({width:boxWidth,height:boxHeight,top:boxTop,left:boxLeft,marginLeft:0,opacity:1}).slideDown('slow',function(){return false;});}
this.insertCTC=function(ctcArgs)
{var ctc_selector=selector;if(buttonMode)
{jQuery(selector).html('<button type="button" class="click_to_call_button">Call Me!</button>');ctc_selector=".click_to_call_button";}
else
{self.insertNumber(number_settings.pn);}
self.initializeModal(window.location.protocol+ctcArgs.cssUrl);jQuery('.jqmWindow').jqm({ctcUrl:window.location.protocol+ctcArgs.ctcUrl,modal:true,trigger:ctc_selector,target:'#jqmContent',onShow:self.loadInIframeModal});}
this.insertNumber=function(number)
{var stripNonDigitsRegex=/[^\d]/g;var strippedNumber=number.replace(stripNonDigitsRegex,"");if(strippedNumber.length==11&&strippedNumber[0]==1)
{strippedNumber=strippedNumber.slice(1,11);}
if(strippedNumber.length!=10)
{self.logMessage('Invalid number: '+number);return;}
var part1=strippedNumber.slice(0,3);var part2=strippedNumber.slice(3,6);var part3=strippedNumber.slice(6);var finalNumber=part1+separator+part2+separator+part3;if(leadingOne)
{finalNumber="1"+separator+finalNumber;}
originalContent=jQuery(selector).html();jQuery(selector).html(finalNumber);}
this.updateNumberOnPage=function(number_settings)
{if(!number_settings||!number_settings.pn||number_settings.pn=='')
{self.restoreOriginalContent();return;}
if(number_settings.ctcArgs)
{self.insertCTC(number_settings.ctcArgs);}
else
{self.insertNumber(number_settings.pn);}}
this.restoreOriginalContent=function()
{if(originalContent)
{self.logMessage("Restoring original content.");jQuery(selector).html(originalContent);}}
this.onResponse=function(data,textStatus)
{if(data.error)
{self.logMessage(data.error);self.restoreOriginalContent();}
else
{self.updateNumberOnPage(data.cookie)
self.storePersistentCookieUnlessTest(data);}
self.storeSessionCookieUnlessTest(data);}
this.storeSessionCookieUnlessTest=function(data)
{if(!testMode&&!data.test_mode)
{var sessionCookieJar=jQuery.cookieJar('sessionInfo',{debug:debugMode,cookie:{domain:data.domain,path:'/'}});sessionCookieJar.setFromObject(data.session_cookie);}}
this.storePersistentCookieUnlessTest=function(data)
{if(!testMode&&!data.test_mode)
{var persistentCookieJar=jQuery.cookieJar('affiliateInfo',{debug:debugMode,cookie:{expires:data.integration_cookie_life,domain:data.domain,path:'/'}});persistentCookieJar.setFromObject(data.cookie);}}
this.logMessage=function(message)
{if(typeof console!='undefined'&&typeof console.log!='undefined'&&debugMode)
{console.log(message);}}
this.getQueryStringHash=function(query_string)
{var query_hash={};var query_params=query_string.substr(1).split("&");for(var i=0;i<query_params.length;++i)
{var param=query_params[i].split("=");query_hash[param[0].toLowerCase()]=param[1];}
return query_hash;}
this.getNumber=function()
{originalContent=jQuery(selector).html();var sessionCookieJar=self.getCookieJar('sessionInfo');var persistentCookieJar=self.getCookieJar('affiliateInfo');var queryHash=self.getQueryStringHash(window.location.search);var queryHashComposite=queryHash['ppcpn'];var targetUpdated=false;var referer=document.referrer;var domainRe=/^https?\:\/\/([^\/])/;var refererDomain=referer.replace(domainRe,"$1");if(queryHashComposite)
{var queryHashPair=queryHashComposite.split("_");var queryHashPpcpn=queryHashPair[0];var queryHashTestAncId=queryHashPair[1];}
var queryNumber=queryHashPpcpn||queryHash[promo_numberid_name.toLowerCase()]||queryHash['ppcan'];var jsonArgs={av_id:advertiser_id,url:window.location.toString(),referer:referer};testMode=queryHashTestAncId||(queryNumber&&queryNumber.replace(/[^\d]/g,'')=="9999999999")||refererDomain.match(/ringrevenue\.com$/);if(testMode)
{self.logMessage('In test mode--skipping cookies');}
else
{var sessionStatus=sessionCookieJar?sessionCookieJar.toObject().status:'unknown';if(sessionStatus=='invalid')
{if(queryNumber)
{sessionStatus='unknown';}
else
{self.logMessage('Server found nothing last time. Aborting web integration for this session.');return;}}
if(persistentCookieJar)
{jsonArgs.cookie=persistentCookieJar.toString();if(queryNumber&&persistentCookieJar.get('pn')!=queryNumber)
{sessionStatus='unknown';}
switch(sessionStatus)
{case'promo_number':case'ctc':case'advertiser_number':self.logMessage('Valid state detected, using persistent data.');self.updateNumberOnPage(persistentCookieJar.toObject());return;case'unknown':self.logMessage('Valid state not found, verifying data.');if(!queryNumber)
{self.logMessage('Setting initial number with cached data.');self.updateNumberOnPage(persistentCookieJar.toObject());targetUpdated=true;}
break;default:self.logMessage('Warning: Unknown state found ('+sessionCookieJar.toObject().affiliateInfo_status+'). Aborting web integration for this session.');return;}}
if(!targetUpdated&&queryNumber)
{self.logMessage('Inserting number: '+queryNumber);self.insertNumber(queryNumber);}}
jQuery.getJSON(window.location.protocol+"//json10.ringrevenue.com/10/map_number?jsoncallback=?",jsonArgs,self.onResponse);}}