<!-- 
/*     Check the required fields in the form
       Copyright (c) 2000 Della-Soft  Sergey Ogarkov

To use this module the form must be created with the following rules
1. The required INPUT fields must have the ID or NAME with prefix "required_"
1.1 All names of INPUT fields in *whole* document must be unique
2. The labels of required fields must have the <SPAN> container.  
3. The ID attribute of the above tag must be the same as the NAME attribute of the appropriated INPUT tag, but with the prefix "labeled_" 
4. The FORM tag must have the event handlers: onsubmit="return checkForm(this.name)" onreset="initForm(this.name)"
*/
IE=Brows.MSIE;

var reqField="required_";
var lblField="labeled_";
var NormColors = new Array();

function checkBlank(FormName) {
  ret=true;
  el=document.forms[FormName].elements;
  for (i=0; i<el.length; i++) {
    s=el[i].id; if(!s) s=el[i].name;
    if ((s.substr(0,reqField.length)==reqField) && (el[i].value.trim()=="")) {
   		errEl=eval(lblField+s.substr(reqField.length));
	    errEl.style.color="Red";
   		ret=false;
	  }
  }
  if (!ret) 
  	alert("Some required fields are empty. Please fill in the fields marked RED and try again");
  return ret;
  }

function checkForm(FormName) {
  initForm(FormName);
  return checkBlank(FormName);
  }
  
function initForm(FormName) {
	el=document.getElementsByTagName("span");
	for (i=0; i<el.length; i++) {
	  s=el[i].id;
	  if (s.substr(0,lblField.length)==lblField) {
        el[i].style.color=NormColors[i];
	    }
	  }
	}

  
function onLoadForm() {
	el=document.getElementsByTagName("span");
	for (i=0; i<el.length; i++) {
	  s=el[i].id;
	  if (s.substr(0,lblField.length)==lblField) {
        NormColors[i]=el[i].style.color;
	    }
	  }
	}

onload=onLoadForm;


// Show or hide elements with particular name
function switchFields(Field, onOff) {
  if (IE) {
	if (document.all.item(Field)) {
	  el=document.all.item(Field);
      if (onOff=="on") t="block"; else t="none";
	  // IE bug!!! if element is single, it is not a collection. Lenght does not work.
	  if (el.length) 
	    for (i=0; i<el.length; i++) el(i).style.display=t;
	  else el.style.display=t;
	  }
	}
  }
  
// Hide elements with particular name
function hideFields(Field) {
  if (IE) switchFields(Field,'off');
  }

// Uncheck Radio Field
var lockOnClick=false;

function uncheck(Field) {
  if (Field.checked) {
    Field.checked=false;
    lockOnClick=true;
	}
  }  
function allow() {
  if (lockOnClick) {
	lockOnClick=false;
    return false;
	}
  else return true;
  }  
  
// Check valid date string
function isValidDate(aDateString) {
  var s, d, dd, mm, yy;
  s=aDateString.split('/');
  dd = s[0];
  mm = s[1];
  yy = s[2];
  d=new Date(yy,mm-1,dd);
  return (mm==d.getMonth()+1) && (dd==d.getDate()) && (yy==d.getFullYear())
  }

//-->


