//----- History -------
//	01/21/2006 - added function openItMsg
//
//declare variables
var timer;
var ratestimer;
var ratesindex = 0;
var rateslist  = new Array();
var tickers=getCookie();
if (tickers!="") tickers=tickers.toLowerCase();



//-------------------------------------------------------------------------------------------------
//this function creates the timer such that every
//second the displayTime function is called
function startTime(){
   timer = setInterval("displayTime()",1000);
   displayTime();
}//end startTime



//-------------------------------------------------------------------------------------------------
//this function terminates the timer
function endTime(){
   clearInterval(timer);
}//end endTime



//-------------------------------------------------------------------------------------------------
//this function creates the timer to display the rates
function startRates(){
   ratestimer = setInterval("displayRates()",3500);
   displayRates();
}//end startRates



//-------------------------------------------------------------------------------------------------
//this function terminates the ratestimer
function endRates(){
   clearInterval(ratestimer);
}//end endRates


//-------------------------------------------------------------------------------------------------
//this function simply displays the time; notice that there is no logic
//display a leading zero for hours, minutes or seconds... That is an
//exercise left for another day.
function displayTime(){
   var currentDateTime = new Date();
   var dt;

    if (currentDateTime.getHours()>11) dt = currentDateTime.getHours()-12;
    else dt = currentDateTime.getHours();

    if (dt == 0) dt = "12"
    else if (dt < 10) dt = "0" + dt;

    document.getElementById("digitalclock").innerHTML = dt
        + ":" + (currentDateTime.getMinutes()<10 ? "0"+currentDateTime.getMinutes()   :  currentDateTime.getMinutes() )
        + ":" + (currentDateTime.getSeconds()<10 ? "0"+currentDateTime.getSeconds()   :  currentDateTime.getSeconds() )
        + " " + (currentDateTime.getHours()  >11 ? "<sup style='font-size:10px'>PM</sup>" : "<sup style='font-size:10px'>AM</sup>");
}//end displayTime




//-------------------------------------------------------------------------------------------------
//sets a ticker symbol into a cookie
function addTicker(){
    if (document.getElementById("txtAdd").value.trim()!=''){
        if (tickers.length==0)
            //string is empty; initialize
            tickers=document.getElementById("txtAdd").value;
        else if (tickers.charAt(tickers.length-1)!=',')
            //last character is not a comma; add a comma seperator
            tickers=tickers+','+document.getElementById("txtAdd").value;
        else
            //last character is already a comma; don't add another one
            tickers=tickers+document.getElementById("txtAdd").value;
        setCookie(tickers);
    }else{
        document.getElementById("txtAdd").value='';//clean any white spacing
        document.getElementById("txtAdd").focus();
    }
}//end addTicker



//-------------------------------------------------------------------------------------------------
//removes a ticker symbol
function removeTicker(t){
    var s = t.toLowerCase();
    tickers=tickers.replace(s,'');      //replace the ticker with nothing
    tickers=tickers.replace(',,',',');  //if the ticker was in the center, then remove the duplicate commas

    if (tickers.length>0){      //if the ticker is not empty, check for 1st position comma, or last position comma
        if (tickers.charAt(0)==',')
            //if the 1st character is a comma, then the ticker was at the beginning; remove the initial comma
            tickers=tickers.substring(1,tickers.length);
        else if (tickers.charAt(tickers.length-1)==',')
            //if the last character is a comma, then the ticker was at the end; remove the last comma
            tickers=tickers.substring(0,tickers.length-1);
    }//if tickers.length


    setCookie(tickers);
}//end removeTicker



//-------------------------------------------------------------------------------------------------
//sets the document cookie
function setCookie(s){
    var fiveYears = 5*365*24*60*60*1000;
    var expDate = new Date();

    expDate.setTime (expDate.getTime()+fiveYears);
    document.cookie = 'tickers=' + escape(s) + '; expires=' + expDate.toGMTString();

    //expDate.setTime (expDate.getTime()-fiveYears);
    //document.cookie = 'tickers=' + escape('') + '; expires=' + expDate.toGMTString();
    ;
    location.reload(true);
}//end setCookie



//-------------------------------------------------------------------------------------------------
//getCookie
function getCookie(){
    var c=document.cookie+';'; //always ensure that there's a trailer semi-colon
    var x='tickers=';
    var sStart,sEnd;

    if (c.indexOf(x)==-1) return '';
    sStart=c.indexOf(x)+x.length;
    sEnd  =c.indexOf(';',c.indexOf(x));

    //alert('1\n'+c+'\n'+x);
    //alert('2\n'+c+'\n'+sStart);
    //alert('3\n'+c+'\n'+sEnd);


    return unescape(c.substring(sStart,sEnd));
}//end getCookie





//-------------------------------------------------------------------------------------------------
function open_calendar(){
    var newWindow;
    var urlstring = 'calendar.htm'
    newWindow = window.open(urlstring,'_blank','height=200,width=280,titlebar=no,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no,dependent')
}//end open_calendar

//-------------------------------------------------------------------------------------------------
function openIt(url){
    var newWindow = window.open(url,'_blank')
}//end openIt


//-------------------------------------------------------------------------------------------------
//openItMsg: confirm with the user if it's ok to open url
function openItMsg(url){
    if (confirm('You are about to leave the Lusitania Savings Bank Web Site !\nClick OK to Continue'))
    	var newWindow = window.open(url,'_blank')
}//end openItMsg


//-------------------------------------------------------------------------------------------------
//JavaScript's version of a Trim
String.prototype.trim = function() {
   return this.replace(/(^\s*)|(\s*$)/g, "");
}



//-------------------------------------------------------------------------------------------------
//this function loads a new rate image making it look like the final image is an interleaving gif
//while taking advantage of this timer, cycle home page images
function displayRates(){
    //from html
    //  <imgText:imgText myImgStr="text string" myAlign="center" myW="151" myH="61"  myFontS="18" myFontC="maroon" myFontB="true" myFontI="false" myAlt="CD/IRA Rates" myBrush="background.jpg" runat="server"/>

    //from script
    //  img.imageUrl="imgtext.aspx?s=" & myImgStr & "&a=" & myAlign & "&w=" & myW & "&h=" & myH & "&fs=" & myFontS & "&fc=" & myFontC & "&br=" & myBrush & "&b=" & myFontB & "&i=" & myFontI


    if (rateslist.length>0)
        document.getElementById("imgrates").src='imgtext.aspx?s=' + rateslist[ratesindex++%rateslist.length] +'APY&a=center&w=151&h=61&fs=16&fc=maroon&br=background.jpg&b=true';


    //while using the same timer, cycle the home page main image
    //NOTE: client changed her mind about cycling the credit card image; comment out for now
    if ((ratesindex%4)==0){
        document.getElementById("homeimg").src='branch2h.jpg';
        //document.getElementById("ccimg").src='ccbusiness.gif';
    } else if ((ratesindex%4)==1){
        document.getElementById("homeimg").src='branch3h.jpg';
        //document.getElementById("ccimg").src='ccpersonal.gif';
    } else if ((ratesindex%4)==2){
        document.getElementById("homeimg").src='branch4h.jpg';
        //document.getElementById("ccimg").src='ccbusiness.gif';
    } else {
        document.getElementById("homeimg").src='branch5h.jpg';
        //document.getElementById("ccimg").src='ccpersonal.gif';
    } //end if
}//end displayRates


