// JavaScript Document

function empty(x)
{
	return x == '';
}

function numeric(x)
{
   var ValidChars = "0123456789.";
   var numeric=true;
   var Char; 
   for (i = 0; i < x.length && numeric == true; i++) 
   { 
     Char = x.charAt(i); 
     if (ValidChars.indexOf(Char) == -1)	 
		 	numeric = false;		 
		}
   return numeric;   
}

function email(x)
{
  email_regx = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	return !(x.search(email_regx) == -1); 
}

function validateForm()
{
	$error_count = 0;

	$email_error_count = 0;
	
	/* validation start */	
	
	if(empty(document.getElementById('name').value))
	{		
		document.getElementById('name').className = 'textinput_error';
		$error_count++;		
	}
	else
	{		
		document.getElementById('name').className = 'textinput';
	}	
	
	if(empty(document.getElementById('organization').value))
	{		
		document.getElementById('organization').className = 'textinput_error';
		$error_count++;		
	}
	else
	{		
		document.getElementById('organization').className = 'textinput';
	}	

	if(empty(document.getElementById('phone').value))
	{		
		document.getElementById('phone').className = 'textinput_error';
		$error_count++;		
	}
	else
	{		
		document.getElementById('phone').className = 'textinput_long';
	}	
	
	if(empty(document.getElementById('email').value))
	{		
		document.getElementById('email').className = 'textinput_error';
		$error_count++;		
	}
	else if(!email(document.getElementById('email').value))
	{
		document.getElementById('email').className = 'textinput_error';
		$error_count++;
		$email_error_count++;
	}
	else
	{		
		document.getElementById('email').className = 'textinput';
	}	
	
	if(empty(document.getElementById('inhands_date').value))
	{		
		document.getElementById('inhands_date').className = 'textinput_med_error';
		$error_count++;		
	}
	else
	{		
		document.getElementById('inhands_date').className = 'textinput_med';
	}		

	if ($error_count > 0 && $email_error_count > 0)
	{
		alert('You have entered an invalid email address, and left one or more of the fields in the form blank.');
	}
	
	
	else if ($error_count > 0)
	{
		alert('You have left one or more of the fields in the form blank.');	
	}	
	
	
	else if ($error_count > 0)
	{
		alert('You have left one or more of the fields in the form blank.');	
	}	
	
	else
	{
		document.getElementById('requestForm').submit();	
	}
	
}
