function isFirefox () {
	return window.sidebar;
}

function isIE () {
	return document.all;
}

function isMac () {
	return navigator.userAgent.toLowerCase().indexOf('mac')!=-1;
}

function isValidNumber(v){return!isNaN(parseInt(v))}

function isLikelyKonqueror3() {
	if(!document.getElementById) return false;
	if(document.defaultCharset || window.opera || !window.print) return false;
	if(window.home) return false; /* Konqueror doesn't support this but Firefox,
	                               * which has silent support for document.all
	                               * when in Quirks Mode does */
	if(document.all) return true; // Konqueror versions before 3.4
	var likely = 1;     // testing for silent document.all support; try-catch used to keep it from        
						// generating errors in other browsers.        
						// try-catch causes errors in IE4 so we use the eval() to hide it.        
						// 
	eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}");        
	return likely;      
}
	
function isKonq () {
	return (isLikelyKonqueror3 && isLikelyKonqueror3());s
}

// ~ Strings Functions ---------------------------------------------------------

function nStrIsWhiteSpace(chr){switch(chr){case ' ': case '\n': case '\t': case '\r':return true}return false}

/**
 * Trim a string
 */
function nStrTrim (s) {
	var l = s.length;
	var b = 0;
	var e   = l;
	for(b=0;b<l;b++){if(!nStrIsWhiteSpace(s.charAt(b))){break}}
	for(e=l;e>0;e--){if(!nStrIsWhiteSpace(s.charAt(e))){break}}
	return s.substring(b,e);
}
/**
 * To test if a given string has unicode characters.
 */
function nStrIsUnicode(s){var l=s.length;for(var i=0;i<l;i++){if(s.charAt(i).charCodeAt()>255){return true}}return false}

// ~ Date/Time function --------------------------------------------------------

function GetTimezone () {
	d = new Date();
	return d.getTimezoneOffset()/(-60);
}

function nMonthNameShort (m) {
	switch(m) {
		case 0: return 'Jan';
		case 1: return 'Feb';
		case 2: return 'Mar';
		case 3: return 'Apr';
		case 4: return 'May';
		case 5: return 'Jun';
		case 6: return 'Jul';
		case 7: return 'Aug';
		case 8: return 'Sept';
		case 9: return 'Oct';
		case 10: return 'Nov';
		case 11: return 'Dec';
		default: return m;
	}
}

function nL0(n){return(n<10)?'0'+n:n}
function nYearNum (y) {
	if (y < 100) {
		return '19' + y;
	}
	if (y < 1900) {
		return 1900 + y;
	}
	return y;
}

var g_now = new Date();

function nDateTimeShortFmt1(d){return nYearNum(d.getYear())+'-'+nL0(d.getMonth()+1)+'-'+nL0(d.getDate())+' '+nL0(d.getHours())+':'+nL0(d.getMinutes())+':'+nL0(d.getSeconds())}
function nDateTimeEmailFmt1(d){
	if (d.getYear()==g_now.getYear() && d.getMonth()==g_now.getMonth() && d.getDate()==g_now.getDate()) {
		var hr   = d.getHours();
		var ampm = 'am';
		if (hr > 12) {
			ampm = 'pm';
			hr -= 12;
		}
		return nL0(hr) + ':' + nL0(d.getMinutes()) + ' ' + ampm;
	}

	if (d.getYear()==g_now.getYear()) {
		return nMonthNameShort(d.getMonth()) + ', ' + d.getDate();
	}
	
	return nYearNum(d.getYear())+'-'+nL0(d.getMonth())+'-'+nL0(d.getDate());
}

function nBrowserSetHomePage (a, url) {
	if (isFirefox()) {
		alert('Please click "Tools", follow by "Options", and click on "Use Current Page" to set this site as your home page');
		return false;
	}
	
	if (isIE()) {
		a.style.behavior='url(#default#homepage)';
		a.setHomePage(url);
		return true;
	}
	
	alert('Please add this page to your home page manually');
	return false;
}

/**
 * Add bookmark.
 */
function nBrowserAddBookmark (url, title)
{
	// If firefox
	if (isFirefox()) {
		window.sidebar.addPanel(title, url, "");
		alert('Bookmark added');
		return true;
	}
	
	// IE
	if (isIE()) {
		try  {
			window.external.AddFavorite(url,title);
		} catch (e) {
			alert('Unable to add bookmark, please add manually: ' + url);
			return false;
		}
		
		alert('Bookmark added');
		return true;
	}
	
	if (isKonq()) {
		alert('Please press CTRL+B to bookmark this site.s')
		return false;
	}
	
	// ERROR, unsupport.
	alert("Your browser does not support this feature.");
	return false;
}
