// 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 get_radiobutton(rd) {
	for (i=rd.length-1; i > -1; i--) {		
		if (rd[i].checked == true) {		
			return rd[i].value;
			break;			
		}
	}
	return false;
}

function test_selectbox(sb) {   
	if (sb.options[sb.selectedIndex].value == '' ) {
		return false;
	}
	return true;
}

function test_checkbox(cb) {
	pass = false;
    if (!cb.length) {
        if (cb.checked == true) {
            pass = true;		
        }
    } else { 
    	for (i=cb.length-1; i > -1; i--) {		
    		if (cb[i].checked == true) {
    			pass = true;			
    			break;			
    		}
    	}
    }
	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 get_radiobutton_value(rd) {
	pass = false;
	for (i=rd.length-1; i > -1; i--) {		
		if (rd[i].checked == true) {
			return rd[i].value			
		}
	}	
}

function get_selectbox_value(sb) {
	return sb.options[sb.selectedIndex].value;
}

function get_checkbox_value(cb) {
	for (i=cb.length-1; i > -1; i--) {
		if (cb[i].checked == true) {
			return cb[i].value;
			break;
		}
	}
	return false;
}

function get_checkbox_status(cb, val) {
	for (i=cb.length-1; i > -1; i--) {
		if (cb[i].checked == true && cb[i].value == val) {
			return true;
			break;
		}
	}
	return false;
}

function test_date(y,m,d) { 
	
	if (m.charAt(0) == "0") { 
		m = parseInt(m.charAt(1)) - 1; 
	} else { 
		m = parseInt(m)-1; 
	} 
	
	if (d.charAt(0) == "0") { 
		d = parseInt(d.charAt(1)); 
	} 
	
	var check = new Date(); 
	check.setFullYear(y,m,d); 
	
	mytest = check.getFullYear() + "-" + check.getMonth()+ "-" + check.getDate(); 
	mydate = y+"-"+ m+"-"+d; 
	
	if (mydate != mytest) { 
		return false; 
	} 
	return true; 
} 
