function countdown()
{
    this.teefurypage = "/pages/teefury.html";
    this.teefurytime = "23:00:00";
    this.teefurythumbdiv = "teefuryblock";
    this.teefuryclock = "teefuryclock";

    this.wootpage = "/pages/shirtwoot.html";
    this.woottime = "00:00:00";
    this.wootthumbdiv = "wootblock";
    this.wootclock = "wootclock";

    this.riptpage = "/pages/ript.html";
    this.ripttime = "00:00:00";
    this.riptthumbdiv = "riptblock";
    this.riptclock = "riptclock";

    this.squidinkpage = "/pages/5quidink.html";
    this.squidinktime = "01:00:00";
    this.squidinkoverlap = 3600;
    this.squidinkthumbdiv = "5quidinkblock";
    this.squidinkclock = "5quidinkclock";

    this.uneeteepage = "/pages/uneetee.html";
    this.uneeteetime = "02:03:00";
    this.uneeteethumbdiv = "uneeteeblock";
    this.uneeteeclock = "uneeteeclock";

    this.shirtadaypage = "/pages/shirtaday.html";
    this.shirtadaytime = "00:00:00";
    this.shirtadaythumbdiv = "shirtadayblock";
    this.shirtadayclock = "shirtadayclock";

    this.stupidpage = "/pages/stupid.html";
    this.stupidtime = "02:00:00";
    this.stupidthumbdiv = "stupidblock";
    this.stupidclock = "stupidclock";

    this.dbhpage = "/pages/dbh.html";
    this.dbhtime = "02:01:00";
    this.dbhoverlap = 7260;
    this.dbhthumbdiv = "dbhblock";
    this.dbhclock = "dbhclock";

    this.DisplayFormat	= "%%H%%:%%M%%:%%S%%";

    this.teefurysecs = 0;
    this.wootsecs = 0;
    this.riptsecs = 0;
    this.squidinksecs = 0;
    this.uneeteesecs = 0;
    this.shirtadaysecs = 0;
    this.dbhsecs = 0;
    this.stupidsecs = 0;

    this.Calcage		= cd_Calcage;
    this.CountBack		= cd_CountBack;

    this.Running = false;
   
    this.dayofweek = 0;

    this.DisplayStr;
}

function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && ( s[l] == ' ' || s[l] == '\n' || s[l] == '\r' || s[l] == '\t' ) )
    {     l++; }
    while(r > l && ( s[r] == ' ' || s[r] == '\n' || s[r] == '\r' || s[r] == '\t' ) )
    {     r-=1;     }
    return s.substring(l, r+1);
} 

