function trim(s)
{       while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
        { s = s.substring(1,s.length); }

	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{ s = s.substring(0,s.length-1); }
	return s;
}

function checkEmail(email)
{	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) return true;
	else return false;
}

function checkNumber(val)
{	var filter  = /^([0-9])+$/;
	if (filter.test(val)) return true;
	else return false;
}

function checkForm()
{
	var errN=0, msg = 'Errors found:'+"\n\n", errors = new Array(), errorFields = new Array(), counter=0;

	if(document.mform.confirmCheck.checked == false)
	{	errorFields[errN] = 'confirmCheck';
		errors[errN] = "You must check the box confirming your acceptance of our terms."; errN++;}

	if(trim(document.mform.height_ft.value) != '')
	{	document.mform.height.value = (document.mform.height.value*1) + (document.mform.height_ft.value*12);
		document.mform.height_ft.value = '';}

	document.mform.legalName.className = 'main';
	if(trim(document.mform.legalName.value) == '')
	{	errorFields[errN] = 'legalName'; 
		errors[errN] = 'missing legal name'; errN++;}

	document.mform.stageName.className = 'main';
	if(trim(document.mform.stageName.value) == '')
	{	errorFields[errN] = 'stageName'; 
		errors[errN] = 'missing stage name'; errN++;}

	document.mform.birthYear.className = 'main';
	if(trim(document.mform.birthYear.value) == '')
	{	errorFields[errN] = 'birthYear'; 
		errors[errN] = 'missing year of birth'; errN++;}

	document.mform.birthMonth.className = 'main';
	if(trim(document.mform.birthMonth.value) == '')
	{	errorFields[errN] = 'birthMonth'; 
		errors[errN] = 'missing month of birth'; errN++;}

	document.mform.birthDay.className = 'main';
	if(trim(document.mform.birthDay.value) == '')
	{	errorFields[errN] = 'birthDay'; 
		errors[errN] = 'missing day of birth'; errN++;}

	document.mform.height.className = 'main auto';
	if(trim(document.mform.height.value) == '')
	{	errorFields[errN] = 'height'; 
		errors[errN] = 'missing height'; errN++;}

	document.mform.weight.className = 'main auto';
	if(trim(document.mform.weight.value) == '')
	{	errorFields[errN] = 'weight'; 
		errors[errN] = 'missing weight'; errN++;}

	document.mform.waist.className = 'main auto';
	if(trim(document.mform.waist.value) == '')
	{	errorFields[errN] = 'waist'; 
		errors[errN] = 'missing waist size'; errN++;}

	document.mform.bust.className = 'main auto';
	if(trim(document.mform.bust.value) == '')
	{	errorFields[errN] = 'bust'; 
		errors[errN] = 'missing bust size'; errN++;}

	document.mform.email.className = 'main';
	if(trim(document.mform.email.value) == '')
	{	errorFields[errN] = 'email'; 
		errors[errN] = 'missing email address'; errN++;}
	if(checkEmail(document.mform.email.value) == false)
	{	errorFields[errN] = 'email'; 
		errors[errN] = 'invalid email address'; errN++;}

	for(i=1;i<6;i++)
	{	tmp = eval('trim(document.mform.file'+i+'.value)');
		if(tmp == '')	counter++;}
	document.mform.file1.className = 'main';
	if(counter == 5)
	{	errorFields[errN] = 'file1';
		errors[errN] = 'atleast 1 image required';}

	if(errors.length > 0)
	{	for(i=0;i<errors.length;i++)
		{	msg = msg + "   · " + errors[i] + "\n";
			eval('document.mform.'+errorFields[i]+'.className += \' error\';');}
		alert(msg+"\n\n");
		return false; 
	}
}
