//<![CDATA[

function processLogin() {
	
	dojo.require("dojo.validate");
	dojo.require("dojo.validate.check");
	dojo.require("dojo.validate.datetime");
	dojo.require("dojo.validate.us");
	dojo.require("dojo.validate.web");	
	
	dojo.byId('loginsubmit').value = 'Please Wait...';
	dojo.byId('loginsubmit').style.width = '120px';		
	
	//document.location.href = 'pages/login_process.asp?sitename=' + dojo.byId('sitename').value + '&username=' + dojo.byId('username').value + '&password=' + dojo.byId('password').value + '&loginremember=' + dojo.byId('loginremember').value;
	
	var bindArgs = {
	sync: true,
	url: 'pages/login_process.asp',
	method: 'post',
	content: {
		sitename: dojo.byId('sitename').value,
		username: dojo.byId('username').value,
		password: dojo.byId('password').value,
		loginremember: dojo.byId('loginremember').value
	},
	error: function(type, data, evt){
		alert('An error occurred and we could not send your request.  Please try again.');
		alert(data);
		dojo.byId('loginsubmit').value = 'Login';
		dojo.byId('loginsubmit').style.width = '80px';	
		
		return false;
	},
	load: function(type, data, evt){
		//alert(data);
		var returnVal = parseFloat(data);
		
		//alert('returnVal: ' + returnVal);
		
		if (returnVal <= 0) { // incorrect username or password
		
			if (returnVal == -2) { // client is attempting to login at wrong login page
				document.location.href = 'http://client.sierrainteractivedev.com/login.aspx?src=ocaa';
			} else {
				dojo.style.show(dojo.byId('login_incorrect'));
				dojo.byId('loginsubmit').value = 'Login';
				dojo.byId('loginsubmit').style.width = '80px';
			}
			return false;
		} else { // Login was successful -- 			
			document.location.href = '/';
			return false;
		}
		
	},
	mimetype: 'text/html'
	};	
	
	// Validate the form contents before submitting
	var valProfile = {
		// filters change the field value and are applied before validation.
		trim: ["username", "password"],
		uppercase: [],
		lowercase: [],
		ucfirst: [],
		digit: [],
		required: ["sitename", "username", "password"],
		dependancies: {},
		constraints: {},
		confirm: {}
	};

	var valResults = dojo.validate.check(dojo.byId('frmLogin'), valProfile);	
	
	if (valResults.isSuccessful()) {	
		dojo.byId('loginsubmit').value = 'Please Wait...';
		dojo.byId('loginsubmit').style.width = '120px';	
		dojo.io.bind(bindArgs);
	} else if (valResults.hasMissing()) {
		alert('Please enter your sitename, username and your password.');
		dojo.byId('loginsubmit').value = 'Login';
		dojo.byId('loginsubmit').style.width = '80px';			
		return false;
	}	
	
	return false;

}

function retrievePassword() {
	dojo.require("dojo.validate");
	dojo.require("dojo.validate.check");
	dojo.require("dojo.validate.datetime");
	dojo.require("dojo.validate.us");
	dojo.require("dojo.validate.web");	
	
	var lost_password_container = dojo.byId('lost_password_container');
	var orig_contents = lost_password_container.innerHTML;
	
	var bindArgs = {
	url: 'pages/retrieve_password.asp',
	method: 'post',
	content: {
		email: dojo.byId('forgotemail').value
	},
	error: function(type, data, evt){
		alert('An error occurred and we could not retrieve your password.  Please try again.');
		dojo.byId('retrievesubmit').value = 'Retrieve Password';
		dojo.byId('retrievesubmit').style.width = '140px';	
	},
	load: function(type, data, evt){
		var returnVal = parseFloat(data);
		if (returnVal == -3) {
			dojo.style.show(dojo.byId('retrieve_not_found'));
			dojo.byId('retrievesubmit').value = 'Retrieve Password';
			dojo.byId('retrievesubmit').style.width = '140px';			
		} else if (returnVal <= 0) {
			dojo.style.show(dojo.byId('retrieve_error'));
			dojo.byId('retrievesubmit').value = 'Retrieve Password';
			dojo.byId('retrievesubmit').style.width = '140px';			
		} else {
			dojo.style.hide(lost_password_container);
			dojo.style.show(dojo.byId('retrieve_success'));
		}
		
	},
	mimetype: 'text/html'
	};	
	
	// Validate the form contents before submitting
	var valProfile = {
		// filters change the field value and are applied before validation.
		trim: ["forgotemail"],
		uppercase: [],
		lowercase: [],
		ucfirst: [],
		digit: [],
		required: ["forgotemail"],
		dependancies: {},
		constraints: {
			"forgotemail" : [dojo.validate.isEmailAddress]
		},
		confirm: {}
	};

	var valResults = dojo.validate.check(dojo.byId('forgotpw'), valProfile);	
	
	if (valResults.isSuccessful()) {
		dojo.byId('retrievesubmit').value = 'Please Wait...';
		dojo.io.bind(bindArgs);
	} else if (valResults.hasMissing()) {
		alert('Please enter an email address.');
		dojo.byId('forgotemail').focus();		
		return false;
	} else if (valResults.isInvalid('forgotemail')) {
		alert('Please enter a valid email address.');
		dojo.byId('forgotemail').focus();
		return false;
	}	
}

//]]>
