﻿// Venture Bank JavaScript File
var currentPage;
var HOME_CONSTANT = 'home';
var ABOUTUS_CONSTANT = 'aboutUs';
var CASHMGMT_CONSTANT = 'cashMgmt';
var DEPOSITS_CONSTANT = 'deposits';
var LENDING_CONSTANT = 'lending';
var CONSUMER_CONSTANT = 'consumer';
var CAREERS_CONSTANT = 'careers';
var LOCATIONS_CONSTANT = 'locations';
var CONTACT_CONSTANT = 'contact';

// *** Begin Pre-Load Hover images ***
var hoverPics = new Array();
hoverPics[0] = 'aboutUsOver.png';
hoverPics[1] = 'careersOver.png';
hoverPics[2] = 'cashMgmtOver.png';
hoverPics[3] = 'consumerOver.png';
hoverPics[4] = 'contactOver.png';
hoverPics[5] = 'depositsOver.png';
hoverPics[6] = 'homeOver.png';
hoverPics[7] = 'lendingOver.png';
hoverPics[8] = 'locationsOver.png';
hoverPics[9] = 'submitOver.jpg';
hoverPics[10] = 'highlightRow.jpg';
hoverPics[11] = 'menuBottomOver.gif';

var hoverBuffer = new Array();
for(var i = 0; i < hoverPics.length; i++) 
{
    hoverBuffer[i] = new Image();	
    hoverBuffer[i].src = (undefined != imagePath) ? imagePath + hoverPics[i] : '/img/' + hoverPics[i];	
}

// *** Begin Top Nav Hover functions ***
function homeHover()
{
    var homeButton = document.getElementById('homeButton');
    homeButton.className = 'homeButton homeButtonOver';
}

function homeLeave()
{
    if (currentPage != HOME_CONSTANT) {
        var homeButton = document.getElementById('homeButton');
        homeButton.className = 'homeButton homeButtonOff';
    }
}

function locationsHover()
{
    var locationsButton = document.getElementById('locationsButton');
    locationsButton.className = 'locationsButton locationsButtonOver';
}

function locationsLeave()
{
    if (currentPage != LOCATIONS_CONSTANT) {
        var locationsButton = document.getElementById('locationsButton');
        locationsButton.className = 'locationsButton locationsButtonOff';
    }
}

function contactHover()
{
    var contactButton = document.getElementById('contactButton');
    contactButton.className = 'contactButton contactButtonOver';
}

function contactLeave()
{
    if (currentPage != CONTACT_CONSTANT) {
        var contactButton = document.getElementById('contactButton');
        contactButton.className = 'contactButton contactButtonOff';
    }
}

function careersHover()
{
    var careersButton = document.getElementById('careersButton');
    careersButton.className = 'careersButton careersButtonOver';
}

function careersLeave()
{
    if (currentPage != CAREERS_CONSTANT) {
        var careersButton = document.getElementById('careersButton');
        careersButton.className = 'careersButton careersButtonOff';
    }
}
// *** End Top Nav Hover functions ***

// *** Begin Main Nav Hover functions ***
function highlight(row, divName)
{
    var menuDiv = document.getElementById(divName + 'Div');
    var rows = menuDiv.getElementsByTagName('div');
    for (var i = 0; i < rows.length; i++)
    {
        if (i == row)
        {
            rows[i].className = 'highlightRow';
            var bottomDiv = document.getElementById(divName + 'BottomDiv');
            if ((i + 1) == rows.length)
            {
                bottomDiv.className = 'bottomOver';
            }
            else 
            {
                bottomDiv.className = 'noHighlight';
            }
        }
        else
        {
            rows[i].className = '';
        }
    }
}

function aboutUsHover()
{
    var aboutUsButton = document.getElementById('aboutUsButton');
    var aboutUsDiv = document.getElementById('aboutUsDiv');
    aboutUsButton.className = 'aboutUsButton aboutUsButtonOver';
    aboutUsDiv.className = '';
    var aboutUsBottomDiv = document.getElementById('aboutUsBottomDiv');
    if (aboutUsBottomDiv.className == 'hidden')
    {
        highlight(-1, 'aboutUs');
        aboutUsBottomDiv.className = 'noHighlight';
    }
}

