
		
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }






		function btnCheckNameOver() {
			if (btnCheckStatus == 'check') {
				$('#btnCheckName').css('background-position','0px -30px');
			}
		}
		function btnCheckNameOut() {
			if (btnCheckStatus == 'check') {
				$('#btnCheckName').css('background-position','top left');
			}
		}
		
		function btnCheckNameClick() {
			//-----------------------------------------------------------------
			// Don't check a name we've already noted is valid or invalid.
			//-----------------------------------------------------------------
				if (btnCheckStatus == 'invalid' || btnCheckStatus == 'valid') {
					return false;
				}
			
			//-----------------------------------------------------------------
			// Get the User Name from the Form
			//-----------------------------------------------------------------
				txtUserName = jQuery.trim($("#username").val());

			//-----------------------------------------------------------------
			// User Name Validation - Make sure it passes basic litmus test.
			//-----------------------------------------------------------------
				result = true;		// Assume the username is valid.
				if (txtUserName == '') 
					result = false;
				
			//-----------------------------------------------------------------
			// If the name is still valid - test it against the database.
			//-----------------------------------------------------------------
				if (result) {
				
				
					$.ajax({
		    			type: 	"GET", 
		    			url:	"./ajax/ajax.php",
		    			async:	false,
		    			data:	({uck: txtUserName}),
		    		    success:	function(data) {
		    		                if (data == 0) {
										btnCheckStatus = 'valid';
										$('#btnCheckName').css('background-position','0px -60px');
										// alert("UserName is OK for: " + txtUserName);
									} else {
										btnCheckStatus = 'exists';
										$('#btnCheckName').css('background-position','0px -90px');
										// alert("UserName Exists for: " + txtUserName);
									}
		    				                
		    	                }
		    		 });
				
			/*	
					$.get("./ajax/ajax.php", {uck: txtUserName}, function(data) {
						if (data == 0) {
							btnCheckStatus = 'valid';
							$('#btnCheckName').css('background-position','0px -60px');
							// alert("UserName is OK for: " + txtUserName);
						} else {
							btnCheckStatus = 'invalid';
							$('#btnCheckName').css('background-position','0px -90px');
							// alert("UserName Exists for: " + txtUserName);
						}
					});
					
					*/
				
				} else {
					btnCheckStatus = 'invalid';
					$('#btnCheckName').css('background-position','0px -90px');
					// alert("Username Fails Validation: " + txtUserName);
				}
				
			//-----------------------------------------------------------------
			// Done processing User Name - Return False for No Good Reason.
			//-----------------------------------------------------------------
				return false;
		}

		function userNameChange() {
			newUserName = $("#username").val();
			if (btnCheckStatus == 'invalid' || btnCheckStatus == 'valid') {
				if (newUserName != txtUserName) {
					btnCheckStatus = 'check';
					$('#btnCheckName').css('background-position','top left');
				}
			}
		}
		
		function btnJoinClick() {
			// Double check name
			// submit form.
			
			
			btnCheckNameClick();
			
			popup = '';
			
			
			if (btnCheckStatus != 'valid') {
				if (btnCheckStatus == 'exists') {
					$.prompt('The User Name you have chosen is already being used.  Please select another User Name.');
				} else {
					$.prompt('Please make sure you have chosen a valid USERNAME before continuing.');
				}
				
			
				
				return false;
			}

			if (jQuery.trim($("#password").val()) == '') {
				$.prompt('You must enter a password.')
				return false;
			}
			if (jQuery.trim($("#passwordverify").val()) == '') {
				$.prompt('Please verify the password.')
				return false;
			}
			
			if ($("#password").val() != $("#passwordverify").val()) {
				$.prompt('Passwords do not match');
				return false;
			}
			
			if (jQuery.trim($("#email").val()) == '') {
				$.prompt('You must enter a valid E-Mail address.')
				return false;
			}
			if (jQuery.trim($("#emailverify").val()) == '') {
				$.prompt('Please verify the E-Mail address.')
				return false;
			}

			

			if ($("#email").val() != $("#emailverify").val()) {
				$.prompt('E-Mail Addresses do not match');
				return false;
			}
			
			
			
			
			
			
			$("#firstname").css('background-color', 'white');
			$("#lastname").css('background-color', 'white');
			$("#address").css('background-color', 'white');
			$("#city").css('background-color', 'white');
			$("#state").css('background-color', 'white');
			$("#country").css('background-color', 'white');
			$("#postalcode").css('background-color', 'white');
			$("#cardnum").css('background-color', 'white');
			$("#cardexp").css('background-color', 'white');
			$("#cardcv2").css('background-color', 'white');
			
			
			
			exp = jQuery.trim($("#cardnum").val());
			if (exp.length != 16) {
				$("#cardnum").css('background-color', 'red');
				popup += '\n    The card number must be 16 numbers long with no spaces.';
				
			} else {
				if (IsNumeric(exp) == false) {
					$("#cardnum").css('background-color', 'red');
					popup += '\n    The card number must be 16 numbers long with no spaces.';
					
				}
			}			
		
			exp = jQuery.trim($("#cardexp").val());
			if (exp.length != 4) {
				$("#cardexp").css('background-color', 'red');
				popup += '\n    The Expiration Date must be in the format of MMDD (ex: 0412 for April 2012).';
				
			} else {
				if (IsNumeric(exp) == false) {
					$("#cardexp").css('background-color', 'red');
					popup += '\n    The Expiration Date must be in the format of MMDD (ex: 0412 for April 2012).';
					
				}
			}			
			
			exp = jQuery.trim($("#cardcv2").val());
			if (exp.length != 3) {
				$("#cardcv2").css('background-color', 'red');
				popup += '\n    The Security Code must be three numbers exactly.';
				
			} else {
				if (IsNumeric(exp) == false) {
					$("#cardcv2").css('background-color', 'red');
					popup += '\n    The Security Code must be three numbers exactly.';
					
				}
			}			
			
			
			
			
			
			
			
			if (jQuery.trim($("#firstname").val()) == '') {
				$("#firstname").css('background-color', 'red');
				popup += '\n    Please enter a valid First Name.';
			}

			if (jQuery.trim($("#lastname").val()) == '') {
				$("#lastname").css('background-color', 'red');
				popup += '\n    Please enter a valid Last Name.';
			}
			
			if (jQuery.trim($("#address").val()) == '') {
				$("#address").css('background-color', 'red');
				popup += '\n    Please enter a valid Address.';
			}
			
			if (jQuery.trim($("#city").val()) == '') {
				$("#city").css('background-color', 'red');
				popup += '\n    Please enter a valid City.';
			}
			
			if (jQuery.trim($("#state").val()) == '') {
				$("#state").css('background-color', 'red');
				popup += '\n    Please enter a valid State.';
			}
			
			if (jQuery.trim($("#country").val()) == '') {
				$("#country").css('background-color', 'red');
				popup += '\n    Please enter a valid Country.';
			}
			
			if (jQuery.trim($("#postalcode").val()) == '') {
				$("#postalcode").css('background-color', 'red');
				popup += '\n    Please enter a valid Postal Code.';
			}
			
			if (jQuery.trim($("#cardnum").val()) == '') {
				$("#cardnum").css('background-color', 'red');
				popup += '\n    Please enter a valid Credit Card Number.';
			}

			if (jQuery.trim($("#cardexp").val()) == '') {
				$("#cardexp").css('background-color', 'red');
				popup += '\n    Please enter a valid Credit Card Expiration Date.';
			}
			
			if (jQuery.trim($("#cardcv2").val()) == '') {
				$("#cardcv2").css('background-color', 'red');
				popup += '\n    Please enter a valid Credit Card CVV2 Code.';
			}




			if (popup != '') {
				$.prompt('In order to continue, please fix the following:' + popup);
			} else {
				// $("#formJoin").submit();
				$.prompt("Hold on a sec while we validate your account");
				
				$("#formJoin").ajaxSubmit(function(responseText, statusText) {
					
					if (responseText == 'ok') {
						$("#formJoin").css('visibility', 'hidden');
					
						// all is good!
						
						// window.location = './videos';
						window.location.replace("http://www.elviswanted.com/videos");

					} else {
						$(".jqimessage").html(responseText);
						return false;


					}
					$.prompt.close();
				
				});
			}
		}