
// returns <true> if strValue is a valid e-mail address
function isEmail(strValue) {
return  strValue.match(/^(\w+\.)*(\w)+@((\w+\.)+\w{2,3})/);
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getRadioFirstCtrlId(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
        {
		if(radioObj.checked)
			return radioObj.id;
		else
			return "";
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].id != undefined) {
			return radioObj[i].id;
		}
	}
	var radioItem = document.getElementByName(radioObj.name)[0];
	if (radioItem == undefined)
   	  return "";
   	else
   	  return(radioItem.id);
}

// returns error message if incorrect / empty
// tab - array of records for each field:
// 0 - control id
// 1 - control caption
// 2 - control type ( V - value, D - dropdown, R - radio )
function verifyReqCtrls(form, tab, verbose) {
  var i, errtext, ctrl_id;

  errtext = "";

  for (i=0;i<tab.length;i++) {
    if (tab[i][2] == "D") {
  // drop down (0 = index of default item)
      with (tab[i][0])
      {
       if (value==null || selectedIndex == 0) {
          errtext=errtext+" - "+tab[i][1]+"\n";
          if (ctrl_id == null)
            ctrl_id = tab[i][0].id;
       } // if control empty
      } // with
    } // if drop down
    else
    if (tab[i][2] == "R") {
  // radio
      value = getCheckedValue(tab[i][0]);
      if (value=="") {
         errtext=errtext+" - "+tab[i][1]+"\n";
         if (ctrl_id == null) {
           ctrl_id = getRadioFirstCtrlId(tab[i][0]);
           if (ctrl_id == "")
             ctrl_id = null;
         }
      } // if control empty
    } // if drop down
    else
  // other controls
    if (tab[i][0].value== null || tab[i][0].value=="" || tab[i][0].value=="-1") {
      errtext=errtext+" - "+tab[i][1]+"\n";
      if (ctrl_id == null)
        ctrl_id = tab[i][0].id;
    } // if control empty
  } // for i

  if (ctrl_id != null) {
    ctrl2 = document.getElementById(ctrl_id);

    cnt = form.elements.length;

    for(var i=0;i<cnt;i++) {
      if (form.elements[i].id == ctrl_id) {
        form.elements[i].focus();
        break;
      } // if control found
    } // for i
  } // if ctrl_id

  if (verbose && errtext!="") {
    errtext="Brak następujących danych:\n"+errtext;
    alert(errtext);
  }
  return errtext;
} // function

function focusControl(aName) {
  document.getElementById(aName).focus();
}


