/* ************************************************************
	The Conference Desk : www.theconferencedesk.com
	Developed by:	The MayaTech Corporation
					http://www.mayatech.com
					301-587-1600
	Filename:		js_form_validate.cfm
	Description:	form field validation routines 
	Revisions:		KJ 8/22/05 initial version
****************************************************************
	Each function accepts a form field object
	Each function returns true/false as to whether there is content in the field

	REQUIRES: 
	prototype trim function
		-available in js_std_functions.js

	USED BY:
	TDC Forms
		-js_check_search_form.js
*/

/*check that at least 1 item in a checkbox group is checked
	or that a single checkbox is checked*/
	function check_checkbox(ele){
		var result=false;
		//if the element is a checkbox group, loop through to find a checked element
		if(typeof(ele.form[ele.name].length)!="undefined"){
			for(i=0; i<ele.form[ele.name].length; i++){
				if(ele.form[ele.name][i].checked){
					result=true;
					break;
				}
			}
		//otherwise just check that the element is checked
		}if(ele.checked){result=true;}
		
		return result;
	}

	/*check that at least 1 item in a radio-button group is checked
	or that a single radio-button is checked*/
	function check_radiobutton(ele){
		var result=false;
		//if the element is a radio-button group, loop through to find a checked element
		if(typeof(ele.form[ele.name].length)!="undefined"){
			for(i=0; i<ele.form[ele.name].length; i++){
				if(ele.form[ele.name][i].checked){
					result=true;
					break;
				}
			}
		//otherwise just check that the element is checked
		}if(ele.checked){result=true;}
		
		return result;
	}

	/*check that a textbox has content*/
	function check_text(ele){
		var result=false;
		if(ele.value.trim()!="")
			result=true;
			
		return result;
	}

	/*check that a select list has a selected element (other than the first item)*/
	function check_select(ele){
		var result=true;
		//check that a single select has something other than and empty string or value==zero selected
		if(ele.type=="select-one"){
			if(ele[ele.selectedIndex].value.length==0 || ele[ele.selectedIndex].value==0){
				result=false;
			}
		//check that a multiple select has a selected index (above the first)
		}else if(ele.type=="select-multiple"){
			result=false; //assume failure; if any list elements is selected, return success
			for(i=1; i<ele.length;i++){
				if(ele[i].selected){
					result=true;
					break;
				}
			}
		}
		
		return result;
	}

	/*pass deletion request through to action page as appropriate
	 - asks for confirmation from user before proceeding*/
	function deletethis(id,what){
		if(confirm("Are you sure you want to delete this item?")){
			document.location="item_delete.cfm?id=" + id + "&what=" + what;
		}
	} 
	