// Overide WindowUtilities getPageSize to remove dock height (for maximized windows)
/*WindowUtilities._oldGetPageSize = WindowUtilities.getPageSize;
WindowUtilities.getPageSize = function() {
  var size = WindowUtilities._oldGetPageSize();
  var dockHeight = $('dock').getHeight(); 
  size.pageHeight -= dockHeight;
  size.windowHeight -= dockHeight;

  return size;
};    
*/

// Overide Windows minimize to move window inside dock  


// blur focused window if click on document
Event.observe(document, "click", function(event) {   
  var e = Event.element(event);
  var win = e.up(".dialog");
  var dock = e == $('dock') || e.up("#dock"); 
  if (!win && !dock && Windows.focusedWindow) {
    Windows.blur(Windows.focusedWindow.getId());                    
  }
})               

 
// Chnage theme callback

function changeTheme(index) {
 
  if (index == currentTheme)
    return;

  var theme, blurTheme;
  switch (index) {
    case 'alphacube':
      theme = "alphacube";
      blurTheme = "alphacube";
      break;
    case 'darkX':
      theme = "darkX";
      blurTheme = "darkX";
      break;
    case 'mac_os_x':
      theme = "mac_os_x";
      blurTheme = "mac_os_x";
      break;
    case 'nuncio':
      theme = "nuncio";
      blurTheme = "nuncio";
      break;
    case 'spread':
      theme = "spread";
      blurTheme = "spread";
      break;
  }
  Windows.windows.each(function(win) {
    win.options.focusClassName = theme; 
    win.options.blurClassName = blurTheme;
    win.changeClassName(blurTheme)
  });
  Windows.focusedWindow.changeClassName(theme);
  currentTheme = index;
}



var currentTheme;
                          	function loginwinX()
                          	{
                          		var jtml='<iframe src="about:blank" name="loginframe" style="width:1px;height:1px;" frameborder="0"></iframe>'+
                          	'<form action="/sashos/logininframex.php" target="loginframe" name="loginfX" id="loginfX" method="POST">'+
                          	'<p><span id="login_error_msg" class="login_error" style="">&nbsp;</span></p> <div style="clear:both"></div>'+
                          	'<p><span class="login_label">Имя</span> <span class="login_input">'+
                          	'<input name="login" type="text"  onKeyPress="return KeyPressLoginFormX(event, 2);"/></span></p>'+
                          	'<div style="clear:both"></div> <p><span class="login_label">Пароль</span> <span class="login_input">'+
                          	'<input name="password" type="password"  onKeyPress="return KeyPressLoginFormX(event, 2);"/></span></p>'+
                          	'<div style="clear:both"></div> </form>';
                          	document.body.style.overflow="hidden";	
                          		$("contentborderZ").style.display="none";
                          		//$("contentborder").ondblclick=function(){loginwin();}
                          		Dialog.confirm(jtml, {
                          			className:"alphacub", 
                          			width:500, 
                          			height:250,
                          			opacity:0.8,
                          			okLabel: "login", 
                          			cancelLabel: "cancel", 
                          			onOk:function(win){ 
				
                          			$('loginfX').submit();
                          			},
                          				   onCancel:function(win){ 
                          				   	document.location="/";
                          				   }
                          		});
                          	}
                          	
                          	
                          	function errorpassX(){

                          	$('login_error_msg').innerHTML='Неправильное имя пользователя или пароль';
                          	new Effect.Shake(Windows.focusedWindow.getId()); return false;	
                          	}
                          	
                          	function KeyPressLoginFormX(e,element)
	{
		var kk = navigator.appName == 'Netscape' ? e.which : e.keyCode;
		if (kk == 13)
		{
			document.forms['loginfX'].submit();
			return false
		}		
		return true
	}
