﻿function zTrack() {
    if (document.cookie.indexOf("zTrack") == -1) {
        var tValue = 'land=' + document.location;
        if (document.referrer != '') {
            tValue = tValue + '&ref=' + document.referrer;
        }
        zSetCookie('zTrack', tValue, 90);
    }
}

function get_hostname_from_url(url) {
    var domain = url.split(/\/+/g)[1];
    if (domain.indexOf('.', 0) > 0) {
        domain = domain.substring(domain.indexOf('.', 0));        
    }    
    return domain;
}

function zSetCookie(c_name, value, expiredays) {
    var zTrack = new Date();
    zTrack.setDate(zTrack.getDate() + expiredays);
    document.cookie = c_name + "=" + value + ((expiredays == null) ? "" : ";expires=" + zTrack.toGMTString() + ";path=/;domain=" + get_hostname_from_url(window.location.href));
    
}

zTrack();
