function plibForm_isEmpty(str) {
  var emptyChars=" \r\n";
  var isEmpty=true;
  for (var i=0;i<=(str.length-1);i++) {
	  isEmpty=isEmpty && (emptyChars.indexOf(str.charAt(i))>-1);
  }
  return(isEmpty);
}

function plibForm_enterSubmit(event,frm) {
  if ((window.event&&window.event.keyCode==13)||
	  (event&&event.which==13)) {
    frm.submit();
  } else
    return true;
}

function plibForm_text(parent) {
  this.parent=parent;
  this.id;
  this.obj=null;
  this.obligated="";
  
  this.setObj=function() {
    this.obj=document.getElementById(this.id);
  }

  this.check=function() {
	if (this.obligated!="")	{
      if (plibForm_isEmpty(this.obj.value)) return(this.obligated); else
                                            return(false);
	} else return(false);
  }
}

function plibForm_radioGroup(parent) {
  this.parent=parent;
  this.id;
  this.objs=null;
  this.obligated="";
  
  this.setObj=function() {
    this.objs=document.getElementsByName(this.id);
  }

  this.check=function() {
	if (this.obligated!="")	{
      var checked=false;
	  for (var i=0;i<this.objs.length;i++) checked=checked||this.objs[i].checked;
      if (!checked) return(this.obligated); else
                    return(false);
	} else return(false);
  }
}

function plibForm_htmledit(parent) {
  this.parent=parent;
  this.id;
  this.obj=null;
  this.obligated="";
  this.editor=null;

  this.body=function() {
    this.editor.generate();
  }

  this.setObj=function() {
    this.obj=document.getElementById(this.id);
  }

  this.check=function() {
	this.obj.value=this.editor.getHTML();
	if (this.obligated!="")	{
      if (plibForm_isEmpty(this.obj.value)) return(this.obligated); else
                                            return(false);
	} else return(false);
  }

}

function plibForm_date(parent) {
  this.parent=parent;
  this.id;
  this.obj=null;
  this.objDay=null;
  this.objMonth=null;
  this.objYear=null;
  this.obligated="";
  this.minYear;
  this.maxYear;

  this.body=function() {
    var html="<input type='hidden' id='"+this.id+"' name='"+this.id+"' value=''/>";
    html+="<select id='"+this.id+"_day' name='"+this.id+"_day'><option value=''></option>";
	for (var i=1;i<=31;i++) html+="<option value='"+i+"'>"+i+"</option>";
	html+="</select>";
    html+="<select id='"+this.id+"_month' name='"+this.id+"_month'><option value=''></option>";
	for (var i=1;i<=12;i++) html+="<option value='"+i+"'>"+lang_month[i-1]+"</option>";
	html+="</select>";
    html+="<select id='"+this.id+"_year' name='"+this.id+"_year'><option value=''></option>";
	for (var i=this.minYear;i<=this.maxYear;i++) html+="<option value='"+i+"'>"+i+"</option>";
	html+="</select>";
	document.write(html);
  }

  this.setObj=function() {
    this.obj=document.getElementById(this.id);
    this.objDay=document.getElementById(this.id+"_day");
    this.objMonth=document.getElementById(this.id+"_month");
    this.objYear=document.getElementById(this.id+"_year");
  }

  this.check=function() {
    this.obj.value=this.objYear.value+"-"+this.objMonth.value+"-"+this.objDay.value;
	if (this.obligated!="")	{
      if (this.objDay.value==""||this.objMonth.value==""||this.objYear.value=="")
	    return(this.obligated);
	  else
        return(false);
	} else return(false);
  }

}

function plibForm_time(parent) {
  this.parent=parent;
  this.id;
  this.obj=null;
  this.objHour=null;
  this.objMinute=null;
  this.obligated="";
  this.stepMinute;

  this.body=function() {
    var html="<input type='hidden' id='"+this.id+"' name='"+this.id+"' value=''/>";
    html+="<select id='"+this.id+"_hour' name='"+this.id+"_hour'><option value=''></option>";
	for (var i=0;i<=23;i++) html+="<option value='"+i+"'>"+i+"</option>";
	html+="</select>:";
    html+="<select id='"+this.id+"_minute' name='"+this.id+"_minute'><option value=''></option>";
	for (var i=0;i<=59;i++) if (i%this.stepMinute==0) html+="<option value='"+i+"'>"+i+"</option>";
	html+="</select>";
	document.write(html);
  }

  this.setObj=function() {
    this.obj=document.getElementById(this.id);
    this.objHour=document.getElementById(this.id+"_hour");
    this.objMinute=document.getElementById(this.id+"_minute");
  }

  this.check=function() {
    this.obj.value=this.objHour.value+":"+this.objMinute.value;
	if (this.obligated!="")	{
      if (this.objHour.value==""||this.objMinute.value=="")
	    return(this.obligated);
	  else
        return(false);
	} else return(false);
  }

}

function plibForm() {
  this.id;
  this.obj=null;
  this.items=new Array();
  this.itemsCount=0;

  this.getItemById=function(id) {
    for (k in this.items)
	  if (this.items[k].id==id) return(this.items[k]);
  }

  this.body=function() {
	this.obj=document.getElementById(this.id);
    for (k in this.items) this.items[k].setObj();
  }

  this.submit=function() {
    for (k in this.items) {
	  if (e=this.items[k].check()) {
	    alert(e);
		return(false);
	  }
	}
	this.obj.submit();
	return(true);
  }
}