function aboutUsLeave(e)
{
   /* var toName;
    if (window.event)
    {   
        toName = window.event.toElement;
        alert(toName);
    }
    else
    {
        toName = e.relatedTarget.id;
        alert(toName);
    }
    //setTimeout('aboutUsLeaveCallback()', 250);*/

    // reset row highlight
    highlight(-1, 'aboutUs'); 
    var aboutUsDiv = document.getElementById('aboutUsDiv');
    var aboutUsBottomDiv = document.getElementById('aboutUsBottomDiv');
    aboutUsDiv.className = 'hidden';
    aboutUsBottomDiv.className = 'hidden';
    if (currentPage != ABOUTUS_CONSTANT && currentPage != CONTACT_CONSTANT) {
        var aboutUsButton = document.getElementById('aboutUsButton');
        aboutUsButton.className = 'aboutUsButton aboutUsButtonOff';
    }
}

function depositsHover()
{
    var depositsButton = document.getElementById('depositsButton');
    var depositsDiv = document.getElementById('depositsDiv');
    depositsButton.className = 'depositsButton depositsButtonOver';
    depositsDiv.className = '';
    var depositsBottomDiv = document.getElementById('depositsBottomDiv');
    if (depositsBottomDiv.className == 'hidden')
    {
        highlight(-1, 'deposits');
        depositsBottomDiv.className = 'noHighlight';
    }
}

function depositsLeave()
{
    // reset row highlight
    highlight(-1, 'deposits'); 
    var depositsDiv = document.getElementById('depositsDiv');
    var depositsBottomDiv = document.getElementById('depositsBottomDiv');
    depositsDiv.className = 'hidden';
    depositsBottomDiv.className = 'hidden';
    if (currentPage != DEPOSITS_CONSTANT) {
        var depositsButton = document.getElementById('depositsButton');
        depositsButton.className = 'depositsButton depositsButtonOff';
    }
}

function cashMgmtHover()
{
    var cashMgmtButton = document.getElementById('cashMgmtButton');
    var cashMgmtDiv = document.getElementById('cashMgmtDiv');
    cashMgmtDiv.className = '';
    cashMgmtButton.className = 'cashMgmtButton cashMgmtButtonOver';
    var cashMgmtBottomDiv = document.getElementById('cashMgmtBottomDiv');
    if (cashMgmtBottomDiv.className == 'hidden')
    {
        highlight(-1, 'cashMgmt');
        cashMgmtBottomDiv.className = 'noHighlight';
    }
}

function cashMgmtLeave()
{
    // reset row highlight
    highlight(-1, 'cashMgmt'); 
    var cashMgmtDiv = document.getElementById('cashMgmtDiv');
    var cashMgmtBottomDiv = document.getElementById('cashMgmtBottomDiv');
    cashMgmtDiv.className = 'hidden';
    cashMgmtBottomDiv.className = 'hidden';
    if (currentPage != CASHMGMT_CONSTANT) {
        var cashMgmtButton = document.getElementById('cashMgmtButton');
        cashMgmtButton.className = 'cashMgmtButton cashMgmtButtonOff';
    }
}

function lendingHover()
{
    var lendingDiv = document.getElementById('lendingDiv');
    var lendingButton = document.getElementById('lendingButton');
    lendingDiv.className = '';
    lendingButton.className = 'lendingButton lendingButtonOver';
    var lendingBottomDiv = document.getElementById('lendingBottomDiv');
    if (lendingBottomDiv.className == 'hidden')
    {
        highlight(-1, 'lending');
        lendingBottomDiv.className = 'noHighlight';
    }
}

function lendingLeave()
{
    // reset row highlight
    highlight(-1, 'lending'); 
    var lendingDiv = document.getElementById('lendingDiv');
    var lendingBottomDiv = document.getElementById('lendingBottomDiv');
    lendingDiv.className = 'hidden';
    lendingBottomDiv.className = 'hidden';
    if (currentPage != LENDING_CONSTANT) {
        var lendingButton = document.getElementById('lendingButton');
        lendingButton.className = 'lendingButton lendingButtonOff';
    }
}

