	
	//SURVEY.JS
	//This page contains javascript to use on the survey page.	

/*****************************************************************************************************************************/
/*****************************************************************************************************************************/

	//FUNCTIONS

	//*************************
	//charsRemaining(id,mc)
	//function to check the chars remaining in a field!
	function charsRemaining(id,mc){
		var len = document.getElementById(id).value.length;
		if (len > mc) {
		document.getElementById(id).value = document.getElementById(id).value.substring(0,mc);
		len = mc;
		}
		
		var message = "";
		message += len + " characters used | ";
		message += mc - len + " characters remaining";
		
		document.getElementById(id + "-CR").innerHTML = message;
	}
	//*************************
	
	
	//*************************	
	//checkboxValues(thisid,retthis)
	//function to return the separate values for a checkbox
	function checkboxValues(thisid,retthis){
		
		//create the object
		checkbox = document.getElementById(thisid);
		
		//what are we returning?
		if(retthis == "value"){
			return checkbox.value;
		} else if(retthis == "checked"){
			return checkbox.checked;
		} else {
			if(checkbox.checked){
				return checkbox.value;
			} else {
				return "";
			}
		}
	}
	//*************************
	
	
	//*************************
	//uncheckAndDisableAll(thisid,exempt)
	//this function will uncheck all checkboxes except the exempt and disable them
	function uncheckAndDisableAll(groupid,exempt){
		
		//get a count of all the options
		var count = document.getElementById(groupid + "-OC").value;		
		
		//check the status of control
		if(document.getElementById(exempt).checked == true){		
			
			//disable them all!
			for(i=1;i<=count;i++){
				if((groupid + "-" + i) != exempt){
					document.getElementById(groupid + "-" + i).checked = false;
					document.getElementById(groupid + "-" + i).disabled = true;
				}
			}
			
			//check for other!
			if(document.getElementById(groupid + "-OTHER")){
				document.getElementById(groupid + "-OTHER").value = "";
				document.getElementById(groupid + "-OTHER").disabled = true;
				document.getElementById(groupid + "-OTHERBLOCK").className = "hideOther";
			}
			
			
		} else {
			
			//enable them all
			for(i=1;i<=count;i++){
				document.getElementById(groupid + "-" + i).disabled = false;
			}
			
			//check for other!
			if(document.getElementById(groupid + "-OTHER")){
				document.getElementById(groupid + "-OTHER").disabled = false;
			}
		}	
		
	}
	//*************************
	
	
	//*************************
	//selectOther(thisid)
	//function to perform when a select box has 'other' selected
	function selectOther(thisid){

		if(selectValues(thisid,"value") == "OTHER"){
			document.getElementById(thisid + "-OTHERBLOCK").className = "showOther";
		} else {
			document.getElementById(thisid + "-OTHER").value = "";
			document.getElementById(thisid + "-OTHERBLOCK").className = "hideOther";	
		}
		
	}
	//*************************
	
	
	//*************************
	//checkboxOther(thisid)
	//function to perform when a checkbox has 'other' checked
	function checkboxOther(groupid,thisid){
	
		if(checkboxValues(thisid,"checked") == true){
			document.getElementById(groupid + "-OTHERBLOCK").className = "showOther";
		} else {
			document.getElementById(groupid + "-OTHER").value = "";
			document.getElementById(groupid + "-OTHERBLOCK").className = "hideOther";	
		}

	}
	//*************************
	
	
	//*************************
	//radioOther(groupid,thisid)
	//function to perform when a radio value of 'OTHER' has been checked
	function radioOther(groupid,thisid){
		
		if(document.getElementById(thisid)){
			if(document.getElementById(thisid).checked == true && document.getElementById(thisid).value == "OTHER"){
				document.getElementById(groupid + "-OTHERBLOCK").className = "showOther";
			} else {
				document.getElementById(groupid + "-OTHER").value = "";
				document.getElementById(groupid + "-OTHERBLOCK").className = "hideOther";		
			}
		}
	}
	//*************************
	
	
	
	
	
	
	//*************************
	//selectValues(thisid,thiselement)
	//function to access parts of a select box value...the label, value or selectedIndex
	function selectValues(thisid,thiselement){
	
		var si 		= document.getElementById(thisid).selectedIndex;
		var value   = document.getElementById(thisid).options[si].value
		var label	= document.getElementById(thisid).options[si].text;
		var output 	= new String("");
		
		switch(thiselement){
		
			case "selectedIndex":
				output = si;
				break;
			case "value":
				output = value;
				break;
			case "label":
				output = label;
				break;
			default:
				output = value;
		}
		
		//return the output
		return output;
	}
	//*************************
