// JavaScript Document

// JavaScript Document

function LogonRedirect()
{
	var sReturn;
	var sParam;
	var divLogonMessage = document.getElementById('divLogonMessage');
	var divLogonExpire = document.getElementById('divLogonExpire');
	var divLogonInvalid = document.getElementById('divLogonInvalid');
	var sUserName = document.getElementById('txtUserName').value;
	var sPassword = document.getElementById('txtPassword').value;
	var sWorkSpace = document.getElementById('txtWorkSpace').value;
	
	if (sWorkSpace == '1') // Rotary District 9800
	{
		sParam = 'logon=' + sUserName + '@d9800&password=' + sPassword;
	}
	else
	{
		sParam = 'logon=' + sUserName + '&password=' + sPassword;
	}

	divLogonMessage.setAttribute("class", "working");
	divLogonMessage.style.display = 'block';
	divLogonInvalid.style.display = 'none';
	divLogonExpire.style.display = 'none';
	sReturn = onDemandLogon(sParam);
	divLogonMessage.setAttribute("class", "");
	if (sReturn.substring(0, 2) == 'OK')
	{
		var aValues = sReturn.split('|');


//		if (sWorkSpace == '2') // Rotary Club of Southbank
//		{
//			window.alert (sWorkSpace);
//			window.alert (aValues[0]);
//			window.alert (aValues[1]);
//			window.alert (aValues[2]);
//			window.alert (aValues[3]);
//		}




		if (unescape(aValues[1]) == "NO") 
		{
			divLogonInvalid.setAttribute("class", "loginText");
			divLogonInvalid.innerHTML = 'Username or password is invalid - please re-enter your details';	
			divLogonInvalid.style.display = 'block';
		}
		else 
		{
			if (aValues[3] == "PASSWORDEXPIRED")
			{
				document.location.href = '/password_change';
			}
			else
			{		
			  	divLogonMessage.setAttribute("class", "loginText");
				divLogonMessage.style.height = '20px';
				divLogonMessage.innerHTML = "logon successful, logging in...";
				//document.location.href = unescape(aValues[1]) + '?sid=' + aValues[2];
				document.location.href = 'http://www.rotarydistrict9800.org.au/members_only_home';
			}
		}
	}
}

function Logoff()
	{
		var sReturn;
		sReturn = onDemandLogoff();
		document.location.href = 'http://www.rotarydistrict9800.org.au';
	}

function changePassword()
{
	var sParam;
	var sReturn;
	var sCurrentPassword = document.getElementById('txtCurrentPassword').value;
	var sNewPassword = document.getElementById('txtNewPassword').value;
	var divChangePassword = document.getElementById('divChangePassword');
	var divContinue = document.getElementById('divContinue');
	sParam = 'method=SITE_USER_CHANGE_PASSWORD&expiredays=365&currentpassword=' + sCurrentPassword + '&newpassword=' + sNewPassword;
	sReturn = onDemandSite(sParam);
	divChangePassword.style.display = 'none';
	divContinue.style.display = 'block';
	divContinue.innerHTML = 'Updating password...';
	if (sReturn.substring(0, 2) == 'OK')
	{
		var aValues = sReturn.split('|');
		window.alert(aValues[0]);
		window.alert(aValues[1]);
		window.alert(aValues[2]);
		window.alert(aValues[3]);
		window.alert(aValues[4]);
		window.alert(aValues[5]);
		window.alert(aValues[6]);
		window.alert(aValues[7]);
		window.alert(aValues[8]);
		//1=STATUS, 2=URL if OK, 3=SessionId, if OK
		if (aValues[1] == 'ER') 
		{
			divChangePassword.style.display = 'block';
			if (aValues[2] == 'PASSWORD_LESS_THAN_6_CHAR.') 
			{
				divContinue.innerHTML = 'New password needs to be 6 char...';
			}
			else // (aValues[2] == 'INCORRECT_CURRENT_PASSWORD')
			{
				divContinue.innerHTML = 'Incorrect current password...';
			}
		}
		if (aValues[1] == 'OK') 
		{
//			if (unescape(aValues[2]) != "#") 
//			{
				divContinue.innerHTML = 'Password updated, transferring...';
			  	document.location.href = 'http://www.rotarydistrict9800.org.au/members_only_home';
//			}
		}
	}
}