function consumerHover()
{
    var consumerButton = document.getElementById('consumerButton');
    var consumerDiv = document.getElementById('consumerDiv');
    consumerButton.className = 'consumerButton consumerButtonOver';
    consumerDiv.className = '';
    var consumerBottomDiv = document.getElementById('consumerBottomDiv');
    if (consumerBottomDiv.className == 'hidden')
    {
        highlight(-1, 'consumer');
        consumerBottomDiv.className = 'noHighlight';
    }
}

function consumerLeave()
{
    // reset row highlight
    highlight(-1, 'consumer'); 
    var consumerDiv = document.getElementById('consumerDiv');
    var consumerBottomDiv = document.getElementById('consumerBottomDiv');
    consumerDiv.className = 'hidden';
    consumerBottomDiv.className = 'hidden';
    if (currentPage != CONSUMER_CONSTANT) {
        var consumerButton = document.getElementById('consumerButton');
        consumerButton.className = 'consumerButton consumerButtonOff';
    }
}

function submitHover(elem)
{
    var loginSubmit = document.getElementById(elem);
    loginSubmit.src = (undefined != imagePath) ? imagePath + 'submitOver.jpg': '/img/submitOver.jpg';
	
}

function submitOut(elem)
{
    var loginSubmit = document.getElementById(elem);
    loginSubmit.src = (undefined != imagePath) ? imagePath + 'submit.jpg' : '/img/submit.jpg';
}

// *** End Main Nav Hover functions ***

// *** Begin Util functions ***
var externalLinkCopy = 'You are now leaving Venture Bank’s website and entering an independent site. Linked sites are not under our control and we are not responsible for the contents of any linked site, any link contained on a linked site, or any changes or updates to the sites. Venture Bank is providing these links to you only as a convenience, and the inclusion of any link does not imply our endorsement of the site. Please be advised that our Privacy Policy does not apply to any linked website. You should consult the Privacy disclosures on any site you visit for specific information about that site’s privacy policy. Thank you for visiting www.venturebankonline.com. We look forward to you visiting our site often.';

function navigateTo(url, newTarget)
{
    if (newTarget)
    {
        if (url.substring(4,0).toLowerCase() == 'http')
        {
            alert(externalLinkCopy);
        }
        window.open(url);
    }
    else
    {
        window.location.href = url;
    }
}

function resizeContent()
{
    // This positions the footer under the content, no matter the length of the content
    var footer = document.getElementById("footerDiv");  
    var leftGlowDiv = document.getElementById("leftGlowDiv");
    var rightGlowDiv = document.getElementById("rightGlowDiv");
    var scroll = document.body.parentNode.scrollHeight;
    if (scroll == 0)
    {
        scroll = document.body.scrollHeight;
    }
    if ( scroll > 775 ) 
    { 
        footer.style.top = scroll + "px"; 
        leftGlowDiv.style.height = scroll + "px";
        rightGlowDiv.style.height = scroll + "px";
    }
}
// *** End Util functions ***

// *** Begin Random Promo Copy functions ***
var copyArray = new Array();
copyArray[0] = '<span class="header">Business Bill Pay</span><ul><li>Bank from anywhere you have internet access</li><li>Eliminate check writing</li><li>Pay anyone: businesses, vendors, or individuals</li><li>Setup email alerts to notify you of upcoming or recently issued payments</li></ul><p><br />Learn more about the convenience of Business Bill Pay <a href="' + applicationPath + 'cashmanagement/electronicpayments/BillPay.aspx">&#62;&#62;&#62;</a></p>';
copyArray[1] = '<span class="header">Consumer Security</span><p>View helpful tips for keeping your identity and account information secure while banking online.</p><p>See how you can help keep your information safe <a href="/SecurityTips.aspx">&#62;&#62;&#62;</a></p>';
copyArray[2] = '<span class="header" style="white-space : nowrap;">Statements on CD-ROM</span><ul><li>Eliminate the need to save volumes of paper statements</li><li>Gain instant access to your monthly statements, credits (deposits), and check images</li></ul><p><br />Convenient, safe and green. Learn more about CD-ROM Statements <a href="' + applicationPath + 'cashmanagement/accountmanagement/StatementsOnCDROM.aspx">&#62;&#62;&#62;</a></p>';
copyArray[3] = '<span class="header">The new Business Resource Center</span><ul><li>Calculate payments with our Loan Calculators</li><li>Download bank forms</li><li>Find useful business links</li><li>Simplify the transition to Venture with business and consumer switch kits</li></ul><br /><p>See what our new Business Resource Center has to offer <a href="' + applicationPath + 'brc/Default.aspx">&#62;&#62;&#62;</a></p>';
// *** End Random Promo Copy functions ***

