/*Example message arrays for the two demo scrollers*/

var pausecontent=new Array()
pausecontent[0]='<font color="maroon"><u>Love The Way You Play:</u></font><br />A Jim James original captured live at a Camden Library gig with Jim on vocals/Guitar & harmonica, David Dodson on guitar and Dan Wilson on Bass.'
pausecontent[1]='<font color="maroon"><u>Out With a Bang:</u></font><br />From the same session with a favorite song from the late John B. Spencer from London.'

var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.news.com" target="_blank">News.com: Technology and business reports</a>'
pausecontent2[1]='<a href="http://www.cnn.com" target="_blank">CNN: Headline and breaking news 24/7</a>'
pausecontent2[2]='<a href="http://news.bbc.co.uk" target="_blank">BBC News: UK and international news</a>'
pausecontent2[3]='<a href="http://news.cnet.com/" target="_blank">CNET: Technology News headlines</a>'
pausecontent2[4]='<a href="http://www.technewsworld.com/" target="_blank">Tech News World: All Tech - All the time</a>'
pausecontent2[5]='<a href="http://www.businessweek.com/technology/" target="_blank">Technology News: BusinessWeek</a>'
pausecontent2[6]='<a href="http://www.wired.com/" target="_blank">Wired: Technology Magazine</a>'
pausecontent2[7]='<a href="News.html">The Good Web news</a>'


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

function breadCrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) { // by Paul Davis - http://www.kaosweaver.com
loc=window.location.toString();subs=loc.substr(loc.indexOf(base)+base.length+1).split("/");
 document.write('<a href="'+getLoc(subs.length-1)+defp+'" class="'+cStyle+'">Home</a>  '+'<span class="'+dStyle+'">'+delStr+'</span> ');
 a=(loc.indexOf(defp)==-1)?1:2;for (i=0;i<(subs.length-a);i++) { subs[i]=makeCaps(unescape(subs[i]));
 document.write('<a href="'+getLoc(subs.length-i-2)+defp+'" class="'+cStyle+'">'+subs[i]+'</a>  '+'<span class="'+dStyle+'">'+delStr+'</span> ');}
 if (nl==1) document.write("<br>");document.write('<span class="'+tStyle+'">'+document.title+'</span>');
}
function makeCaps(a) {
  g=a.split(' ');for (l=0;l<g.length;l++) g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
  return g.join(" ");
}
function getLoc(c) {
  var d="";if (c>0) for (k=0;k<c;k++) d=d+"../"; return d;
}

// expects an input element
// throws a string exception that must be caught and should be alerted.
// ielem is required.
function ValidateDate(ielem)
{
   var maxdaysinmonth        = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
   var input_date         = ielem.value;
   var min_date           = "";
   var max_date           = "";
   var slash1             = -1;
   var slash2             = -1;
   var n_month            = 0;
   var n_day              = 0;
   var n_year             = 0;
   var str_day            = "";
   var str_month          = "";
   var str_year           = "";
   var slash_count        = 0;
   var msg                = "";
   var date_format        = "mm/dd/yyyy";
   
   // validate the input date
   if (!input_date)
   {
       msg = "You must enter a Date. (format = mm/dd/yyyy)";
       throw new String("PA_DateErr" + msg);
   }

   // check for chars other than numerics or slashes
   for(var i = 0; i < input_date.length; i++)
   {
       if ((input_date.substr(i,1) < "0" || input_date.substr(i,1) > "9") &&
            input_date.substr(i,1) != "/")
           break;
       else
           if (input_date.substr(i,1) == "/")
               slash_count++;
   }

   if (input_date.length != i || slash_count > 2)
   {
       msg = "Malformed Date\nA valid date has " + date_format + " format.";
       throw new String("Error: " + msg);
   }

   if (input_date.length < 8 || input_date.length > 10)
   {
       if (input_date.length < 8)
           msg = "Short form not valid.\nA valid date has " + date_format + " format.";
         //  alert("You cannot use short date format for Date.");
       else
           msg = "Too many Characters for "+ date_format + " format.";

       throw new String("Error: " + msg);
   }

    slash1 = input_date.indexOf("/",0);
    if (slash1 < input_date.length -1 )
    {
        slash2 = input_date.indexOf("/",slash1 + 1);
    }

    // break date into components
   if ( slash1 == -1 && slash2 == -1 && input_date.length == 8)
   {
       str_month   = input_date.substr(0,2);
       str_day = input_date.substr(2,2);
       str_year  = input_date.substr(4,4);
   }
   else
       if (slash1 == 2 && slash2 == 5 ||
           slash1 == 1 && slash2 == 3 ||
           slash1 == 2 && slash2 == 4 ||
           slash1 == 1 && slash2 == 4 )
       {
       	   str_month   = input_date.substr(0,slash1);
       	   str_day     = input_date.substr(slash1 +1, slash2);
       	   str_year    = input_date.substr(slash2 + 1, input_date.length - (slash2 + 1));
       	   if(str_year.length != 4)
       	   {
       	      msg = "A valid year has four digits (mm/dd/YYYY).";
       	      throw new String(msg);
       	   }
       }
       else
       {
       	   msg = "A valid date has " + date_format + " format.";
       	   throw new String(msg);
       }

   // make sure these components are really numeric
   if (isNaN(n_day = parseInt(str_day, 10)) ||
       isNaN(n_month = parseInt(str_month, 10)) ||
       isNaN(n_year = parseInt(str_year, 10)) )
   {
       msg = "Month, day and year must all be numeric";
       throw new String("Error: " + msg);
   }

   // validate year ???

   //validate the month range
   if (n_month > 12 || n_month < 1 )
   {
       msg = "Date is incorrect, month may be mis-typed.\nPlease ensure date is in (mm/dd/yyyy) format.";
       throw new String("Error: " + msg);
   }

   // validate the day range
   if (n_day > maxdaysinmonth[n_month] || n_day < 1)
   {
       msg = "Date is incorrect, day may be mis-typed.\nPlease ensure date is in (mm/dd/yyyy) format.";
       throw new String("Error: " + msg);
   }

   // check leap year calculation
   if (n_month == 2 && n_day == 29)
   {
      if((n_year % 4) != 0  ||  (n_year % 4) == 0 && (n_year % 100) == 0 && (n_year % 400) != 0)
         throw new String("Error: " + n_year + " has only 28 days in February");
   }

   // rebuild the ielem.value
   str_year = "" + n_year;
   if(n_month < 10)
      str_month = "" + "0" + n_month;
   else
      str_month = "" + n_month;

   if(n_day < 10)
      str_day = "" + "0" + n_day;
   else
      str_day = "" + n_day;

   ielem.value = "" + str_month + "/" + str_day + "/" + str_year;
   return 0;
}

function convertFieldDateString(arg)
{// takes a string date in mm/dd/ccyy and returns ccyymmdd
   //alert(arg);
   var str = arg.substr(6,4) + arg.substr(0,2) + arg.substr(3,2);
   return str;

}
