/*************** UTILITIES ****************/

var usragent=navigator.userAgent.toLowerCase();
var is_mac  = (usragent.indexOf("mac") != -1);
var is_win  = (usragent.indexOf("win") != -1);
var is_ie   = (usragent.indexOf("msie") != -1); 
var is_nav  = ((usragent.indexOf('mozilla')!=-1) && (usragent.indexOf('spoofer')==-1) 
            && (usragent.indexOf('compatible') == -1) && (usragent.indexOf('opera')==-1) 
            && (usragent.indexOf('webtv')==-1));
var PrintWindow;
function popUpWin( url, newTool, newLocation, newStatus, newMenubar, newResizable, newScrollbars, newWidth, newHeight, newLeft, newTop ) {
	if (is_ie ||  is_nav)  {
		if (PrintWindow != null && !PrintWindow.closed)  {
			oldWin = PrintWindow;
			oldWin.name = "oldWin";
			oldWin.close();
		}
	}
	PrintWindow=window.open( url,"newWin","toolbar=" + newTool + ",location=" + newLocation + ",status=" + 
													 newStatus + ",menubar=" + newMenubar + ",resizable=" + newResizable + ",scrollbars=" + 
													 newScrollbars + ",width=" + newWidth + ",height=" + newHeight + ",left=" + newLeft + ",top=" + newTop );

	if (PrintWindow.opener == null) PrintWindow.opener = popupWin;
	PrintWindow.opener.name = "origWin";
	PrintWindow.focus();
}
	
function closeWin() {
	this.close();
	PrintWindow = null;
}

(function($) {
	$.fn.reverseOrder = function() {
		return this.each(function() {
			$(this).prependTo( $(this).parent() );
	});
};
})(jQuery);

jQuery.fn.reverse = function() {
  return this.pushStack(this.get().reverse(), arguments);
};

jQuery.fn.sort = function() {
  return this.pushStack( [].sort.apply( this, arguments ), []);
};

function findPos( obj ) {
	var curleft = curtop = 0;
	if( obj.attr( "offsetParent" ) ) {
		curleft = $(obj).attr( "offsetLeft" );
		curtop = $(obj).attr( "offsetTop" );
		while( obj = $(obj).attr( "offsetParent" ) ) {
			curleft += $(obj).attr( "offsetLeft" );
			curtop += $(obj).attr( "offsetTop" );
		}
	}
	return [curleft,curtop];
}

function GetBrowserWindowSize() {
	var b = -1,a = -1;
	if( typeof( window.innerWidth ) == "number" ) {
		b = window.innerWidth;
		a = window.innerHeight;
	}
	else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			b = document.documentElement.clientWidth;
			a = document.documentElement.clientHeight;
		}
		else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				b = document.body.clientWidth;
				a = document.body.clientHeight;
			}
		}
	}
	return { width:b, height:a };
}

function clickNewsItem( id )
{
	var f = document.formNews;
	if( f == null ) return;
	f.donthackme.value = "stop";
	f.itemid.value = id;
	f.action = "viewnews.php";
	f.submit();
}

function getURLParam( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null ) return "";
  else return results[1];
}

var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}
