﻿function showFormWindow (oParams) {
	if ( !oParams ) oParams = new Object();
	if ( oParams.visible == undefined ) oParams.visible = true;
	if (oParams.name == undefined) oParams.name = 'w-form';

	var wLogin;

	var wformlogin = document.getElementById(oParams.name+"-login");
	var wformadduser = document.getElementById(oParams.name+"-adduser");

	if ( wLogin = document.getElementById(oParams.name) ) {
		if ( !wLogin.initialized ) {
			wLogin.initialized = true;
			wLogin.visible = false;

			
			var wBackground = document.getElementById(oParams.name+"-background");
			wBackground.style.opacity = ".8";
			wBackground.style.filter = "alpha(opacity=80)";
			
			if ( window.addEventListener ) {
				window.addEventListener("resize", resizeLoginWindow, false);
				window.addEventListener("scroll", resizeLoginWindow, false);
			} else if ( window.attachEvent ) {
				window.attachEvent("onresize", resizeLoginWindow );
				window.attachEvent("onscroll", resizeLoginWindow );
			}
		}
		
		wLogin.visible = oParams.visible;
		wLogin.style.display = oParams.visible ? "block" : "none";

		
		wformlogin.style.display = wLogin.style.display;
		wformadduser.style.display = oParams.visible ? "none" : "block";


		resizeLoginWindow(oParams.name);
	}
}

function showFormAddUser() {

    var wformlogin = document.getElementById("w-form-login");
    var wformadduser = document.getElementById("w-form-adduser");

    wformlogin.style.display = "none";
    wformadduser.style.display = "block";

}

function resizeLoginWindow(e) {
	var wLogin;
	
	if ( wLogin = document.getElementById(e) ) {
		if ( wLogin.visible ) {
			wLogin.style.width  = String(document.documentElement.clientWidth) + "px";
			wLogin.style.height = String(document.documentElement.clientHeight) + "px";
			wLogin.style.top    = window.pageYOffset != undefined ? String(window.pageYOffset) + "px" : document.documentElement.scrollTop + "px";
			wLogin.style.left   = window.pageXOffset != undefined ? String(window.pageXOffset) + "px" : document.documentElement.scrollLeft + "px";
			
			var wBackground = document.getElementById(e+"-background");
			wBackground.style.width  = wLogin.style.width;
			wBackground.style.height = wLogin.style.height;
			
			var wWindow = document.getElementById(e+"-window");
			wWindow.style.left = String((document.documentElement.clientWidth / 2) - (wWindow.offsetWidth / 2)) + "px";
			wWindow.style.top  = String((document.documentElement.clientHeight / 2) - (wWindow.offsetHeight / 2)) + "px";
		}
	}
}
