// Copyright information must stay intact
// FormCheck v1.10
// Copyright NavSurf.com 2002, all rights reserved
// Creative Solutions for JavaScript navigation menus, scrollers and web widgets
// Affordable Services in JavaScript consulting, customization and trouble-shooting
// Visit NavSurf.com at http://navsurf.com

function formCheck(formobj){
        //first check to see if either by post or by download has been selected
        var byPostChecked = formobj.elements.bypost.checked;
        var byDownloadChecked = formobj.elements.bydownload.checked;
        var abort=0;

        //if neither field is checked ask user to select download method and abort validation
        if (byPostChecked != 1 && byDownloadChecked != 1)
            {
                alert("Please select how you would like to receive your brochure");
                return false;
            }


        //if by post is NOT checked only validate non-address fields

        if (byPostChecked != 1)
        {
	// name of mandatory fields
	var fieldRequired = Array("name", "email", "tel", "employees", "message");
	// field description to appear in the dialog box
	var fieldDescription = Array("Name", "Email Address", "Telephone Number", "Number of Employees", "Message");
	// dialog message
	var alertMsg = "Please fill in the following fields:\n";
        }
    
        //ELSE if By Post IS checked include address fields in validation
        else
        {
	// name of mandatory fields
	var fieldRequired = Array("name", "address1", "postcode", "email", "tel", "employees", "message");
	// field description to appear in the dialog box
	var fieldDescription = Array("Name", "First Line of Address", "Postcode", "Email Address", "Telephone Number", "Number of Employees", "Message");
	// dialog message
	var alertMsg = "Please fill in all details including your address.\n";
        }

        


	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}

}