$(function(){
  $.datepicker.setDefaults({duration:'fast',showAnim:'fadeIn'})
  $('fieldset.toggler').setupToggleFieldset();           // start closed            
  $('fieldset.toggler-open').setupToggleFieldset(true);  //start open
  $('textarea').maxLength();      
});



// on the event page, when someone selects a drop-down box town, copy it to the town input
// field and reset the select box
function copyTo(select_box_id, input_box_id) {
  from = $('#'+select_box_id)
  to = $('#'+input_box_id)
  to.focus();
  to.val(from.val());
  from.attr('selectedIndex', 0);

}




function preventNonNumeric(e) {
   allowedKeys = new Array(37,38,39,40,8,9, 0,48,49,50,51,52,53,54,55,56,57);
   key = e.which ? e.which : e.keyCode; //capital a-f= 65-70; a-f=97-102; nums=48-57, tab=9, arrrows=37-40, bkspc=8
   if (! in_array(allowedKeys,key) && !(e.ctrlKey==true) ) { e.preventDefault(); e.returnValue = false; }
}





function in_array(arr,obj) { 
//Array.prototype.in_array = function(obj){ 
//  return new RegExp('(^|\,)'+obj+'(\,|$)','gi').test(this);
  return new RegExp('(^|\,)'+obj+'(\,|$)','gi').test(arr);
} 
  
  
// truncate a string to len length, appending text to the end if needed  
function truncate(str,len,text) {
  if (!text) text = '...'
  if (str.length + text.length > len) {
    return str.substring(0,len-text.length) + text
  } else {
    return str
  }  
}
  
  
  
  
function clearForm (form) {
  $(form).find(":text").val('')
  $(form).find("select").val('')
}
  
    
  
  
  
  
  
  
