
// Function used to hidden sections of code on a page
	function hideStuff() {
		var n = arguments.length, el, id;
		for (var i=0; i<n; i++) {
			id = arguments[i];
			if ((el = document.getElementById(id)) || (el = document.all[id])) {
				if (el.style) el.style.visibility = 'hidden';
				document.getElementById(id).style.display = "none";
			}
		}
	}

// Function used to show sections of code on a page
	function showStuff() {
		var n = arguments.length, el, id;
		for (var i=0; i<n; i++) {
			id = arguments[i];
			if ((el = document.getElementById(id)) || (el = document.all[id])) {
				if (el.style) el.style.visibility = 'visible';
				document.getElementById(id).style.display = "block";
			}
		}
	}
	
// Set the radio button with the given value as being checked
// Do nothing if there are no radio buttons
// If the given value does not exist, all the radio buttons are reset to unchecked
	function setRadio( radioObj , newValue ) {
		if(!radioObj) {
			return;
		}
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			radioObj.checked = (radioObj.value == newValue.toString());
			return;
		}
		for(var i = 0; i < radioLength; i++) {
			//radioObj[i].checked = false; // clears each radio
			if(radioObj[i].value == newValue.toString()) {
				radioObj[i].checked = true; // sets the one radio requested
			}
		}
		
	}
	
// Return the value of the radio button that is checked
// Return an empty string if none are checked, or there are no radio buttons
	function getRadio(radioObj) {
		if(!radioObj) {
			return "";
		}
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			if(radioObj.checked) {
				return radioObj.value;
			} else {
				return "";
			}
		}
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				var j = i + 1;
				return radioObj[i].value;
			}
		}
		return;
	}

// Function to validate a phone number to the (###)###-#### format
	function validate_phone(phone) {
		
		var el = getElementByName(phone);
		var GoodChars = "0123456789";
		alert("GoodChars: " + GoodChars);
		var str;
		alert("inside validate phone function");
		if (el.length != 13 ) {
			alert("not enough characters");
			return false;
		}
		txt = el.value;
		if ( txt.charAt(0) == "(" && txt.charAt(4) == ")" && txt.charAt(8) == "-" ) {
			txt = txt.replace("(","");
			txt = txt.replace(")","");
			txt = txt.replace("-","");
			for (i = 0 ; i < txt.length ; i++) {
				if (GoodChars.indexOf(txt.charAt(i)) == -1) {
					alert("there are characters other than numbers");
					return false;
				}
			}			
			for ( x=0 ; x<el.length ; x++ ) {
			}
		} else {
			alert("brackets and hyphen not in the right location");
			return false;
		}
	}

// Function to add custom validation using the Gen_Validator javascript	
	function DoCustomValidation() {
		var frm = document.forms['children'];
		if(false == validate_phone(frm.phone)) {
			sfm_show_error_msg('Please enter a valid Phone Number');
			return false;
		} else {
			return true;
		}
	}
	
// Function to change the value of a variable
	function changeVar(num,val) {
		
	}
	
// Function to save a file
	function savefile( f ) {
		f = f.elements;  //  reduce overhead
		alert(f);
		var w = window.frames.w;
		if( !w ) {
			w = document.createElement( 'iframe' );
			w.id = 'w';
			w.style.display = 'none';
			document.body.insertBefore( w, null );
			w = window.frames.w;
			if( !w ) {
				w = window.open( '', '_temp', 'width=100,height=100' );
				if( !w ) {
					window.alert( 'Sorry, the file could not be created.' ); return false;
				}
			}
		}
		var d = w.document,
		ext = f.ext.options[f.ext.selectedIndex],
		name = f.filename.value.replace( /\//g, '\\' ) + ext.text;
		d.open( 'text/plain', 'replace' );
		d.charset = ext.value;
		if( ext.text==='.txt' ) {
			d.write( f.txt.value );
			d.close();
		} else {  //  '.html'
			d.close();
			d.body.innerHTML = '\r\n' + f.txt.value + '\r\n';
		}
		if( d.execCommand( 'SaveAs', null, name ) ){
			window.alert( name + ' has been saved.' );
		} else {
			window.alert( 'The file has not been saved.\nIs there a problem?' );
		}
		w.close();
		return false;  //  don't submit the form
	}