///---------------------------

/* System functions */

/*
	// The $-method is a shortcut to get an element by id
	function $(elementId)
	{
		return document.getElementById(elementId);
	}

	// The double $-method is a shortcut to get elements by name.
	function $$(tagName)
	{
		return document.getElementsByTagName(tagName);
	}
*/
	// The triple $-method is a shortcut to get elements by tag name.
	function $$$(elementName)
	{
		return document.getElementsByName(elementName);
	}

	function setInnerHTML(object, text){
		object.innerHTML = text;
	}

/* System methods */

/// Måste lösa detta på något annat sätt...

var agt=navigator.userAgent.toLowerCase();

var is_major = parseInt(navigator.appVersion);

var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

var is_nav6up = (is_nav && (is_major >= 5));

var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_crappyNetscape = false;

// bug in netscape 6.0, onload doesn't always fire.
is_crappyNetscape = (agt.indexOf("netscape6/6.0") != -1)

///----

var OS,browser,version,total,thestring;

function getUserInfo()
{
	var detect = navigator.userAgent.toLowerCase();

	if (checkIt(detect, 'konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt(detect, 'safari')) browser = "Safari"
	else if (checkIt(detect, 'omniweb')) browser = "OmniWeb"
	else if (checkIt(detect, 'opera')) browser = "Opera"
	else if (checkIt(detect, 'webtv')) browser = "WebTV";
	else if (checkIt(detect, 'icab')) browser = "iCab"
	else if (checkIt(detect, 'msie')) browser = "Internet Explorer"
	else if	(checkIt(detect, 'firefox')) browser = "Firefox"
	else if (!checkIt(detect, 'compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt(detect, 'linux')) OS = "Linux";
		else if (checkIt(detect, 'x11')) OS = "Unix";
		else if (checkIt(detect, 'mac')) OS = "Mac"
		else if (checkIt(detect, 'win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
}

function checkIt(obj, string)
{
	place = obj.indexOf(string) + 1;
	thestring = string;
	return place;
}



function PopupWindow(Popup_Url, Popup_Height, Popup_Width, Popup_Unique)
{
	getUserInfo();

	try
	{
		var WindowArguments = null;
		var WindowArguments_IE = null;
		var newwindow = null;
		var Window_Left = 0;
		var Window_Top = 0;
//		var Dependent = 'dependent=1,';
		var Dependent = '';
//		var Modal = 'modal=yes,';
		var Modal = '';


		if(browser != 'Internet Explorer')
		{
			Window_Left=(screen.availWidth/2)-(Popup_Width/2);
			Window_Top=(screen.availHeight/2)-(Popup_Height/2);
	
			if(!Popup_Unique)
				Popup_Unique = new String (Math.random()).substring (2, 11);

			WindowArguments = 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,'+ Dependent + Modal +'height=' + Popup_Height + ',width=' + Popup_Width + ',left = ' + Window_Left + ',top = ' + Window_Top;

			newwindow = window.open(Popup_Url, Popup_Unique, WindowArguments);
		
			if (!newwindow.opener)
				newwindow.opener = self;
		
			if (window.focus)
				newwindow.focus();


		}
		else
		{
			Window_Left=(screen.availWidth/2)-(Popup_Width/2);
			Window_Top=(screen.availHeight/2)-(Popup_Height/2);
	
			WindowArguments_IE = 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,'+ Dependent + Modal +'height=' + Popup_Height + ',width=' + Popup_Width + ',left = ' + Window_Left + ',top = ' + Window_Top;

			if(!Popup_Unique)
				Popup_Unique = new String (Math.random()).substring (2, 11);


			newwindow = window.open(Popup_Url, Popup_Unique, WindowArguments_IE);

			if (!newwindow.opener)
				newwindow.opener = self;

			if (window.focus)
				newwindow.focus();


		}


	}
	catch(myError)
	{
		alert('An error occured!\n\n' + myError.name + ': ' + myError.message );
	}
	
	return newwindow;

}

//Generic ajax functions

// Get the HTTP Object
function getHTTPObject()
{
	if (window.ActiveXObject)
	{
		try
		{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest();
	}
  else
  {
		alert("Din webbläsare har inte stöd för AJAX.");
		return null;
	}
}

var http_request = false;

function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
      	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
      }
  } else if (window.ActiveXObject) { // IE
      try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
  }
  if (!http_request) {
      alert('Kan inte skapa XMLHTTP instans');
      return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}



