function submitbutton_reg(aType) { 
	var ajaxVar = getAjaxRequestVariable(); 
	var lGUID = mnsGUID();
	var query = createRegistrationQuery(lGUID,aType); 

	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
			sendRegistrationEmail(lGUID);
		} 
	} 
	ajaxVar.open("POST", "cgi-bin/mnsCreateEmailEncryption.cgi", true); 
	
	//Send the proper header information along with the request
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try       {ajaxVar.send(query);} 
	catch (e) {alert(e);} 
} 

function sendRegistrationEmail(aGUID) { 
	var ajaxVar = getAjaxRequestVariable(); 
	var query = createRegistrationQuery(aGUID); 
	var sentEmailMessage = "Your Compraiser registration has been recieved. An email has been sent to you. To finish the registration process, open the email and follow the directions to activate your account.";

	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
			var sendQuery = ajaxVar.responseText; 
		} 
	} 

	ajaxVar.open("POST", "php-bin/mnsSendAccountMail.php", true); 
	
	//Send the proper header information along with the request
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try { 
		ajaxVar.send(query); 
		alert(sentEmailMessage);
	} 
	catch (e) { alert(e); } 
} 

function updatePreferences(aGUID,aType) { 
	var ajaxVar = getAjaxRequestVariable(); 
	var query = createRegistrationQuery(aGUID,aType); 
	var sentEmailMessage = "Your Compraiser preferences have been updated.";

	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
			var sendQuery = ajaxVar.responseText; 
		} 
	} 

	ajaxVar.open("POST", "php-bin/mnsUpdatePreferences.php", true); 
	
	//Send the proper header information along with the request
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try { 
		ajaxVar.send(query); 
		alert(sentEmailMessage);
	} 
	catch (e) { alert(e); } 
} 

function submitRemindRequest() { 
	var ajaxVar = getAjaxRequestVariable(); 
	var emailID = document.getElementById("RMD_email");
	var query = emailID.name + "=" + emailID.value;
	var sentEmailMessage = "Your Request has been recieved.\nAn email containing the information you requested has been sent.";

	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
			var sendQuery = ajaxVar.responseText; 
		} 
	} 

	ajaxVar.open("POST", "php-bin/mnsSendRemindMail.php", true); 
	
	//Send the proper header information along with the request
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try { 
		ajaxVar.send(query); 
		alert(sentEmailMessage);
	} 
	catch (e) { alert(e); } 
} 

function createRegistrationQuery(aGUID, aType) { 
	var pairs = new Array();
	var nameID     = document.getElementById("ACNT_name");
	var usernameID = document.getElementById("ACNT_username");
	var emailID    = document.getElementById("ACNT_email");
	var passwordID = document.getElementById("ACNT_password");

	pairs.push(nameID.name     + "=" + nameID.value); 
	pairs.push(usernameID.name + "=" + usernameID.value); 
	pairs.push(emailID.name    + "=" + emailID.value); 
	pairs.push(passwordID.name + "=" + passwordID.value); 
	pairs.push("guid=" + aGUID); 
	pairs.push("type=" + aType); 
  if (aType == 1) {
  	var phoneID       = document.getElementById("ACNT_phone");
  	var addressID     = document.getElementById("ACNT_address");
  	var webpageID     = document.getElementById("ACNT_webpage");
  	var brokerageID   = document.getElementById("ACNT_brokerage");
  	var corporateID   = document.getElementById("ACNT_corporate");
  	var licenseID     = document.getElementById("ACNT_license");
  	var licensetypeID = document.getElementById("ACNT_licensetype");
  	var commentsID    = document.getElementById("ACNT_comments");

  	pairs.push(phoneID.name       + "=" + phoneID.value); 
  	pairs.push(addressID.name     + "=" + addressID.value); 
  	pairs.push(webpageID.name     + "=" + webpageID.value); 
  	pairs.push(brokerageID.name   + "=" + brokerageID.value); 
  	pairs.push(corporateID.name   + "=" + corporateID.value); 
  	pairs.push(licenseID.name     + "=" + licenseID.value); 
  	pairs.push(licensetypeID.name + "=" + licensetypeID.value); 
  	pairs.push(commentsID.name    + "=" + commentsID.value); 
  }
	return pairs.join("&"); 
}

function mnsActivateAccount(aEncryptedString) {
	var ajaxVar = getAjaxRequestVariable(); 
  var query = ("id=" + aEncryptedString);

	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
			var ajaxResponse = ajaxVar.responseText; 

			var myString = ajaxResponse;
			var mySplitResult = myString.split(",");
			setCookie("mnsStatic",mySplitResult[0],0);
			setCookie("mnsUserName",mySplitResult[1],0);
			setCookie("mnsCredits",1,0);

		} 
	} 
	ajaxVar.open("POST", "cgi-bin/mnsActivateAccount.cgi", true); 
	
	//Send the proper header information along with the request
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try       {ajaxVar.send(query);} 
	catch (e) {alert(e);} 
}

/*
	var form = document.registrationForm; 
	var r = new RegExp("[<|>|"|'|%|;|(|)|&|+|-]", "i"); 
	// do field validation 
	if (form.name.value == "") { 		    alert( "Please enter your name." ); 
	} else if (form.username.value == "") {     alert( "Please enter a User name." ); 
	} else if (r.exec(form.username.value) || form.username.value.length < 3) {
				 		    alert( "Please enter a valid Username:. More than 2 characters and contain 0-9,a-z,A-Z" ); 
	} else if (form.email.value == "") { 	    alert( "Please enter a valid e-mail address." ); 
	} else if (form.password.value.length < 6) {alert( "Please enter a valid password. No spaces, more than 6 characters and contain 0-9,a-z,A-Z" ); 
	} else if (form.password2.value == "") {    alert( "Please verify the password." ); 
	} else if ((form.password.value != "") && (form.password.value != form.password2.value)){
						    alert( "Password and verification do not match, please try again." ); 
	} else if (r.exec(form.password.value)) {   alert( "Please enter a valid Password:. No spaces, more than 6 characters and contain 0-9,a-z,A-Z" ); 
	} else { 
		form.submit(); 
	} 
*/
 
