function validateAndSendUserProfileForm() {
	errormessages = new Array();
	firstname = document.userprofileform.firstname.value;
	lastname = document.userprofileform.lastname.value;
	birthdate = document.userprofileform.birthdate.value; 
	gender = document.userprofileform.gender.options.selectedIndex;
	occupation = document.userprofileform.occupation.value;
	address = document.userprofileform.address.value;
	zipcode = document.userprofileform.zipcode.value;
	city = document.userprofileform.city.value;
	country = document.userprofileform.country.value;
	secretque = document.userprofileform.secretque.value;
	secretanswer = document.userprofileform.secretanswer.value;
	about = document.userprofileform.about.value;

	if( firstname == "" ) { errormessages.push( "Du glömde att ange ditt förnamn." ); }
	if( lastname == "" ) { errormessages.push( "Du glömde att ange ditt efternamn." ); }
	if( birthdate == "" ) { errormessages.push( "Du glömde att ange ditt födelsedatum." ); }
	else {
		if ( !validateDate( birthdate ) ) {
			errormessages.push( "Du skrev inte in ditt födelsedatum i rätt format." );
		}
	}

	if( gender == "0" ) { errormessages.push( "Du glömde att ange om du är flicka eller pojke." ); }
	if( occupation == "" ) { errormessages.push( "Du glömde att ange din sysselsättning." ); }

	if( address == "" ) { errormessages.push( "Du glömde att ange din gatuadress." ); }
	if( zipcode == "" ) { errormessages.push( "Du glömde att ange ditt postnummer." ); }
	if( city == "" ) { errormessages.push( "Du glömde att ange din stad." ); }
	if( country == "" ) { errormessages.push( "Du glömde att ange vilket land du bor i." ); }

	if( secretque == "" ) { errormessages.push( "Du glömde att ange din hemliga fråga." ); }
	if( secretanswer == "" ) { errormessages.push( "Du glömde att ange svaret på din hemliga fråga." ); }

	if( errormessages.length > 0 ) {
		mes = "Följande fel inträffade:\n\n";
		for( i = 0; i < errormessages.length; i++ ) {
			mes += (i+1) + ": " + errormessages[i] + "\n";
		}
		showAlertMessage( mes );
		return false;
	}
	request = createRequest();

	var url = "userprofileinfoupdater.php";
	el = document.getElementById( 'personalinfomessageplace' );
	request.open("POST", url, true);
	request.onreadystatechange = function showConfirmation() {
		if ( request.readyState == 4 ) {
			if ( request.status == 200 ) {
				var response = request.responseText;
				el.innerHTML = "<IMG SRC=pics/working.gif BORDER=0 ALIGN=BOTTOM STYLE=\"text-align:bottom;\"> " + response;
				setTimeout( "emptyElement( 'personalinfomessageplace' )", 3000);
			}
			else {
				showAlertMessage( "Det uppstod ett fel när dina nya uppgifter skulle sparas!\nFelkod: " + request.status );
			}
		}
		else {
			el.innerHTML = "<IMG SRC=pics/working.gif BORDER=0 ALIGN=BOTTOM STYLE=\"text-align:bottom;\"> Laddar... Var god v&auml;nta..."; 
		}
	}
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	bodyofrequest = "firstname=" + firstname + "&lastname=" + lastname + "&birthdate=" + birthdate + "&gender=" + gender + "&occupation=" + occupation +
							"&address=" + address + "&zipcode=" + zipcode + "&city=" + city + "&country=" + country + "&secretque=" + secretque +
							"&secretanswer=" + secretanswer + "&about=" + about;
	request.send( bodyofrequest );
	return true;
}

function validateUserProfilePicForm() {
	userprofilepic = document.userprofilepicform.userprofilepic.value;
	if( userprofilepic == "" ) {
		showAlertMessage( "Du glömde att ange namnet på bildfilen." );
		return false;
	}
	return true;
}

function emptyProfilepicSpot() {
	emptyElement( "profilepicmessagespot" );
}

