function accountname(){ 
	var firstname = document.WebToLeadForm.first_name.value = capitaliseFirstLetter(document.WebToLeadForm.first_name.value);
	var lastname = document.WebToLeadForm.last_name.value = capitaliseFirstLetter(document.WebToLeadForm.last_name.value);
	var accountname = lastname + ", " + firstname;
	document.getElementById('account_name').value = accountname;
	//document.getElementById('accountname').innerHTML = document.getElementById('account_name').value;
}
function capitaliseFirstLetter(string) { 
    return string.charAt(0).toUpperCase() + string.slice(1); 
}

function validateNumber(field, msg, phone, min, max) { 
	if (!msg && !phone) { msg = "Please enter a valid number"; }   
	if (!min) { min = 1 }  
	if (!max) { max = 255 } 
	if (phone) { 
		min = 10 
		max = 10
		var stripped = field.value.replace(/[\(\)\.\+\-\ ]/g, ''); 
		
		if ((isNaN(parseInt(stripped))) || stripped.length < min || stripped.length > max) {  
			alert(msg);  
			field.focus();  
			field.select();  
			return false;  
		}  
	}else if((isNaN(parseInt(field.value))) || field.value.length < min || stripped.value.length > max) {  
		alert(msg);  
		field.focus();  
		field.select();  
		return false;  
	} 
 
	return true; 
}

function validateString(field, msg, min, max) {  
	if (!min) { min = 1 }  
	if (!max) { max = 255 }  
	 
	if (!field.value || field.value.length < min || field.value.max > max) {  
		alert(msg);  
		field.focus();  
		field.select();  
		return false;  
	}  
	 
	return true;  
}

function validateEmail(email, msg, optional) {  
	if (!email.value && optional) {  
		return true;  
	}  
 
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;  
	if (!re_mail.test(email.value)) {  
		alert(msg);  
		email.focus();  
		email.select();  
		return false;  
	}  
	 
	return true;  
}

function validateHuman(){
	document.getElementById('human').value = "54";
}

function submit_form(){
	isValid =  validateString(this.first_name, 'Please enter your first name', 3, 15) && validateString(this.last_name, 'Please enter your last name', 3, 15) && validateEmail(this.webtolead_email1, 'Please enter your email address') && validateNumber(this.phone_work,'Please enter a valid phone number',true) && document.getElementById('human').value == '55';
	if(isValid){
		document.WebToLeadForm.action = "http://realtytech.sugarondemand.com/index.php?entryPoint=WebToLeadCapture";
		document.WebToLeadForm.submit();
	}else
	{
		return false;
	}
}
