function queryDates(start_date,end_date) {
  if (start_date=="" || end_date==""){
    return;
  }

  // parse a date in yyyy-mm-dd format
  function parseDate(input) {
    var parts = input.match(/(\d+)/g);
    return new Date(parts[0], parts[1]-1, parts[2]); // months are 0-based
  }

  if (parseDate(end_date) < parseDate(start_date)) {
    document.getElementById("txtHint").innerHTML="<div class=\"ui-widget\"> <div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\"> <p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: .3em;\"></span> <strong>Alert:</strong>End date is before start date!</p> </div> </div>";
  } else {
    document.getElementById("txtHint").innerHTML="";
  }
}

// prints an alert in the given div ID if the field is empty
function alertIfEmpty(divid,value){
  var val = '';
  val = value;
  if (val.match(/^\s*$/)) {
    document.getElementById(divid).innerHTML="<div class=\"ui-widget\"> <div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\"> <p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: .3em;\"></span> <strong>Alert:</strong>&nbsp;Field must not be empty.</p> </div> </div>";
  } else {
    document.getElementById(divid).innerHTML="<div class=\"ui-widget\"> <div class=\"ui-state-highlight ui-corner-all\" style=\"padding: 0 .7em;\"> <p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: .3em;\"></span> <strong>Info:</strong>&nbsp;OK!</p> </div> </div>";
  }
}

function DisplayFormValues(the_id,the_div)
{
  var str = '';
  var elem = document.getElementById(the_id).elements;

  //var elem = document.getElementById('add_child').elements;
  for(var i = 0; i < elem.length; i++)
  {
    str += "<b>Type:</b>" + elem[i].type + "&nbsp&nbsp";
    str += "<b>Name:</b>" + elem[i].name + "&nbsp;&nbsp;";
    str += "<b>Value:</b><i>" + elem[i].value + "</i>&nbsp;&nbsp;";
    str += "<BR>";
  } 
  document.getElementById(the_div).innerHTML = str;
}

function verifyFormNotEmpty(the_id)
{
  var elem = document.getElementById(the_id).elements;
  for(var i = 0; i < elem.length; i++)
  {
    if ((elem[i].type != 'submit') && (elem[i].value.match(/^\s*$/))) //TODO: what about reset input?
    {
      alert("All fields of this form must be filled out.");
      elem[i].focus();
      return false;
    }
  }
  return true;
}

function queryChildInDB(the_div,child_name) {

  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      if (xmlhttp.responseText.match(/true/g)) 
      {
        document.add_child.sub.disabled=false;
      } else {
        document.add_child.sub.disabled=true;
      }
      document.getElementById(the_div).innerHTML=xmlhttp.responseText.replace(/true|false/g,'');
    }
  }
  xmlhttp.open("GET","query-child.php?child_name="+child_name,true);
  xmlhttp.send();
}


