

function doRequest(where,post,doFunction,error) {

  this.Display = function(result) { doFunction(result.responseText); }

  this.Fail = function(result){ if(error) alert(error);}

  YAHOO.util.Connect.asyncRequest('POST',where,{success:this.Display,failure:this.Fail},post);       

}



function changeValidateRequired(formname,name,required) {

  for(var i=0; i<validate[formname].length; i++)

    if(validate[formname][i][0] == name) { validate[formname][i][2] = required; break; }  

}



function my_popup(module, field_array, call_back_function, form_name) {

  if(!call_back_function) call_back_function = "set_return";

  if(!form_name) form_name = "EditView";

  return open_popup(module, 900, 700, "", true, false, {"call_back_function":call_back_function,"form_name":form_name,"field_to_name_array":field_array});

}



function addEvent(object,eventName,do_function) {

  if(typeof(object) == "string") object = document.getElementById(object);

  if(!object) { alert('No object in function addEvent!'); return; }

  if(object.addEventListener) {

    object.addEventListener(eventName, do_function, false);

	} else {

		object.attachEvent('on'+eventName, do_function);

	} 

}





function FormLoader() {



  this.module;

  this.createModule;

  this.fieldName;

  this.buttonName = 'FormLoaderButton';

  

  this.load = function(module,createModule,fieldName) {

    this.module = module;

    this.createModule = createModule;

    this.fieldName = fieldName;

  }

  

  this.createButton = function() {

    var b = document.createElement('input');

    b.type = 'button';

    b.className = 'button';

    b.name = this.buttonName;

    b.value = 'Create';

    b.FL = this;

    b.onclick = function() {

      if(this.FL.createModule == '') return;

      if(this.FL.onButtonClick) var data = this.FL.onButtonClick();

      window.open("index.php?module="+this.FL.module+"&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName="+this.FL.fieldName+"&createModule="+this.FL.createModule+(data?data:''),"Create10"+this.FL.module,"resizable=yes,scrollbars=no,status=no,height=540,width=700").focus(); 

    }

    return b;

  }

//  this.setEditDblClick = function(edit) { edit.FL=this; edit.ondblclick=this.editDblClick; } 

  this.editDblClick = function() {

      if(this.FL.createModule == '') return;

      if(this.FL.onEditDblClick) var data = this.FL.onEditDblClick();

      window.open("index.php?module="+this.FL.module+"&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName="+this.FL.fieldName+"&createModule="+this.FL.createModule+(data?data:''),"Create10"+this.FL.module,"resizable=yes,scrollbars=no,status=no,height=540,width=700").focus(); 

  }

  

  this.responseData = function(data) {

    if(this.onResponseData) this.onResponseData(data);

  }

  

  this.onResponseData;



  this.addPostData = function() {

    if(this.onAddPostData) 

      return this.onAddPostData();

    else 

      return '';

  }  



  this.onAddPostData;

  this.onButtonClick;

}







