﻿// JScript File

var theSignInState=0;

function toggleSignIn(theState){
    theSignInState=theState;
    var theBox = document.getElementById('signInBox');
    if (theSignInState==0) {
        theBox.style.display="block";
        document.getElementById('username').select();
        theSignInState=1;
    } else if (theSignInState==1){
        theBox.style.display="none";
    }
}
function alertTargetedLinks() {
    if (document.getElementById("heroContainer")) {
        initHero();
    }
    var allLinks=document.getElementsByTagName('a');
    for (inc=0; inc<allLinks.length; inc++){
        if (allLinks[inc].target!=null){
            if (allLinks[inc].target!="" && allLinks[inc].target!="_self" && allLinks[inc].target!="LocalLink"){
                allLinks[inc].onclick=function() {alert('You are leaving the Skagit State Bank website for this request.')};
            }
        }
    }
}

function cancelSignIn(){
    document.getElementById('username').value="User ID";
    document.getElementById('userPassword').value="password";
    document.getElementById('personalLogin').checked=false;
    document.getElementById('businessLogin').checked=false;
    toggleSignIn(1);
}

function submitSignIn(){
    if (document.getElementById('username').value=="User ID") {
        alert("Please use a valid User ID.");
    } else if (document.getElementById('userPassword').value==""){
        alert("Please use a valid password.");
    } else if (document.getElementById('personalLogin').checked==false && document.getElementById('businessLogin').checked==false){
        alert("Please select your account type.");
    } else{
        document.forms[0].action="";
        document.forms[0].submit();
    }
}
    

// Edit Tabs
    function showTab(theAnchor){
        var theAnchors = document.getElementById('theFolderTabs').getElementsByTagName('a');
        var theTDs = document.getElementById('theTabsContainer').getElementsByTagName('td');
        var theTabs= new Array();
        for (y=0; y<theTDs.length; y++){
            if (theTDs[y].id.indexOf("Tab")!=-1){
                theTabs.push(theTDs[y]);
            }
        }
        for (x=0; x<theAnchors.length; x++){
            if (theAnchor==theAnchors[x]){
                theAnchors[x].className="on";
                theTabs[x].style.display="block";
            } else {
                theAnchors[x].className="";
                theTabs[x].style.display="none";
            }
        }
    }

    var fadeElement;
    var theTabsToFade;
    var upFadeOpacity = 0;
    var downFadeOpacity = 100;
    var crossFadeTimer;
    var crossFadeInc = 20;
    var theCurrentAnchor;
    var play = 1;
    var theTimer;
    var slideDuration=5000;

    function togglePlay(){
        if (play == 0 ){
            document.getElementById('playPause').innerHTML="<div class='playOff'></div>";
            window.clearTimeout(theTimer);
            play=1;
        } else {
            nextTourPane();
            document.getElementById('playPause').innerHTML="<div class='playOn'></div>";
            theTimer=window.setTimeout("nextTourPane()", slideDuration);
            play=0;
        }    
    }
    
    function initTour(){
        theCurrentAnchor=document.getElementById('theClientTourTabs').getElementsByTagName('a')[0];
        //theTimer=window.setTimeout("nextTourPane()", slideDuration);

    }
    
    function nextTourPane(){
        if (theTimer){
            window.clearTimeout(theTimer);
        }
        theAnchors = document.getElementById(theCurrentAnchor.parentNode.id).getElementsByTagName('a');
        for (x=0; x<theAnchors.length; x++){
            if (theAnchors[x].id.indexOf('playPause')==-1 && theAnchors[x].id.indexOf('next')==-1 && theAnchors[x].id.indexOf('previous')==-1){
                if (theCurrentAnchor==theAnchors[x]){
                    if (x+1<theAnchors.length-3){
                        showClientTab(theAnchors[x+1]);
                    } else {
                        showClientTab(theAnchors[0]);
                    }
                    break;
                }
            }
        }
        if (play==0){
            theTimer=window.setTimeout("nextTourPane()", slideDuration);
        }
    }
    function previousTourPane(){
        if (theTimer){
            window.clearTimeout(theTimer);
        }
        theAnchors = document.getElementById(theCurrentAnchor.parentNode.id).getElementsByTagName('a');
        for (x=0; x<theAnchors.length; x++){
            if (theAnchors[x].id.indexOf('playPause')==-1 && theAnchors[x].id.indexOf('next')==-1 && theAnchors[x].id.indexOf('previous')==-1){
                if (theCurrentAnchor==theAnchors[x]){
                    if (x==0){
                        showClientTab(theAnchors[theAnchors.length-4]);
                    } else {
                        showClientTab(theAnchors[x-1]);
                    }
                    break;
                }
            }
        }
        if (play==0){
            theTimer=window.setTimeout("nextTourPane()", slideDuration);
        }
    }
    
    function showClientTab(theAnchor){
        if (!crossFadeTimer) {
            var theAnchors = document.getElementById(theAnchor.parentNode.id).getElementsByTagName('a');
            theCurrentAnchor=theAnchor;
            var theTDs = document.getElementById(theAnchor.parentNode.nextSibling.id).getElementsByTagName('td');
            var theTabs= new Array();
            for (y=0; y<theTDs.length; y++){
                if (theTDs[y].id.indexOf("Tab")!=-1){
                    theTabs.push(theTDs[y]);
                }
            }
            for (x=0; x<theAnchors.length; x++){
                if (theAnchors[x].id.indexOf('playPause')==-1 && theAnchors[x].id.indexOf('next')==-1 && theAnchors[x].id.indexOf('previous')==-1){
                    if (theAnchor==theAnchors[x]){
                        theAnchors[x].className="on";
                        theTabs[x].style.display="block";
                        var theInput = theTabs[x].getElementsByTagName('input');
                        fadeElement=theTabs[x];
                        
                    } else {
                        theAnchors[x].className="";
                        //theTabs[x].style.display="none";
                    }
                }
            }
            theTabsToFade=theTabs;
            crossFadeTabs();
       }
    }
    
    function crossFadeTabs(){
        if (crossFadeTimer) {
            window.clearTimeout(crossFadeTimer);
        }
        if (upFadeOpacity <= 100){
            for (x=0; x<theTabsToFade.length; x++){
                if (theTabsToFade[x]==fadeElement){
                    //fadeElement.style.display="block";
                    if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4) {
                        fadeElement.filters.alpha.opacity=upFadeOpacity;
                    } else {
                        fadeElement.style.opacity=upFadeOpacity/100;
                    }
                } else if (theTabsToFade[x].src!=""){
                    if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4 && theTabsToFade[x].filters.alpha.opacity!=0) {
                        theTabsToFade[x].filters.alpha.opacity=downFadeOpacity;
                    } else if (theTabsToFade[x].style.opacity!=0){
                        theTabsToFade[x].style.opacity=downFadeOpacity/100;
                    }
                    if (downFadeOpacity==0){
                            theTabsToFade[x].style.display="none";
                    }
                }
            }
            upFadeOpacity=upFadeOpacity + crossFadeInc;
            downFadeOpacity=downFadeOpacity - crossFadeInc;
            crossFadeTimer=window.setTimeout("crossFadeTabs()", 100);
        } else {
            if (fadeElement.getElementsByTagName('input')[0]){
                fadeElement.getElementsByTagName('input')[0].focus();
            }
            upFadeOpacity = 0;
            downFadeOpacity = 100;
            window.clearTimeout(crossFadeTimer);
            crossFadeTimer=null;
        }
    }
