﻿
var hdnWebsite = '';
var isIFrame = 0;

function JointApplicant(obj, objpnl, objchk) {
    var pnl = document.getElementById(objpnl);
    var chk = document.getElementById(objchk);
    if (obj.innerHTML == "Second Applicant - Click Here To Include") 
    {
        obj.innerHTML = "Second Applicant - Click Here To Remove";
        pnl.style.display = "block";
        chk.checked = true;
    } 
    else 
    {
        obj.innerHTML = "Second Applicant - Click Here To Include";
        pnl.style.display = "none";
        chk.checked = false;
    }
    if (isIFrame == 0) {
        doParentResize();
    }
}

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
    return '';
}

function CreateHiddenIFrame() {
    var mframe;
    try {
        mframe = document.createElement('iframe');
        mframe.id = 'HiddenInnerIFrame';
        mframe.style.display = 'none';
        mframe.style.height = '10px';
        mframe.style.width = '10px';
        mframe.setAttribute('style', 'display:none; width:0px; height:0px;visibility: hidden;');
        document.getElementsByTagName("body")[0].appendChild(mframe);
        /*document.write('<iframe id="HiddenInnerIFrame" width="10" height="10" style="display:none;"></iframe>');*/
    }
    catch (err) {
        document.body.appendChild(mframe);
    }
}

function doParentResize() {
    var hdnIFrame = document.getElementById('HiddenInnerIFrame');
    var hdnHeight = Math.max(document.body.offsetHeight, document.body.scrollHeight);
    hdnIFrame.src = '' + hdnWebsite + 'iframe_callback.html?height=' + hdnHeight;
}

function doLoadResize() {
    var params = window.location.search.substring(1).split('&');
    var height;
    for (var i = 0, l = params.length; i < l; ++i) {
        var parts = params[i].split('=');
        switch (parts[0]) {
            case 'height':
                height = parseInt(parts[1]);
                break;
        }
    }
    if (typeof (height) == 'number') {
        window.top.doUpdateIFrame(height + 30);
    }
}

function doUpdateIFrame(height) {
    var iframe = document.getElementById('AppIFrame');
    iframe.setAttribute('height', height);
}

function CreateApplicationIFrame(skinID, isIFrame, isHidden) {
    document.write('<iframe id="AppIFrame" frameborder="0" border="0" scrolling="no" width="600" height="580" src="about:blank" style="border:none;"></iframe>');
    var applicationIFrame = document.getElementById('AppIFrame');
    var doc = applicationIFrame.contentDocument;
    if (doc == undefined || doc == null)
        doc = applicationIFrame.contentWindow.document;
    doc.open();
    doc.write('<p style="text-align:center;font-family:Arial;font-size:12px;">Preparing Application Form...</p><p style="text-align:center;"><img src="http://services.jstfinancial.com/forms/images/loading.gif" border="0" alt="Loading..."/></p>');
    doc.close();
    applicationIFrame.src = 'http://services.jstfinancial.com/forms/apply.aspx?skinID=' + skinID + '&IFrame=' + isIFrame + '&hideHeaderFooter=' + isHidden + '&affid=' + querySt('affid');
}

function CreateContactIFrame(skinID, isIFrame, isHidden) {
    document.write('<iframe id="AppIFrame" frameborder="0" border="0" scrolling="no" width="600" height="300" src="about:blank" style="border:none;"></iframe>');
    var contactFrame = document.getElementById('AppIFrame');
    var doc = contactFrame.contentDocument;
    if (doc == undefined || doc == null)
        doc = contactFrame.contentWindow.document;
    doc.open();
    doc.write('<p style="text-align:center;font-family:Arial;font-size:12px;">Preparing Contact Form...</p>');
    doc.close();
    contactFrame.src = 'http://services.jstfinancial.com/forms/contact.aspx?skinID=' + skinID + '&IFrame=' + isIFrame + '&hideHeaderFooter=' + isHidden
}

function CreateUnsubscribeIFrame(skinID, isIFrame, isHidden) {
    document.write('<iframe id="AppIFrame" frameborder="0" border="0" scrolling="no" width="600" height="150" src="about:blank" style="border:none;"></iframe>');
    var unsubFrame = document.getElementById('AppIFrame');
    var doc = unsubFrame.contentDocument;
    if (doc == undefined || doc == null)
        doc = unsubFrame.contentWindow.document;
    doc.open();
    doc.write('<p style="text-align:center;font-family:Arial;font-size:12px;">Preparing Unsubscribe Form...</p>');
    doc.close();
    unsubFrame.src = 'http://services.jstfinancial.com/forms/unsubscribe.aspx?skinID=' + skinID + '&IFrame=' + isIFrame + '&hideHeaderFooter=' + isHidden
}

function endRequest(sender, args) {
    if (isIFrame == 0) {
        doParentResize();
    }
}
   