function cd_Calcage(secs, num1, num2, add1)
{
  s = (((Math.floor(secs/num1))%num2)+add1).toString();
  if (s.length < 2) s = "0" + s;
  return (s);
}
function cd_CountBack()
{
    if( this.teefurysecs % 60 == 0 )
    {    
        if (http)
        {
            var myurl = 'http://www.teemagnet.com/scripts/gettimeXML.php';
            myRand = parseInt(Math.random()*999999999999999);
            var modurl = myurl+"?rand="+myRand;
            http.open("POST", modurl, true);

            http.onreadystatechange = function (aEvt) 
            {
    	        if(http.readyState == 4)
                {
                    if(http.status == 200) 
                    {
            var timeValue = http.responseXML.getElementsByTagName("timenow")[0];

            var tomorrow = http.responseXML.getElementsByTagName("tomorrow")[0].childNodes[0].nodeValue;

      	    var dnow = new Date(timeValue.childNodes[0].nodeValue);
            var dthen = new Date(tomorrow + " " + my_timer.teefurytime );
            var ddiff = new Date(dthen-dnow);
	    my_timer.teefurysecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.woottime );
            ddiff = new Date(dthen-dnow);
	    my_timer.wootsecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.ripttime );
            ddiff = new Date(dthen-dnow);
	    my_timer.riptsecs = Math.floor(ddiff.valueOf()/1000);


            dthen = new Date(tomorrow + " " + my_timer.uneeteetime );
            ddiff = new Date(dthen-dnow);
	    my_timer.uneeteesecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.shirtadaytime );
            ddiff = new Date(dthen-dnow);
	    my_timer.shirtadaysecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.squidinktime );
            ddiff = new Date(dthen-dnow);
	    my_timer.squidinksecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.dbhtime );
            ddiff = new Date(dthen-dnow);
	    my_timer.dbhsecs = Math.floor(ddiff.valueOf()/1000);

            dthen = new Date(tomorrow + " " + my_timer.stupidtime );
            ddiff = new Date(dthen-dnow);
	    my_timer.stupidsecs = Math.floor(ddiff.valueOf()/1000);


    my_timer.dayofweek = http.responseXML.getElementsByTagName("dayofweek")[0].childNodes[0].nodeValue;

           UpdatePage( my_timer.teefurysecs%86400, my_timer.teefurypage, 
                           my_timer.teefurythumbdiv, false, false );

            UpdatePage( my_timer.wootsecs%86400, my_timer.wootpage, 
                           my_timer.wootthumbdiv, false, false );

            UpdatePage( my_timer.riptsecs%86400, my_timer.riptpage, 
                           my_timer.riptthumbdiv, false, false );

            UpdatePage( my_timer.squidinksecs%86400, my_timer.squidinkpage, 
                           my_timer.squidinkthumbdiv, true, false );

            UpdatePage( my_timer.uneeteesecs%86400, my_timer.uneeteepage, 
                           my_timer.uneeteethumbdiv, false, false );

            UpdatePage( my_timer.shirtadaysecs%86400, my_timer.shirtadaypage, 
                           my_timer.shirtadaythumbdiv, false, false );

            UpdatePage( my_timer.dbhsecs%86400, my_timer.dbhpage, 
                           my_timer.dbhthumbdiv, false, true );

            UpdatePage( my_timer.stupidsecs%86400, my_timer.stupidpage, 
                           my_timer.stupidthumbdiv, false, false );


            my_timer.Running = true;


                    }
                }
	    };
            http.send(null);
	}
    }

if( my_timer.Running )
{
    this.teefurysecs--;
    this.wootsecs--;
    this.riptsecs--;
    this.squidinksecs--;
    this.uneeteesecs--;
    this.shirtadaysecs--; 
    this.dbhsecs--; 
    this.stupidsecs--; 

           UpdatePage( my_timer.teefurysecs%86400, my_timer.teefurypage, 
                           my_timer.teefurythumbdiv, false, false );

            UpdatePage( my_timer.wootsecs%86400, my_timer.wootpage, 
                           my_timer.wootthumbdiv, false, false );

            UpdatePage( my_timer.riptsecs%86400, my_timer.riptpage, 
                           my_timer.riptthumbdiv, false, false );

            UpdatePage( my_timer.squidinksecs%86400, my_timer.squidinkpage, 
                           my_timer.squidinkthumbdiv, true, false );

            UpdatePage( my_timer.uneeteesecs%86400, my_timer.uneeteepage, 
                           my_timer.uneeteethumbdiv, false, false );

            UpdatePage( my_timer.shirtadaysecs%86400, my_timer.shirtadaypage, 
                           my_timer.shirtadaythumbdiv, false, false );

            UpdatePage( my_timer.stupidsecs%86400, my_timer.stupidpage, 
                           my_timer.stupidthumbdiv, false, false );


            UpdatePage( my_timer.dbhsecs%86400, my_timer.dbhpage, 
                           my_timer.dbhthumbdiv, false, true );


//--------------
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.teefurysecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.teefurysecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.teefurysecs,1,60,0));
       document.getElementById(this.teefuryclock).innerHTML = this.DisplayStr;
//--------------
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.wootsecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.wootsecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.wootsecs,1,60,0));
       document.getElementById(this.wootclock).innerHTML = this.DisplayStr;
//--------------
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.riptsecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.riptsecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.riptsecs,1,60,0));
       document.getElementById(this.riptclock).innerHTML = this.DisplayStr;

//--------------
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.uneeteesecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.uneeteesecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.uneeteesecs,1,60,0));
       document.getElementById(this.uneeteeclock).innerHTML = this.DisplayStr;
//--------------
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.shirtadaysecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.shirtadaysecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.shirtadaysecs,1,60,0));

       document.getElementById(this.shirtadayclock).innerHTML = this.DisplayStr;

