// This is RIC Corp's common JavaScript routines

function getOrg() {
    var aCookies=document.cookie.split("; ")
    for (var i=0; i<aCookies.length; i++) {
        var aOneCookie=aCookies[i].split("=")
        if ("Org"==aOneCookie[0]) { return unescape(aOneCookie[1]) }
    }
    return "0"
}

function getName() {
    var aCookies=document.cookie.split("; ")
    for (var i=0; i<aCookies.length; i++) {
        var aOneCookie=aCookies[i].split("=")
        if ("Name"==aOneCookie[0]) { return unescape(aOneCookie[1]) }
    }
    return "to the home of RIC Corp, ConCentRICs and the I.A.C.U."
}

function getAddr(iSrc, iOpt, iNav, textColor) {
    var org = getOrg()
    var prefix = "../Htdocs/"
    var imgprefix = "../images/"
    var img = ""

    if (iSrc==0) { prefix = "Htdocs/" }
    if (iOpt==0) { return org }
    if (iOpt==1) {
	img = "homeico.gif"
        addr = "../Index.htm"
        desc = "Home Page"
    }
    if (iOpt==2) {
	img = "concentico.gif"
        addr = "Concent.htm"
        desc = "ConCentRICs"
    }
    if (iOpt==3) {
	img = "contactico.gif"
        addr = "Contact.htm"
        if (org != "0") { addr = "Contacts.htm" }
        desc = "Contacts"
    }
    if (iOpt==4) {
	img = "supportico.gif"
        addr = "Support.htm"
        if (org != "0") {
            prefix = ""
            addr = "http://www.riccorp.com/cgi-bin/bkofweb.exe?102|" + org
        }
        desc = "Support"
    }
    if (iOpt==5) {
	img = "downloadico.gif"
        var update = "0"
        var iacu = "IACU;54321;1;2;3;4;6;8;11;14;16;17;18;20;25;30;32;34;35;37;42;43;44;45;50;51;54;57;59;61;63;64;69;70;72;74;77;81;83;84;85;89;90;91;92;93;94;"
        if (org > 90000) { update = "1" }
        var testorg = iacu.split(";")
        for (var i=1; i < testorg.length && update == "0"; i++) {
            if (testorg[i] == org) { update = "1" }
        }
        addr = "Dwnload8.htm"
        if (update == "1") { addr = "Dwnload7.htm" }
        desc = "Downloads"
    }
    if (iOpt==6) {
	img = "iacu2ico.gif"
        addr = "Iacumain.htm"
        desc = "IACU"
    }
    if (iOpt==7) {
	img = "pictures2ico.gif"
        addr = "Pictures.htm"
        desc = "Pictures"
    }
    if (iOpt==8) {
	img = "introico.gif"
        addr = "Intro.htm"
        desc = "RIC Corp Information"
    }
    if (iOpt==12) {
        addr = "Prodnone.htm"
        if (org != "0") { addr = "Prodzero.htm" }
        desc = "Product Demonstration"
    }
    if (iOpt==50) {
        prefix = ""
        addr = "http://www.riccorp.com/cgi-bin/bkofweb.exe?114|" + org
        desc = "Request/Comment"
    }
    if (iOpt==51) {
        addr = "Gallery0.htm"
        if (org != "0") { addr = "Gallery2.htm" }
        desc = "People Gallery"
    }
    if (iOpt==52) {
        addr = "Gallery0.htm"
        if (org != "0") { addr = "Gallery2.htm" }
        sCmd = ("<a href=" + prefix + addr +">")
        return sCmd
    }
    if (iOpt==109) {
        prefix = ""
        addr = "http://www.riccorp.com/cgi-bin/bkofweb.exe?109|" + org + "|1|" + iSrc + "|" + iSrc
        desc = iSrc
    }
    var style = ""
    if (iNav != 1 && iNav != 2) { img = "" }
    style = " style='color: " + textColor + "; text-decoration: none'"
    var image = ""
    if (img != "") { image = "<img src=" + imgprefix + img + " border=none><br>\r\n" }
    if (iSrc==0) { sCmd = ("<a href=" + prefix + addr + ">") }
    else { sCmd = ("<a href=" + prefix + addr + style + ">" + image + desc + "</a>") }
    return sCmd
}

function getOptions(iSrc, iSkip, iNav, textColor) {
    if (iNav == 2) {
    	document.write("\r\n<table width=50% cellspacing=0 cellpadding=10 border=0><tr>\r\n")
    }
    else {
    	document.write("\r\n<center><table width=100% cellspacing=0 cellpadding=10 border=0><tr>\r\n")
    }
    for (var i=1; i<9; i++) {
        if (i != iSkip) {
	    if (iSkip != 0) {
		sCmd = ("<td width=14%><center><span style='font-family: system; font-size: 10px'><b>" + getAddr(iSrc, i, iNav, textColor) + "</b></span></center></td>\r\n")
	        document.write(sCmd)
		if (iNav == 2 && i == 5) { document.write("</tr><tr>\r\n") }
	    }
	    else {
		sCmd = ("<td width=12%><center><span style='font-family: system; font-size: 10px'><b>" + getAddr(iSrc, i, iNav, textColor) + "</b></span></center></td>\r\n")
	        document.write(sCmd)
	    }
        }
    }
    document.write("</tr></table></center>\r\n\r\n")
}

