﻿var xmlHttp;
function openDoc(id, docType, prosName) {
    setProsNameCookie(prosName);
    setDocTypeCookie(docType);
    window.open("Fund.aspx?ProsID=" + id + "&DocType=" + docType, null, 'status=no, toolbar=no, scrollbars=yes, resizable=yes, menubar=no, titlebar=no, location=no');
}

function openPDF(pdf, docType, num) {
    setDocTypeCookie(docType);
    //document.cookie = "Link=" + num;
    resetLinks();
    top.frames["pdf"].location.href = pdf;
}

//function openPDF(pdf, pdf2, docType, num, sourceSite) {
//    setDocTypeCookie(docType);
//    document.cookie = "PDF2=" + pdf2;
//    var cookiePDF = getCookie("PDF2");
//    resetLinks();
//    top.frames["pdf"].location.href = pdf;
//}

function goToURL(url) {
    top.location.href = url;
}

function mouseOver(row) {
    document.getElementById("DocumentTableRow" + row).className = "DocumentTableRowOver";
}

function mouseOut(row) {
    document.getElementById("DocumentTableRow" + row).className = "DocumentTableRow";
}

function setDocTypeCookie(docType) {
    document.cookie = "AFDocType=" + docType;
}

function setProsNameCookie(prosName) {
    document.cookie = "P=" + prosName;
}

function cleanForm() {
    document.cookie = "AFDocType=0;expires=Fri, 14 Oct 1900 12:00:00 UTC;";
    document.cookie = "Link=0;expires=Fri, 14 Oct 1900 12:00:00 UTC;";
}

function init(cookieValue) {
    if (cookieValue == "SP") {
        document.cookie = "AFDocType=SP";
        document.getElementById("Td1").className = "Table1CellSelected"
    }

    else if (cookieValue == "P") {
        document.cookie = "AFDocType=P";
        document.getElementById("Td2").className = "Table1CellSelected"
    }

    else if (cookieValue == "S") {
        document.cookie = "AFDocType=S";
        document.getElementById("Td3").className = "Table1CellSelected"
    }

    else if (cookieValue == "AR") {
        document.cookie = "AFDocType=AR";
        document.getElementById("Td4").className = "Table1CellSelected"
    }

    else if (cookieValue == "SAR") {
        document.cookie = "AFDocType=SAR";
        document.getElementById("Td5").className = "Table1CellSelected"
    }
//    var docTypeCookie = getCookie("AFDocType");
//    if ((docTypeCookie == "") || (docTypeCookie == null)) {
//        //document.cookie = "PDF=PDFs%2FSumm.pdf";
//        document.getElementById("Td1").className = "Table1CellSelected";
//    }

//    else if (docTypeCookie == "SP") {
//        document.getElementById("Td1").className = "Table1CellSelected";
//    }

//    else if (docTypeCookie == "P") {
//        document.getElementById("Td2").className = "Table1CellSelected";
//    }

//    else if (docTypeCookie == "S") {
//        document.getElementById("Td3").className = "Table1CellSelected";
//    }

//    else if (docTypeCookie == "AR") {
//        document.getElementById("Td4").className = "Table1CellSelected";
//    }

//    else if (docTypeCookie == "SAR") {
//        document.getElementById("Td5").className = "Table1CellSelected";
//    }
}

function resetLinks() {
    for (var i = 1; i <= document.getElementById("recordCount").value; i++) {
        document.getElementById("Td" + i).className = "Table1CellOver";
    }

}

//function trackActivity(code, docID, docType) {
//    xmlHttp = GetXmlHttpObject();
//    if (xmlHttp == null) {
//        alert("Your browser does not support AJAX!");
//        return;
//    }
//    var url = "TrackActivity.aspx";
//    url = url + "?P=" + code + "&PD=" + docID + "&D=" + docType;

//    xmlHttp.onreadystatechange = stateChanged;
//    xmlHttp.open("GET", url, true);
//    xmlHttp.send(null);
//}

function trackActivity(code, docTypeID, docType, tID) {
    var url = "TrackActivity.aspx";
    url = url + "?ProsID=" + code + "&DocType=" + docType + "&DocID=" + docTypeID + "&tid=" + tID;

    location.href = url;
}

function stateChanged() {
    if (xmlHttp.readyState != 4) {
        //document.getElementById("SDFundListPanel").innerHTML = "<img src='Images/loader_sm.gif' align='absmiddle'> Loading";
    }

    if (xmlHttp.readyState == 4) {
        //alert(getCookie("TID"));
    }
}

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // IE 7+, Firefox, Opera, Safari, Chrome
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // IE 5, IE 6
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function getCookie(name) {
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    if (value == null) {
        return "";
    }
    else {
        return value[1];
    }
}