//--------------   
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.squidinksecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.squidinksecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.squidinksecs,1,60,0));

       document.getElementById(this.squidinkclock).innerHTML = this.DisplayStr;

//--------------   
/*

    var tmp = this.squidinksecs%86400;


//    if( (my_timer.dayofweek == 7 || my_timer.dayofweek == 0) )
//    {
//       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
//            this.Calcage(this.squidinksecs,3600,24,24));
//    }
//    else 
    if( my_timer.dayofweek == 6 )
    {
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.squidinksecs,3600,24,24));
    }
    else
    {
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.squidinksecs,3600,24,0));
    }
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.squidinksecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.squidinksecs,1,60,0));
       document.getElementById(this.squidinkclock).innerHTML = this.DisplayStr;
//--------------
*/            
    tmp = this.dbhsecs%86400;

    if( (my_timer.dayofweek == 7 || my_timer.dayofweek == 0) && tmp < this.dbhoverlap)
    {
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.dbhsecs,3600,24,24));
    }
    else if( my_timer.dayofweek == 6 && tmp > this.dbhoverlap)
    {
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.dbhsecs,3600,24,24));
    }
    else
    {
       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.dbhsecs,3600,24,0));
    }

       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.dbhsecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.dbhsecs,1,60,0));
       document.getElementById(this.dbhclock).innerHTML = this.DisplayStr;


//--------------

       this.DisplayStr = this.DisplayFormat.replace(/%%H%%/g,		
            this.Calcage(this.stupidsecs,3600,24,0));
       this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		
            this.Calcage(this.stupidsecs,60,60,0));
       this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		
            this.Calcage(this.stupidsecs,1,60,0));
       document.getElementById(this.stupidclock).innerHTML = this.DisplayStr;

}
  setTimeout("my_timer.CountBack()", 1000);
}


function UpdatePage(secs, page, div, squidink, dbh)
{
//            if( ! my_timer.Running || secs%60 == 0 )
            if( ! my_timer.Running || ( ( secs > 85800 || secs < 600 ) && secs%60 == 0 ) )
            {


/*
   if( squidink )
   {
       if( my_timer.dayofweek == 7 || my_timer.dayofweek == 0 )
       {
           page = "/pages/no5quidink.html";
       }
       else if( my_timer.dayofweek == 6 )
       {
           page = "/pages/no5quidink.html";
       }
   }
*/
   if( dbh )
   {
       if( my_timer.dayofweek == 7 || my_timer.dayofweek == 0 )
       {
           page = "/pages/nodbh.html";
       }
       else if( my_timer.dayofweek == 6 && 
                     secs > my_timer.dbhoverlap )
       {
           page = "/pages/nodbh.html";
       }
       else if( my_timer.dayofweek == 1 && 
                     secs < my_timer.dbhoverlap )
       {
           page = "/pages/nodbh.html";
       }
   }


               var myXMLHttpRequest = GET_XMLHTTPRequest();
    
               if (myXMLHttpRequest)
               {
                   var myurl = page;
                   myRand = parseInt(Math.random()*999999999999999);
                   var modurl = myurl+"?rand="+myRand;
                   myXMLHttpRequest.open("POST", modurl, true);
                   myXMLHttpRequest.onreadystatechange = function (aEvt) 
                   {
               	    if(myXMLHttpRequest.readyState == 4)
                       {
        	    document.getElementById(div).innerHTML = 
myXMLHttpRequest.responseText;
                       }
              	   };
                   myXMLHttpRequest.send(null);
               }

if( dbh )
{
               var myXMLHttpRequest2 = GET_XMLHTTPRequest();
    
               if (myXMLHttpRequest2)
               {
                   var myurl = '/pages/dbh_price.html';
                   myRand = parseInt(Math.random()*999999999999999);
                   var modurl = myurl+"?rand="+myRand;
                   myXMLHttpRequest2.open("POST", modurl, true);
                   myXMLHttpRequest2.onreadystatechange = function (aEvt) 
                   {
               	    if(myXMLHttpRequest2.readyState == 4)
                       {
        	    document.getElementById("dbhpriceblock").innerHTML = 
myXMLHttpRequest2.responseText;
                       }
              	   };
                   myXMLHttpRequest2.send(null);
               }
}
            }
}
