// login popup ver 0.1
// will be moved to fs_global.js

var formHTML = '<form method="post" action="userlogin.cfm?do=login" name="userlogin" ><table cellpadding="4" cellspacing="0" border="0"> <tr><td align="right">username</td><td><input type="text" value="" maxlength="50" name="username" /></td></tr> <tr><td align="right">password</td><td><input type="password" value="" maxlength="50" name="password" /></td></tr> <tr><td colspan="2" align="right"><input type="submit" value="login" name="submit"/> <a href="#" id="loginCancel">cancel</a></td></tr> </table> <div align="center"><a href="userlogin.cfm?do=forgot">Forget your username/password?</a></div> </form>';

function fsLoginSetup(){
	aList = document.getElementsByTagName('a');
	for (var i=0; i < aList.length; i++) {
		if (aList[i].className == "fsLogin") {
			aList[i].onclick = function() { fsPopupLogin(); return false; }
		};
	};	

	formDiv = document.createElement('div');
	formDiv.id = "fsLoginForm";
	formDiv.innerHTML = formHTML;
	
	overlayDiv = document.createElement('div');
	overlayDiv.id = "fsLoginOverlay";
	
	document.body.insertBefore(formDiv,document.getElementById('bodydiv').nextSibling);
	document.body.insertBefore(overlayDiv,document.getElementById('bodydiv').nextSibling);
	
	document.getElementById('fsLoginOverlay').onclick = function() { fsCloseLogin() };
	document.getElementById('loginCancel').onclick = function() { fsCloseLogin() };
	
}

function fsPopupLogin() {

	document.getElementById('fsLoginOverlay').style.display = "block";


	f = document.getElementById('fsLoginForm');
	f.style.display = "block";

	//find the center of the window
	if(isIE){
		f.style.left = (document.body.clientWidth/2) - (f.scrollWidth/2);
		f.style.top = (document.body.clientHeight/2) - f.scrollHeight;
	}else{
		f.style.left = (window.innerWidth/2) - (f.scrollWidth/2);
		f.style.top = (window.innerHeight/2) - f.scrollHeight;
	}
	
	document.userlogin.username.focus();
	
	//hide elements from IE6
	if(isIE && navigator.appVersion.indexOf("MSIE 6.0") > 0){
		ele = document.getElementsByTagName('select');
		for (var i=0; i < ele.length; i++) { ele[i].style.visibility = "hidden"; }
	}
	
}

function fsCloseLogin () {
	
	document.getElementById('fsLoginOverlay').style.display = "none";
	document.getElementById('fsLoginForm').style.display = "none";

	if(isIE && navigator.appVersion.indexOf("MSIE 6.0") > 0){
		ele = document.getElementsByTagName('select');
		for (var i=0; i < ele.length; i++) { ele[i].style.visibility = "visible"; }
	}

	
}


addOnloadEvent(fsLoginSetup);