// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

showing_id = new Array()    // keeps track of ID of  selection group currently showing in images and highlighted as well as history
openID = 0      // id of element to open in adjustHeightWidth
start = 0     // id of top level of foldout heirarchy (reset in index.rhtml)
editcat = 1  // id of category to be moved, renamed, deleted or adde to in category editor
editname = "selection"  // name of editcat
running = '0'  // id of running timer

function goHome()
{
window.location="http://aerulean.com"
}

function ajaxRequest(url)
{
  if (!$('progress_indicator')) {new Ajax.Request(url, {asynchronous:true, evalScripts:true}); return false;}
  else {
    new Ajax.Request(url, {
      asynchronous:true, evalScripts:true, 
      onLoading:function(request){Element.show('progress_indicator')},
      onComplete:function(request){hideProgressIndicator()}
      })
    return false
    }
}

function backToSearch()
{
	window.location.pathname = "/select/index"
}
 
function backToLogin()
{
	window.location.pathname = "/company/index"
}
 
function reactivateAccount()
{
	window.location.pathname = "/company/reactivate_account"
}
 
function authorize()
{
  if (window.opener) {} else {window.location="http://aerulean.com"}
}

function forgotPassword()
{
	window.location.pathname= "/company/forgot_password?name=" + $('username').value
}
 
function nameSelect(txt,li)
{
  newName = true
  name = li.innerHTML.replace(/<p>|<\/p>|<strong>|<\/strong>/gi,"").replace(/I>/g,'i>').replace(/<i>/,';SI;').replace(/<\/i>/,';EI;')  //needs to be case insensitive because IE uses uppercase  
//  if (/((Firefox|MSIE|Safari|Chrome)[\/\s]\d+\.\d+)/.test(navigator.userAgent)) { browser = RegExp.$1 }
  url = "/select/name_select?name=" + name + "&showing=" + showing_id + "&version=" + version
	ajaxRequest(url)
}
  
function fileSelect(txt,li,pid)
{
  newName = true
  file = li.innerHTML.replace(/<p>|<\/p>|<strong>|<\/strong>/gi,"")    
  url = "/admin/file_select?file=" + file + "&pid=" + pid
	ajaxRequest(url)
}
  
function changeGenusPlant(event,sel,pid)
{
  url = "/admin/menu_redraw?selected_plant=" + sel.replace(/\..*/,'') + "&pid=" + pid
 ajaxRequest(url)
}

