function registerUser(){
	verifyUserName("username");
	
	if(form_validate('register','fieldOnly','Please enter your first name.', 'fname', 'generalText','Please enter your last name.', 'lname', 'generalText','E-mail is not valid.', 'email', 'email'
	,'Please enter a username.', 'username', 'generalText'
	,'Please enter your password.', 'password', 'generalText'
	,'Please verify your password.', 'password2', 'generalText')){
		
		age ="";
		// get age
		field = document.register.age;
		for(i=0; i < field.length; i++){
			if(field[i].checked){
				age = field[i].value;
			}
		}

		var myXHR = new XHR({method: 'post', onRequest: registerSuccess}).send('/inc/p/registerProc.php', 'email='+$('email').value+'&fname='+$('fname').value+'&lname='+$('lname').value+'&age='+age+'&username='+$('username').value+'&password='+$('password').value+'&subscribe='+$('subscribeBox').value+'&subscribeSponsor='+$('subscribeSponsorBox').value);
	}
	return false;
}

function registerSuccess(){
	$('registrationForm').setHTML('<p style="text-align: center;"><br/><img src="/img/thanks-for-signing-up.gif" alt="Thank you for signing up!" /></p>');
}

window.addEvent('domready', function() {
	// Run when the page is loaded!
	if($('imageRotation')){
		rotateHomeImage.delay(rotationDelay);
	}
	
	if($('contestRotation')){
		rotateContestImage.delay(rotationDelay);
	}
});

var rotationDelay = 5000 // time in milleseconds
var currentImageRotation = 1;
function rotateHomeImage(){
	//$('rotation_'+currentImageRotation).removeClass("visible").addClass("hidden");
	new Fx.Style('rotation_'+currentImageRotation,'opacity').start(1,0);
	
	currentImageRotation++;
	if(!$('rotation_'+currentImageRotation)){
		currentImageRotation = 1;
	}
	
	new Fx.Style('rotation_'+currentImageRotation,'opacity').start(0,1);
	//$('rotation_'+currentImageRotation).removeClass("hidden").addClass("visible");
	
	rotateHomeImage.delay(rotationDelay);
}

var currentContestImageRotation = 1;
function rotateContestImage(){

	new Fx.Style('contest_'+currentContestImageRotation,'opacity').start(1,0);
	
	currentContestImageRotation++;
	if(!$('contest_'+currentContestImageRotation)){
		currentContestImageRotation = 1;
	}
	
	new Fx.Style('contest_'+currentContestImageRotation,'opacity').start(0,1);
	
	rotateContestImage.delay(rotationDelay);
}

function contactForm(){
	if(form_validate('contact','fieldOnly','Please enter your name.', 'name', 'text','E-mail is not valid.', 'email', 'email','Please enter a comment', 'comment', 'generalText')){
		var myXHR = new XHR({method: 'post', onRequest: contactSuccess}).send('/inc/p/contactProc.php', 'email='+$('email').value+'&name='+$('name').value+'&comment='+$('comment').value+'&firstName='+$('firstName').value);
	}
	return false;
}

function contactSuccess(){
	$('registrationForm').setHTML('<p style="text-align: center;"><br/><img src="/img/thanks-for-contacting-us.gif" alt="Thank you for contacting us!" /></p>');
}

/* VERIFY USERNAME */

function verifyUserName(el){
	if($(el).value){
		$('userNameLink').setHTML("Verifying...");
		var myXHR = new XHR({method: 'post', onSuccess: verifyUserNameResponse}).send('/inc/p/verifyUserName.php', 'username='+$(el).value);
	}
	
	return false;
}

function verifyUserNameResponse(response){
	if(response == 1){
		$('userNameLink').setHTML("It's available!");
	}else{
		$('userNameLink').setHTML("Not available.");
		if($('usernameField')){
			$('usernameField').value = "";
		}else{
			$('username').value = "";
		}
	}
}