// *** Begin Contact Us Code ***
function doContactSubmit()
{
    var commentName = document.getElementById('commentName');
    if (commentName.value == '')
    {
        alert('Please enter your name.');
        return false;
    }
    
    var commentTextBox = document.getElementById('commentTextBox');
    var commentDD = document.getElementById('commentCategoryDD');
    if (commentTextBox.value == 'Comments' || commentTextBox.value == '' || commentDD.value == '')
    {
        alert('A comment category must be chosen and text must be entered.');
        return false;
    }
    
    var commentEmail = document.getElementById('commentEmail');
    var commentPhone = document.getElementById('commentPhone');
    
    if (commentEmail.value == '' && commentPhone.value == '')
    {
        alert('Please enter your Email Address');
        return false;
    }
    
    if (!isValidEmail(commentEmail.value))
    {
        alert('Please enter a valid Email Address');
        return false;
    }
    
    return true;
}

function clearCommentText()
{
    var commentTextBox = document.getElementById('commentTextBox');
    if (commentTextBox.value == 'Comments')
    {
        commentTextBox.value = '';
    }
}
// *** End Contact Us Code ***

// *** Begin Login Code ***
function doLoginRefresh()
{
    var loginTo = document.getElementsByName('loginTo');
    var remote = document.forms[0];
    var accessID = document.getElementById('AccessID');
    var nmUID = document.getElementById('nmUID');
    var nmRTN = document.getElementById('nmRTN');
    
    if(loginTo[0].checked == true)
    {
		nmUID.value = accessID.value;
		nmRTN.value = '091017196';          
		remote.action = 'https://www.ecom-venturebankonline.com/EBC_EBC1961/EBC1961.asp?WCI=Process&WCE=RemoteLogon&IRL=T&nmRTN=';
		if (accessID.value != "")
		{
		    setTimeout('document.forms[0].reset()', 200);
		    return true;
		}
	    else
		{
		    alert("\n Please Enter a valid Access ID.  Thank you!"); 
		    return false;
		}	
 	}
    else if(loginTo[1].checked == true)
    {
        remote.action = 'https://www.ecom-venturebankonline.com/PBI_PBI1961/pbi1961.asp?WCI=RemoteLogin&amp;Rt=091017196&amp;LogonBy=Connect3&PRMACCESS=Account';
		if (accessID.value != "")
		{
		    setTimeout('document.forms[0].reset()', 200);
		    return true;
		}
	    else
		{
		    alert("\n Please Enter a valid Access ID.  Thank you!\n\n\t"); 
		    return false;
		}	
 	}
 	else 
 	{
 	    alert("\n Please Select an Account Type.  Thank you!\n\n\t"); 
		return false;
    }
}

function accessIdKeyEvent(e)
{
    if (e.keyCode == 13)
    {
        if (doLoginRefresh()) 
        {
            document.getElementById('formMain').submit(); 
        }
    }
}

var autocomplete = {
    off : function(srcInputID) {
        var tag = document.getElementById(srcInputID);
        if (tag) {
            tag.value = '';
        }
    }
}

// *** End Login Code ***

