/*	
Author: Will Martinez
Website: www.willmartinez.com
JS Type: Form Validator
Version 1.1

Instructions

Include this file like this: <script src="js/form_validator.js" type="text/javascript"></script>

In the Form tag add :
onSubmit=" return checkWholeForm(this)">

Normal textbox example:	
why += isEmpty(form.name.value, "Full Name");
	
RadioButton Example:
why += radioChecked(form.homeType, "Property Type");
	
DropDownBox Example:
why += checkDropdown(form.Title.value, "Title");
With Drop down boxes if you the first item in the list is something like 'Select...' please its value is 0 - So for example: value="0". I would also recommend adding values to the other items. 	

CheckBox Example:
why += checkBoxChecked(form.terms, " Terms and Conditions");
Notice that there is no .value after the checkbox name unlike the in the other validators.  


	
*/

function checkWholeForm(form, type) {

    var why = "";
if(type=="cv"){
why += isEmpty(form.name.value, "Name");
why += isEmpty(form.company.value, "Company");
}
why += isEmpty(form.email.value, "Email");

 if (why != "") {
       alert("Please fill in the following fields: \n"+why);
       return false;
    }
	else if(why == ""){
		 if(type=="cv"){
			sendRequest();
	 		}
			else if(type=="email"){
				emailSubmit();
			}
	return true;
	}
}



function isEmpty(strng, str){
var error = "";
  if (strng.length == 0){
     error = "-"+str+"\n";
  }
return error;	  
}

function checkDropdown(choice, str){
    var error = "";
	if (choice == "0"){
       error = "-"+str+"\n";
    }    
return error;
}

function radioChecked(radiobutton, str){
var error = "";
  for(i=0; i<radiobutton.length; i++){
 	 if(radiobutton[i].checked == true){
		 error = "";
		 break;
	 }
  	 else{
		 error = "-"+str+"\n";
	}
  }
return error;	  
}

function checkBoxChecked(checkbox, str){
    var error = "";
	if (!checkbox.checked){
       error = "-"+str+"\n";
    }    
return error;
}

