function contactIsValid() {
	$( 'form_submit' ).disabled = 'disabled';
	var reg = /^[_A-z0-9-\.]+(\.[_A-z0-9-]+)*@[A-z0-9-\.]+\.+[A-z0-9-]{1,}$/;
	
	if( $F('lastname') == '') {
		displayFormError('Please fill your lastname');
		return false;
	} else if( $F('firstname') == '') {
		displayFormError('Please fill your firstname');
		return false;
	} else if( $F('email') == '') {
		displayFormError('Please fill your email');
		return false;
	} else if( !reg.test($('email').value)) {
		displayFormError('Wrong email format');
		return false;
	} else if( $F('comment') == '') {
		displayFormError('You have to say something.');
		return false;
	}
	
	return true;
}

function fiskarettecontactIsValid() {
	$( 'form_submit' ).disabled = 'disabled';
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	
	if( $F('comment') == '') {
		displayFormError('You have to say something.');
		return false;
	}
	
	return true;
}

function creationIsValid() {
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	
	if( $F('title') == '') {
		displayFormError('Please fill a title for your creation.');
		return false;
	} else if( $F('comment') == '') {
		displayFormError('You have to say something about your creation.');
		return false;
	} else if( $F('photo_1') == '' && $F('photo_2') == '' && $F('photo_3') == '' && $F('photo_4') == '' && $F('photo_5') == '') {
		displayFormError('You have to give a least one photo.');
		return false;
	}
	
	return true;
}

function challengeIsValid() {
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	
	if( $F('title') == '') {
		displayFormError('Please fill a title for your creation.');
		return false;
	} else if( $F('comment') == '') {
		displayFormError('You have to say something about your creation.');
		return false;
	} else if( $F('photo_1') == '' && $F('photo_2') == '' && $F('photo_3') == '' && $F('photo_4') == '' && $F('photo_5') == '') {
		displayFormError('You have to give a least one photo.');
		return false;
	} else if( !$F('rules')) {
		displayFormError('You have to agree the challenge rules.');
		return false;
	}
	
	return true;
}

function designTeamRegistrationIsValid() {
	if( $F( 'category' ) == 'other' && $F( 'other' ) == '' ) {
		displayFormError('Please specify your favourite creative preference');
		return false;
	} else if( $F( 'category2' ) == 'other' && $F( 'other2' ) == '' ) {
		displayFormError('Please specify your second creative preference');
		return false;
	} else if( $F('comment') == '') {
		displayFormError('Enter your motivations.');
		return false;
	} else if( $F('photo_1') == '' && $F('photo_2') == '' && $F('photo_3') == '' && $F('photo_4') == '' && $F('photo_5') == '') {
		displayFormError("You have to upload at least one picture of one of your creations.");
		return false;
	} else if( !$F('conditions')) {
		displayFormError('You have to accept the Design Team conditions of use.');
		return false;
	}
	
	return true;
}

function postIsValid() {
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	
	if( $F('category') == 0) {
		displayFormError('You have to choose a category.');
		return false;
	} else if( $F('title') == '') {
		displayFormError('Post\'s title is required.');
		return false;
	} else if( $F('comment') == '') {
		displayFormError('Post\'s text is required.');
		return false;
	}
	
	return true;
}

