var ie4=document.all;
var ns4=document.layers;
var ns6=document.getElementById && !document.all;
var Stopped = 0;
var Running = 0;
var ClockPos;
var newDate;
var myClock;
var ProClock;
var num_Difference;
var numDifference;
var currentDate;
var myFont;											// Font for Clock
var myFont_size;									// Font Size of clock
var myFont_color;									// Font Color
var myFont_bgcolor;									// Background Color
var myAlignment;									// Alignment of clock
var myWidth;										// Width of clock
var do_12hr;										// 12/24 hour format 0=24hr, 1=12hr
var ShowDate;										// SHow the date 0=False, 1=True
var hAprv;
var dAprv;
var Old_Browser = "";
var DaysOfWeek = new Array(7);
DaysOfWeek[0] = "Sun";
DaysOfWeek[1] = "Mon";
DaysOfWeek[2] = "Tue";
DaysOfWeek[3] = "Wed";
DaysOfWeek[4] = "Thu";
DaysOfWeek[5] = "Fri";
DaysOfWeek[6] = "Sat";
var MonthsOfYear = new Array(12);
MonthsOfYear[0] = "Jan";
MonthsOfYear[1] = "Feb";
MonthsOfYear[2] = "Mar";
MonthsOfYear[3] = "Apr";
MonthsOfYear[4] = "May";
MonthsOfYear[5] = "Jun";
MonthsOfYear[6] = "Jul";
MonthsOfYear[7] = "Aug";
MonthsOfYear[8] = "Sep";
MonthsOfYear[9] = "Oct";
MonthsOfYear[10] = "Nov";
MonthsOfYear[11] = "Dec";

// Browser Testing
if (ie4 || ns6) { document.write('<span id="IEClock"></span>'); }
else if (document.layers) { document.write('<ilayer id="PosNS" visibility="hide"><layer id="NSClock"></layer></ilayer>'); }
else { Old_Browser = "true"; display_clock(); }

// This function starts up the clock
// If no or incorrect StartDate, clock assume currentDate default setting
function Begin_Clock(StartDate,cFont,cSize,cColor,cBgColor,cDate,c12Hr,cWidth,cAlign){
	if (StartDate=="undefined" || StartDate=='') currentDate = new Date();
	else currentDate = new Date(StartDate);
	if (cFont == "undefined" || cFont == '' ) myFont="Verdana";	else myFont=cFont;
	if (cSize == "undefined" || cSize == '' ) myFont_size="8"; else myFont_size=cSize;
	if (cColor == "undefined" || cColor == '' ) myFont_color="#FFFFFF"; else myFont_color=cColor;	
	if (cBgColor == "undefined" || cBgColor == '' ) myFont_bgcolor=""; else myFont_bgcolor=cBgColor;
	if (cAlign == "undefined" || cAlign == '' ) myAlignment="right"; else myAlignment=cAlign;
	if (cDate == "1" ) ShowDate=1; else ShowDate=0;
	if (c12Hr == "1" ) do_12hr=1; else do_12hr=0;
	if (cWidth == "undefined" || cWidth == '' ) myWidth=200; else myWidth=cWidth;
	numDifference =  currentDate.getTime();
	num_Difference = currentDate.getTime();	
	newDate = new Date(numDifference);
	Stopped=0;
	Running=1;
	display_clock();
	}

function Stop_Clock(){
	Stopped=1;
}
	
// The Clock routine
// Called every 1000 cycles to update every second.
function display_clock() {
	if (Old_Browser == "yes") { return; }
	if (ns4) document.PosNS.visibility="show"
	numDifference = num_Difference;
	var clock = new Date(numDifference);
	var day = clock.getDay();
	var mday = clock.getDate();
	var month = clock.getMonth();
	var year = clock.getYear();
	var hours = clock.getHours();
	var minutes = clock.getMinutes();
	var seconds = clock.getSeconds();
	dAprv = "th";
	switch(mday){
		case 1:
		case 21:
		case 31: dAprv = "st";
		case 2:
		case 22: dAprv = "nd";
		case 3:
		case 23: dAprv = "rd";
	}
	if (do_12hr) {
		hAprv = "AM";
		if (hours > 12) { hAprv = "PM"; hours = hours - 12; }
		if (hours == 0) { hours = 12; }
	} else hAprv = "";
	if (minutes <= 9) { minutes = "0"+minutes; }
	if (seconds <= 9) { seconds = "0"+seconds; }
	myClock = '<div style="font-family:'+myFont+'; font-size:'+myFont_size+'pt; color:'+myFont_color+'; background: '+myFont_bgcolor+'; width: '+myWidth+'; text-align: '+myAlignment+'" width="'+myWidth+'">';
	myClock += hours+':'+minutes+':'+seconds+' '+hAprv;
	if (ShowDate) { myClock += ' | '+DaysOfWeek[day]+', ' + mday + "" + ' '+MonthsOfYear[month]+' 2006'; }
	myClock += '</div>';
	if (Old_Browser == "true") {
		document.write(myClock);
		Old_Browser = "yes";
		return;
	}
	if (ns4) {
		ClockPos = document.PosNS;
		ProClock = ClockPos.document.NSClock;
		ProClock.document.write(myClock);
		ProClock.document.close();
	} else if (ie4) { IEClock.innerHTML = myClock; }
	else if (ns6){ document.getElementById("IEClock").innerHTML = myClock; }            
	numDifference =  num_Difference + 1000;
	num_Difference = numDifference;
	if (Stopped==0) setTimeout("display_clock()",1000); 
	if (Stopped==1) Running=0;
}

