function dateUpdate(cal) {
    var date = cal.date;
    var time = date.getTime()
    // use the _other_ field
    var field = document.getElementById(cal.params.displayDiv);
    if (field != 'null' && field != null)
    {
        var date2 = new Date(time);
        field.innerHTML = "<b>"+date2.print("%b %d, %Y")+"</b>";
    }
    else
    {
      var cells=document.getElementsByTagName('span');
      alert(cells.length);
      for (i=0;i<cells.length;i++)
      {
        alert(cells[i].id+":"+cells[i].innerHTML);
      }
    }
}

function startVenuesDropDown(obj)
{
  if (obj.value=='Venue (City, St)')
    obj.value='';
}

function clearFilters()
{
  document.filterForm.agelimitFilter.selectedIndex=0;
  document.filterForm.startDateFilter.selectedIndex=0;
  document.filterForm.endDateFilter.selectedIndex=1;
  document.filterForm.priceFilter.selectedIndex=0;
  document.filterForm.locationFilter.selectedIndex=0;
  document.filterForm.URL_STATE.selectedIndex=0;
  document.filterForm.tourNameFilter.selectedIndex=0;
  document.filterForm.bandsFilter.value='';
  document.filterForm.submit();
}

function synchAllInput(obj, prefix)
{
  var text = document.getElementById(obj).value;
  var arr = document.getElementsByTagName('input');
  for(var i=0; i < arr.length;i++)
  {
    if (arr[i].id.indexOf(prefix)>=0 )
    {
      arr[i].value=text;
    }
  }
}


function toggleAddEnable(checkbox,count)
{
  var theRow = getElementFromID('eventDiv'+count);
  var cells = theRow.getElementsByTagName('td');
  
  for (i=0;i<cells.length;i++)
  {
    cells[i].className=((checkbox.checked)?"innerTdBlah":"eventstabledefaultone");  
  }
  cells = theRow.getElementsByTagName('tr');
  for (i=0;i<cells.length;i++)
  {
    cells[i].className=((checkbox.checked)?"innerTrBlah":"eventstabledefaultone");  
  }
  cells = theRow.getElementsByTagName('table');
  for (i=0;i<cells.length;i++)
  {
    cells[i].className=((checkbox.checked)?"innerTableBlah":"eventstabledefaultone"); 
  }
  
  cells = theRow.getElementsByTagName('input');
  for (i=0;i<cells.length;i++)
  {
    if (cells[i].id != checkbox.id)
      cells[i].disabled=!(checkbox.checked);  
  }
  cells = theRow.getElementsByTagName('select');
  for (i=0;i<cells.length;i++)
  {
      cells[i].disabled=!(checkbox.checked);  
  }
}
function setStateDropDown(state, myText)
{
  var ins = myText.lastIndexOf(')');
  if (ins>0)
  {
    myText = myText.substring(ins-3,ins);
  }
  Select_Value_Set(state, myText.replace(/^\s+|\s+$/g, ''));
}



function checkForm(user)
{
  var arr = document.getElementsByTagName('input');
  var alertsMessage = "";
  for(var i=0; i < arr.length;i++)
  {
    if (arr[i].id.indexOf('date[')>=0 && (arr[i].checked || arr[i].type=='hidden'))
    {
      var obj;
      var id =parseInt(arr[i].value);
      if (isDefined('date'+arr[i].value))
      {
        obj = document.getElementById('date'+arr[i].value);

        if (obj.value == '')
        {
          alertsMessage += "Event "+ (id+1)+") forgot date\n";
        }
      }
      obj = document.getElementById('location'+arr[i].value);
      if (obj.value == '' || obj.value == 'Venue (City, St)')
      {
        alertsMessage += "Event "+ (id+1)+") forgot location\n";
      }
      obj = document.getElementById('bandName'+arr[i].value);
      
      if (obj.value == '')
      {
        alertsMessage += "Event "+ (id+1)+") forgot bands\n";
      }
    }
  }
  if (!user)
  {
	  if (document.getElementById('blahspoom').value == '')
	  {
	    alertsMessage += "Spam Blocker not set";
	  }
	  else if (document.getElementById('blahspoom').value != '4')
	  {
	    alertsMessage += "Spam Blocker not correct ";   
	  }
	}
  if (alertsMessage != "")
  {
    alert (alertsMessage);
    return false;
  }
  return true;
  //check the spammers
  //check the dates
  //check the locations
  //check the bands
  return false;
}

