// JavaScript Document

var msInitialPassword;

function BeanTalkRegistration()
{

	var sReturn;
	var sParam;

	var divWorking = document.getElementById('divWorking');
	var divLoading = document.getElementById('divLoading');

	if (RegistrationValidate())
	{

		sReturn = onDemandSite(sParam);

		divWorking.innerHTML = 'Registering please wait...';
		divWorking.style.width = '200px';
		divWorking.style.display = 'block';	
		divLoading.setAttribute("class", "working");	
		
		sParam = 'method=REGISTER_SITE_ADD_USER&site=1027&membership=303&group=3618&logonsuffix=@bean-talk.com';
		sParam = sParam + '&firstname=' + document.getElementById('txtFirstName').value; //first name
		sParam = sParam + '&surname=' + document.getElementById('txtSurname').value; //surname
		sParam = sParam + '&email=' + document.getElementById('txtEmail').value; //email
		sParam = sParam + '&phone=' + document.getElementById('txtPhone').value; //phone
		sParam = sParam + '&streetsuburb=' + document.getElementById('txtmSuburb').value; //mailing suburb
		sParam = sParam + '&sq4941=' + document.getElementById('txtSurveyTEXT4941').value; //industry
		sParam = sParam + '&sq4942=' + document.getElementById('cboSurvey4942').value; //turnover
		sParam = sParam + '&sq5746=' + document.getElementById('txtQuestion5746').value; //website
		
		if (document.getElementById('txtBusinessName').value != '')
		{
			sParam = sParam + '&businessname=' + document.getElementById('txtBusinessName').value; //business name
			sParam = sParam + '&tradename=' + document.getElementById('txtBusinessName').value; //business name
		}
		
		sReturn = onDemandRegister(sParam);
		//window.alert(sReturn)
		divWorking.style.display = 'none';
		divLoading.style.display = 'none';
		
		if (sReturn.substring(0, 2) == 'OK')
		{
			var aValues = sReturn.split('|');

			if (aValues[0] == 'OK') 
			{
				
				//EMAIL TO PERSON REGISTERING
				var msInitialPassword = aValues[3];
				sParam = 'method=SITE_SEND_EMAIL&site=916&document=26094&select=' + aValues[5] + '&[INITIALPASSWORD]=' + msInitialPassword;
				sReturn = onDemandSite(sParam);
				document.location.href = '/member_sign_up_response';		
				
				//EMAIL TO SITE OWNER
				sParam = 'method=SITE_SEND_EMAIL&site=916&subject=New Bean Talk Member Registration&message=' + 
				'This is a new registration for Bean Talk' + '<br/><br/>' + 
				'Name: ' + document.getElementById('txtFirstName').value + ' ' + document.getElementById('txtSurname').value + '<br/>' + 
				'Email: ' + document.getElementById('txtEmail').value + '<br/>' +
				'Business: ' + document.getElementById('txtBusinessName').value + '<br/>' + 
				'Phone: ' + document.getElementById('txtPhone').value + '<br/>' +
				'Suburb: ' + document.getElementById('txtmSuburb').value + '<br/>' +
				'Industry: ' + document.getElementById('txtSurveyTEXT4941').value + '<br/>' +
				'Turnover: ' + document.getElementById('cboSurvey4942').options[document.getElementById('cboSurvey4942').selectedIndex].text + '<br/>' +
				'Website: ' + document.getElementById('txtQuestion5746').value +
				'&email=halyh@cfooncall.com.au';
				sReturn = onDemandSite(sParam);
			}	
		}
		else
		{
			window.alert('Sorry an error has occured when processing your registration, please contact us to find out more.');
		}
	
	}
}




function RegistrationValidate() 
{

	sOnDemandValidateMessage = '';
	sOnDemandValidateObject = '';

	onDemandValidate('txtFirstName', 'First Name', '');
	onDemandValidate('txtSurname', 'Surname', '');
	onDemandValidate('txtEmail', 'Email', '');
	
	if (!onDemandIsEmail(document.getElementById('txtEmail').value))
	{
		sOnDemandValidateMessage = sOnDemandValidateMessage + '\r\n # Not a valid email address.';
	}
					
					
	onDemandValidate('txtPhone', 'Phone', '');
	onDemandValidate('txtBusinessName', 'Business Name', '');
	onDemandValidate('txtmSuburb', 'Mailing Suburb', '');
	onDemandValidate('txtQuestion5746', 'Website', '');
	onDemandValidate('txtSurveyTEXT4941', 'Industry', '');
	onDemandValidate('cboSurvey4942', 'Turnover', '');

	if (sOnDemandValidateMessage != '')
	{
		window.alert('Sorry can\'t submit your registration as:\r\n' + sOnDemandValidateMessage);
		document.getElementById(sOnDemandValidateObject).focus();
		return (false);
	}
	else
	{
		return (true);
	}
}	
