
// request

function ajaxDeactivate() {
	
  var phoneNumLength = 10;
	
  var form = document.forms["formDeactivate"];
	
	// validate address
	if (form.email.value.length <= 0 && form.phone.value.length <= 0) {
	  ajaxError("Please enter your phone number or email address.");
		form.phone.focus();
		return;
	}
	
  // validate phone number
  if (form.phone.value.length > 0) {
	  var numCount = 0;
	  for (a = 0; a < form.phone.value.length; a++ ) {
			var number = form.phone.value.substr(a,1);
			if (!isNaN(number)) numCount++;
		}
		if (numCount != phoneNumLength) {
		  if (numCount > 1) {
			  var cd = 'are';
			} else {
			  var cd = 'is';
			}
		  ajaxError("Your phone number must be 10 digits (currently there "+cd+" "+numCount+").  Please correct your phone number and try again.");
			form.phone.focus();
			return;
		}
	}
	
	// validate email
	if (form.email.value.length > 0) {
	  if (form.email.value.indexOf("@") == -1 || form.email.value.indexOf(".") == -1) {
  	  ajaxError("The email address you entered is invalid.  Please double check the email address value.");
  		form.email.focus();
			return;
		}
	}
	
  if (!hasAjax) {
	  form.submit();  
		return;
	}
	
  var postStr = createGetStringFromForm('formDeactivate');
  var url = "/ajax/ajaxDeactivate.php";
  httpRequest("POST",url,1,deactivateResponse,postStr);
	
}

// response

function deactivateResponse() {
  if (request.readyState == 4) {
	  if (request.status == 200) {
      var mytext = request.responseText;
      if (mytext == '1') {
			  ajaxError("You have successfully deactivated your Z1sms.net subscription.  You may re-subscribe by completing the normal sign up process.  Thank you for participating.");
        window.location.href = '/';
			}
			else {
			  ajaxError(mytext);
			} 
		}
		else {
		  ajaxError("A communications problem occured attempting to deactivate.  Please try again.");
		}
  }
}
