/* needs /html/js/dl/cookie.js */

    function showRegForm(dwnldcount) {

        document.getElementById('next_steps_content').style.display = "none";
        document.getElementById('urs_mini_form').style.display = "block"; 

        var countToken = null != dwnldcount ? '-' + dwnldcount : '';
        var path = window.location.pathname;
        var oid = path.replace(/\/3001-/, '\/3051-');
		oid = oid.replace(/\//, '');
        oid = oid.replace(/.html/, '');
        var oidElements = path.split('-');
        var nodeElements = oidElements[1].split('_');
        var node = nodeElements[0];
        var pid = oidElements[2];
        pid = pid.replace(/.html/, '');
        var tag = 'http://dw.com.com/clear/c.gif?oid=' + oid + '&sId=17&ptId=3051&onId=' + node + '&asId=' + pid + '&pId=' + pid + '&ctype=dlcount&cval=' + dwnldcount;

        document.rgprm_trkng.src = tag;
        document.rgprm.action = '/1300-20-133.html?tag=pdl-rgprm-btn' + countToken + '&path=' + path + '%3Ftag%3Dpdl-rgprm-confirm' + countToken + '%26idl%3Dn';
        document.rgprm.EMAILADDR.focus();

    }

    function showNextSteps() {
        document.getElementById('next_steps_content').style.display = "block";
        document.getElementById('urs_mini_form').style.display = "none";
    }

    function showOrHideRegForm() {
        var dwnldcount = null != getCookie("dwnlds") ? getCookie("dwnlds").split('|')[0] : 0;
        if ( parseInt(dwnldcount) > 1 && window.document.referrer.indexOf("part=dl-") < 0) {
            showRegForm(dwnldcount);
        } else {
            showNextSteps();
        }
    }
    

    function showRegAndWatchListPromo() {
            defaultErrorHandler = handleAjaxErrorRegPromo;
           document.getElementById('urs_mini_form').style.display = "block";

    }
 
    

    /* deprecated - use setMyDownloadsCookiePDL */
    function buildPDLCookieValue() {

        var count = 0;
        var pidString = '';
        var pid = '';
        
        // get the existing cookie value
        var dwnlds = getCookie("dwnlds");
        if (null != dwnlds && '' != dwnlds) {
            // split cookie into count and pid string, increment existing count
            var dwnldsElements = dwnlds.split('|');
            count = null != dwnldsElements[0] ? parseInt(dwnldsElements[0]) : count;
            pidString = dwnldsElements.length > 1 && null != dwnldsElements[1] ? dwnldsElements[1] : '';
	}

        // get pid out of the oid
        var path = window.location.pathname;
        path = path.replace(/.html/, '');
        var oidElements = path.split('-');
        var pid = null != oidElements[2] ? oidElements[2] : '';

        // if pid in not already in the list, add it
        if (pidString.indexOf(pid) < 0) {

            // prepend the new pid to the existing string
            pidString = '' != pidString ? pid + '-' + pidString : pid;

            // if there are more than max pids, remove oldest pids
            var max = 20;
            var pidArray = pidString.split('-');
            var pidCount = pidArray.length
            var newPidString = '';
            if (pidCount > max) {
                for (var i = 0; i<max; i++) {
                    if (i > 0) {
                        newPidString = newPidString + '-';
                    }
                    newPidString = newPidString + pidArray[i];
                }
                pidString = newPidString;
            }
            //increment the count
            count = count + 1;

        }

        return "dwnlds", count + '|' + pidString;

    }

function setMyDownloadsCookiePDL(myDownloadsCookie) {
    // get pid out of the oid
        var path = window.location.pathname;
        path = path.replace(/.html/, '');
        var oidElements = path.split('-');
        var pid = null != oidElements[2] ? oidElements[2] : '';

        // if pid in not already in the list, add it
        if (myDownloadsCookie.pidString.indexOf(pid) < 0) {

                // prepend the new pid to the existing string
                myDownloadsCookie.pidString = '' != myDownloadsCookie.pidString ? pid + '-' + myDownloadsCookie.pidString : pid;

                // if there are more than max pids, remove oldest pids
                var max = 20;
                var pidArray = myDownloadsCookie.pidString.split('-');
                var pidCount = pidArray.length;
                var newPidString = '';
                if (pidCount > max) {
                    for (var i = 0; i<max; i++) {
                            if (i > 0) {newPidString = newPidString + '-';}
                            newPidString = newPidString + pidArray[i];
                    }
                myDownloadsCookie.pidString = newPidString;
                }

                //increment the count
                myDownloadsCookie.count = parseInt(myDownloadsCookie.count) + 1;

        }

    // set (or reset) the cookie
    setMyDownloadsCookie(myDownloadsCookie);
}
