function validate(){
      
var theForm = document.forms[3].elements
var alertText = "";
var itemchecked = false;

    for(i=0; i<theForm.length; i++)      
     {if(theForm[i].type == "radio") 
       {var radiogroup = theForm[theForm[i].name];        
        for(var j = 0 ; j < radiogroup.length ; j++) 
         {if(radiogroup[j].checked) 
	     {itemchecked = true;                       
	      break;      
           }
	   }
       }
     }           
    
   if(!itemchecked) 
    {alertText += ("You must select one of the options in order to vote!\t\n\n");

    }      
   if(alertText)
    {alert(alertText);
     return false;
    }

else
return true;   
}

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name", "email", "comments");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Your Name", "Your Email Address", "Your Comments");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";      	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			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 (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

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

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

function verify() {
var themessage = "____________________________________________________\nYou are required to complete the following fields: ";
if (document.mform.name.value=="") {
themessage = themessage + "\n -  Your Name";
document.mform.name.focus();
}
if (document.mform.email.value=="") {
themessage = themessage + "\n -  Your E-mail Address";
	if (document.mform.name.value) {
	document.mform.email.focus();
	}
}
else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.mform.email.value)) {
themessage = themessage + "\n -  Your E-mail Address - (Format is Invalid) ";
    if (document.mform.name.value) {
	document.mform.email.select();
	}
}
if (document.mform.comments.value=="") {
themessage = themessage + "\n -  Your Comments";
	if (document.mform.name.value) {
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.mform.email.value)) {
		document.mform.email.select();
		}		
   		else if (document.mform.email.value) {
	    document.mform.comments.focus();
	    }
	}
}
//alert if fields are empty and cancel form submit
if (themessage == "____________________________________________________\nYou are required to complete the following fields: ") {
return true;

}
else {
alert(themessage + "\n____________________________________________________\nPlease correct the errors and submit again!\n \n");
return false;
   }
}

function openWindow(url, name) {
  popupWin = window.open(url, name, 'resizable,dependent,width=480,height=360,left=100,top=120')
}

function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
  myField.focus();
  sel = document.selection.createRange();
  sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == 0) {
  var startPos = myField.selectionStart;
  var endPos = myField.selectionEnd;
  myField.value = myField.value.substring(0, startPos)
  + myValue
  + myField.value.substring(endPos, myField.value.length);
  } else {
  myField.value += myValue;
  }
  }


