var phone;
var smsDisplay;
var smsDisplayHTML;

function testSMS() {
	
	phone1 = getElement('phone1').value;
	phone2 = getElement('phone2').value;
	if(phone2.charAt(0) == '0') phone2 = phone2.substr(1);
	phone = phone1 + " " + phone2;
	
	smsDisplay = getElement('smsDisplay');
	smsDisplayHTML = smsDisplay.innerHTML;
	
	smsDisplay.innerHTML = "<img src='images/processing.gif' alt='' /> Sending message...";
	
	scriptPath = 'scripts/test_sms.ajax';
	sendData = 'textNumber=' + phone;

	processAjax(_testSMS);
}

function _testSMS(response) {

  if(response == 'Success!') {
  	smsDisplay.innerHTML = "<img src='images/available.png' alt='' /> <span style='color: green;'>Message sent to " + phone + ".<\/span>";
  
  } else {
  	smsDisplay.innerHTML = smsDisplayHTML;
  	alert(response);
  }
}


function updateSMS() {
	
	var smsForm = document.forms.smsTest_form;
	var countryCode = smsForm.country[smsForm.country.selectedIndex].value;
	
	if(countryCode.charAt(0) == '#') {
		getElement('unavailable').innerHTML = "Sorry, the SMS reminder service is not available in "+countryCode.substr(1)+".";
		toggleDisplay('available', 'none', true);
		toggleDisplay('unavailable', 'inline', true);
	} else {
		toggleDisplay('available', 'inline', true);
		toggleDisplay('unavailable', 'none', true);	
	}
	
	smsForm.phone1.value = countryCode;
	smsForm.phone2.focus();
}