$(document).ready(function() {
   if (gup('gclid') != '' || $.cookie('gclid') != null) {
    // Replace the text matches:
    $('*', 'body')
        .andSelf()
        .contents()
        .filter(function(){
            return this.nodeType === 3;
        })
        .filter(function(){
            // Only match when contains 'simple string' anywhere in the text
            return this.nodeValue.indexOf('1800 287 462') != -1;
        })
        .each(function(){
            this.nodeValue = this.nodeValue.replace(/1800 287 462/g, "1800 618 508");
        });

// Replace the a tag matches:
    $("a[href*='1800287462']").each(function( intIndex ){
        $(this).attr('href', $(this).attr('href').replace(/1800287462/g, "1800618508"));
    });

    // Replace the image matches:
    $("img[src*='1800287462']").each(function( intIndex ){
        $(this).attr('src', $(this).attr('src').replace(/1800287462/g, "1800618508"));
    });

    var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 1000));         // 1 minute from now
    var options = { path: '/', expires: date };
    $.cookie('gclid', true, options);
    setInterval(updateGclid, 58000);
   } 
});

function updateGclid() {
    var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 1000));         // 1 minute from now
    var options = { path: '/', expires: date };
    $.cookie('gclid', true, options);
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
