﻿
function expEscape(text) {
    var e = escape(text);
    return e.replace(/\//g, '%2F');
}

function recordClickObservation(clickedObject) {
   /* try {
        var spinTimeout = 150;
        var obsUrl = 'http://exp.msn.com/ro2.aspx?obs=olabs_click_test' +
                    '&euid=' + readCookie("exp_uid") +
                    '&k1=cid&v1=' + clickedObject.id +
                    '&k2=link_uri&v2=' + expEscape(clickedObject.href) +
                    '&k3=link_title&v3=' + expEscape(clickedObject.innerHTML) +
                    '&k4=source_url&v4=' + expEscape(window.location);


        fireBeaconCall(obsUrl);
    }
    catch (e) {}*/
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}


function spin(spinDuration) {
    // if we want to pause, then we need to spin for a spell
    var startTime = (new Date()).getTime();
    
    while ((new Date()).getTime() - startTime < spinDuration) { }
}

function fireBeaconCall(url) {
    //check whether to fire the call

    if (readCookie("exp_offline") == null) {
        // create an image object
        var img = new Image();
        // hook the onload and onerror events to keep a reference until it's done
        img.onload = img.onerror = function() {
            // reset the handlers so they don't leak
            img.onload = img.onerror = null;
        };

        // set the src property to make the request
        img.src = url;
    }
}