﻿var xmlHttp;

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 parseQueryString(url, param) {
    param = param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + param + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null)
        return "";
    else
        return results[1];
}

function setDocTypeCookie(docType) {
    document.cookie = "IFDocType=" + docType;
}

function init(cookieValue) {
    resetLinks();
    
    if (cookieValue == "SP") {
        document.cookie = "IFDocType=SP";
        document.getElementById("Td1").className = "Table1CellSelected"
    }

    else if (cookieValue == "P") {
        document.cookie = "IFDocType=P";
        document.getElementById("Td2").className = "Table1CellSelected"
    }

    else if (cookieValue == "S") {
        document.cookie = "IFDocType=S";
        document.getElementById("Td3").className = "Table1CellSelected"
    }

    else if (cookieValue == "AR") {
        document.cookie = "IFDocType=AR";
        document.getElementById("Td4").className = "Table1CellSelected"
    }

    else if (cookieValue == "SAR") {
        document.cookie = "IFDocType=SAR";
        document.getElementById("Td5").className = "Table1CellSelected"
    }

    else if (cookieValue == "XBRL") {
        document.cookie = "IFDocType=XBRL";
        document.getElementById("Td6").className = "Table1CellSelected"
    }
    else {
        document.cookie = "IFDocType=P";
        document.getElementById("Td2").className = "Table1CellSelected"
    }
    if ((getCookie("PDF") == "") || (getCookie("PDF") == null)) {
        //document.cookie = "PDF=PDFs%2FSumm.pdf";
        //document.cookie = "PDF=" + top.frames["pdf"].src;
    }

    var docTypeCookie = getCookie("IFDocType");
}

function resetLinks() {
    for (var i = 1; i <= 5; i++) {
        document.getElementById("Td" + i).className = "Table1CellOver";
    }
}

function getCookie(name) {
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    if (value == null) {
        return "";
    }
    else {
        return value[1];
    }
}

function resizeRow() {
    document.getElementById("Table1").width = 1004;
    document.getElementById("Td1").width = 205;
    document.getElementById("Td2").width = 205;
    document.getElementById("Td3").width = 300;
    document.getElementById("Td4").width = 169;
    document.getElementById("Td5").width = 205;
}

function resizeTable() {
    document.getElementById("Table1").width = 799;
    document.getElementById("Td1").width = 1;
    document.getElementById("Td2").width = 205;
    document.getElementById("Td3").width = 300;
    document.getElementById("Td4").width = 205;
    document.getElementById("Td5").width = 205;
}

function checkWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (myWidth >= 1016) {
        resizeRow();
    }
    else {
        resizeRow();
        document.getElementById("Table1").width = '100%';
    }

    //    window.alert('Width = ' + myWidth);
    //    window.alert('Height = ' + myHeight);
}

//function trackActivity(code, docType) {
//    xmlHttp = GetXmlHttpObject();
//    if (xmlHttp == null) {
//        alert("Your browser does not support AJAX!");
//        return;
//    }
//    var url = "TrackActivity.aspx";
//    url = url + "?C=" + code + "&D=" + docType;

//    xmlHttp.onreadystatechange = stateChanged;
//    xmlHttp.open("GET", url, true);
//    xmlHttp.send(null);
//}

function trackActivity(code, docType, tID) {
    var url = "TrackActivity.aspx";
    url = url + "?cu=" + code + "&dt=" + docType + "&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;
}
