function ElapsedTime(inFromDate,inToDate) { 
var inFromDate = (arguments.length == 0) ? new Date() : arguments[0]; 
var inToDate = (arguments.length == 1) ? new Date() : arguments[1]; 

// if (arguments.length == 0) var inFromDate = new Date(); // IE4 has a bug in constructors, 
// if (arguments.length == 1) var inToDate = new Date(); // so use above method. 

var fromDate = new Date(inFromDate); 
var toDate = new Date(inToDate); 

var tempDate = new Date(); 
if (fromDate.getTime() > toDate.getTime()) { 
tempDate = new Date(fromDate); 
fromDate = new Date(toDate); 
toDate = new Date(tempDate); 
} 
var totMonths = 12*toDate.getFullYear() + toDate.getMonth() + 
-12*fromDate.getFullYear() - fromDate.getMonth() 
var years = Math.floor(totMonths / 12) 
var months = totMonths - 12*years 
if (dateAsNumber(toDate,"D") < dateAsNumber(fromDate,"D")) months -= 1 
if (months < 0) { 
months = 0 
if (years > 0) years -= 1 
} 

var yearsOff = years + fromDate.getFullYear() 
var monthsOff = months + fromDate.getMonth() 
if (monthsOff >= 12) { 
monthsOff -= 12 
yearsOff += 1 
} 
var tempDate = new Date(fromDate); 
tempDate.setFullYear(yearsOff); 
tempDate.setMonth(monthsOff); // might push us into early next month, so... 
while (tempDate.getDate() < fromDate.getDate() && tempDate.getDate() < 9 ) 
tempDate.setTime(tempDate.getTime() - 1000*60*60*24); // Feb 29 etc. 

var milliSecs = toDate.getTime() - tempDate.getTime(); 
var oneSecond = 1000; 
var oneMinute = 60 * 1000; 
var oneHour = 60 * oneMinute; 
var oneDay = 24 * oneHour; 
var oneWeek = 7 * oneDay; 
var weeks = Math.floor(milliSecs / oneWeek); 
//milliSecs -= weeks * oneWeek; 
var days = Math.floor(milliSecs / oneDay); 
milliSecs -= days * oneDay; 
var hours = Math.floor(milliSecs / oneHour); 
milliSecs -= hours * oneHour; 
var minutes = Math.floor(milliSecs / oneMinute); 
milliSecs -= minutes * oneMinute; 
var seconds = Math.floor(milliSecs / oneSecond); 

/*var timeValue = "I am "; 
if (years) timeValue += years + ((years==1) ? " year, " : " years, "); 
if (months) timeValue += months + ((months==1) ? " month, " : " months, "); 
if (weeks) timeValue += weeks + ((weeks==1) ? " week, " : " weeks, "); 
if (days) timeValue += days + ((days==1) ? " day, " : " days, "); 
var timeValueDays = timeValue.substring(0 , timeValue.length - 2); 
timeValue += hours + ((hours==1) ? " hour, " :" hours, "); 
timeValue += minutes + ((minutes==1) ? " minute, and " : " minutes, and "); 
timeValue += seconds + ((seconds==1) ? " second old." : " seconds old.");*/

var timeValue = "ด.ญ.ณัฏฐนิตา สุรเดช | ชื่อเล่น นิต้า | อายุ "; 
if (years) timeValue += years + ((years==1) ? " ปี, " : " ปี, "); 
if (months) timeValue += months + ((months==1) ? " เดือน, " : " เดือน, "); 
//if (weeks) timeValue += weeks + ((weeks==1) ? " สัปดาห์, " : " สัปดาห์, "); 
if (days) timeValue += days + ((days==1) ? " วัน, " : " วัน, "); 
var timeValueDays = timeValue.substring(0 , timeValue.length - 2); 
timeValue += hours + ((hours==1) ? " ชั่วโมง, " :" ชั่วโมง, "); 
timeValue += minutes + ((minutes==1) ? " นาที, " : " นาที, "); 
timeValue += seconds + ((seconds==1) ? " วินาที ค่ะ" : " วินาที ค่ะ"); 

this.years = years; 
this.months = months; 
this.weeks = weeks; 
this.days = days; 
this.hours = hours; 
this.minutes = minutes; 
this.seconds = seconds; 
this.text = timeValue; 
this.textDays = timeValueDays; 
} 

function dateAsNumber(inDate,inWhat) { 
var what = "", yearBit = 0, monthBit = 0 
if (typeof(inWhat) == "undefined" || inWhat.toString() == "" || inWhat.toString() == null) inWhat = "" 
what = inWhat.toString().toUpperCase() 
if (what != "M" && what != "D") // we want yyyy bit 
yearBit = inDate.getFullYear() * Math.pow(10,13); 
if (what != "D") // we want month bit 
monthBit = inDate.getMonth() * Math.pow(10,11); 
return yearBit + 
monthBit + 
inDate.getDate() * Math.pow(10,09) + 
inDate.getHours() * Math.pow(10,07) +
inDate.getMinutes() * Math.pow(10,05) + 
inDate.getSeconds() * Math.pow(10,03) + 
inDate.getMilliseconds() 
} 

//  *****  SET the DATE and TIME HERE  ***** 
//  ( Remembering that in Java Dates, 
//       months go from 0 (Jan) to 11 (Dec) ) 

function ageClock() { 
var leaveDate = new Date(2007,10,01,22,22) // 1 พฤศจิกายน 2007 22:22 
var now = new Date(); 
var elapsed = new ElapsedTime(leaveDate,now);
return elapsed.text;
}

function getElement(id) {
return document.all ? document.all(id) : 
document.getElementById ? document.getElementById(id) :
document.layers ? document.layers[id] : 
null;
}

function centerShowIt(id) {
var winMid, aD = getElement('ageDisplay');
if (!aD) return;
if (window.innerWidth) winMid = innerWidth/2;
else if (document.body) winMid = document.body.clientWidth/2;
if (!document.layers) {
aD.style.left = winMid - aD.offsetWidth/2;
aD.style.visibility = 'visible';
} else {
aD.pageX = winMid - aD.clip.width/2;
aD.visibility = 'show';
}
}

function update() {
var text = ageClock();
var aD = getElement('ageDisplay');
if (!aD) return;
if (!document.layers) {
aD.innerHTML = text + ' ';
} else {
aD.document.write('<SPAN class="bodytext">' + text + ';</SPAN>');
aD.document.close();
}
setTimeout('update()',1000);
}

/* NS4 resize bug fix from webreference.com */
if (document.layers) {
origWidth = innerWidth;
origHeight = innerHeight;
}
if (document.layers) window.onresize = function() {
               if (innerWidth != origWidth || innerHeight != origHeight) 
               location.reload();
}
/********************************************/

window.onload = update;
