var agt = navigator.userAgent.toLowerCase();

var gbIE = (agt.indexOf("msie") != -1);
var gbNN = (navigator.appName.indexOf("Netscape") != -1);

var gbNN4 = (null!=document.layers)
var gbOpera = (agt.indexOf("opera")!=-1)
var gbNN6 = (agt.indexOf("mozilla/5")!=-1)
var gbIE5 = (agt.indexOf("msie 5")!=-1 || agt.indexOf("msie 6")!=-1)
var gbWebTV = (agt.indexOf("webtv")!=-1)

var gbDom = (gbNN6 || gbIE5 || gbOpera)
var gbIE4 = (gbIE && !(gbDom||gbNN4))

var WIN = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var MAC = (agt.indexOf("mac")!=-1);

var _console = null;

//.........................................................................................
// DEPRECATED: check MSIE version (is needed for compatibility with old pages)
var MyBrowserNam=navigator.appName;
var MyBrowserAgent=navigator.userAgent;
function msieversion() {
	var msie=MyBrowserAgent.indexOf("MSIE");
	if (msie > 0) return parseInt (MyBrowserAgent.substring (msie+5, MyBrowserAgent.indexOf ( ".", msie )))
	else return 0
}

//.........................................................................................
// Generate email string
function biEmail() {
	return "belarussiainside" + '\x40' + "gmail" + '\x2E' + "c" + '\x6F' + "m";
}

//.........................................................................................
// CURRENTLY NOT USED: check server name for "belarusinside.org"
function isBelarusMirror() {
	var hostName = document.location.host; // server name
	hostName = hostName.match(/(belarusinside\.org)/); // check for "www.belarusinside.org" string
	if (RegExp.$1 == 'belarusinside.org') {
		return true;
	} else {
		return false;
	}
}

//.........................................................................................
// open new popup window with auto centering it

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2.5 : 10;
	TopPosition = (screen.height) ? (screen.height-h)/2.5 : 10;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	_console = window.open(mypage,myname,settings);
	_console.focus()
}

//.........................................................................................
// open new window with title, inner text, 
// specified width and height of window and submit button appearance

function showwin( title, text, width, height, submitbutton ) {
	leftPosition = (screen.width) ? (screen.width-width)/2 : 10;
	topPosition = (screen.height) ? (screen.height-height)/2 : 10;
	_console = window.open("", "", "width="+width+",height="+height+",top="+topPosition+",left="+leftPosition+",toolbar=no,menubar=no,resizable=yes,scrollbars=no");
	_console.document.open("text/html");
	_console.document.writeln("<html>");
	_console.document.writeln("<head>");
	_console.document.writeln("<title>" + title + "</title>");
//		_console.document.writeln('<link REL="STYLESHEET" TYPE="text/css" HREF="gen.css">');
	_console.document.writeln("</head>");
	_console.document.writeln('<body bgcolor="#6e887d" marginwidth=0 marginheight=0 leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0>');
	_console.document.writeln('<div align="center">');
	_console.document.writeln('<table cellpadding=0 cellspacing=0 border=0 width="100%" height="100%"><tr><td align="center" valign="middle" width="100%">');
	_console.document.writeln(" \
<table cellpadding=10 cellspacing=0 border=0> \
<tr><td class='title1'>" + title + "</td></tr> \
<tr><td>" + text + "</td></tr></table><br>");
	_console.document.writeln(submitbutton);
	_console.document.writeln("&nbsp;&nbsp;</td></tr></table></div>");
	_console.document.writeln("</body></html>");
	_console.focus();
}
//.........................................................................................
// open picture in new window with title, inner text, 
// specified width and height of window and submit button appearance

function showpic( body, title, width, height ) {
	leftPosition = (screen.width) ? (screen.width-width)/2 : 10;
	topPosition = (screen.height) ? (screen.height-height)/2 : 10;
	_console = window.open("", "", "width="+width+",height="+height+",top="+topPosition+",left="+leftPosition+",toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
	_console.document.open("text/html");
	_console.document.writeln("<html>");
	_console.document.writeln("<head>");
	_console.document.writeln("<title>" + title + "</title>");
//		_console.document.writeln('<link REL="STYLESHEET" TYPE="text/css" HREF=".gen.css">');
	_console.document.writeln("</head>");
	_console.document.writeln('<body bgcolor="#6e887d" marginwidth=0 marginheight=0 leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0>');
	_console.document.writeln('<script>try{document.body.style.cursor="wait"}catch(e){}</script>');
	_console.document.writeln('<table cellpadding=0 cellspacing=0 border=0 width="100%" height="100%" style="background-position: center; background-repeat: no-repeat; background-image:url(\'/img/hourglass.gif\');"> \
<tr><td align="center" valign="top" width="100%" height="100%"><a href="javascript:window.close();void(0)"><img src="' + body + '" border=0 title="' + title + ' (click to close this window)" alt="' + title + ' (click to close this window)"></a></td></tr></table>');
	_console.document.writeln;
	_console.document.writeln('<script>try{document.body.style.cursor="auto"}catch(e){}</script>');
	_console.document.writeln("</body></html>");
	_console.focus();
}

//.........................................................................................
// shorten the textareas

function textarealimit(fieldname, limit) {
	str = fieldname.value.trim();
	if (str.length >= limit-1) {
		alert('You have reached the space limit (' + limit + ' characters) for this field.');
		fieldname.value = str.substring(0,limit-2);
	}
}

// These functions will trim leading, trailing or all spaces from a string
// arg = the value you wish to have trimmed..

//===================================
function trimString(arg) {
//===================================
	str = this != window? this : str;
    str.replace(/^\s*/, '').replace(/\s*$/, ''); 
	return str;
}

//===================================
function ltrimString(arg) {
//===================================
	str = this != window? this : str;
    str.replace(/^\s*/, ''); 
	return str;
}

//===================================
function rtrimString(arg) {
//===================================
	str = this != window? this : str;
    str.replace(/\s*$/, ''); 
	return str;
}

//The above function is set up so that it can be added as a method to the 
//String.prototype:

String.prototype.trim = trimString;
String.prototype.ltrim = ltrimString;
String.prototype.rtrim = rtrimString;

