/*	Nyl Brian Ong - UPLB Administrative Services
	File: clock.js
	Description: displays the date and time based on the users computer clock.
*/

function showTime() {
	var date_today = new Date()
	
	var weekday = new Array(7)
	weekday[0] = "Sunday"
	weekday[1] = "Monday"
	weekday[2] = "Tuesday"
	weekday[3] = "Wednesday"
	weekday[4] = "Thursday"
	weekday[5] = "Friday"
	weekday[6] = "Saturday"
	
	var month_name = new Array(12)
	month_name[0] = "January"
	month_name[1] = "February"
	month_name[2] = "March"
	month_name[3] = "April"
	month_name[4] = "May"
	month_name[5] = "June"
	month_name[6] = "July"
	month_name[7] = "August"
	month_name[8] = "September"
	month_name[9] = "October"
	month_name[10] = "November"	
	month_name[11] = "December"	
	
	var mn = month_name[date_today.getMonth()]
	var dn = weekday[date_today.getDay()]
	var d = date_today.getDate()
	var y = date_today.getFullYear()
	var h = date_today.getHours()
	var m = checkTime(date_today.getMinutes())
	var s = checkTime(date_today.getSeconds())
	var ap = "AM"

	if (h > 12) {
		h = h - 12
		ap = "PM"
	}
	
	if (h == 0)
		h = 12
	
	document.getElementById('time-cont').innerHTML = dn + ", " + mn + " " + d + ", " + y + " " + h + ":" + m + " " + ap
	t = setTimeout('showTime()',500)
}

/* adds a leading zero to a one digit number */
function checkTime(i) {
	if (i < 10) {
		i = "0" + i
	}
	return i
}

/* stops the clock from ticking */ 
function stopTime() {
	clearTimeout(t);
}

function showDiv() {
	document.getElementById('content_invis').style.visibility = "visible";
	document.getElementById('content_invis').style.position = "static";
}

function typeNews() {
	if (cnt != ( newsString.length + 1 ) ) {
		document.getElementById("announce").innerHTML = newsString.substr(0,cnt) + "_";
		cnt++;
		setTimeout("typeNews()",100);
	} else {
		cnt = 1;
		setTimeout("typeNews()",4000);
	}
}