
		function clearerrors()
		{
				document.getElementById("error").innerHTML = "";
				document.getElementById("error").style.display = "none";
				document.getElementById("usertextbox").style.border = "1px solid #000";
				document.getElementById("usernamediv").style.display = "none";
		}
		
		function error( errStr, focus )
		{
				document.getElementById("error").style.display = "block";
				document.getElementById("error").innerHTML = errStr;
				
				//now lets highlight the box and set focus
				focus.style.border = "2px solid #a00";
				focus.focus();
		}
		
		YAHOO.namespace("reg.container");
		
		function showwaiter(){
			/*
			 if (!YAHOO.reg.container.wait) {

				YAHOO.reg.container.wait = new YAHOO.widget.Panel("wait",  
		                                                    { width: "240px", 
		                                                      fixedcenter: true, 
		                                                      close: false, 
		                                                      draggable: false, 
		                                                      zindex:500,
		                                                      modal: false,
		                                                      visible: false
		                                                    } 
		                                                );
				YAHOO.reg.container.wait.setHeader("Checking username availability");
				YAHOO.reg.container.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
				YAHOO.reg.container.wait.render(document.getElementById("usernamediv"));
				YAHOO.reg.container.wait.show();
			}else{
				YAHOO.reg.container.wait.show();
			}
			*/
		}
		
		function hidewaiter(){
			//YAHOO.reg.container.wait.hide();
		}
            

		function clearError( inForm )
		{
			var child = inForm.elements;
			for( var i = 0; i < child.length; i++ )
			{
				if( child[i].tagName == "INPUT" )
					child[i].style.border = "#000 solid 1px";
			}
		}
		
		function isAlphaNumeric(val)
		{
			
			if (val.match(/^[a-zA-Z0-9_]+$/))
			{
				if ( val.match(/[a-zA-Z0-9]/)){ // must contain at least 1 alpha
					return true;
				}else{
					return false;
				}
			}
			else
			{
				return false;
			} 
	}
	
		var handleSuccessUsernameAvailCallback = function(o){ 
			//hidewaiter();
			if( o.responseText == 0 ){ // this user is not available
						txt = "This username is already taken. Please try another one.";
						YAHOO.util.Dom.get("usernamemessagediv").style.color = "#990000";	
						YAHOO.util.Dom.get("usernamemessagediv").innerHTML= txt;
						YAHOO.util.Dom.get("usernamediv").style.display= "block";
						document.getElementById("usertextbox").style.border = "2px solid #a00";
						document.getElementById("usertextbox").focus();
			}else{
						txt = "This username is available for you to use!";	
						YAHOO.util.Dom.get("usernamemessagediv").style.color = "#009900";
						YAHOO.util.Dom.get("usernamemessagediv").innerHTML= txt;
						YAHOO.util.Dom.get("usernamediv").style.display= "block";
						document.getElementById("usertextbox").style.border = "1px solid #000";
						document.getElementById("pass").focus();
			}
	
	    };
	    
		var handleFailureUsernameAvailCallback = function(o){ 
				return false;
		};
		
		var isUsernameAvailCallback = 
		{ 
				success:handleSuccessUsernameAvailCallback, 
				failure: handleFailureUsernameAvailCallback 
		};
	
		function usernameAvailable( username, uid)
		{
			if( username == "" ) 
				{
					error("Error: The username field can not be empty.", document.f1.username); 
					return false;
				}
				if( username.length < 4 ) 
				{
					error("Error: The username must be 4 or more characters.",  document.f1.username); 
					return false;
				}
				
				if( isAlphaNumeric( username) != true ){
					error("Error: The username must only contain alphanumeric chars ( a-z, A-Z, 0-9 ) and underscore chars with at least one alphanumeric char.", document.f1.username); 
					return false;
				}	
				
			// check if valid user before we add it
			
			var sUrl = "/extras/usernameavail?username="+username+"&uid="+uid; 
			var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, isUsernameAvailCallback); 
			showwaiter();
		}
		
		function validateFormOnSubmit( theForm )
		{
				//clearError( theForm );

				email = theForm.email.value;
				username = theForm.username.value;
				password = theForm.password.value;
				verifypassword = theForm.verifypassword.value;
				if( theForm.sbcaptcha != null ){
					captcha = theForm.sbcaptcha.value;
				}
							
				if( username == "" ) 
				{
					error("Error: The username field can not be empty.", theForm.username); 
					return false;
				}
				if( username.length < 4 ) 
				{
					error("Error: The username must be 4 or more characters.", theForm.username); 
					return false;
				}
				
				if( isAlphaNumeric( username) != true )
				{
					error("Error: The username must only contain alphanumeric chars ( a-z, A-Z, 0-9 ) and underscore chars with at least one alphanumeric char.", theForm.username); 
					return false;
				}	
				
				if( username == password ) 
				{
					error("Error: The username and password fields must be different.", theForm.password); 
					return false;
				}
				
				if( password == email ) 
				{
					error("Error: The password and email fields must be different.", theForm.email); 
					return false;
				}
				
				if( password == "" ) 
				{
					error("Error: The password field can not be empty.", theForm.password); 
					return false;
				}
				if( password.length < 4 ) 
				{
					error("Error: The password must be 4 or more characters.", theForm.password); 
					return false;
				}	

				if( verifypassword == "" ) 
				{
					error("Error: The verify password field can not be empty.", theForm.verifypassword); 
					return false;
				}		

				if( password != verifypassword )
				{
					error("Error: The password fields do not match.", theForm.password); 
					return false;
				}
				
				// validate if empty
				if( email == "" )
				{
					error( "Error: The email address field can not be empty.", theForm.email);
					return false;
				}
				
				// validate emails
				var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
				if (!(emailFilter.test(email))) 
				{ 
					error( "Error: Please enter a valid email address.", theForm.email);
					return false;
				}
				
				var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
				if (email.match(illegalChars)) 
				{
					error( "Error: The email address contains illegal characters. Please enter a valid email address.", theForm.email);
					return false;
				}
				
				// validate if empty
				if( theForm.sbcaptcha != null ){
					if( (captcha == "") || (captcha.length < 5) )
					{
						error( "Error: The captcha field can not be empty and it must be 5 characters.", theForm.sbcaptcha);
						return false;
					}
				}

				if( !theForm.tos.checked )
				{
						error( "Error: Please accept the SimplyBox Terms of Service Agreement.", theForm.tos);
						return false;
				} 

			return true;

		}


