activeURL = window.location.protocol + "//" + window.location.host;	

function checkEmail(emailaddress) {
	$.ajax({
   		type: "POST",
   		url: activeURL+"/code/mastercode.cfm",
   		data: "action=checkEmail&email="+emailaddress,
		success: function(data){
			if(data == "true") {
				document.regForm.email.value = 'Email is already registered.';
				document.regForm.email.focus();
				document.regForm.email.select();
			}
   		} });
}

function checkSite(siteURL) {
	$.ajax({
   		type: "POST",
   		url: activeURL+"/code/mastercode.cfm",
   		data: "action=checkSite&siteURL="+siteURL,
		success: function(data){
			if(data == "true") {
				document.regForm.siteurl.value = 'Site name is already taken!';
				document.regForm.siteurl.focus();
				document.regForm.siteurl.select();
			}
   		} });
}

function checkRegForm() {
	if(document.regForm.email.value <= 0) {
		alert("Please enter your email address");
		document.regForm.email.focus();
		document.regForm.email.select();
		return false; }

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.regForm.email.value;
   		if(reg.test(address) == false) {
      			alert('Please enter a valid email address');
				document.regForm.email.focus();
				document.regForm.email.select();
      			return false;}

	if(document.regForm.password.value <= 0) {
		alert("Please enter a password");
		document.regForm.password.focus();
		document.regForm.password.select();
		return false; }
				
	if(document.regForm.password.value != document.regForm.passwordB.value) {
		alert("Your passwords did not match.\nPlease check and try again");
		return false; }
}

function sendForm(siteURL){ 
	$.ajax({
   		type: "POST",
   		url: activeURL+"/code/mastercode.cfm",
   		data: "action=checkSite&siteURL="+siteURL,
		success: function(data){
			if(data == "true") {
				document.regForm.siteurl.value = 'Site name is already taken!';
				document.regForm.siteurl.focus();
				document.regForm.siteurl.select();
			}
			
			if(data == "false"){
				if(document.regForm.email.value <= 0) {
				alert("Please enter your email address");
				document.regForm.email.focus();
				document.regForm.email.select();
				return }
				
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   				var address = document.regForm.email.value;
   				if(reg.test(address) == false) {
      			alert('Please enter a valid email address');
				document.regForm.email.focus();
				document.regForm.email.select();
      			return;}
				
				if(document.regForm.password.value <= 0) {
				alert("Please enter a password");
				document.regForm.password.focus();
				document.regForm.password.select();
				return; }
				
				if(document.regForm.password.value != document.regForm.passwordB.value) {
				alert("Your passwords did not match.\nPlease check and try again");
				return; }
				
				document.regForm.submit();	
			}
   		} });
}