//<SCRIPT language="JavaScript1.2">
// -----------------------------------------------------------
// -- Form support functions
// -----------------------------------------------------------
function date_change(day, month, year, date) {
      date.value = year[year.selectedIndex].value + "-" + month[month.selectedIndex].value + "-" + day[day.selectedIndex].value;
}
function mdate_change(day, month, year, date) {
      date.value = year[year.selectedIndex].value + "-" + month[month.selectedIndex].value + "-" + day.value;
}

// -----------------------------------------------------------
// -- Form check functions
// -----------------------------------------------------------
function check_email(form_val) {
	email_rx = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if(email_rx.test(form_val)) { return 1; }
	else { return 0; }
}
function check_halfnumber(form_val) {
	real_rx = /^-?[0-9]+\.?[05]?$/;
	if(real_rx.test(form_val) == true) { return 1; }
	else { return 0; }
}
function check_real(form_val) {
	real_rx = /^-?\d+\.\d+$|^-?\d+$/;
	if(real_rx.test(form_val) == true) { return 1; }
	else { return 0; }
}
function check_blank(form_val) {
	blank_rx = /^[\s]*$/;
	if(blank_rx.test(form_val)) { return 1; }
	else { return 0; }
}
function check_percent(form_val) {
	digit_rx = /^\d\d?\d?$/;
	if(digit_rx.test(form_val) ){
		val = parseInt(form_val);
		if(val > 100 || val < 0) { return 0; }
		else { return 1; }
	} else { return 0; }
}
function check_money(form_val) {
	money_rx = /^-?\d+(\.\d\d?)?$/;
	if(money_rx.test(form_val) ){ return 1; }
	else { return 0; }
}
function check_int(form_val) {
	digit_rx = /^-?\d+$/;
	if(digit_rx.test(form_val) ){ return 1; }
	else { return 0; }
}
function check_alpha(form_val) {
	alpha_rx = /^[a-zA-Z]+$/;
	if(alpha_rx.test(form_val) ){ return 1; }
	else { return 0; }
}
function check_alphanumeric(form_val) {
	alphanumeric_rx = /^[a-zA-Z0-9]+$/;
	if(alphanumeric_rx.test(form_val) ){ return 1; }
	else { return 0; }
}
function check_alphanumericunderscore(form_val) {
	alphanumericunderscore_rx = /^[a-zA-Z0-9_]+$/;
	if(alphanumericunderscore_rx.test(form_val) ){ return 1; }
	else { return 0; }
}
function radiobox_select_check(form_val) {
        var return_value = 0;
        for (i=0; i < form_val.length; i++) {
                if(form_val[i].checked == true) {
                        return_value = 1;
                        break;
                }
        }
        return return_value;
}
function check_select_blank(form_sel) {
	var return_value = 0;
	blank_rx = /^[\s]*$/;
	if(blank_rx.test(form_sel.options[form_sel.selectedIndex].value)){ 
		return 1; 
	}
	return return_value;
}
// -----------------------------------------------------------
// -- 
// -----------------------------------------------------------
function check_equal(val1, val2) {
	if(val1 == val2){ return 1; }
	else { return 0; }
}
function number_positive(val1) {
	v1 = parseFloat(val1);
	if(v1 >= 0.0){ return 1; }
	else { return 0; }
}
function number_gt(val1, val2) {
	v1 = parseFloat(val1);
	v2 = parseFloat(val2);
	if(v1 > v2){ return 1; }
	else { return 0; }
}
function number_lt(val1, val2) {
	return number_gt(val2, val1);
}
function number_eq(val1, val2) {
	v1 = parseFloat(val1);
	v2 = parseFloat(val2);
	if(v1 == v2){ return 1; }
	else { return 0; }
}
function start_with_alpha(form_val) {
	alpha_rx = /^[a-zA-Z].*$/;
	if(alpha_rx.test(form_val)){ return 1; }
	else { return 0; }
}

// -----------------------------------------------------------
// -- Date check functions
// -----------------------------------------------------------
function getFullYear(d) {
    var y=d.getYear();
    if(y<1000) y += 1900;
    return y;
}

function blank_date(form_value) {
    if (form_value == "--" || check_blank(form_value)){
        return true;
    }
    return false;
}

function date_check(form_value) {
    if (form_value == "--" || check_blank(form_value)){
        return true;
    }
    else {
        a = form_value.split("-");
        if(a.length == 3){
            if(check_int(a[0]) && check_int(a[1]) && check_int(a[2])) {
                var d;
                day   = a[0];
                month = a[1]-1;
                year  = a[2];
                d = new Date(year, month, day);
                if(d.getDate() == day && d.getMonth() == month && getFullYear(d) == year) {
                    return true;
                }
            }
        }
        return false;
    }
}

function date_gt(form_valuea, form_valueb) {
  if(date_check(form_valuea) && date_check(form_valueb)) {
      a = form_valuea.split("-");
      b = form_valueb.split("-");
      d1 = new Date(a[2], a[1]-1, a[0]);
      d2 = new Date(b[2], b[1]-1, b[0]);
      if(d1.getTime() > d2.getTime()){
         return true;
      }
  }
  return false;
}
function date_lt(form_valuea, form_valueb) {
	return date_gt(form_valueb, form_valuea);
}

function date_future( form_value ) {
  if( check_blank( form_value ) ) return false;
  var today=new Date()
  var year=today.getYear()
  if (year < 1000) year+=1900
  var day=today.getDay()
  var month=today.getMonth()+1
  if (month<10) month="0"+month
  var daym=today.getDate()
  if (daym<10) daym="0"+daym
  var todayStr = daym+"-"+month+"-"+year;
  return date_gt(form_value, todayStr);
}

function date_past( form_value ) {
  if( check_blank( form_value ) ) return false;
  var today=new Date()
  var year=today.getYear()
  if (year < 1000) year+=1900
  var day=today.getDay()
  var month=today.getMonth()+1
  if (month<10) month="0"+month
  var daym=today.getDate()
  if (daym<10) daym="0"+daym
  var todayStr = daym+"-"+month+"-"+year;
  return date_gt(todayStr, form_value);
}

function follow_url(u, t, w, h) {
    if(t == "_self") {
        location.replace(u);
    }
    else {
        args="width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=0";
        remote=window.open(u,t,args);
        if (remote != null) {
            if (remote.opener == null) {
                remote.opener = self;
	    }
        }
    }
}
	
//</SCRIPT>
