// MILLENNIUM3 PUBLIC

function LogonRedirect()
	{
		var sReturn;
		var sParam;
		var divLogon = document.getElementById('divLogon');
		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 d = new Date();

		sParam = 'logon=' + sUserName + '&Password=' + sPassword;
		sParam = sParam + '&gmtoffset=' + d.getTimezoneOffset();
		
		divLogonInvalid.style.display = 'none';
		divLogonExpire.style.display = 'none';
		divLogon.style.display = 'none';
		divLogonMessage.setAttribute("class", "working");
		divLogonMessage.style.display = 'block';

		sReturn = onDemandLogon(sParam);

		//window.alert(sReturn);

		divLogonMessage.setAttribute("class", "");

		if (sReturn.substring(0, 2) == 'OK')
			{
			var aValues = sReturn.split('|');

			//window.alert(aValues[1]);

			if (aValues[0] == 'OK') {

				if (unescape(aValues[1]) == "NO") 
				{
					if (aValues[2] == "LOGONFAILED")
					{
					divLogonInvalid.innerHTML = 'Username or password is invalid - please re-enter your details above';	
					divLogonInvalid.style.display = 'block';
					divLogon.style.display = 'block';
					}
				}
				else 
				{
					divLogonMessage.style.fontSize = '12px';
					divLogonMessage.innerHTML = "logon successful, logging in...";
				
					if (aValues[3] == "PASSWORDEXPIRED")
					{
						document.location.href = '/change-password/' + aValues[2];
					}
					else
					{		
						if (unescape(aValues[1]) != "#") 
						{
							document.location.href = 'https://millennium3.myworkspace.com?sid=' + aValues[2];
					  	}
					}
				}
			}
		}
	}

function Logoff()
	{
		var sReturn;
		

		sReturn = onDemandSend('/directory/ondemand/logoff.asp');
		document.location.href = 'http://www.samiskitchen.com.au';
		

		//window.alert(sReturn);

		
	}

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');

	if ($('#txtNewPassword').val() != $('#txtNewPasswordConfirm').val())
	{
		window.alert('The new passwords do not match, please check and try again.');
	}
	else
	{

		sParam = 'method=SITE_USER_CHANGE_PASSWORD&site=1039&currentpassword=' + sCurrentPassword + '&newpassword=' + sNewPassword;
			
		sReturn = onDemandSite(sParam);
	
		//window.alert(sReturn);

		divChangePassword.style.display = 'none';
		divContinue.style.display = 'block';

		divContinue.innerHTML = 'Updating password...';

		if (sReturn.substring(0, 2) == 'OK')
		{
			var aValues = sReturn.split('|');

			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
				{
					divContinue.innerHTML = 'Inccrrect currect password...';
				}
			}

			if (aValues[1] == 'OK') 
			{
				if (unescape(aValues[2]) != "#") 
				{
					divContinue.innerHTML = 'Transferring...';
				  	document.location.href = 'https://millennium3.myworkspace.com' + '?sid=' + aValues[3];
				}

			}
		}
	}
}



