function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function checkUser(strEmail, intAccountID) {

	var url = 'admin/ajax_CheckUser.cfm';
	var pars = 'strName=' + strEmail + '&intID=' + intAccountID + '&tableName=accounts&valueColumnName=strEmail&IDcolumnName=intAccountID';
	
	//create the ajax request
	var myAjax = new Ajax.Request(
	        url,
	        {
	                method: 'get',
	                parameters: pars,
	                onComplete: showResponse
	        }
	);      
}

//ajax callback method
function showResponse(data) {
	//alert(data.responseText);
      if (data.responseText == 1){
      	alert('Email is already used. Please try something else');
      	return false;
      }else{
      	if(validateForm( document.gronk, 0, 1, 0, 1, 17 )){
      		document.gronk.submit();
      	}else{
      		return false;
      	}
      	
      }
}

function toggleitem(a){
	x=document.getElementById(a);
	if(x.style.display=="block"){
		x.style.display="none"
	}else{
		x.style.display="block"
	}
}

function displayBlock(id){
 	document.getElementById(id).style.display='block';
}
function displayNone(id){
 	document.getElementById(id).style.display='none';
}

function radio_button_checker(radioField)
{	
	
	// set var radio_choice to false
	var radio_choice = false;
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < radioField.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (radioField[counter].checked)
		radio_choice = true; 
	}
	
	if (!radio_choice)
	{
		return (false);
	}
return (true);
}

function OpenEditWindow(strURL, strTitle, intWidth, intHeight, scrollbars)
	{
		var intWindowLeft
		var intWindowTop
		var msgWindow
		
		
		// find out the numbers to center the screen.
		intWindowLeft = (screen.width - intWidth) / 2;
		intWindowTop = (screen.height - intHeight) / 2;
		window.open(strURL,strTitle,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scrollbars + ',resizable=0,width=' + intWidth + ',height=' + intHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop);	
	}	
	
function trim(s)
{
return s.replace(/^\s+|\s+$/g, "");
}	
	
function isFloat(s)
{
var n = trim(s);
return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
}	

function LTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
	}
function RTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
	}
function Trim(str) {
	return LTrim(RTrim(str));
	}

