function ValidateDate(el,datepart,onenter,setdefvalue)
{
if (datepart == 'd') {
   defvalue = setdefvalue;
   maxlength = 2;
}
if (datepart == 'm') {
   defvalue = setdefvalue;
   maxlength = 2;
}
if (datepart == 'y') {
   defvalue = setdefvalue;
   maxlength = 4;
}

//correct values
if ((!onenter) && (datepart == 'y') && (parseInt(el.value) <= 99)) {
   el.value='19' + el.value;
}

if (isNaN(parseInt(el.value))) {
   if (onenter) {
   el.value = '';
   } else {
   el.value = defvalue;
   }
   el.maxlength = maxlength;
} else {
   if (el.value != parseInt(el.value)) {
   el.value=parseInt(el.value);
   }
}
//validate
var danes = new Date();
if (!onenter) {
if (datepart == 'd') {
   if (!((parseInt(el.value) <= 32) && (parseInt(el.value) > 0))) {
      return false;
   }
}
if (datepart == 'm') {
   if (!((parseInt(el.value) <= 12) && (parseInt(el.value) > 0))) {
      return false;
   }
}
if (datepart == 'y') {
   if (!((parseInt(el.value) <= parseInt(danes.getFullYear())) && (parseInt(el.value) > 0))) {
      return false;
   }
}
}

}

function FormBlockFindTR(el)
{
trel = null;
tmpel = el;
imaxparentnodes = 10;
iparentnode = 1;
found = false;
while (iparentnode<=imaxparentnodes) {
  if (tmpel == null) {
     break;
  } else {
    if (tmpel.tagName == 'TR') {
       found = true;
       break;
    }
  }
  tmpel = tmpel.parentNode;
  iparentnode = iparentnode + 1;
}
if (found) {
  trel = tmpel;
}
return trel;
}

function FormBlockGetIsValidEl(trel)
{
if (trel.tagName != 'TR') {
   trel = FormBlockFindTR(trel);
}
inputel = null;
inputels = trel.getElementsByTagName('input');
if (inputels != null) {
   //inputel = inputels.getElementById('FormBlockIsValid');
   for (iinput = 0; iinput < inputels.length; iinput++) {
       if (inputels[iinput].id == 'FormBlockIsValid') {
          inputel = inputels[iinput];
       }
   }
}
return inputel;
}

function FormBlockGetIsValid(trel)
{
valid = true;
inputel = FormBlockGetIsValidEl(trel);
if (inputel != null) {
   if (inputel.value == 'true') {
      valid = true;
   } else {
      valid = false;
   }
}
return valid;
}

function FormBlockGetSetIsValid(trel, valid)
{
inputel = FormBlockGetIsValidEl(trel);
if (inputel != null) {
   inputel.value = valid;
}
}

function FormBlockFocus(el)
{
trel = FormBlockFindTR(el);
if (trel != null) {
   trel.className = 'active';
}
}

function FormBlockBlur(el)
{
trel = FormBlockFindTR(el);
valid = FormBlockGetIsValid(trel);
if (trel != null) {
   if (valid) {
   trel.className = '';
   } else {
   trel.className = 'trvalidateerror';
   }
}
}

function FormBlockSelectFirstInput(el)
{
inputels = el.getElementsByTagName('input');
if (inputels != null) {
   inputel = inputels[0];
   inputel.focus();
}
}

function FormBlockInit_SetEventsToEl(el,setonclick)
{
if ((el.onfocus == null)) {
el.onfocus = function() { FormBlockFocus(this); };
}
if ((el.onblur == null)) {
el.onblur = function() { FormBlockBlur(this); };
}
if (setonclick) {
el.onclick = function() { FormBlockSelectFirstInput(this); };
}
}

function FormBlockInit(tableid)
{
tableel = document.getElementById(tableid);
if (tableel != null) {
   for (irow = 0; irow < tableel.rows.length; irow++) {
       trel = tableel.rows[irow];
       FormBlockInit_SetEventsToEl(trel,false);
       trcells = trel.cells;
       for (icell = 0; icell < trcells.length; icell++) {
         trcell = trcells[icell];
         hasinputfields = false;
         inputels = trcell.getElementsByTagName('input');
         if (inputels != null) {
            for (iinput = 0; iinput < inputels.length; iinput++) {
              inputel = inputels[iinput];
              if (inputel.type != 'hidden') {
                 hasinputfields = true;
                 FormBlockInit_SetEventsToEl(inputel,false);
              }
            }
         }
         selectels = trcell.getElementsByTagName('select');
         if (selectels != null) {
            for (iinput = 0; iinput < selectels.length; iinput++) {
              selectel = selectels[iinput];
              hasinputfields = true;
              FormBlockInit_SetEventsToEl(selectel,false);
            }
         }
         if (hasinputfields) {
         FormBlockInit_SetEventsToEl(trcell,false);
         } else {
         FormBlockInit_SetEventsToEl(trcell,true);
         }
       }
   }
}
}

function ValidateField(el, validationtype, minvalue, maxvalue)
{
minvalue = parseInt(minvalue);
if (isNaN(minvalue)) {
minvalue = 1;
}
maxvalue = parseInt(maxvalue);
if (isNaN(maxvalue)) {
maxvalue = Math.pow(10000,10000);
}

if ((validationtype == 'text') || (validationtype == '')) {
   if ((el.value.length >= minvalue) && (el.value.length <= maxvalue)) {
     return true;
   } else {
     return false;
   }
}
if ((validationtype == 'email')) {
   if ((el.value.length >= minvalue) && (el.value.length <= maxvalue)) {
     if ((el.value.indexOf("@") > 0) && (el.value.indexOf("@") < el.value.length-1)) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
}
if ((validationtype == 'number')) {
   intval = parseInt(el.value);
   if (isNaN(intval)) {
     return false;
   } else {
     if ((intval >= minvalue) && (intval <= maxvalue)) {
       return true;
     } else {
       return false;
     }
   }
}
if ((validationtype == 'select')) {
   if ((el.value == '')) {
   return false;
   } else {
   return true;
   }
}

}

function ValidateAllFields(mailelid, alertmessage)
{
idvalid = true;
mainel = document.getElementById(mailelid);
inputels2 = mainel.getElementsByTagName('input');
if (inputels2 != null) {
   for (iinput2 = 0; iinput2 < inputels2.length; iinput2++) {
     inputel2 = inputels2[iinput2];
     FormBlockBlur(inputel2);
     if (!FormBlockGetIsValid(inputel2)) {
        idvalid = false;
        break;
     }
   }
}
if (!idvalid) {
   alert(alertmessage);
}
return idvalid;
}