function showLevel() {
    Iacu = getOrg()
    sCmd = ("You have minimum access to this website")
    if (Iacu > 90000) {
        sCmd = ("You have System access and can get to the <a href=../Htdocs/Develope.htm><u>Development Page</u></a>")
    }
    else {
        if (Iacu > 50000) {
            sCmd = ("You have limited access to this website")
        }
        else {
            if (Iacu > 0) {
                sCmd = ("You have full access to this website")
            }
        }
    }
    document.write(sCmd)
}

function backButton(sDesc) {
    sCmd = ("<p><center><input type='button' value='")
    document.write(sCmd)
    sCmd = (sDesc + "' onClick='history.back()'></center><p>")
    document.write(sCmd)
}

function logEntry(iSwt, sDesc) {
    sIacu = "0"
    sWho = "";
    var aCookies=document.cookie.split("; ")
    for (var i=0; i<aCookies.length; i++) {
        var aOneCookie=aCookies[i].split("=")
        if ("Org"==aOneCookie[0]) {
            sIacu = unescape(aOneCookie[1])
            for (var i=0; i<aCookies.length; i++) {
                var aOneCookie=aCookies[i].split("=")
                if ("Name"==aOneCookie[0]) { sWho = unescape(aOneCookie[1]) }
            }
        }
    }
    if (sIacu == "0") {
        for (var i=0; i<aCookies.length; i++) {
            var aOneCookie=aCookies[i].split("=")
            if ("Login"==aOneCookie[0]) { sIacu = unescape(aOneCookie[1]) }
        }
    }
    if (sIacu == "0") {
        chrono = new Date()
        sIacu = (chrono.getHours() * 10000) + (chrono.getMinutes() * 100) + chrono.getSeconds() + 100000
        document.cookie=("Login=" + sIacu + "; expires=Fri, 25 Dec 2020 23:59:59 UTC; path=/;")
    }
    if (iSwt == "0") {
         for (var i=0; i<aCookies.length; i++) {
            var aOneCookie=aCookies[i].split("=")
            if ("Session"==aOneCookie[0]) { iSwt = "4" }
        }
        if (iSwt == "4") { iSwt = "0" }
        else { iSwt = "3" }
   }
    if (iSwt == "1") {
        for (var i=0; i<aCookies.length; i++) {
            var aOneCookie=aCookies[i].split("=")
            if ("Session"==aOneCookie[0]) {
                iSwt = "0"
                sDesc = "Home Page"
            }
        }
    }
    if (iSwt == "1") {
        if (sWho != "") sDesc = sWho
        document.cookie=("Session=Login; path=/")
    }
    if (iSwt == "3") {
        document.cookie=("Session=Login; path=/")
        iSwt = "0"
        if (sWho == "") sWho = sDesc
        sCmd = ("<object classid='http://www.riccorp.com/cgi-bin/bkofweb.exe?7|" +
            sIacu + "|" + iSwt + "|" + sWho + "|'></object>")
        document.write(sCmd)
        iSwt = "1"
    }
    sCmd = ("<object classid='http://www.riccorp.com/cgi-bin/bkofweb.exe?7|" +
        sIacu + "|" + iSwt + "|" + sDesc + "|'></object>")
    document.write(sCmd)
}

function freeCd() {
    if (getOrg() >= 50000) {
        document.write("<p><center><a href='support.htm#FreeCD'><img src='../Images/FreeCd.gif'></a></center><p>") 
    }
}

function setUploadLog() {
    strVal = document.uploadfile.Whatever.value
    strExpire = "Fri, 25 Dec 2020 23:59:59 UTC"
    document.cookie = ( "Upload=" + escape(strVal) + "; expires=" +
                      strExpire + "; path=/;")
}

function setUploadLog2() {
    strVal = document.uploadfile2.Whatever.value
    strExpire = "Fri, 25 Dec 2020 23:59:59 UTC"
    document.cookie = ( "Upload=" + escape(strVal) + "; expires=" +
                      strExpire + "; path=/;")
}

function setUploadLog3() {
    strVal = document.uploadfile3.Whatever.value
    strExpire = "Fri, 25 Dec 2020 23:59:59 UTC"
    document.cookie = ( "Upload=" + escape(strVal) + "; expires=" +
                      strExpire + "; path=/;")
}

function getUploadInfo() {
    var aCookies=document.cookie.split("; ")
    for (var i=0; i<aCookies.length; i++) {
        var aOneCookie=aCookies[i].split("=")
        if ("Upload"==aOneCookie[0]) {
            sFile = unescape(aOneCookie[1])
            return sFile
        }
    }
    return "No file information was found"
}

function getUploadData() {
    strFile = "Unknown"
    var aCookies=document.cookie.split("; ")
    for (var i=0; i<aCookies.length; i++) {
        var aOneCookie=aCookies[i].split("=")
        if ("Upload"==aOneCookie[0]) {
            strFile = unescape(aOneCookie[1])
        }
    }
    sCmd = "<input type='hidden' name='FileName' value='" + strFile + "'>"
    return sCmd
}
