$(document).ready(function() {

	var typeWatchOptions = {

	callback:function(){ checkUsernameAvailability(); },

		wait:750

	}

	

	//Watch for when typing is finished in the username field.

	$("#username").typeWatch(typeWatchOptions);

	

	//When a user is typing in the username field, we don't want the availability status to show.

	$("#username").keypress(function() {

	$('#usernameAvailability').text('');

	});

	

});

 

//does the AJAX username lookup

function checkUsernameAvailability() {

//	$('#usernameAvailability').text('Checking availability...');

	$('#imgChkUsr').attr('src', '/site/images/loadingIcon.gif');

	$.post('/site/php/action.php', { username: $('#username').val(), action: "checkUsernameAvailability" }, function(data) {

		$('#imgChkUsr').attr('src', '/site/images/' + data);

		if (data == 'userNOIcon.gif'){$('#signupDivUsername').attr('class', 'frontInput inputFail'); 	$('#usernameAvailability').text('Username taken.');}

		else{$('#signupDivUsername').attr('class', 'frontInput'); 		$('#usernameAvailability').text(''); }

	});

}







$(document).ready(function() {

	$("#uEmail").keyup(function(){

		var email = $("#uEmail").val();

		if(email != 0)

		{

			isValidEmailAddress(email);

		} else {

			$('#imgChkEmail').attr('src', '/site/images/userNOIcon.gif');	  

			$('#signupDivEmail').attr('class', 'frontInput');				

		}

	});

});



function isValidEmailAddress(emailAddress) {

	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

	var results = pattern.test(emailAddress);



	if (results == true){

		$.post('/site/php/action.php', { uEmail: emailAddress, action: "checkEmailAvailability" }, function(data) {

			if (data == 'true')

			{

				$('#imgChkEmail').attr('src', '/site/images/userOKIcon.gif');	

				$('#signupDivEmail').attr('class', 'frontInput');				

			}

			else

			{

				$('#imgChkEmail').attr('src', '/site/images/userNOIcon.gif');

				$('#signupDivEmail').attr('class', 'frontInput inputFail');		

			}

		});

	}

	else

	{

		$('#imgChkEmail').attr('src', '/site/images/userNOIcon.gif');

		$('#signupDivEmail').attr('class', 'frontInput inputFail');		

	}

	

	

}





function ValidateForm(){

	var emailID=document.signup.userMail;

	var checkUsername;



	if ($('#imgChkUsr').attr('src') != '/site/images/userOKIcon.gif'){

			alert("The username you have choosen seems to be invalid. Please select another one.");

			return false;

		}



	if ($('#imgChkPsw').attr('src') != '/site/images/userOKIcon.gif' && $('#imgChkPsw2').attr('src') != '/site/images/userOKIcon.gif'){

		alert("Your password information seems to be incorrect.");

		document.getElementById('userPass').focus();

			return false;

	}



	if ($('#imgChkEmail').attr('src') != '/site/images/userOKIcon.gif'){

			alert("The email you have choosen seems to be invalid. Please select another one.");

			return false;

		}



	if ($('#captcha').val() == ''){

			alert("You need to fill in the code in the picture to the left.\nIt's a four (4) letter code.");

			return false;

		}

	document.signup.submit();

}