function changeGenus(event,val,pid)
{
  url = "/admin/change_genus?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeSpecies(event,val,pid)
{
  url = "/admin/change_species?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeCultivar(event,val,pid)
{
  url = "/admin/change_cultivar?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeFamily(event,val,pid)
{
  url = "/admin/change_family?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeSynonym(event,val,pid)
{
  url = "/admin/change_synonym?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeSellingName(event,val,pid)
{
  url = "/admin/change_selling_name?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeCommonNames(event,val,pid)
{
  url = "/admin/change_common_names?new_name=" + val + "&pid=" + pid
 ajaxRequest(url)
}

function changeAdditionalData(event,oldval,newval,cid,pid)
{
  url = "/admin/change_additional_data?olddata=" + oldval + "&newdata=" + newval + "&cid=" + cid + "&pid=" + pid
 ajaxRequest(url)
}

function updateGenusList(event,val)
{
  url = "/admin/update_genus_list?genus=" + val
  ajaxRequest(url)
}

function createCategory(event,val,cid)
{
  url = "/admin/create_category?name=" + val + "&cid=" + cid
 ajaxRequest(url)
}

function startOver()
{
	window.location.pathname = "/select/start_over" 
}
 
function checkName()
{
	if ($('plant_name').value == "") {
    removeName()
    }
}
 
function removeName()
{
  clearName()
  url = "/select/name_remove?showing=" + showing_id + "&version=" + version
  ajaxRequest(url)
}

function clearName()
{
  $('plant_name').value = 'plant name'
  $('plant_name').style.color=''
}

function addSelection(cat_id,parent_id)
{ 
	el = $('foldout_item' + cat_id)
  if (el && el.style.cursor != 'default' && el.parentNode.style.cursor != 'default') { // do nothing if grayed out either individually or as group
    if (el = $('cat_line' + showing_id[showing_id.length - 1])) {el.style.backgroundColor = '' }    // unhighlight previous selected group if it exists
    if (version == '0.5' && parent_id != showing_id[showing_id.length-1]) { i = showing_id.indexOf(parent_id); if (i >= 0) {showing_id.splice(i,1)}; showing_id.push(parent_id) }  //move to end or add at end if not at end
    $('foldout_item_span' + cat_id).style.backgroundColor = '#f2f2eb'
    url = "/select/add_selection?category=" + cat_id + "&showing=" + showing_id + "&open_id=" + parent_id + "&version=" + version
	  ajaxRequest(url)
    }
}
  
function removeSelection(cat_id)
{
	$('foldout_item_span' + cat_id).style.backgroundColor = ''
	url = "/select/remove_selection?category=" + cat_id + "&showing=" + showing_id + "&version=" + version
	ajaxRequest(url)
}

function removeBox(cat_id)
{
  if (cat_id == 'name') {
    return "<img class=\"remove\" src=\"/images/remove_selected.gif\" onclick=\"removeName()\" onmouseover=\"this.src='/images/remove_selected_rollover.gif' \" onmouseout=\"this.src='/images/remove_selected.gif' \" />"
    }
  else {
    return "<img class=\"remove\" src=\"/images/remove_selected.gif\" onclick=\"removeSelection('" + cat_id + "')\" onmouseover=\"this.src='/images/remove_selected_rollover.gif' \" onmouseout=\"this.src='/images/remove_selected.gif' \" />"
    }
}

function checkUsername(name)
{
	url = "/company/check_username?name=" + name
	ajaxRequest(url)
}

function checkPassword(password,confirmation)
{
  if (password.length < 6) {$('password_message').innerHTML = "Password must be at least six characters"}
  else if (confirmation.length == 0 || password == confirmation) {$('password_message').innerHTML = ""}
  else {$('password_message').innerHTML = "Passwords don&rsquo;t match; please correct!"}
}

function checkPasswordConfirm(password,confirmation)
{
  if (password == confirmation) {$('password_message').innerHTML = ""}
  else {$('password_message').innerHTML = "Passwords don&rsquo;t match; please correct!"}
}

function gray(id,color)
{
  el1 = $(id)
  el1.style.color = color
  if (id.match('category')) {  }  // don't change cursor on category ids
  else { el1.style.cursor = 'default' }
}

function ungray(id)
{
  el = $(id)
  el.style.color = ''
  el.style.cursor = ''
}

function fadeIn(id, imageType)
{
  el =$('foldout_item'+id)
  if (!el) {el=$('category'+id) } // if no foldout_item with id, then must be a category
  if (imageType == 'plant' || el.style.cursor != 'default' ) {   // image is a thumbnail on search results page or on a plant information page or a category image not selected or in need of graying out
    Effect.Appear('div_image' + id, {duration: 0.25, from: 0, to: 1.0})   //just display image
    }
  else {  // image is a category image corresponding to grayed out text
    $('div_image' + id).style.cursor = 'default'   // display default cursor since no selections are allowed
    $('caption' + id).style.cursor = 'default'
    $('image' + id).style.cursor = 'default'
    $('spacer' + id).style.cursor = 'default'
    if (version=='0.0' || imageType == 'category') {  // either V0.0 or not selected
      Effect.Appear('div_image' + id, {duration: 0.25, from: 0, to: 0.2})
      }
    else {  // imageType must be "selected_category"; turn on border, highlight caption box, do not gray out image
      $('div_image' + id).style.border = "2px solid #e5e2db"
      Effect.Appear('div_image' + id, {duration: 0.25, from: 0, to: 1.0})
      new Effect.Highlight('caption_box' + id, {startcolor: '#ffffee', endcolor: '#c1baa0', restorecolor: '#c1baa0'})  
      }
    }
  }

function clearTo(id)
{
  while (showing_id.length > 0 && showing_id.pop() != id) {}  //  remove from end back to id
  showing_id.push(id)
}

function closeAll()
{
  while ((id = showing_id.pop()) != start) {  //  remove from end back to id
    $('foldout' + id).style.display = 'none'
    $('img' + id).src = '/images/menu_arrow_up.png'
  }  
  showing_id.push(start)
  showIdImages()
}

function aFoldoutToggle(event,n,name)  // simple version for text-only (admin) use
{ 
  if (event.button == 2) {
    editcat = n    // records which category right menu is opened for (used by moveTo, deleteCategory, createCategory, renameCategory [the last two via checkCR])
    editname = name  // name of same category
    $('right_menu').style.display = ''
    $('right_menu').style.left = event.clientX + 'px'
    $('right_menu').style.top = event.clientY + 'px'
    }
  else {
    el = $('foldout' + n)
    if (el) {
      if (el.style.display != 'none') { el.style.display = 'none' }
      else { el.style.display = '' }
      }
  }
}

function foldoutOpen(n)  //    (for right click menu foldout in admin category editor--close all; then open one)
{ 
    uls = document.getElementsByTagName('ul')
    for (i=0; i<uls.length; i++) if (uls[i].id.match(/mfoldout/)) uls[i].style.display = 'none'
    $('mfoldout' + n).style.display = '' 
 }
 
function moveTo(n)
{
  $('top').style.display = 'none'
  url = "/admin/move_category?parent=" + n + "&cat=" + editcat
	ajaxRequest(url)
}

function checkCR(e,action,name)
{
	keynum = e.keycode || e.which
  if (keynum == 13) {
    $('new_item').style.display = 'none'   //  hide input box for next time menu is opened
    $('rename').style.display = 'none'   //  hide input box for next time menu is opened
    $('right_menu').style.display = 'none'   //  hide right-click menu
    url = "/admin/" + action + "?cat=" + editcat + "&name=" + name
    ajaxRequest(url)
    }
}

function deleteCategory()
{
  url = "/admin/delete_category?cat=" + editcat
  result = confirm("Are you sure you want to delete the category \"" + editname + "\"?  This operation cannot be undone and deletes all connections of this category to plants!")
  if (result) ajaxRequest(url) 
}

function toggleSelection(cid, pid)  // admin function to add or remove a category from a plant
{
  el = $('foldout_item_span' + cid)
  if (el.style.backgroundColor != '') {
    el.style.backgroundColor = ''
    url = "/admin/remove_category?cid=" + cid + "&pid=" + pid 
  }
  else {
    el.style.backgroundColor = '#aaffaa'
    url = "/admin/add_category?cid=" + cid + "&pid=" + pid 
    }
	ajaxRequest(url)
}

function foldoutToggle(n)  // toggles display state of element 'foldoutn'
{
  el = $('cat_line' + showing_id[showing_id.length-1])
  if (el) el.style.backgroundColor = ""    // unhighlight last group if exists and highlighted
  openID = 0
  id = 'foldout' + n
  elf = $(id)
  elc = $('cat_item' + n)
  eli = $('img' + n)
  if (elf.style.display != 'none') {   // menu category open so close it
    elf.style.display = 'none'
    eli.src = '/images/menu_arrow_up.png'
    if (n == showing_id[showing_id.length-1]) {
//      $('categoryspan' + n).style.backgroundColor = ''
      showing_id.pop()
      }
    else if (showing_id.length > 1 ) {  // don't need to do anything further if top level highlighted
      el_showing = $('foldout'+showing_id[showing_id.length-1])
      el = el_showing.parentNode
      parent_found = false
      while (el.id != 'foldout'+start && !parent_found) {
         el=el.parentNode
        parent_found = (el == elf)
        }
      el_parent = elf.parentNode.parentNode
      parent_id = parseInt(el_parent.id.replace(/foldout/,''))
      if (parent_found) {  
        clearTo(parent_id)  //  remove from end back to parent_id
        }
      else { // just remove group id and any children from history unless its parent is the last one, or it's not in history, in which case do nothing
        index = showing_id.indexOf(n)
        if (index < showing_id.length-1 && index >= 0) {  
          showing_id.splice(showing_id.indexOf(n),1)
          for (i=index;i<showing_id.length-1;i++) { 
            index_found =false
            el = $('foldout' + showing_id[i])
            while (el.id != 'foldout'+start && !index_found) {  
              el = el.parentNode
              index_found = (el.id == 'foldout' + n)
              }  
            if (index_found) { showing_id.splice(i,1); i-- }   // child found; therefore delete it
            if (i>showing_id.length-3) {break}  // quit loop if next would be last one
            }
          }
        }
      }
    }
  else {
    openID = n       // delay actually opening element until after running showIdImages which recalculates counts and then calls adjustHeightWidth
    if (el = $('category' + showing_id[showing_id.length - 1])) {el.style.backgroundColor = '' }    // unhighlight previous selected group if it exists
    showing_id.push(n)  
    }
  showIdImages(openID)
  if (openID) { // finally open foldout if needed
    elf.style.display = 'block'
    eli.src = '/images/menu_arrow_down.png'
    }  
  }  

function showIdImages(openID)
{
	url = "/select/show_ID_images?showing=" + showing_id + "&open_id=" + openID + "&version=" + version
	ajaxRequest(url)
}
	
function showPlant(id,picIds)
{
	url = "/select/show/" + id 
  htmltext = ''
  for (i=0; i<picIds.length;i++) { 
    htmltext += "<img id='small_image" + picIds[i] + "' src='select/show_image/" + picIds[i] + "' />"
    htmltext += "<img id='big_image" + picIds[i] + "' src='select/show_large_image/" + picIds[i] + "' />"
  }
  $('species_images').innerHTML = htmltext
	window.open(url,"_blank","top=5,left=5,height=750,width=1019,resizable=yes,channelmode=no,fullscreen=no,scrollbars=yes")
}
 
function googleSearch(plant)
{
	url = "http://www.google.com/search?q=" + plant
	window.open(url,"_blank","top=40,left=40,height=600,width=800,resizable=yes,toolbar=yes,channelmode=no,fullscreen=no,scrollbars=yes")
}
 
function showSelected(image_type,sortby)
{
  url = "/select/show_selected?image_type=" + image_type + "&sortby=" + sortby+ "&showing=" + showing_id + "&version=" + version 
  ajaxRequest(url)
}

function changePasswordBox()
{
  $('pass_temp').style.display = 'none'
  $('pass_real').style.display = ''
  $('password').focus()
}
  
function restorePasswordBox()
{
  if ($('password').value == '' ) {
    $('pass_temp').style.display = ''
    $('pass_real').style.display = 'none'
    }
}

function restoreNameBox()
{
  if ($('name').value == '' ) {
    $('name').value = 'Username'
    }
}

function showSpeciesImages(id)
{
	url = "/select/show_species_images/" + id
  ajaxRequest(url)
}

function showBiggerSpeciesImage(plantID,picID)
{
	url = "/select/show_bigger_species_image/"+ plantID + "?pic_id=" + picID
  ajaxRequest(url)
}
	
/*
function show_more_images(directory)
{
	url = "/select/show_more_images?directory=" + directory
  ajaxRequest(url)
}
	
function show_bigger_image(image)
{
	url = "/select/show_bigger_image?image=" + image
  ajaxRequest(url)
}
	
	*/
/*function match_heights()
{     
  for (i=0;i<document.images.length;i++) {
    if (!document.images[i].complete && document.images[i].src != "")     // in IE, second condition triggers a false on 'complete' property
        { setTimeout("match_heights()",1000); return }   // if any image not yet loaded, wait one second and retry
    }
    el1 = $('foldout' + start)
    offset1 = 61
    offset2 = 20
    min_height = 666   // (for panel2)
    offset3 = 72
    if (!el1) {el1 = $('panel1'); offset1 = 0; offset2 = -5; min_height = 616; offset3 = 22; }
    el2 = $('panel2')
    el3 = $('panel1_middle')
    if (el1 && el2 && el3)  { //do nothing if any element is missing
      el2.style.height = "auto"
//      el3.style.height = "auto"
//      if (el3.offsetHeight < el1.offsetHeight +offset1)
//        { el3.style.height = (el1.offsetHeight + offset1) + 'px' }  //extend panel1_middle to hold panel1 
      if (el2.offsetHeight < el3.offsetHeight + offset2)
        { el2.style.height = (el3.offsetHeight + offset2) + 'px' }   //extend panel 2 to match
//      else
//        { el3.style.height = (el2.offsetHeight - offset2) + 'px' }
      if (el2.offsetHeight < min_height)          // stretch both panels if text panel doesn't fill screen
        { el2.style.minHeight = min_height + 'px';  }
      }
    hideProgressIndicator()
  }  */

function adjustFooter()
{
if (window.clientHeight > 800) {$('V0footer').style.bottom = window.clientHeight}
}

function hideProgressIndicator()
  {
  for (i=0;i<document.images.length;i++) {
    if (!document.images[i].complete && document.images[i].src != "")     // in IE, second condition triggers a false on 'complete' property
        { setTimeout("hideProgressIndicator()",1000); return }   // if any image not yet loaded, wait one second and retry
    }
    el = $('progress_indicator')
    if (el) { el.style.display="none" }       
    else { setTimeout("hideProgressIndicator()",500) }  //wait .5 sec and retry
  }
    
  
function adjustHeightWidth(id,nacross)    // right now nacross can be 0, 3, or 4 and sets image size, 0 is for admin
  {
    switch (nacross) {
      case 0:
        high = 300
        imageHigh = 200
        wide = 230
        itop = 203
        break
      case 3:
        high = 230
        imageHigh = 200
        wide = 230
        itop = 203
        break
      case 4:
        high = 170
        imageHigh = 140
        wide = 170
        itop = 143
        break
      }
    el = $('image' + id)
    elA = $('div_image' + id)
    elB = $('div_image_div' + id)
    elC = $('div_image_div_div' + id)
    if (elA) {  
      elA.style.width = (wide + 6) + 'px'
      elA.style.height = (high + 6) + 'px'
      elB.style.width = (wide + 4) + 'px'
      elB.style.height = (high + 4) + 'px'
      elC.style.top = itop + 'px'
      elC.style.left = '0'
      elC.style.height = (high - itop) + 'px'
      elC.style.width = (wide + 4) + 'px'
      }
    if (el.height < 10) { Effect.Appear(elA); setTimeout('adjustHeightWidth('+id+','+nacross+')',200); return; } // IE sets height to 0 if image is not showing!  If so, start fade-in, wait 200 ms, retry 
    if (el.height > imageHigh)
      { el.width *= (imageHigh/el.height); el.height = imageHigh }
    if (el.width > wide)
      { el.height *= (imageHigh/el.width); el.width = wide }
    el.style.top = (imageHigh + 2 - el.height)/2 + 'px'
    el.style.left = (wide + 4 - el.width)/2 + 'px'
//    Effect.Appear(id, {duration: 0.25, from: 0, to: 1.0})
  }

function positionAutoCompleteDropdown()    //resets dropdown position for MSIE 8 only
{
       $('auto_complete_ul').style.margin = "-62px 0 0 -120px" 
 }

/* function adjustBigImg(imageno)
{
  el = $('big_img')
  el2=$('div_big_img')
  if (el.height > 270)
    { el.width *= (270/el.height); el.height = "270" }
    if (el.width > 300)
      { el.height *= (300/el.width); el.width = "300" }
    el.style.top = (272 - el.height)/2 + 'px'
    el.style.left = (304 - el.width)/2 + 'px'
    el2.style.top = 40 + Math.floor((imageno-1)/4)*180 + 'px'
    el2.style.left = 10 + (imageno-1)%4*137 + 'px'
    Effect.Appear('div_big_img')
}
 */
function respond(event)
{
  bits = event.target.name.split('|')   // arguments are encoded in 'name' of <img> element
  if (bits[0] == 0)     // No children; implement select
    { select(event, bits[1], bits[2]) }
  else if (bits[0] == 'show')  // Looking at thumbnails; implement show_plant
    { show_plant(bits[1]) }
  else     // implement foldout_toggle
    { foldout_toggle(bits[2]) }
}

function adjustHeightWidth300(imageno)
  {
    el = $("image"+imageno)
    if (el.height > 270)
      { el.width *= (270/el.height); el.height = "270" }
    if (el.width > 3000)
      { el.height *= (300/el.width); el.width = "300" }
    el.style.top = (272 - el.height)/2 + 'px'
    el.style.left = (304 - el.width)/2 + 'px'
    Effect.Appear("div_image"+imageno)
    }

function strip(string)   //removes spaces at beginning and end
{
  return string.replace(/\s*(.+)\b\s*/,"$1")
}

function change_cactus_category_name()
{
  el = $('categories')
  heading = document.getElementById('labels_heading').value
  subheading = document.getElementById('labels_subheading').value
  category = document.getElementById('labels_category').value
  new_category = (heading.toLowerCase() + '__' + ((subheading == '')? '' : subheading + '__') + category).replace(/ /g,'_')
  el.options[el.selectedIndex].innerHTML = new_category
}

function update_labels(heading,subheading,category)
{
  $('labels_heading').value = heading
  $('labels_subheading').value = subheading
  $('labels_category').value = category
} 

function el_delete (array,el)
{
  out = new Array()
  for (x in array) {
    if (array[x] != el) {
      out.push(array[x])
      }
    }
  return out
}

function showHint(event,id,text)
{
if (version == '0.5' && running != 'X') {   //suppress if X timer is running
  running = id
  mouseX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)
  mouseY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)
  timer = setTimeout("showHint2('" + mouseX + "','" + mouseY + "','" + id + "','" + text + "')",1600)   // wait 1600 ms before acting
  }
}

function showXHint(event,id,text)
{
  running = id
  if (timer) clearTimeout(timer)  // clear any running timer such as for breadcrumb hint
  mouseX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)
  mouseY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)
  timer = setTimeout("showHint2('" + mouseX + "','" + mouseY + "','" + id + "','" + text + "')",1600)   // wait 1600 ms before acting
}

function showIHint(event,id)
{
if (version == '0.5' ) { 
  el =$('foldout_item'+id)
  if (!el) {el=$('category'+id) } // if no foldout_item with id, then must be a category
  if ( el.style.cursor == 'default' ) {   // image is a grayed out catetggory image
    running = id
    mouseX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)
    mouseY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)
    timer = setTimeout("showHint2('" + mouseX + "','" + mouseY + "','" + id + "','" + 'no longer a useful selection' + "')",1600)   // wait 1600 ms before acting
    }
  }
}

