var f;
var rf;

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(i=0; i < e.length ;i++)
{
	if(ok.indexOf(e.charAt(i))<0)
	{ 
		return (false);
	}	
} 

	if (document.images) 
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);		
		} 
	}
}

function requestAccess()
{
	if( rf.email.value == "" )
	{
		Ext.MessageBox.alert("Oops!","Please enter your email address.");
		return false;
	}
	if( rf.email.value != "" )
	{
		if(!check_email(rf.email.value))
		{
			Ext.MessageBox.alert("Oops!","Please enter a valid email address.");
			return false;
		}
		else
		{
			Ext.Ajax.request({
				url: '/common/cfx/gallery.login.cfm',
				method: 'POST',
				form: 'requestLoginForm'
			});
			
			var _msg = '<div class="x-confirm"><b>Thank you for submitting your request.</b><br />Your request for access will be processed shortly.</div>';
			Ext.get("sp").update(_msg);	
		}
		
	}
}


function galleryLogin()
{
	if(	f.password.value == "" )
	{
		Ext.MessageBox.alert("Oops!","Please enter the password.");
		return false;
	}
	
	Ext.Ajax.request({
		url: '/common/cfx/gallery.login.cfm',
		method: 'POST',
		form: 'galleryLoginForm',
		success:function(r)
		{
			var data = eval('(' + r.responseText + ')');
			if(data.success)
			{
				f.submit();
			}
			else
			{
				Ext.MessageBox.alert("Login","Sorry, the password you entered was incorrect.<br/>Please try again.");
			}
		}
		
	});
	
}
Ext.onReady(function(){
	f = document.galleryLoginForm;
	rf = document.requestLoginForm;	
});
					 
					 