/* OnlineOpinion (S3tS v3.1.1) Supports passing domains in argument */
/* This product and other products of OpinionLab, Inc. are protected by U.S. Patent No. 6606581, 6421724, 6785717 B1 and other patents pending. */

var custom_var,
_sp = '%3A\\/\\/',
_rp = '%3A//',
_poE = 0.0,
_poX = 0.0,
_sH = screen.height,
_d = document,
_w = window,
_ht = escape(_w.location.href),
_hr = _d.referrer,
_tm = (new Date()).getTime(),
_kp = 0,
_sW = screen.width;
function _fC(_u) {
    _aT = _sp + ',\\/,\\.,-,_,' + _rp + ',%2F,%2E,%2D,%5F';
    _aA = _aT.split(',');
    for (i = 0; i < 5; i++) {
        eval('_u=_u.replace(/' + _aA[i] + '/g,_aA[i+5])')
    }
    return _u
};
function O_LC(new_domain) {
    //Code modified by Rajeev to capture the product section data into variable custom_var - START

    var bc = document.getElementById('bc');
    var body = (document.getElementsByTagName('body'))[0];
    var classAttributeOfBody = body.className;

    var li;
    custom_var = null;

    //If Breadcrumbs are not present and the it is the homepage, then custom_var value is the title of the webpage and
    //the URL of the page is suffixed with "home_page"
    if ((bc == null) && (classAttributeOfBody == 'default')) {
        custom_var = 'Tesco Direct Homepage';
        var newPageURL;
        var pageURL = _ht;
        if (_ht.indexOf('.aspx', 0) != -1) {
            newPageURL = _ht.substring(0, _ht.indexOf('.aspx', 0)) + '/home_page/';
        }
        else {
            newPageURL = _ht + '/home_page/';
        }
    }

    //If the feedback is from a product details page, assign the title of the page to the custom_var variable and
    //suffix 'product_details_page' to the page URL
    else if ((bc == null) && (classAttributeOfBody == 'product')) {
    custom_var = 'Details Of The Product - ' + document.title;
        var newPageURL;
        var pageURL = _ht;
        if (_ht.indexOf('.aspx', 0) != -1) {
            newPageURL = _ht.substring(0, _ht.indexOf('.aspx', 0)) + '/product_details_page/' + custom_var;
        }
        else {
            newPageURL = _ht + '/product_details_page/' + custom_var;
        }
    }

    //If Breadcrumbs are present and it is a listing page, then add the individual crumbs to the custom_var variable and
    //re-write the URL of the page to add 'product_listing_page' and the breadcrumb info at the end
    else if ((bc != null) && (bc.hasChildNodes())) {
        for (var i = 0; i < bc.childNodes.length; i++) {
            if ((bc.childNodes[i].nodeName == 'LI') || (bc.childNodes[i].nodeName == 'li')) {
                li = bc.childNodes[i];

                if (li.hasChildNodes()) {
                    if ((li.firstChild.nodeName == 'A') || (li.firstChild.nodeName == 'a')) {

                        if ((typeof custom_var == 'undefined') || (custom_var == null)) {
                            custom_var = li.firstChild.innerHTML;
                        }
                        else {
                            custom_var = custom_var + '~' + li.firstChild.innerHTML;
                        }
                    }
                    else {
                        if (typeof custom_var == 'undefined') {
                            custom_var = li.innerHTML;
                        }
                        else {
                            custom_var = custom_var + '~' + li.innerHTML;
                        }
                    }
                }
            }
        }
        
        var pageURL = _ht;
        var newPageURL;
        var newCustom_Var = custom_var;
        
        var tmp = newCustom_Var.split('~');
        newCustom_Var = tmp.join('-');
        if (_ht.indexOf('.aspx', 0) != -1) {
            newPageURL = _ht.substring(0, _ht.indexOf('.aspx', 0)) + '/product_listing_page/' + newCustom_Var;
        }
        else {
            newPageURL = _ht + '/product_listing_page/' + newCustom_Var;
        }
    }

    //If the feedback is from a checkout stage page, assign the className of the body tag to the custom_var variable and
    //suffix 'checkout_page' and the className of the body tag to the page URL
    else if ((bc == null) && (classAttributeOfBody.indexOf('checkout') != -1)) {
        custom_var = classAttributeOfBody;
        var newPageURL;
        var pageURL = _ht;
        if (_ht.indexOf('.aspx', 0) != -1) {
            newPageURL = _ht.substring(0, _ht.indexOf('.aspx', 0)) + '/checkout_page/' + classAttributeOfBody;
        }
        else {
            newPageURL = _ht + '/checkout_page/' + classAttributeOfBody;
        }
    }

    //If the feedback is from a content page, assign the className of the body tag to the custom_var variable and
    //suffix 'content_page' and the className of the body tag to the page URL
    else {
        custom_var = classAttributeOfBody;
        var newPageURL;
        var pageURL = _ht;
        if (_ht.indexOf('.aspx', 0) != -1) {
            newPageURL = _ht.substring(0, _ht.indexOf('.aspx', 0)) + '/content_page/' + custom_var;
        }
        else {
            newPageURL = _ht + '/content_page/' + custom_var;
        }
    }

    //Code modified by Rajeev to capture the product section data into variable custom_var - END

    _domain = _ht.replace('https%3A//', '').replace('http%3A//', '');
    if (typeof new_domain == 'undefined' || new_domain == '') {
        _sp = '%3A\\/\\/';
        _rp = '%3A//'
    } else {
        _sp = '%3A\\/\\/' + _domain.substr(0, _domain.indexOf('/'));
        _rp = '%3A//' + new_domain
    }
    _w.open('https://secure.opinionlab.com/ccc01/comment_card.asp?time1=' + _tm + '&time2=' + (new Date()).getTime() + '&prev=' + _fC(escape(_hr)) + '&referer=' + _fC(newPageURL) + '&height=' + _sH + '&width=' + _sW + '&custom_var=' + custom_var + '|' + _fC(_ht), 'comments', 'width=535,height=192,screenX=' + ((_sW - 535) / 2) + ',screenY=' + ((_sH - 192) / 2) + ',top=' + ((_sH - 192) / 2) + ',left=' + ((_sW - 535) / 2) + ',resizable=yes,copyhistory=yes,scrollbars=no')
};
function _fPe() {
    if (Math.random() >= 1.0 - _poE) {
        O_LC();
        _poX = 0.0
    }
};
function _fPx() {
    if (Math.random() >= 1.0 - _poX) O_LC()
};
window.onunload = _fPx;
function O_GoT(_p) {
    _d.write('<a href=\'javascript:O_LC()\'>' + _p + '</a>');
    _fPe()
}
