var historyName;
var cookieName = "page_history";
var cookieInfo;
var showPopup = false;
var arr = new Array();
var http_request;
var response_array;
var stop_toolbar; //=1 when to stop the d2p toolbar
var d2p_url = 'http://www.d2pass.com/';
function setCookie (name, value){
        document.cookie = name + '=' + escape(value) + ";path=/;"
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(cookieName){
        var search = cookieName + '=';
        if (document.cookie.length>0) {
                offset = document.cookie.indexOf(search);
                if (offset != -1){
                        offset += search.length;
                        end             = document.cookie.indexOf(';',offset);
                        if(end == -1)
                                end = document.cookie.length;
                        return unescape(document.cookie.substring(offset,end));
                }
        }
        return null;
}

var cookieInfo = getCookie("page_history")

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showHistory(){
        if(cookieInfo){
                document.write("<table width='100%' height=20 cellspacing=0 cellpadding=2 border=0><tr><td>");
                arr = cookieInfo .split("|")
                for(var i=0; i < arr.length; i++){
                        var temp = arr[i].split("::");
                        var title = temp[0];
                        if(title.length>13) title = title.substring(0, 13)+'...';
                        var url = temp[1];
                        if(i>0) document.write("&nbsp;>&nbsp;");
                        document.write("<a href=" + url + ">" + title + "</a>");
                }
                document.write("</td></tr></table>");
        }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkHistory(arrLocal){
        for(i=0; i<arrLocal.length; i++){
                strHistory = arrLocal[i]
                strHistoryName = (strHistory.split("::"))[0]
                if(strHistoryName.indexOf(historyName) > -1 && strHistoryName.length == historyName.length)
                        return false
        }
        return true
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(!historyName)
        historyName = (document.title).replace(" Pacopacomama", "")


if(cookieInfo){
        arr = cookieInfo .split("|")
        if(historyName != "" && checkHistory(arr)){
                if(arr.length >= 5)
                        arr = (arr.slice(1,5)).concat(new Array(historyName+"::"+document.URL))
                else
                        arr = arr.concat(new Array(historyName+"::"+document.URL))
                setCookie(cookieName,  (cookieInfo = arr.join("|")))
        }
} else {
        setCookie(cookieName, historyName+"::"+document.URL)
}

function showD2PToolbar() {
  if (stop_toolbar != 1) {
        netia = getCookie('NetiA');
        ml = '';
        if(netia) {
            cForm = netia.split(":");
            check = /.+@.+\..+/;
            if (cForm[0].match(check)) {
                document.write('<center><div class="d2_toolbar"><TABLE cellSpacing=0 cellPadding=0 width=950 border=0 ><TBODY><TR><TD height=23><iframe src="' + d2p_url + 'toolbarD2P/www.pacopacomama.com');
                document.write('?user_name=' + cForm[0]);
                document.write('" frameBorder=0 width="100%" scrolling=no height=23></iframe></TD></TR></TBODY></TABLE></div></center>');
            }
        }
  }
}
