function dump_props(obj, obj_name)
{
   var result = "";
   for (var i in obj)
   {
      result += obj_name + "." + i + " = " + obj[i] + "<BR>";
   }
   result += "<HR>";
   return result
}

function e(id)
{
   return document.getElementById(id);
}

function gv(id)
{
   if (e(id)) return e(id).value;
}

function sv(id, value)
{
   if (e(id)) e(id).value = value;
}

function gc(id)
{
   if (e(id)) return e(id).className;
}

function sc(id, cl)
{
   if (e(id)) e(id).className = cl;
}

function gvradio(radioobj)
{
   for (var i = 0; i<radioobj.length; i++)
     if (radioobj[i].checked) return radioobj[i].value;
}

function getOption(id)
{
   var ops = e(id).options;
   var value = gv(id);
   for (i=0; i<ops.length; i++)
     if (ops[i].value == value) return ops[i].innerHTML;
}

function setOption(id, val)
{
   var ops = e(id).options;
   var value = gv(id);
   for (i=0; i<ops.length; i++)
     if (ops[i].value == value)
       {ops[i].innerHTML = val; break;}
}

function delOption(id)
{
   var el = e(id);
   el.removeChild(el.childNodes[el.selectedIndex]);
}

function addOption(id, option)
{
   if (e(id)) e(id).appendChild(option);
}

function moveOptions(id1, id2)
{
   var options = e(id1).childNodes;
   var i = 0;
   while(i < options.length)
   {
      if (options[i].selected) e(id2).appendChild(options[i]);
      else i++;
   }
}

function getDisplay(id)
{
   if (e(id)) return e(id).style.display;
}

function isShow(id)
{
   return (getDisplay(id) != 'none');
}

function hide(id)
{
   if (e(id)) e(id).style.display = "none";
}

function show(id)
{
   if (e(id)) e(id).style.display = "block";
}

function ShowHide(id)
{
   var obj = e(id);
   if (obj.style.display == "none") obj.style.display = "block";
   else obj.style.display = "none";
}

var currentBodyCursor;

function setCursor(obj, cursor)
{
   if (obj) obj.style.cursor = cursor;
}

function getCursor(obj)
{
   if (obj) return obj.style.cursor;
}

function pushCursor()
{
   currentBodyCursor = getCursor();
}

function popCursor()
{
   setCursor(currentBodyCursor);
}

function checkNumberInt(str)
{
   var re = /^[\d]*$/;
   return re.test(str);
}

function checkNumberFloat(str)
{
   var re = /^[\d]*[\.,]?[\d]*$/;
   return re.test(str);
}

function checkEmail(str)
{
   var re = /[a-z\d-_\.]+@[a-z\d-_]+(\.[a-z\d_-]+)/i;
   return re.test(str);
}

function checkDate(str)
{
   var re = /^[\d]{1,2}\/[\d]{1,2}\/[\d]{4}$/;
   return re.test(str);
}

function ins(id, data)
{
   if (e(id)) e(id).innerHTML = data;
}

function validLocation(countryid, stateid, cityid)
{
   if (gv(countryid) == 0)
   {
      alert("Select country...");
      e(countryid).focus();
      return false;
   }
   if (gv(countryid) == 204)
   {
      if (gv(stateid) == 0)
      {
         alert("Select State...");
         e(stateid).focus();
         return false;
      }
      if(gv(cityid) == 0 || gv(cityid) == -1)
      {
         alert("Select City...");
         e(cityid).focus();
         return false;
      }
   }
   else if(gv(cityid) == 0 || gv(cityid) == -1)
   {
      alert("Select City...");
      e(cityid).focus();
      return false;
   }
   return true;
}

function validDateFromTo(fromid, toid)
{
   if (!checkDate(gv(fromid)))
   {
      alert("Date 'from' is invalid");
      sv(fromid, '');
      e(fromid).focus();
      return false;
   }
   if (!checkDate(gv(toid)))
   {
      alert("Date 'to' is invalid");
      sv(toid, '');
      e(toid).focus();
      return false;
   }
   return true;
}

function validFind(id)
{
   if (!validLocation('sel_countryid_'+id, 'sel_stateid_'+id, 'sel_cityid_'+id) || !validDateFromTo('from_'+id, 'to_'+id)) return false;
   return true;
}

function formFindSubmit()
{
   if (validFind('find')) e('form_find').submit();
}

function validImageFile(id)
{
   var path = e(id).value;
   if (!path) return true;
   var ext = path.lastIndexOf(".");
   if (ext == -1) return false;
   ext = path.substring(ext+1).toLowerCase();
   var arr = ['jpeg', 'jpg', 'gif', 'png'];
   for (var i=0; i<arr.length; i++)
     if (ext == arr[i]) return true;
   return false;
}

function isEmpty(id)
{
   if (!id || !e(id)) return true;
   var type = e(id).type;
   switch (type)
   {
      case 'text':
      case 'select-multiple':
        return (gv(id) == '');
      case 'select-one':
        return (gv(id) == '' || gv(id) == 0)
      case 'radio':
        return !e(id).checked;
      case 'hidden':
        if (id.substring(0, 9) == 'countryid' || id.substring(0, 7) == 'stateid' || id.substring(0, 6) == 'cityid')
        return (gv(id) == '0');
      default:
        return true;
   }
}

function isEmptyForm(formid)
{
   var flg = true;
   var elements = document.forms[formid];
   for (i=0; i<elements.length; i++)
     flg &= isEmpty(elements[i].id);
   return flg;
}

function setValidDate(obj, min, max, format)
{
   if (!obj.value) return;
   var farr = format.split("/");
   var d = obj.value.split("/");
   for (var i=0; i<3; i++) d[farr[i]] = d[i];
   dg = new Date(d['y'], d['m'], d['d']);
   if (min)
   {
      d = min.split("/");
      for (var i=0; i<3; i++) d[farr[i]] = d[i];
      dm = new Date(d['y'], d['m'], d['d']);
      if (dg.valueOf() < dm.valueOf()) obj.value = min;
   }
   if (max)
   {
      d = max.split("/");
      for (var i=0; i<3; i++) d[farr[i]] = d[i];
      dm = new Date(d['y'], d['m'], d['d']);
      if (dg.valueOf() > dm.valueOf()) obj.value = max;
   }
}

function formatDate(date, informat, outformat)
{
   if (!date) return;
   var inarr = informat.split("/");
   var outarr = outformat.split("/");
   var datearr = date.toString().split("/");
   var d = "";
   for (var i=0; i<3; i++) datearr[inarr[i]] = datearr[i];
   for (var i=0; i<3; i++) d += datearr[outarr[i]]+"/";
   return d.substr(0, d.length-1);
}

function cmpDate(from, to, format)
{
   var dfrom = new Date(formatDate(from, format, 'm/d/y'));
   var dto = new Date(formatDate(to, format, 'm/d/y'));
   if (dfrom.valueOf() > dto.valueOf()) return -1;
   else if (dfrom.valueOf() < dto.valueOf()) return 1;
   else return 0;
}