﻿// Begin StringBuilder Helper: 
//   Initializes a new instance of the StringBuilder class 
//   and appends the given value if supplied. 093208 
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}
// End StringBuilder Helpers



var returnVal = new StringBuilder(); //added 092308
var finishedLoading = false;

function includeCalculatorContent()
{
 QS = scrubQS(document.location.search);
 LOCATION = document.location.href.replace(document.location.search, "");
 QSVARS = QS.substring(1,QS.length);
 
 var protocolURL;
 if (LOCATION.substring(0,5) == "https") { protocolURL = "https://"; }
 else { protocolURL = "http://";}

 baseURL = "www.timevaluecalculators.com/TimeValueCalculators/Calculator.aspx?";
 queryURL = "RESPONSE=ASJSTRING&REFERREDBY=" + escape(LOCATION);
 if (QS.indexOf("TEMPLATE_ID") == -1) 
 { queryURL += "&TEMPLATE_ID=" + TEMPLATE_ID; }
 if ((PASSTHROUGH != "") && (QS.indexOf("PASSTHROUGH") == -1))
 { queryURL += "&PASSTHROUGH=" + escape(PASSTHROUGH); }
 if (QSVARS != "") { queryURL += "&" + QSVARS; }

 //force load of specific calculator if CALULATORID is defined
 if ((typeof(window['CALCULATORID']) != "undefined") && (CALCULATORID != "") && (QSVARS.indexOf("CALCULATORID") == -1)) 
 { queryURL += "&CALCULATORID=" + CALCULATORID; }

 //force hideformtag if defined
 if ((typeof(window['HIDEFORMTAG']) != "undefined") && (HIDEFORMTAG != "") && (QSVARS.indexOf("HIDEFORMTAG") == -1)) 
 { queryURL += "&HIDEFORMTAG=" + HIDEFORMTAG; }

 URL = protocolURL + baseURL + queryURL;
 
 document.write('<SCR' + 'IPT LANGUAGE="JavaScript" onLoad="finishedLoading=true;" SRC="');
 document.write(URL + '" TYPE="text/javascript"></SCR' + 'IPT>');
 document.write('<SCR' + 'IPT LANGUAGE="JavaScript" onLoad="finishedLoading=true;" SRC="');
 document.write(protocolURL + "www.timevaluecalculators.com/TimeValueCalculators/Includes/docwrite.js" + '" TYPE="text/javascript"></SCR' + 'IPT>');
}

function scrubQS(QS)
{
    if (
    (QS.toUpperCase().indexOf("<") > -1) ||  
    (QS.toUpperCase().indexOf("%3C") > -1) ||  
    (QS.toUpperCase().indexOf(">") > -1) ||  
    (QS.toUpperCase().indexOf("%3E") > -1) ||  
    (QS.toUpperCase().indexOf("SCRIPT") > -1) ||  
    (QS.toUpperCase().indexOf(";") > -1) ||  
    (QS.toUpperCase().indexOf("%3B") > -1) ||  
    (QS.toUpperCase().indexOf("{") > -1) ||  
    (QS.toUpperCase().indexOf("%7B") > -1))
    { QS = "";}
    return QS;
}

includeCalculatorContent();