var theCookie = "" + document.cookie;
var ind = theCookie.indexOf("myURL");
if (ind == -1 || "myURL" == "") {
    if (document.referrer != "") {
        var x = document.referrer;
        var z = x.split("/");

        if (z[2] != document.domain) {
            var expdate = new Date();
            expdate.setTime(expdate.getTime() + 365 * (24 * 60 * 60 * 1000));

            document.cookie = "myURL" + "=" + document.URL + "; expires=" + expdate.toUTCString() + ";domain=mydomain.com; path=/";
        }
    }
}