// $Id: class.FtdSignup.js,v 1.11 2006/05/22 14:46:40 bart Exp $

var FtdSignup = new Object();


FtdSignup.transferTeamNameToHostname = function() {
	$('teamName').value = trimString($F('teamName'));	
	$('subDomain').value = $F('teamName').replace(/[^-a-zA-Z0-9]/g, '').replace(/^-/, '').toLowerCase();	
	this._setSiteAddressInOverview(false);
	this.checkHostname();
};


FtdSignup.checkHostname = function() {
	var options = {
		method: 'post',
		postBody: 	'ajax=checkHostname'+'&subDomain='+$F('subDomain'),
		onSuccess: function() {
			FtdSignup._checkHostnameSuccess(arguments[0]);
		},
		onFailure: function(response) {
			FtdSignup._checkHostnameFailure(arguments[0]);				
		}
	}
	new Ajax.Request(urlSignup, options);
};


FtdSignup._checkHostnameSuccess = function(response) {
	$('hostnameFeedback').innerHTML = response.responseText;
	$('hostnameFeedback').style.display = (response.responseText == '' ? 'none' : '');
	this._setSiteAddressInOverview( !(response.responseText == '' || response.responseText == null) );
}


FtdSignup._checkHostnameFailure = function(response) {
	// ajax request failed... do checks after posting the form, I guess
	$('hostnameFeedback').innerHTML = '';
	$('hostnameFeedback').style.display = 'none';
	this._setSiteAddressInOverview(true);
}


FtdSignup._setSiteAddressInOverview = function(defaultText) {
	if (arguments.length==0) {
		defaultText = false;	
	}
	var txt;
	if (defaultText || $F('subDomain') == '') {
		txt = messages['reviewNoSitename'];
	} else  {
		txt = 'http://' + $F('subDomain') + '.' + hostName;
	}
	FtdSignup._clearAllChildren('siteAddressOverview');
	$('siteAddressOverview').innerHTML = txt;
}


FtdSignup.toggleSubmitButton = function() {
	$('submitButton').disabled = !$('agreeAll').checked;
}


FtdSignup._clearAllChildren = function(parent) {
	while($(parent).firstChild) {
		$(parent).removeChild($(parent).firstChild);	
	}
}


FtdSignup.togglePaymentType = function(lang) {
	if (lang == 'nl') {
		this._togglePaymentTypeNL();
	}
}


FtdSignup._togglePaymentTypeNL = function() {
	if ($('paymentTypePaypal').checked) {
		$('trPaymentPaypal').style.display = '';	
		$('trPaymentIncasso').style.display = 'none';	
	} else {
		$('trPaymentIncasso').style.display = '';	
		$('trPaymentPaypal').style.display = 'none';	
	}
}