function showHint2(mouseX,mouseY,id,text)
{
  body_width = document.body.offsetWidth   
  window_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth   //accommodated various browsers
  right_edge = (window_width + body_width)/2
  el = $('hint')
  width = el.offsetWidth ? el.offsetWidth : (el.clip ? el.clip.width : 150)
  el.style.top = mouseY -30 + 'px'
  left = mouseX -80 - width/4
  if (left < 2) left = 2
  else if (left + width > right_edge - 20) left = right_edge - width - 20
  el.style.left = left + 'px'
  el2 =$('foldout_item'+id)
  if (!el2) {el2=$('category'+id) } // if no foldout_item with id, then must be a category
  if (id != 'B' && id != 'X' && id != '0' && el2.style.cursor == 'default') {  // code for a category hint, ghosted out: set alt text
    text =  "no longer a useful selection"
    }
  if (id != 'B' && id != 'X'&& id != '0' && text == 'none') { }  //  do nothing if not ghosted and no hint
  else {  // either not a category hint or not ghosted and text available
    el.innerHTML = text
    el.style.display = ""
    setTimeout("hideHint()",5000)   // turn off after 5 sec
    }
}

function hideHint()
{
  running = '0'
  if (timer) clearTimeout(timer)
  setTimeout("$('hint').style.display = 'none' ",1000)   // wait 1 sec, then turn off
}  

