function hideall()
{
	var number_of_possible = 50;
	var advice_boxes = new Array();
	
	for(var i=0;i<number_of_possible;i++)
	{
		advice_boxes[i] = 'advice_box_' + i;
	}
	
	var adBoxLen = advice_boxes.length;
	for (var i=0;i<adBoxLen;i++)
	{
		var j = i + 1;
		if(document.getElementById(advice_boxes[j]))
		{
			document.getElementById(advice_boxes[j]).className = 'hide';
		}
		else
		{
			return;
		}
	}

}
function focusToNext(thislength)
{
	if(thislength == 5)
	{
		document.form_b1.business_phone_number2.focus()
	}
}
function focusToExt()
{
	var thislength = document.getElementById("landline").value.length;
	if(thislength == 7)
	{
		document.getElementById("landline_ext").focus()
	}
}
function reFocus()
{
	var thisLength = document.getElementById("landline_area").value;
	if(thisLength.length == 5)
	{
		document.getElementById("landline").focus();
	}
}
function testXMLhttp()
{
	var returnRealObject = null;
	try
	{// Mozilla (Firefox), Opera 8+, Safari
		returnRealObject = new XMLHttpRequest();
	}
	catch (e)
	{// IE
		try
		{
			returnRealObject = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			returnRealObject = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return returnRealObject;
}
function xhrState() 
{
	if (xhrObject.readyState == 4)
	{
		if(xhrObject.responseText == 'T')
		{// T = username in database
			thisYesNo.style.color = '#cc0000';
			thisYesNo.style.fontWeight = 'bold';
			thisYesNo.innerHTML = '* Username Taken';
		}
		else
		{// N = username not in database
			thisYesNo.style.color = '#000000';
			thisYesNo.style.fontWeight = 'normal';
			thisYesNo.innerHTML = '* Username Available';
		}
	}
}

function checkUser(str)
{
	thisYesNo = document.getElementById('yesNo');
	var myRegExp = /^[A-Za-z0-9]+$/;
	thisYesNo.style.color = '#cc0000';
	thisYesNo.style.fontWeight = 'bold';
	if(str.length == 0)
	{
		thisYesNo.innerHTML = '*';
		return;
	}
	else if(!myRegExp.test(str))
	{
		thisYesNo.innerHTML = '* Just Letter &amp; Numbers';
		return;
	}
	else if(str.length < 6)
	{
		thisYesNo.innerHTML = '* Enter a Longer Username';
		return;
	}
	xhrObject = testXMLhttp();
	if (xhrObject == null)
	{
		thisYesNo.innerHTML = '*';
		return;
	} 
	var url = 'ajaxcheckuser.php?name=' + str;
	xhrObject.onreadystatechange = xhrState;
	xhrObject.open('GET', url, true);
	xhrObject.send(null);
}
function checkPass(str)
{
	thisPassYesNo = document.getElementById('passYesNo');
	var myRegExp = /^[A-Za-z0-9]+$/;
	thisPassYesNo.style.color = '#cc0000';
	thisPassYesNo.style.fontWeight = 'bold';
	if(str.length == 0)
	{
		thisPassYesNo.innerHTML = '*';
		return;
	}
	else if(!myRegExp.test(str))
	{
		thisPassYesNo.innerHTML = '* Just Letter &amp; Numbers';
		return;
	}
	else if(str.length < 6)
	{
		thisPassYesNo.innerHTML = '* Enter a Longer Password';
		return;
	}
	else
	{
		thisPassYesNo.style.color = '#000000';
		thisPassYesNo.style.fontWeight = 'normal';
		thisPassYesNo.innerHTML = '* Password OK';
		return;
	}
}
function checkPass2(str)
{
	thisPass2YesNo = document.getElementById('pass2YesNo');
	thisPass2YesNo.style.color = '#cc0000';
	thisPass2YesNo.style.fontWeight = 'bold';
	if(str.length == 0)
	{
		thisPass2YesNo.innerHTML = '*';
		return;
	}
	else if(document.getElementById('pass1'))
	{
		if(str != document.getElementById('pass1').value)
		{
			thisPass2YesNo.innerHTML = '* Passwords Do Not Match';
			return;
		}
	}
	else if(document.getElementById('password'))
	{
		if(str != document.getElementById('password').value)
		{
			thisPass2YesNo.innerHTML = '* Passwords Do Not Match';
			return;
		}
	}
	thisPass2YesNo.style.color = '#000000';
	thisPass2YesNo.style.fontWeight = 'normal';
	thisPass2YesNo.innerHTML = '* Password OK';
	return;
}
function checkBeforeSend()
{
	if(document.getElementById('password'))
	{
		// Business Registration Form
		firstPass = document.getElementById('password');
		secondPass = document.getElementById('password2');
		thisUser = document.getElementById('user');
	}
	else
	{
		// Home User Registration Form
		firstPass = document.getElementById('pass1');
		secondPass = document.getElementById('pass2');
		thisUser = document.getElementById('username');
	}
	var myRegExp = /^[A-Za-z0-9]+$/;
	
	alertText = '';
	if(thisUser.value.length == 0)
	{
		alertText = 'You Need To Enter A Username';
	}
	else if(firstPass.value.length == 0)
	{
		alertText = 'You Need To Enter A Password';
	}
	else if(secondPass.value.length == 0)
	{
		alertText = 'You Need To Re-Enter The Password';
	}
	else if(thisUser.value.length < 6)
	{
		alertText = 'The Username You Have Entered Is Not Long Enough';
	}
	else if(firstPass.value.length < 6)
	{
		alertText = 'The Password You Have Entered Is Too Short';
	}
	else if(firstPass.value != secondPass.value)
	{
		alertText = 'The Passwords You Have Entered Do Mot Match';
	}
	else if(!myRegExp.test(firstPass.value))
	{
		alertText = 'Your Password Should Only Contain Letters and Numbers';
	}
	else if(!myRegExp.test(thisUser.value))
	{
		alertText = 'Your Username Should Only Contain Letters and Numbers';
	}
	
	if(alertText == '')
	{
		return true;
	}
	else
	{
		alert(alertText);
		return false;
	}
}