// *** Begin Calculator Code (ripped from old Venture site)***
function checkNumber(input, min, max, msg)
{   
    msg = msg + " field has invalid data: " + input.value;
    var str = input.value;
    for (var i = 0; i < str.length; i++)
        {   var ch = str.substring(i, i + 1)
            if ((ch < "0" || ch > "9") && ch != '.')
                {   alert(msg);    return false;    }
        }
    var num = parseFloat(str)
    if (num < min || num > max)
        {   alert(msg + " not in the range " + min + " to " + max);
            return false;
        }
    input.value = str;
    return true;
}
function computeField(input)
{   
    if (input.value != null && input.value.length != 0)
    {
        input.value = "" + eval(input.value);
    }
    computeForm();
}
function computeForm()
{   
    var payments = document.getElementById('payments');
    var interest = document.getElementById('interest');
    var principal = document.getElementById('principal');
    var payment = document.getElementById('payment');
    if (payments.value == null ||
        payments.value.length == 0 ||
        interest.value == null ||
        interest.value.length == 0 ||
        principal.value == null ||
        principal.value.length == 0)
    {
        return;
    }
    if (!checkNumber(principal, 100, 9999999, "Principal") ||
        !checkNumber(payments, 1, 480, "Number of Payments") ||
        !checkNumber(interest, .001, 99, "Interest"))
    {
        payment.value = "Invalid";
        return;
    }
    var i = interest.value;
    if (i < 1)
    {   
        i *= 100;    
        interest.value = i;    
    }
    i /= 1200;
    var pow = 1;
    for (var j = 0; j < payments.value; j++)
    {
        pow = pow * (1 + i);
    }
    var monthly = (principal.value * pow * i) / (pow - 1);
    payment.value = Math.ceil(100 * monthly)/100;
}
function clearForm(form)
{   
    form.principal.value = "";
    form.payments.value = "";
    form.interest.value = "";
}
function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function dosum()
{
    var IR = document.getElementById('IR');
    var IB = document.getElementById('IB');
    var FA = document.getElementById('FA');
    var YR = document.getElementById('YR');
    var MC = document.getElementById('MC');
    var FB = document.getElementById('FB');

    var mi = IR.value / 1200;
    var base = IB.value;
    FA.value = "";
    var pp = 0;
    var yr = 0;
    for (i=0; i < YR.value * 12; i++)
    {
        base = base * (1 + mi) + 1 * MC.value;
        pp++;
        if (pp == 12)
        {
            yr++
            if (yr < 10) 
            { 
                sp = " " 
            } 
            else 
            { 
                sp = "" 
            }
            FA.value = FA.value + "\n" + sp + yr + " : " + floor(base)
            pp = 0;
        }
    }
    FB.value = floor(base)
}

// *** End Calculator Code ***

// *** Begin Random Color Bar image code ***
var sidePics = new Array();
sidePics[0] = '01.png';
sidePics[1] = '02.png';
sidePics[2] = '03.png';
sidePics[3] = '04.png';
sidePics[4] = '05.png';
sidePics[5] = '06.png';
sidePics[6] = '07.png';
   
function colorBarRandomImg() 
{ 
    var colorBarBottomDiv = document.getElementById('colorBarBottomDiv');
    if (colorBarBottomDiv)
    {
        var colorChoice = Math.round(Math.random()*(sidePics.length-1));
        var colorImg = document.createElement('img');
        colorImg.src = (undefined != imagePath) ? imagePath + '/side/' + sidePics[colorChoice] : '/img/side/' + sidePics[colorChoice];
        colorBarBottomDiv.appendChild(colorImg);
    }
}
// *** End Random Color Bar image code ***


// Taken from http://en.wikibooks.org/wiki/JavaScript/Best_Practices
function isValidEmail(str) {
  // These comments use the following terms from RFC2822:
  // local-part, domain, domain-literal and dot-atom.
  // Does the address contain a local-part followed an @ followed by a domain?
  // Note the use of lastIndexOf to find the last @ in the address
  // since a valid email address may have a quoted @ in the local-part.
  // Does the domain name have at least two parts, i.e. at least one dot,
  // after the @? If not, is it a domain-literal?
  // This will accept some invalid email addresses
  // BUT it doesn't reject valid ones. 
  var atSym = str.lastIndexOf("@");
  if (atSym < 1) { return false; } // no local-part
  if (atSym == str.length - 1) { return false; } // no domain
  if (atSym > 64) { return false; } // there may only be 64 octets in the local-part
  if (str.length - atSym > 255) { return false; } // there may only be 255 octets in the domain

  // Is the domain plausible?
  var lastDot = str.lastIndexOf(".");
  // Check if it is a dot-atom such as example.com
  if (lastDot > atSym + 1 && lastDot < str.length - 1) { return true; }
  //  Check if could be a domain-literal.
  if (str.charAt(atSym + 1) == '[' &&  str.charAt(str.length - 1) == ']') { return true; }
  return false;
}
