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 textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
	countfield.value = maxlimit - field.value.length;
	}
	
thumbsDir=new Array();
thumbsArray=new Array();
preloadedimages=new Array();
timeouts=new Array();

function isloaded(img) {
  if (!img.complete)
    return false;
  if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0)
    return false;
  return true;
}

function loadimage(path, id, num){
  if (typeof(preloadedimages[id][num])!='undefined')
    return;
  preloadedimages[id][num]=new Image();
  preloadedimages[id][num].src=path+thumbsArray[id][num];
}

function showimage(path, id, cnt, num){
  if (!isloaded(preloadedimages[id][num])){
    timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 50);
    return;
  }
  document.getElementById('img_src_'+id).src=preloadedimages[id][num].src;
  if (++num==cnt)
    num=0;
  loadimage(path, id, num);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 800);
}

function startPreview(id){
  path=thumbsDir[id];
  num=thumbsArray[id].length;
  if (typeof(preloadedimages[id])=='undefined')
    preloadedimages[id]=new Array();
  loadimage(path, id, 1);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+num+", 1)", 800);
  loadimage(path, id, 0);
}

function stopPreview(id){
  clearTimeout(timeouts[id]);
  document.getElementById('img_src_'+id).src=preloadedimages[id][0].src;
}
