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") { // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } } } referrer = cookvalue[1]; if (referrer != "Nothing") { var str = referrer; } // 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") { // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } // We found a value match. Set doreplace to Y... if (value == "PPC") { overridevariablevalue = value; doreplace = "Y"; ruleset = "V"; setcookie = "Y"; continueeval = "N"; } } } } // 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; } // 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 (overridevariablevalue == "PPC") { replacePhoneNum("8009897874","8555852279"); } if (overridevariablevalue == "PPC") { replacePhoneNum("9372976182","9378136585"); } if (overridevariablevalue == "PPC") { replacePhoneNum("5137718784","5136665853"); } if (overridevariablevalue == "PPC") { replacePhoneNum("6143373300","6145858341"); } if (overridevariablevalue == "PPC") { replacePhoneNum("9372247874","9377055854"); } if (overridevariablevalue == "PPC") { replacePhoneNum("5136598947","5136665585"); } if (overridevariablevalue == "PPC") { replacePhoneNum("5137717874","5136665857"); } if (overridevariablevalue == "PPC") { replacePhoneNum("9373137881","9377055856"); } if (overridevariablevalue == "PPC") { replacePhoneNum("5136728160","5136665859"); } if (overridevariablevalue == "PPC") { replacePhoneNum("6145861580","6145322585"); } } if (ruleset == "R") { } //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