function SC_Refs(frmName){
  this.options_refs = new Array();
  this.frmName=frmName;

  this.addRef=addRef;
  this.updateCombos=updateCombos;
  this.init=init;

  function addRef(source,dest){
    if (document.forms[this.frmName].elements && document.forms[this.frmName].elements[source] && document.forms[this.frmName].elements[dest]){
      var ref = new Array();
      ref.source=source;
      ref.dest=dest;
      this.options_refs[this.options_refs.length]=ref;
    }
  }

  function updateCombos(sel){
    //alert("input");
    var i;
    var val;
    if (sel.selectedIndex>=0){
      val=sel.options[sel.selectedIndex].value;

    } else {
      val=-1;
    }

    for (var i=0;i<this.options_refs.length;i++){
//      alert(this.options_refs[i].dest + ' + ' + sel.name);
      if (this.options_refs[i].dest==sel.name){
//        alert ("Treba updatovat "+this.options_refs[i].source+" Dest:"+sel.name);
        //saving options------------------
        var par = "combo="+this.options_refs[i].source+"&ID="+sel.form[this.options_refs[i].dest].value;
        var comb =sel.form[this.options_refs[i].source];
        var to =this.options_refs[i].source;
        var t = this;
        $.ajax({
            type        : "GET",
            url         : "/libs/ajax/combo.php",
            dataType    : "text",
            data        : par,
            async       : false,
            success     :function(msg){
//                alert ('Updatujem '+i+" [name="+to+"]");
                $("[name="+to+"]").empty();
                $("[name="+to+"]").append(msg);
                t.updateCombos(comb);
            },
            error       :function(msg){
                alert('fail');
            }
        });
      }
    }
  }

  function init(refs){
    var i;
    for (i=0;i<this.options_refs.length;i++){
      //adding handler
      if (document.forms[this.frmName].elements && document.forms[this.frmName].elements[this.options_refs[i].dest]){
        document.forms[this.frmName].elements[this.options_refs[i].dest].onchange=function(){refs.updateCombos(this);}//changeHandler;
      }
    }
  }

}
