﻿/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Sandeep Gangadharan :: http://www.sivamdesign.com/scripts/ */

function showcurrenttime() {
	document.getElementById("currenttime").innerHTML = formatTime();
	setTimeout('showcurrenttime()',30000);
}

function showcurrenttime2(nminoffset,nRemote) {
	document.getElementById("currenttime2").innerHTML = formatTime(nminoffset,nRemote);
	setTimeout('showcurrenttime2('+nminoffset+','+nRemote+')',30000);
}

function formatTime(nAddMin,nRemote) {
	//var amnames = new Array("","Jan","Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec");
	var amnames = new Array("","jan","feb", "mar", "apr", "may", "jun", "jul", "aug", "sep","oct", "nov", "dec");
	var adays = new Array("su","mo","tu","we","th","fr","sa","su");
	if (typeof(nAddMin)=='undefined') {
		nAddMin= 0;
	}
	if (typeof(nRemote)=='undefined') {
		nRemote = 0;
	}
	now = new Date();
//	now.setTime(now.getTime() + (nAddMin*60*1000) - (nRemote * (now.getTimezoneOffset()*60*1000)));
	if (nRemote!=0) {
		now.setTime( now.getTime() + (now.getTimezoneOffset()*60*1000) + (nRemote*60*60*1000) );
		mtz = now.getTimezoneOffset() - (nAddMin);
		mhh = now.getHours();
		mmi = now.getMinutes();
		mss = now.getSeconds();
		myy = now.getFullYear();
		mmo = now.getMonth()+1;
		mma = amnames[mmo];
		mdw = now.getDay();
		mdy = adays[mdw];
		mdd = now.getDate();
	} else {
		now.setTime(now.getTime() + (nAddMin*60*1000));
		mtz = now.getTimezoneOffset() - (nAddMin);
		mhh = now.getHours();
		mmi = now.getMinutes();
		mss = now.getSeconds();
		myy = now.getFullYear();
		mmo = now.getMonth()+1;
		mma = amnames[mmo];
		mdw = now.getDay();
		mdy = adays[mdw];
		mdd = now.getDate();
	}
	cret = "";
	if (mmo <= 9) {
		mmo = "0" + mmo; }
	if (mdd <= 9) {
		mdd = "0" + mdd; }
	if (mmi <= 9) {
		mmi = "0" + mmi; }
	if (mss <= 9) {
		mss = "0" + mss ; }
	if (mhh < 10) {
		mhh = "0" + mhh ; }
    //cret = myy + '-' + mma + '-' + mdd + ' ' + mhh + ':' + mmi + ':' + mss + ' ' + (-mtz/60);
//    cret = mdy + ' ' + myy + ' ' + mma + ' ' + mdd + ' ' + mhh + ':' + mmi + ' (GMT' + ((mtz>=0) ? '' : '+') + (-mtz/60) + ')';
    cret = mdy + ' ' + myy + ' ' + mma + ' ' + mdd + ' ' + mhh + ':' + mmi;
//    cret = cret + ' ' + nAddMin + ' ' + now.getTimezoneOffset();
    var now2 = new Date();
    //cret = now2.toGMTString() ;
	return cret;
}

function formatMySqlDT(nAddMin) {
	if (typeof(nAddMin)=='undefined') {
		nAddMin= 0;
	}
	now = new Date();
	now.setTime(now.getTime() + (nAddMin*60*1000));
	mhh = now.getHours();
	mmi = now.getMinutes();
	mss = now.getSeconds();
	myy = now.getFullYear();
	mmo = now.getMonth()+1;
	mdd = now.getDate();
	cret = "";
	if (mmo <= 9) {
		mmo = "0" + mmo; }
	if (mdd <= 9) {
		mdd = "0" + mdd; }
	if (mmi <= 9) {
		mmi = "0" + mmi; }
	if (mss <= 9) {
		mss = "0" + mss ; }
	if (mhh < 10) {
		mhh = "0" + mhh ; }
    cret = myy + '-' + mmo + '-' + mdd + ' ' + mhh + ':' + mmi + ':' + mss;
	return cret;
}	

function makeHHMM(nSecs) {
	mhh = parseInt(nSecs/3600);
	mmi = parseInt((nSecs-(mhh*3600))/60);
	//if (mhh < 10) {
	//	mhh = "0" + mhh ; }
	if (mhh <= 9) {
		mhh = "0" + mhh; }
	if (mmi <= 9) {
		mmi = "0" + mmi; }
    cret = mhh + ':' + mmi;
	return cret;
}


