// -----------------------------------------------------------------------------
function isvalidusername(checkstr) 
{
	var allowedchars = 'abcdefghijklmnopqrstuvwxyz1234567890_-.@';
	var temp=checkstr;
	if(temp.length < 6){return false;}
	temp=temp.toLowerCase();
	for (var i=0; i< temp.length; i++) 
	{
		if (allowedchars.indexOf(temp.charAt(i)) == -1) {return false;}
	}
	return true;	
}
// -----------------------------------------------------------------------------
function isvalidpassword(checkstr) 
{
	var allowedchars = 'abcdefghijklmnopqrstuvwxyz1234567890';
	var temp=checkstr;
	if(temp.length < 6) {return false;}
	temp=temp.toLowerCase();
	for (var i=0; i< temp.length; i++) 
	{
		if (allowedchars.indexOf(temp.charAt(i)) == -1) {return false;}
	}
	return true;	
}
// -----------------------------------------------------------------------------
function isvalidforsql(checkstr) 
{
	var notallowed = '\' " % #';
	for (var i=0; i< checkstr.length; i++) 
	{
	if (checkstr.charAt(i) != ' ')
		{
			if (notallowed.indexOf(checkstr.charAt(i)) != -1)
				{
					return false;
				}
		}
	}
return true;
}
// -----------------------------------------------------------------------------
function iszerolength(checkstr)
{
	for (var i=0; i< checkstr.length; i++) 
	{
		if (checkstr.charAt(i) != ' ')
		{
			return false;
		}
	}
return true;
}
// =============================================================================
// Function To Register Users Via Seller Net Proceeds Application
function AcceptRegistrant()
{
	var RegType = 'CALC';
	RegisterAccount(RegType);
	return;
}
// -----------------------------------------------------------------------------
// Function To Register Users Via Document Listing Application
function AcceptDocumentRegistrant()
{
	var RegType = 'DOC';
	RegisterAccount(RegType);
	return;
}
// -----------------------------------------------------------------------------
// Check Request and Add the Account if Valid
function RegisterAccount(RegType)
{
	var msgStr ='';
	if(!isvalidforsql(main.txtAgentName.value))
		{
			switch (RegType)
				{
					case "CALC" :
						msgStr = 'Agent Name Has Invalid Characters';
						break;
					case "DOC" :
						msgStr = 'Name Has Invalid Characters';
						break;
					default :
						msgStr = 'Name Has Invalid Characters';
						break;
				} 
		alert(msgStr);
		main.txtAgentName.focus();
		return;
		}
	if(iszerolength(main.txtAgentName.value))
		{
			switch (RegType)
				{
					case "CALC" :
						msgStr = 'Agent Name is Required';
						break;
					case "DOC" :
						msgStr = 'Name is Required';
						break;
					default :
						msgStr = 'Name is Required';
						break;
				} 
		alert(msgStr);
		main.txtAgentName.focus();
		return;
		}

	if(!isvalidforsql(main.txtBroker.value))
		{
			switch (RegType)
				{
					case "CALC" :
						msgStr = 'Broker Name Has Invalid Characters';
						break;
					case "DOC" :
						msgStr = 'Company Name Has Invalid Characters';
						break;
					default :
						msgStr = 'Company Name Has Invalid Characters';
						break;
				} 
		alert(msgStr);
		main.txtBroker.focus();
		return;
		}
	if(iszerolength(main.txtBroker.value))
		main.txtBroker.value=' ';

	if(!isvalidforsql(main.txtAddress1.value))
		{
		alert('Address Has Invalid Characters');
		main.txtAddress1.focus();
		return;
		}
	if(iszerolength(main.txtAddress1.value))
		main.txtAddress1.value=' ';

	if(!isvalidforsql(main.txtPhone.value))
		{
		alert('Telephone Has Invalid Characters');
		main.txtPhone.focus();
		return;
		}
	if(iszerolength(main.txtPhone.value))
		main.txtPhone.value=' ';

	if(!isvalidforsql(main.txtFax.value))
		{
		alert('Fax Has Invalid Characters');
		main.txtFax.focus();
		return;
		}
	if(iszerolength(main.txtFax.value))
		main.txtPhone.value=' ';

	if(!isvalidusername(main.txtEmail.value))
		{
		alert('Email must have\n characters (a-z,0-9,_-@.)');
		main.txtEmail.focus();
		return;
		}

	if(!isvalidforsql(main.txtCity.value))
		{
		alert('City Has Invalid Characters');
		main.txtCity.focus();
		return;
		}
	if(iszerolength(main.txtCity.value))
		main.txtCity.value=' ';

	if(!isvalidforsql(main.txtState.value))
		{
		alert('State Has Invalid Characters');
		main.txtState.focus();
		return;
		}
	if(iszerolength(main.txtState.value))
		main.txtState.value=' ';

	if(!isvalidforsql(main.txtZip.value))
		{
		alert('Zip Code Has Invalid Characters');
		main.txtZip.focus();
		return;
		}
	if(iszerolength(main.txtZip.value))
		main.txtZip.value=' ';

	if(!isvalidusername(main.txtUsername.value))
		{
		alert('Username must have\n6 characters (a-z,0-9,_@.)');
		main.txtUsername.focus();
		return;
		}
	if(!isvalidpassword(main.txtPassword.value))
		{
		alert('Password must have\n6 characters (a-z,0-9)');
		main.txtPassword.focus();
		return;
		}
	document.forms.main.submit(); // submit the form
}
// -----------------------------------------------------------------------------
function blurEvent(Ctrl)
{
	switch(Ctrl.name) 
	{
		case "txtEmail":
			olastCtrl=Ctrl;
			if(!isvalidforsql(Ctrl.value))
				break;
			if(iszerolength(Ctrl.value))
				break;
			if(iszerolength(main.txtUsername.value)){main.txtUsername.value=Ctrl.value;}
	}
}