function dayUse(minDays,daily)
{
$('user_agreement').innerHTML = "User Agreement:  Your credit card will be pre-authorized when you sign up, but your card "
    + "will not be charged until the end of your 24-hour free trial.  If you cancel your account before then, "
    + "no charge will be made.  Thereafter, each non-refundable purchase of at least $" + minDays * daily + " buys at least "
    + minDays + " 24-hour periods of unlimited use with as much time as you like between days of use."
$('signup_button').style.visibility = "visible"
$('days_to_buy').style.display = ""
$('charge_line').style.display = ""
$('signup_button_text').innerHTML = "Sign Up"
}

function monthlySubscription()
{
$('user_agreement').innerHTML = "Subscription Agreement:  You will be charged $19.95 when you sign up, and $24.95 every month "
    + "thereafter unless and until you cancel your subscription or Aerulean gives you notice of a change in terms. Your "
    + "subscription is month-to-month. No refunds will be issued, but no further charges will be made after you cancel. "
    + "Thus, if you cancel within the first month, you will not be charge more than your initial $19.95."
$('signup_button').style.visibility = "visible"
$('days_to_buy').style.display = "none"
$('charge_line').style.display = "none"
$('signup_button_text').innerHTML = "Subscribe"
}

function checkDays(minDays,rate)
{
  days = Math.round(Number($('user_days').value))
  if( days < minDays) { days = minDays}
  $('user_days').value = days
  $('charge').innerHTML = (days*rate).toFixed(2)
  new Effect.Highlight('charge_line', {startcolor: '#ffffdd', endcolor: '#ffffff', restorecolor: '#ffffff'})  
}