function eventDel(id)
{
  var anc = getElementFromID("eDA"+id); 
  if (anc.innerHTML == 'del' && confirm('Are you sure?'))
  {
    newNoteValue = "type=eventdel&action=del&id="+id;
    if (!isObject(http))
    {
      document.location = "/events.php?"+newNoteValue;
    }
    else if (!ajaxIsBusy ) 
      {
          http.open("GET", "/processAJAX.php?" + newNoteValue+"&nc="+Math.floor(Math.random()*123245), true);
          ajaxIsBusy = anc;
          http.onreadystatechange = handleEventDelToggleResponse;
          ajaxIsBusy.style.color="red";
          http.send(null);
    } 
  }
}

function checkBands(bandNameField)
{
  var anc = getElementFromID(bandNameField);  
    newNoteValue = "type=checkbands&action=check&bands="+anc.value;
    if (!isObject(http))
    {
     
    }
    else if (!ajaxIsBusy ) 
      {
          http.open("GET", "/processAJAX.php?" + newNoteValue+"&nc="+Math.floor(Math.random()*123245), true);
          ajaxIsBusy = anc;
          http.onreadystatechange = handleCheckBandsResponse;
          ajaxIsBusy.style.color="red";
          http.send(null);
    } 
}

function handleCheckBandsResponse()
{ 
 if (http.readyState == 4) {
    if (http.status == 200) {
      ajaxIsBusy.style.color="black";
    } else {
      alert("Unable to update note: " + http.status);
    }   
  ajaxIsBusy.value = http.responseText;
    ajaxIsBusy = 0;
 }
}

function toggleEvent(id)
{
  var anc = getElementFromID("ePMA"+id);  
  var newNoteValue = anc.innerHTML;
  if (newNoteValue == '+')
    newNoteValue = "type=event&action=add&id="+id;
  else
    newNoteValue = "type=event&action=del&id="+id;
  if (!isObject(http))
  {
    document.location = "/events.php?"+newNoteValue;
  }
  else if (!ajaxIsBusy) 
    {
        http.open("GET", "/processAJAX.php?" + newNoteValue+"&nc="+Math.floor(Math.random()*123245), true);
        ajaxIsBusy = anc;
        http.onreadystatechange = handleEventToggleResponse;
        ajaxIsBusy.style.color="red";
        http.send(null);
  } 
}
function handleEventDelToggleResponse()
{ 
 if (http.readyState == 4) {
    if (http.status == 200) {
      ajaxIsBusy.style.color="white";
    } else {
      alert("Unable to update note: " + http.status);
    }   
    var result = http.responseText;
    if (result.indexOf('un'+'auth'+'ori'+'zed')>0)
    ajaxIsBusy.innerHTML= 'failed';
    else
    ajaxIsBusy.innerHTML= 'deleted';
    ajaxIsBusy = 0;
 }
}

function handleEventToggleResponse()
{ 
 if (http.readyState == 4) {
    if (http.status == 200) {
      ajaxIsBusy.style.color="white";
    } else {
      alert("Unable to update note: " + http.status);
    }
    if (ajaxIsBusy.innerHTML == '+')
    { 
      ajaxIsBusy.innerHTML = '-';
    }
    else
    {
      ajaxIsBusy.innerHTML= '+';
    }
    ajaxIsBusy = 0;
 }
}


