﻿/*
 * 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)
 */



function setPayPerCallTarget(selector,advertiser_id,promo_numberid_name,separator,leadingOne,buttonMode,debug)
{PayPerCall.load({id:advertiser_id,numberSelector:selector,numberSeparator:separator,numberLeadingOne:leadingOne,ctcUseButton:buttonMode,networkParamName:promo_numberid_name,jqueryNoConflict:false,debug:debug});}
var PayPerCall={load:function(config)
{var param_or_default=function(param,default_val)
{return(typeof param=="undefined")?default_val:param;};var self=this;var advertiser_id=config['id'];var jQuery_no_conflict=param_or_default(config['jqueryNoConflict'],true);var selector=param_or_default(config['numberSelector'],'');var show_selector=param_or_default(config['showSelector'],'');var hide_selector=param_or_default(config['hideSelector'],'');var not_visible_selector=param_or_default(config['notVisibleSelector'],'');var show_number_callback=param_or_default(config['onLoadWithNumber'],null);var no_number_callback=param_or_default(config['onLoadNoNumber'],null);var promo_numberid_name=param_or_default(config['networkParamName'],'sid');var separator=param_or_default(config['numberSeparator'],'-');var leadingOne=param_or_default(config['numberLeadingOne'],true);var buttonMode=param_or_default(config['ctcUseButton'],true);var buttonContent=param_or_default(config['ctcButtonContent'],null);var debugMode=param_or_default(config['debug'],false);var testMode=false;var originalContent=null;if(jQuery_no_conflict)
{jQuery.noConflict();}
if(typeof advertiser_id=='undefined'||advertiser_id=='YOUR_ID_HERE')
{alert('PayPerCall Web Integration: id must be set');return false;}
var getCookieJar=function(name)
{if(!jQuery.cookie('rrCookie_'+name))
{return null;}
return jQuery.cookieJar(name);};var onCTCWindowLoad=function(hash)
{var modal=jQuery(hash.w);var ctcUrl=hash.c.ctcUrl;var modalContent=jQuery("iframe",modal);modalContent.html('').attr('src',ctcUrl);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;});};var insertCTC=function(number_settings)
{var ctcArgs=number_settings.ctcArgs;var ctc_selector=selector;if(buttonMode)
{jQuery(selector).html(buttonContent||'<button type="button">Call Now!</button>').addClass('click_to_call_button');ctc_selector=".click_to_call_button";}
else
{if(number_settings&&hasPhoneNumber(number_settings))
{insertNumber(formatPhoneNumber(number_settings.pn));}
else
{restoreOriginalContent(true);}}
var css_tag=document.createElement("link");css_tag.setAttribute("rel","stylesheet");css_tag.setAttribute("type","text/css");css_tag.setAttribute("href",window.location.protocol+ctcArgs.cssUrl);document.getElementsByTagName("head")[0].appendChild(css_tag);if(jQuery('.jqmWindow').length==0)
{jQuery('body').append('<div id="modalWindow" class="jqmWindow" style="display:none"><div id="jqmTitle"><div class="jqmClose" onfocus="this.blur();">close</div><span id="jqmTitleText">Call Now</span></div><iframe id="jqmContent" src=""></iframe></div>');}
jQuery('.jqmWindow').jqm({ctcUrl:window.location.protocol+ctcArgs.ctcUrl,modal:true,trigger:ctc_selector,target:'#jqmContent',onShow:onCTCWindowLoad});};var insertNumber=function(number)
{if(selector)
{originalContent=jQuery(selector).html();jQuery(selector).html(number);}};var updateNumberOnPage=function(number_settings,preview_only)
{if(number_settings)
{var formattedNumber=hasPhoneNumber(number_settings)?formatPhoneNumber(number_settings.pn):'';if(number_settings.ctcArgs)
{insertCTC(number_settings);onShowNumber(preview_only,true,formattedNumber);return;}
if(formattedNumber!='')
{insertNumber(formattedNumber);onShowNumber(preview_only,false,formattedNumber);return;}}
restoreOriginalContent();};var onShowNumber=function(preview_only,is_ctc,number)
{if(show_selector&&!is_ctc&&buttonMode)
{logMessage("Showing element: "+show_selector);jQuery(show_selector).show();}
if(hide_selector)
{logMessage("Hiding element: "+hide_selector);jQuery(hide_selector).css('display','none');}
if(not_visible_selector)
{logMessage("Setting element to invisible: "+not_visible_selector);jQuery(not_visible_selector).css('visibility','hidden');}
if(!preview_only&&jQuery.isFunction(show_number_callback))
{logMessage("Calling onLoadWithNumber callback");show_number_callback.apply(this,[is_ctc,number]);}}
var onNoNumber=function()
{if(jQuery.isFunction(no_number_callback))
{logMessage("Calling onLoadNoNumber callback");no_number_callback.apply(this);}};var hasPhoneNumber=function(number_settings)
{return number_settings.pn&&number_settings.pn!='';};var formatPhoneNumber=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)
{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;}
return finalNumber;};var restoreOriginalContent=function(is_ctc)
{if(originalContent&&selector)
{logMessage("Restoring original content.");jQuery(selector).html(originalContent);}
if(!is_ctc)
{onNoNumber();}};var onResponse=function(data,textStatus)
{if(data.error)
{logMessage(data.error);restoreOriginalContent();}
else
{updateNumberOnPage(data.cookie)
storePersistentCookieUnlessTest(data);}
storeSessionCookieUnlessTest(data);};var 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);}};var 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);}};var logMessage=function(message)
{if(typeof console!='undefined'&&typeof console.log!='undefined'&&debugMode)
{console.log(message);}};var 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;};var getNumber=function()
{originalContent=selector?jQuery(selector).html():'';var sessionCookieJar=getCookieJar('sessionInfo');var persistentCookieJar=getCookieJar('affiliateInfo');var queryHash=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)
{logMessage('In test mode--skipping cookies');}
else
{var sessionStatus=sessionCookieJar?sessionCookieJar.toObject().status:'unknown';if(sessionStatus=='invalid')
{if(queryNumber)
{sessionStatus='unknown';}
else
{logMessage('Server found nothing last time. Aborting web integration for this session.');onNoNumber();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':logMessage('Valid state detected, using persistent data.');updateNumberOnPage(persistentCookieJar.toObject());return;case'unknown':logMessage('Valid state not found, verifying data.');if(!queryNumber)
{logMessage('Setting initial number with cached data.');updateNumberOnPage(persistentCookieJar.toObject(),true);targetUpdated=true;}
break;default:logMessage('Warning: Unknown state found ('+sessionCookieJar.toObject().affiliateInfo_status+'). Aborting web integration for this session.');onNoNumber();return;}}
if(!targetUpdated&&queryNumber)
{logMessage('Inserting number from query param: '+queryNumber);insertNumber(formatPhoneNumber(queryNumber));}}
jQuery.getJSON(window.location.protocol+"//json3.ringrevenue.com/3/map_number?jsoncallback=?",jsonArgs,onResponse);}
jQuery(document).ready(function(){getNumber();});}};
