function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm()
{ //v4.0
	var i, p, q, nm, test, num, min, max, errors='', args=MM_validateForm.arguments;
  
  	// check if the declaration has been agreed to or not
	if(!MM_findObj('Declaration - I Agree').checked)
		errors += '- You have to agree to the declaration to apply as a reseller.\n';
  
	for (i=0; i < (args.length-2); i += 3)
	{
	  	test	= args[i+2];
		val		= MM_findObj(args[i]);
		
	    if (val)
		{
			nm = val.id;
			
			if ((val = val.value) != "")
			{
				if (test.indexOf('isEmail') != -1)
				{
					p = val.indexOf('@');
					
					if (p < 1 || p == (val.length - 1))
						errors += '- ' + nm + ' must contain an e-mail address.\n';
				}
				else if (test != 'R')
				{
					num = parseFloat(val);
					
					if (isNaN(val))
						errors += '- ' + nm + ' must contain a number.\n';
					
					if (test.indexOf('inRange') != -1)
					{
						p	= test.indexOf(':');
						min	= test.substring(8, p);
						max	= test.substring(p + 1);
						
						if (num < min || max < num)
							errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
					}
				}
			}
			else if (test.charAt(0) == 'R')
				errors += '- '+nm+' is required.\n';
		}
	}
	
	// Check the username and password - minimum 6 charaters
	var username = MM_findObj('Username').value.length;
	var passwordl = MM_findObj('Password').value.length;
	var password = MM_findObj('Password').value;
	var password2 = MM_findObj('Retype Password').value;
	if(username<6)				errors += '- Username required to be at least 6 characters.\n';
	if(passwordl<6)				errors += '- Password required to be at least 6 characters.\n';
	if(password != password2)	errors += '- Passwords do not match.\n';
	
	// check the business type
	var retail		= MM_findObj('Business - Retail Store').checked;
	var home		= MM_findObj('Business - Home').checked;
	var showroom	= MM_findObj('Business - Commercial Dealer - Showroom').checked;
	var noshowroom	= MM_findObj('Business - Commercial Dealer - No Showroom').checked;
	if(!retail && !home && !showroom && !noshowroom)
		errors += '- Please select which best describes your business.\n';
	
	if (errors)
  		alert('The following error(s) occurred:\n' + errors);
	
	document.MM_returnValue = (errors == '');
}

function _formcheck()
{
	// all other form fields
	MM_validateForm(
					'Username','','R',
					'Password','','R',
					'Retype Password','','R',
					
					'Trade Name','','R',
					'Registered Name','','R',
					'Registration Number','','R',
					'Vat Registration Number','','R',
					
					'Postal Address & Code','','R',
					'Delivery Address & Code','','R',
					
					'Telephone Number','','R',
					'Email Address','','RisEmail',
					
					'Accounts Department - Contact Person','','R',
					'Accounts Department - Telephone Number','','R',
					'Accounts Department - Email Address','','R',
					
					'Sales Manager - Contact Person','','R',
					'Sales Manager - Telephone Number','','R',
					'Sales Manager - Email Address','','R',
					
					'MD/CEO - Contact Person','','R',
					'MD/CEO - Telephone Number','','R',
					'MD/CEO - Email Address','','R',
					
					'Bank','','R',
					'Account No','','R',
					'Branch','','R',
					'Branch Code','','R',
					
					'Declaration - Name','','R',
					'Declaration - Capacity','','R',
					'Declaration - Date','','R',
					
					'Directors/Members/Partners/Owners - Name','','R',
					'Directors/Members/Partners/Owners - Address','','R',
					'Directors/Members/Partners/Owners - ID Number','','R',
					
					'Name of Landlord','','R',
					'Address of Landlord','','R',
					
					'External Sales','','R',
					'Administrative','','R',
					'Support','','R',
					
					'Percentage Computer Hardware Sales','','R',
					'Percentage Computer Software Sales','','R',
					'Percentage Custom Software Development','','R',
					'Percentage Computer Training','','R',
					'Percentage Repairs and Servicing','','R',
					'Percentage Web Development','','R',
					'Percentage Design','','R',
					
					'Company Profile','','R'
					);
	return document.MM_returnValue;
}