jQuery(function($) {

   

 });



function validate_email(field) {

	with (field) {

		apos=value.indexOf("@");

		dotpos=value.lastIndexOf(".");

		if (apos<1||dotpos-apos<2) {

			return false;

		} else {

			return true;

		}

	}

}



function validate_register_form(thisform) {

	with (thisform) {

		var errorCount=0;

		var errorMessage="<ul>";

		email.style.backgroundColor="white";

		first_project_name.style.backgroundColor="white";

		if (validate_email(email)==false||email.value==null||email.value=="") {

			errorMessage=errorMessage+"<li>You must enter a valid email address</li>";

			email.style.backgroundColor="#F5B1B2";

			email.focus;

			errorCount++;

		}

		if (first_project.checked==true) {

			if (first_project_name.value==null||first_project_name.value=="") {

				errorMessage=errorMessage+"<li>You have chosen to create your first project, so you need to enter a name for that project</li>";

				first_project_name.style.backgroundColor="#F5B1B2";

				first_project_name.focus;

				errorCount++;

			}

		}

		errorMessage=errorMessage+"</ul>";

		if (errorCount>0) {

			$("#register_message").hide();

			$("#register_message").html(errorMessage);

			$("#register_message").css({color:"red"});

			$("#register_message").show("fast");

			return false;

		} else {

			$.ajax({

				url: "../functions/check_email.php",

				type: "POST",

				data: "email="+email.value,

				error: function(){

					alert("Error loading XML document");

				},

				success: function(xml){

					if ($("email_result",xml).text()=="success") {

						//The email address is not in use so submit the form

						$("#register_form").attr("onsubmit","");

						$("#register_form").submit();

					} else {

						$("#register_message").hide();

						$("#register_message").html("<ul><li>That email address is taken</li></ul>"); 

						$("#register_message").css({color:"red"});

						$("#register_message").show("fast");

						$("#email").css({backgroundColor:"#F5B1B2"});

					}

				}

			});

			return false;

		}

	}

}