function inscriptionIsValid() {
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	
	if( $F('lastname') == '') {
		displayFormError('Your lastname is required.');
		return false;
	} else if( $F('firstname') == '') {
		displayFormError('Your firstname is required.');
		return false;
	} else if( $F('pseudo') == '') {
		displayFormError('Your pseudonym is required.');
		return false;
	} else if( $F('pwd') == '') {
		displayFormError('Your password is required.');
		return false;
	} else if( $F('pwd2') == '') {
		displayFormError('Your password\'s confirmation is required.');
		return false;
	} else if( $F('pwd') != $F('pwd2')) {
		displayFormError('Your password\'s confirmation is wrong.');
		return false;
	} else if( $F('email') == '') {
		displayFormError('Your email is required.');
		return false;
	} else if( !reg.test($('email').value)) {
		displayFormError('Wrong email format.');
		return false;
	} else if( $F('address') == '') {
		displayFormError('Your address is required.');
		return false;
	} else if( $F('zip_code') == '') {
		displayFormError('Your zip code is required.');
		return false;
	} else if( $F('city') == '') {
		displayFormError('Your city is required.');
		return false;
	} else if( $F('country') == '') {
		displayFormError('Your country is required.');
		return false;
	} else if( $F('captcha') == '') {
		displayFormError('You have to recopy the image text.');
		return false;
	} else if( !$F('disclaimer')) {
		displayFormError('You have to accept the term of use.');
		return false;
	}
	
	return true;
	//verifiyCaptcha($F('captcha'));
}

function verifiyCaptcha(captcha) {
	var myAjax = new Ajax.Request(
			'/captcha.php',
			{
				method: 'get',
				parameters: 'c='+captcha,
				onComplete: function(originalRequest) {
					if( originalRequest.responseText == 'ok') {
						alert('oui');
						return true;
					} else {
						alert('non');
						return false;
					}
				}
			});
}

function passwordIsValid() {
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
	if( $F('lost-email') == '') {
		displayFormError('Your email is required');
		return false;
	} else if( !reg.test($('lost-email').value)) {
		displayFormError('Wrong email format.');
		return false;
	} else {
		return true;
	}
}



function inscriptionIsValid2() {
	
	if( $F('lastname') == '') {
		displayFormError('Please enter your last name.');
		return false;
	} else if( $F('firstname') == '') {
		displayFormError('Please enter your first name.');
		return false;
	} else if( $F('pseudonym') == '') {
		displayFormError('Please enter your pseudonym.');
		return false;
	} else if( $F('region') == '') {
		displayFormError('Please enter your county.');
		return false;
	} else if( $F('passwd') != '' && $F('passwd') != $F('passwd2')) {
		displayFormError('Your password\'s confirmation is required');
		return false;
	} else if( $F('address') == '') {
		displayFormError('Please enter your address.');
		return false;
	} else if( $F('zip_code') == '') {
		displayFormError('Please enter your postcode.');
		return false;
	} else if( $F('city') == '') {
		displayFormError('Please enter your city.');
		return false;
	} else if( $F('country') == '') {
		displayFormError('Please enter your country.');
		return false;
	}
	
	if( $F('craft') == '' && $F('craft2') == '' && $F('craft3') == '' && $F('craft3') == '' && $F('craft5') == '' && $F('craft6') == '' && $F('crop') == '') {
		if( confirm("You have not fill the \"Crafting & Me\" section.\n\n You would fill this section later.\n\nWould you like to fill it now ?")) {
			changeForm('2');
			return false;
		}
	}
	
	if( $F('passion') == '' && $F('music') == '' && $F('color') == '' && $F('dish') == '' && $F('activity') == '' && $F('super') == '') {
		if( confirm("You have not fill the \"My favourites\" section\n\n. You would fill this section later.\n\nWould you like to fill it now ?")) {
			changeForm('3');
			return false;
		}
	}
	
	if( $F( 'email_val' ) != $F( 'email' ) ) {
		//alert( "Tu as demandé à changer d'adresse email.\n\nUn e-mail vient d'être envoyé à " + $F( 'email_val' ) + ", tu devra cliquer dans le lien présent dans cet e-mail pour valider ce changement.\n\nAttention le lien dans l'email n'est valable que pendant 48H." );
		alert( "You ask for changing your e-mail address.\n\nWe just sent you an e-mail to " + $F( 'email_val' ) + ", you have to click the link inside this e-mail to validate your e-mail address' change.\n\nWarning, the link is only available for 48 hours." );
	}
	
	return true;
	//verifiyCaptcha($F('captcha'));
}

function displayFormError( text ) {
	alert( text );
	$( 'form_submit' ).disabled = false;
}
