var rleft = 0;

function goleft() {
	var rn = document.getElementById('tramway');
	var rwidth = rn.clientWidth;

	if(rleft <= (-1 * rwidth)) {
		rleft = (document.body.clientWidth - 360);
		rn.style.left =	rleft + 'px';
	}
	else {
		rleft -= 1;
		rn.style.left = rleft + 'px';
	}

	setTimeout("goleft()", 40);
}

function gotramway() {
	var rn = document.getElementById('tramway');
	rleft = 936;
	rn.style.left = rleft + 'px';

	setTimeout("goleft()", 40);
}

function changeInputType(oldElm,iType,iValue,noFocus) {
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  newElm.onfocus = function() {
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',
      (this.value.toLowerCase()=='password')?'':this.value);
    if(newElm) newElm.hasFocus=true;
  }
  newElm.onblur = function() {
    if(this.hasFocus)
    if(this.value=='' || this.value.toLowerCase()=='password') {
      changeInputType(this,'text','password',true);
    }
  }
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(iValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

function showpass() {
  obj = document.getElementById("passwordfield");
  var ua = navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && (document.all || 
    (ua.indexOf('khtml/3.4')!=-1))) && !(((ua.indexOf('safari')!=-1) && 
    !window.print) || (document.defaultCharset && !window.print)))
      changeInputType(obj,'text','password',true);
}

function showlogin(obj) {
		obj.value = '';
}

addLoadHandler(showpass);
//addLoadHandler(gotramway);

function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
		    oldHandler();
		    handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}

var resId=0;
var imgWndw;

function imgOpen(imgLink,Title) {
    if (typeof(window.resizeBy)=='undefined') return true;

imgWndw=window.open('',imgLink.target,'width=100,height=100'+',toolbar=no,menubar=no,location=no,status=no,'+'resizable=yes,scrollbars=no,left='+(screen.width>>>2)+',top='+(screen.height>>>4));
    self.focus();
    var imgTitle=(Title)?Title:imgLink.href;
    with (imgWndw.document){
        open();
        write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'+
			'<html xmlns="http://www.w3.org/1999/xhtml">'+
			'<head>'+
			'<title>'+imgTitle+'</title>'+
			'</head>'+
			'<body style="margin:0;padding:0;position:fixed;overflow:none;background-color:#FFFFFF">'+
			'<a href="#" title="Закрыть окно" onclick="window.close();"><img src="'+imgLink.href+'" border="0" alt="'+imgTitle+'" title="Закрыть окно" /></a>'+
			'</body>'+
			'</html>');
        close();
    }
    resId=setTimeout('imgResize()',300);
    return false;
}

function imgResize() {
    var w=imgWndw.document.images[0].width;
    if (w>screen.availWidth) w=screen.availWidth;
    var h=imgWndw.document.images[0].height;
    if (h>screen.availHeight) h=screen.availHeight;
    if (w>50 && h>50) {
        var ww=(imgWndw.innerWidth)?imgWndw.innerWidth:((document.body)?imgWndw.document.body.clientWidth:null);
        var wh=(imgWndw.innerHeight)?imgWndw.innerHeight:((document.body)?imgWndw.document.body.clientHeight:null);
		if(ww==w) {
			ww = 100;
		}
		if(wh==h) {
			wh = 100;
		}
        if (ww && wh) {
            imgWndw.resizeBy(w-ww,h-wh);
        }
        imgWndw.focus();
        clearTimeout(resId);
    }
}
