/*   Countdown für teppichdeal.de
 *   Endzeit des Deals ist am jeden Montag
 */
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
    theyear=yr; themonth=m; theday=d
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000)
        todayy+=1900
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todayh=today.getHours()
    var todaymin=today.getMinutes()
    var todaysec=today.getSeconds()
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
    futurestring=montharray[m-1]+" "+d+", "+yr
    dd=Date.parse(futurestring)-Date.parse(todaystring)
    dday=Math.floor(dd/(60*60*1000*24)*1)
    dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
    dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
    dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
  
    if(dday < 10) dday = "0" + dday;
    if(dhour < 10) dhour = "0" + dhour;
    if(dmin < 10) dmin = "0" + dmin;
    if(dsec < 10) dsec = "0" + dsec;
  
    if(dday < 2) { 
        dayLabel = "Tag" 
    } else {
        dayLabel = "Tage" 
    }				
    document.getElementById('countdown').innerHTML = " "+dday+" : "+dhour+" : "+dmin+" : "+dsec+" ";    
    document.getElementById('timetext').innerHTML = " "+dayLabel+" Std. Min. Sek. ";
    setTimeout("countdown(theyear,themonth,theday)",1000)
   
}

// TT - Begin
actualDateTime = new Date(); // aktueller Datum und Uhr Zeit           
actualWeekday = actualDateTime.getDay(); // aktueller Wochentag 
if (actualWeekday == 0) { 
    actualWeekday = 7;
}
else if (actualWeekday == 1) {
    actualWeekday = 8;
}
            
// ******** countdown - Finde nächsten Dienstags ********
diffTag = 9 - actualWeekday;  
nextTuesday = new Date(new Date().getTime() + (diffTag*24*60*60*1000)); // Ergebnis: Datum des nächsten Dienstags für countdown

// Datum im Format Y.m.d
monthTue = nextTuesday.getMonth()+1;
yearTue = nextTuesday.getYear();
dayTue = nextTuesday.getDate();
if(dayTue < 10) dayTue = "0" + dayTue;
if(monthTue < 10) monthTue = "0" + monthTue;
if(yearTue < 1000) yearTue+=1900;

//nextTueFormat = yearTue + "," + monthTue + "," + dayTue;
//alert("Nächster Dienstag ist =   "+nextTueFormat);       

// ******** Datum von-bis - Finde nächsten Montag ********  
diffNextMonday = diffTag - 1;
nextMonday = new Date(new Date().getTime() + (diffNextMonday*24*60*60*1000)); // Ergebnis: Datum des nächsten Montags             
thisMonday = new Date(new Date().getTime() + ((diffNextMonday-6)*24*60*60*1000)); // Ergebnis: Datum des diesen Montags             

// Datum im Format d.m.Y
monthNextMon = nextMonday.getMonth()+1;
yearNextMon = nextMonday.getYear();
dayNextMon = nextMonday.getDate();
if(dayNextMon < 10) dayNextMon = "0" + dayNextMon;
if(monthNextMon < 10) monthNextMon = "0" + monthNextMon;
if(yearNextMon < 1000) yearNextMon+=1900;
nextMonFormat = dayNextMon + "." + monthNextMon + "." + yearNextMon;
//alert("  ++ Nächster Montag ist =   "+nextMonFormat); 

// Datum im Format d.m.Y
monthThisMon = thisMonday.getMonth()+1;
yearThisMon = thisMonday.getYear();
dayThisMon = thisMonday.getDate();
if(dayThisMon < 10) dayThisMon = "0" + dayThisMon;
if(monthThisMon < 10) monthThisMon = "0" + monthThisMon;
if(yearThisMon < 1000) yearThisMon+=1900;
thisMonFormat = dayThisMon + "." + monthThisMon + "." + yearThisMon;
//alert("  -- Dieser Montag ist =   "+thisMonFormat);
document.getElementById('dateFromTo').innerHTML = " "+thisMonFormat+" - "+nextMonFormat+" ";
//document.getElementById('jsToDate').innerHTML = " "+nextMonFormat;
// TT End 

//enter the count down date using the format year/month/day
//countdown(2012,1,1)
countdown(yearTue,monthTue,dayTue)
