var Application =  {
  lastId: 0,
  currentSampleNb: 0,

  getNewId: function() {
    Application.lastId++;
    return "window_id_" + Application.lastId;
  }
}

function ThisWin(location) {
			win = Windows.getFocusedWindow();
			win.setAjaxContent(location, {}, false, false);
			win.show();
			win.toFront();
}

function OpenWin(location, width, height, name) {
			var wHeight = ((document.documentElement.clientHeight - height) / 2) + document.documentElement.scrollTop;
			var wWidth = ((document.documentElement.clientWidth - width) / 2) + document.documentElement.scrollLeft;
			win = new Window(Application.getNewId(), {className: "apport_style", title: name, width:width, height:height, showEffectOptions: {duration:0.2}, hideEffectOptions: {duration:0.2}});
			win.setAjaxContent(location, {}, false, false);
			win.setLocation(wHeight, wWidth);
			win.show();
			win.toFront();
			win.setDestroyOnClose();
}

function NewWin(location) {

			var wHeight = ((document.documentElement.clientHeight - 394) / 2) + document.documentElement.scrollTop;
			var wWidth = ((document.documentElement.clientWidth - 351) / 2) + document.documentElement.scrollLeft;
			win = new Window(Application.getNewId(), {className: "apport_style", title: "Nyheter", width:351, height:394, showEffectOptions: {duration:0.2}, hideEffectOptions: {duration:0.2}});
			win.setAjaxContent(location, {}, false, false);
			win.setLocation(wHeight, wWidth);
			win.show();
			win.toFront();
			win.setDestroyOnClose();
}

function LoginWin(location) {
			var wHeight = ((document.documentElement.clientHeight - 415) / 2) + document.documentElement.scrollTop;
			var wWidth = ((document.documentElement.clientWidth + 238) / 2) + document.documentElement.scrollLeft;
			win = new Window(Application.getNewId(), {className: "apport_style", title: "Login", width:234, height:415, showEffectOptions: {duration:0.2}, hideEffectOptions: {duration:0.2}});
			win.setAjaxContent(location, {onSuccess:paus}, false, false);
			win.setLocation('32', wWidth);
			win.show();
			win.toFront();
			win.setDestroyOnClose();
}

function TechWin(location) {
			var wHeight = ((document.documentElement.clientHeight - 394) / 2) + document.documentElement.scrollTop;
			var wWidth = ((document.documentElement.clientWidth - 540) / 2) + document.documentElement.scrollLeft;
			win = new Window(Application.getNewId(), {className: "apport_style", title: "Case", width:540, height:394, showEffectOptions: {duration:0.2}, hideEffectOptions: {duration:0.2}});
			win.setAjaxContent(location, {}, false, false);
			win.setLocation(wHeight, wWidth);
			win.show();
			win.toFront();
			win.setDestroyOnClose();
}

function CaseWin(location) {
			var wHeight = ((document.documentElement.clientHeight - 528) / 2) + document.documentElement.scrollTop;
			var wWidth = ((document.documentElement.clientWidth - 590) / 2) + document.documentElement.scrollLeft;
			win = new Window(Application.getNewId(), {className: "apport_style", title: "Case", width:590, height:528, showEffectOptions: {duration:0.2}, hideEffectOptions: {duration:0.2}});
			win.setAjaxContent(location, {}, false, false);
			win.setLocation(wHeight, wWidth);
			win.show();
			win.toFront();
			win.setDestroyOnClose();
}

function paus() {
		window.setTimeout('setFocus()', 200)
	}

function setFocus() {

	// read cookie
	var loginName = readCookie('APPORT_LOGIN_NAME');
	var loginDomain = readCookie('APPORT_LOGIN_DOMAIN');

	// set information in form
	if(loginName)
		document.getElementById('username').value = loginName;
	if(loginDomain)
		document.getElementById('domain').value = loginDomain;

	// set focus
	if(loginName && loginDomain)
		document.getElementById("password").focus();
	else
		document.getElementById("username").focus();
}

function changePage(newLoc)
 {
   nextPage = newLoc.options[newLoc.selectedIndex].value

   if (nextPage != "")
   {
      document.location.href = nextPage
   }
 }