// test value for day entry in date
function test_date_day(val)
{
  var pattern = /^[1-9]\d{0,1}$/;

  if( val.match(pattern)==null )
  {
    return false;
  }
  
  return true;
}

// test value for year entry in date
function test_date_year(val)
{
  var pattern = /^[1-9]\d{3}$/;

  if( val.match(pattern)==null)
  {
    return false;
  }
  return true;
}

// test number (maximum length is 32 digits)
function test_number(val)
{
  var pattern = /^\d{1,32}$/;

  if( val.match(pattern)==null)
  {
    return false;
  }
  return true;
}

// test email - approximate
function test_email(val)
{
  var pattern =  /.*@.*\..*/;

  if( val.match(pattern)==null)
  {
    return false;
  }
  return true;
}

function test_phone_number(val) {
  var pattern = /[^0-9, ,-]/;

  if( val.match(pattern)) {
    return false;
  }
  return true;
}

function test_radiobutton(rd) {
	pass = false;
	for (i=rd.length-1; i > -1; i--) {		
		if (rd[i].checked == true) {
			pass = true;			
			break;			
		}
	}
	return pass;
}

function test_selectbox(sb) {
	if (sb.options[sb.selectedIndex].value == '') {
		return false;
	}
	return true;
}

function test_checkbox(cb) {
	pass = false;
	
	if (cb.length) {
		for (i=cb.length-1; i > -1; i--) {		
			if (cb[i].checked == true) {
				pass = true;			
				break;			
			}
		}
	} else if (cb.checked == true) {
		pass = true;			
	}
	return pass;
}

function get_myelement(obj) {
  if(document.getElementById){ //DOM
    css = document.getElementById(obj).style;
  } else {
    if(document.all){// IE
    	css = document.all[obj].style;
    }
    if(document.layers){//NS
      css = document.layers[obj];
    }
  }
   return css;
}

function iswaytooYoung(thisform) {  
  byear = thisform.year.options[thisform.year.selectedIndex].value;
  bmonth = thisform.month.options[thisform.month.selectedIndex].value;
  bday = thisform.day.options[thisform.day.selectedIndex].value;
  under18 = false;  
  var myDate=new Date()
  
  if(byear != "" && bmonth != "" && bday != "") {
    if((myDate.getFullYear() -byear) < 18) {
      under18 = true;
    }
    else { 
      if((myDate.getFullYear() -byear) == 18 ) {
        if(myDate.getMonth() < bmonth ) {
          under18 = true;
        }
        else {
          if(myDate.getMonth() == bmonth ) {
            if(myDate.getDate() < bday ) {
              under18 = true;
            }
          }
        }
      }
    }
  }  
  return under18;
}

function get_radiobutton_value(rd) {
	pass = false;
	for (i=rd.length-1; i > -1; i--) {		
		if (rd[i].checked == true) {
			return rd[i].value			
		}
	}	
}
