var setcookie = "N"; var doreplace = "N"; var ruleset = "None"; var continueeval = "Y"; var referrer = "Nothing"; var overridevariablevalue = "Nothing"; // Examine cookie var curCookie = document.cookie.split("; "); for (var i=0; i < curCookie.length; i++) { var crumb = curCookie[i].split("="); var name = crumb[0]; var value = crumb[1]; // Found a Cookie if (name == "HubCookie") { // Pull values from the HubCookie var cookvalue = value.split("|"); overridevariablevalue = cookvalue[0]; if (overridevariablevalue != "Nothing") { value = overridevariablevalue; // We found our variable name.. Now look at values. if (name = "PhoneScript") { } } referrer = cookvalue[1]; if (referrer != "Nothing") { var str = referrer; var patt = new RegExp ("google.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } var patt = new RegExp ("bing.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } var patt = new RegExp ("yahoo.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } } // This was set to Y in the template because that is used later, but we DONT want to rewrite the cookie here. setcookie = "N"; } } // Only do this if HubCookie was NOT found... if (continueeval == "Y") { //Examine URL string var searchString = document.location.search; searchString = searchString.substring(1); var nvPairs = searchString.split("&"); for (i = 0; i < nvPairs.length; i++) { var nvPair = nvPairs[i].split("="); var name = nvPair[0]; var value = nvPair[1]; // We found our variable name.. Now look at values. if (name = "PhoneScript") { } } } // Only do this if HubCookie was NOT found AND URL string evaluation failed to find anything... if (continueeval == "Y") { //Examine referrer var str = document.referrer; var patt = new RegExp ("google.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } var patt = new RegExp ("bing.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } var patt = new RegExp ("yahoo.com","i"); if (patt.test(str)==true) { doreplace = "Y"; setcookie = "Y"; continueeval = "N"; var ruleset = "R"; referrer = str; } } // START myscript FUNCTION function myscript() { //Start Rewrite // START replacePhoneNum FUNCTION function replacePhoneNum(oldTxt, newTxt, node) { node = node || document.body; var children = node.childNodes, i = 0; while (node = children[i]) { if (node.nodeName == "SCRIPT") { replacePhoneNum(oldTxt, newTxt, node); } else if (node.nodeName == "A") { var href_value = node.getAttribute("href"); //var href_value = jQuery(node).attr("href"); var contains = false; var index; var n1 = oldTxt.substring(0, 3); var n2 = oldTxt.substring(3, 6); var n3 = oldTxt.substring(6); var pat = "(^|\S|\.|\s){0,1}" + n1 + "(\-|\S|\.|\s){0,1}(\-|\S|\.|\s){0,1}" + n2 + "((\s|\.|\-){0,2})" + n3; var newRegex = new RegExp(pat); // does the href contain any of the numbers? if (newRegex.test(href_value)) { contains = true; } // Swap if found if (contains === true) { new_href = "tel:" + newTxt; node.setAttribute("href", new_href); //jQuery(node).attr("href", new_href); } replacePhoneNum(oldTxt, newTxt, node); } else if (node.nodeType == Node.TEXT_NODE) { // break old number into parts var o1 = oldTxt.substring(0, 3); var o2 = oldTxt.substring(3, 6); var o3 = oldTxt.substring(6); // break new number into parts var m1 = newTxt.substring(0, 3); var m2 = newTxt.substring(3, 6); var m3 = newTxt.substring(6); // create pattern and RegEx to find the old number var pat = "(^|\S|\.|\s){0,1}" + o1 + "(\-|\S|\.|\s){0,1}(\-|\S|\.|\s){0,1}" + o2 + "((\s|\.|\-){0,2})" + o3; var re = new RegExp(pat, "g"); node.textContent = node.textContent.replace(re, function(match, p1, p2, p3, p4, offset, string) { var finalstr = p1 !== undefined ? p1 : ''; finalstr += m1; finalstr += p2 !== undefined ? p2 : ''; finalstr += p3 !== undefined ? p3 : ''; finalstr += m2; finalstr += p4 !== undefined ? p4 : ''; finalstr += m3; return finalstr; }); } else { replacePhoneNum(oldTxt, newTxt, node); } i++; } } // END replacePhoneNum FUNCTION if (ruleset == "V") { } if (ruleset == "R") { var patt = new RegExp ("google.com","i"); if (patt.test(str)==true) { replacePhoneNum("8127528700","8559120141"); } var patt = new RegExp ("bing.com","i"); if (patt.test(str)==true) { replacePhoneNum("8127528700","8559120141"); } var patt = new RegExp ("yahoo.com","i"); if (patt.test(str)==true) { replacePhoneNum("8127528700","8559120141"); } } //End Rewrite if (setcookie == "Y") { // Set cookie // We need to add a PATH substatement here to specify the ROOT directory for landing pages in directories... days=30; // number of days to keep the cookie myDate = new Date(); myDate.setTime(myDate.getTime()+(days*24*60*60*1000)); // Build a HubCookie value that includes the overridevariablevalue | referrer for later processing if they come back. document.cookie = 'HubCookie=' + overridevariablevalue + '|' + referrer + '; path=/; expires=' + myDate.toGMTString(); } } // END myscript function /* function onloadhandler() { window.onLoad = myscript(); } */ if (doreplace == "Y") { //Get browser and Page - Delay if IE and FindaLocation due to Google map conflict var browser=navigator.appName; var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); if (browser=="Microsoft Internet Explorer" && sPage == "FindaLocation.aspx") { setTimeout('myscript();', 5); } else { setTimeout('myscript();', 5); } } // End If DoReplace is Y