var suggestedID;
var available;

function generateID() {

  var bride = trialForm.bride.value;
  var groom = trialForm.groom.value;
  
  if((bride != '') && (groom != '') && (trialForm.subdomain.value == '')) {
    
    scriptPath = 'scripts/generate_id.php';
    sendData = 'bride=' + bride + '&groom=' + groom;
    
    processAjax(_generateID);
  }
}


function _generateID(response) {

  if(response != '') {
    suggestedID = response;
    trialForm.subdomain.value = response;
  }
}


function checkAvailability() {
 
  available = true;
  var test = trialForm.subdomain.value;
  
  if(test == suggestedID) {

    available = true;
    
  } else {
  
    scriptPath = 'scripts/check_availability.php';
    sendData = 'test=' + test;
    
    processAjax(_checkAvailability);
  }
}


function _checkAvailability(response) {

  if(response == 'taken') available = false;
  else available = true;
}


function updateCountry() {

  var countryCode = trialForm.country[trialForm.country.selectedIndex].value;

  scriptPath = 'scripts/update_country.php';
  sendData = 'countryCode=' + countryCode;
    
  processAjax(_updateCountry);
}


function _updateCountry(response) {

  if(dateFormat != response) {
    
    var weddingDate = trialForm.weddingDate.value;
    
    if(weddingDate != '') {
      var dateArray = new Array();
      dateArray = weddingDate.split('/');
        
      trialForm.weddingDate.value = dateArray[1] + '/' + dateArray[0] + '/' + dateArray[2];
    }
  }
    
  dateFormat = response;
  trialForm.dateFormat.value = dateFormat;

  if(dateFormat == 'euro') cal1 = new calendar1(trialForm.weddingDate);
  else cal1 = new calendar2(trialForm.weddingDate);
}


function processSignup() {

	if(checkForm('trial_form') == true) {
		
		var email = trialForm.email.value;
		var isp = '';
		
		if(email.indexOf('@hotmail.') > 0) isp = 'hotmail';
		else if(email.indexOf('@yahoo.') > 0) isp = 'yahoo';
		else if(email.indexOf('@msn.') > 0) isp = 'msn';
		else if(email.indexOf('@live.') > 0) isp = 'windows live';
		else if(email.indexOf('@gmail.') > 0) isp = 'gmail';
		else if(email.indexOf('@aol.') > 0) isp = 'aol';
		
		if(isp != '') {
		
			if(confirm("Customers using "+isp+" email addresses have recently been experiencing delays receiving their activation email.\n\nClick OK to continue with your "+isp+" address, or Cancel to change to a different address. ") == false) {
				
				trialForm.email.focus();
				return false;
			
			} else {
				return true;
			}
		
		} else {
			return true;
		}
	}
	return false;
}







/* backwards compatible */

function countrySelect() {

  var countryCode = trialForm.country[trialForm.country.selectedIndex].value;

  scriptPath = 'scripts/update_country.php';
  sendData = 'countryCode=' + countryCode;
    
  processAjax(_countrySelect);
}


function _countrySelect(response) {

  if(dateFormat != response) {
    
    var weddingDate = trialForm.weddingDate.value;
    
    if(weddingDate != '') {
      var dateArray = new Array();
      dateArray = weddingDate.split('/');
        
      trialForm.weddingDate.value = dateArray[1] + '/' + dateArray[0] + '/' + dateArray[2];
    }
  }
    
  dateFormat = response;
  trialForm.dateFormat.value = dateFormat;

  if(dateFormat == 'euro') cal1 = new calendar1(trialForm.weddingDate);
  else cal1 = new calendar2(trialForm.weddingDate);
}