// JavaScript Document

var if_correct = true;

function spankme()
{
	alert("this works"	);
	//document.onSubmit() = false;
	return false;
}

function not_correct()
{
	return if_correct = false;	
}

function correct()
{
	return if_correct = true;	
}
//to check to see if textboxes are blank


function isblank(info)
{
	
	name = info.value;
	
	
	if((name != '  ') && (name != '\n') && (name !='')) 
	{
		//alert("is not blank")
		return true;
		
	}
	else	
	{	
		show_errors(info);
		not_correct();
	}
}
function show_errors(info)
{	
	info.value = "Error";
	info.style.color = "Red";		
	
}

function check_num_form(info)
{	
	//alert("Checking to see if it is blank "+isblank(info))
	if(isblank(info))
	{
		//alert("there is NO number here "+isblank(info));	
		check_for_length(info);
	}
	
}

function check_if_numeral(info)
{
	
	
	//alert("check if letter is in number  "+info.value);
	var non_numeral = info.value;
	
	for(var i = 0; i<= non_numeral.length; i++)
	{
		
		//alert(" the letter is "+non_numeral.charAt(i)+ " at " + i);
		if(!(non_numeral.charAt(i) <= "9")) 
		 {
			show_errors(info);	
			not_correct();
		 }
	}
	
}


function check_for_length(info)
{
	var num = info.value;
	
	if(num.length == "7")
	{
		//alert("not enough numbers");
		check_if_numeral(info);
	}		
	else
		{
			show_errors(info);		
			not_correct();
		}
	
}

function check_e_mail(info)
{
	
	var mail = info.value;	
	
	if(!((mail.indexOf(".") > 2) && (mail.indexOf("@") > 0)))
	{
		show_errors(info);		
		not_correct();
	}
	
}

function radio_check()
{
	var boolean_value
	
	var value = complaintform.wastetype.length;
	
	for (counter = 0; counter < complaintform.wastetype.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
		
		
		if((complaintform.wastetype[counter].checked))
		{
			boolean_value = complaintform.wastetype[counter].checked;
			waste_type = complaintform.wastetype[counter].value; 		
			//alert("it works");
		}
	}	
	if (!boolean_value)
	{	
		alert("Please select a Waste Type:\n \nBulk Waste:\n Missed Garbage Collection : \n Old Vehicle:  \n Dead Animal: ");
		not_correct();
	}
	else
	{return true
	
	}
}


function check_txt_form()
{
	var txtname= ['first_name','last_name','address','direction','contact_num','other_num','e_mail','wastetype'];
	
	for(var i=0; i <= txtname.length-1; i++)
	{
		
		var names = txtname[i];		
		switch (i)
		{
			case 0 :
			info = document.getElementById('first_name');			
			isblank(info);			
			break;		
			
			case 1 :
			 info = document.getElementById('last_name');			
			 isblank(info);
			break;	
			
			case 2:
			info = document.getElementById('address');			
			isblank(info);
			break;	
			
			case 3:
			info = document.getElementById('directions');						
			isblank(info);
			break;	
			
			case 4:
			info = document.getElementById('contact_num');			
			check_num_form(info);
			break;		
			
			case 5:
			info = document.getElementById('other_num');			
			check_num_form(info);
			break;		
			
			case 6:
			info = document.getElementById('e_mail');			
			check_e_mail(info);
			break;
			
			case 7:
			radio_check();
			break;
			
		}	
		
	}	
	
}

function reset_txt_form()
{
	var txtname= ['first_name','last_name','address','direction','contact_num','other_num','e_mail','wastetype'];
	
	for(var i=0; i <= txtname.length-1; i++)
	{
		
		var names = txtname[i];		
		switch (i)
		{
			case 0 :
			info = document.getElementById('first_name').value =" ";						
			//alert("the value is"+ info)
			break;		
			
			case 1 :
			 document.getElementById('last_name').value =" ";
			
			break;			
			
			
		}	
		
	}	
	
}

function refresh_form()
{
	correct();
}

function main()
{
	
	check_txt_form(this);
	if(!if_correct)
	{	
		alert("This form is incorrect \n Please press the Reset Button to re-enter Data");
		return false;		
		
	}
	else if(if_correct)
	{	
		
		return true;	
		
		
	}
	
		
}
function resetmain()
{
		main();
		reset_txt_form();
}

