function DocumentLibraryObject(pid,jobID,orderID,div){
  this.productKey=pid;
  this.jobID=jobID;
  this.orderID=orderID;
  this.previewMode=false;
  this.div=div;
  this.htmlDiv=new HTMLParse(this.div);
  var i=0;
  this.CUSTOMER=i++;
  this.CATEGORY=i++;
  this.IMAGE=i++;
  this.DETAIL=i++;
  this.UDESIGNIT=i++;
  this.INVENTORY=i++;
  this.PRICING=i++;
  if(PREFS.DocLib_Sets){
    this.SETS=i++;
  }
  this.WEIGHT=i++;
  this.inventoryList=null;
}

DocumentLibraryObject.prototype.copy=function(){
  var params=new AjaxFormContent();
  params.addNameValue('mdl','docLib/copy.aj');
  params.addNameValue('prod_Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  ajaxPostFunction(params,function(sc,st,rt,rxml){
    var newKEY=getTagValue(rxml,'productkey');
    if(newKEY>0) location.replace('index.iml?mdl=docLib/products.mdl&EDIT=1&Product_KEY='+newKEY);
  },'ajax.iml')  
}

DocumentLibraryObject.prototype.edit=function(){
  hide('EDIT_LINKS');
  show('CANCEL_LINK');  
  show('LOADING');
  var params=new AjaxFormContent();
  params.addNameValue('mdl','docLib/resource.aj');
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){
    instance.res=new HTMLParse(rt);
    instance.htmlDiv.display[0].node.style["display"]="none";
    for(i=0; i<instance.res.section.length;i++){
      instance.div.insertBefore(instance.res.section[i].node,instance.htmlDiv.display[0].node);
      instance.processEditor(i);
    }
    instance.viewInventory();
    hide('LOADING');
  },'ajax.iml')  
  hide('QUANTITY_SELECT');
  hide('DOC_SUBMIT');
  hide('DOC_PREVIEW');
  hide('PAGEFLEX_PREVIEW');
  hide('Step_1');
  show('Step_2');
  var s2=el('Step_2');
  if(s2) s2.className="";
  if(el('FB_Container_7_'+this.productKey)!=null)     
      FormBuilderOpen(el('FB_Container_7_'+this.productKey),7,this.productKey);
}
DocumentLibraryObject.prototype.closeEditor=function(){
  location.replace('index.iml?mdl=docLib/products.mdl&Product_KEY='+this.productKey);
}

DocumentLibraryObject.prototype.processEditor=function(i){
    var instance=this;
    this.res.section[i].editor[0].node.style["display"]="none";
    //setMouseOver(this.res.section[i].action[0].node,'black-sm');
    this.res.section[i].action[0].node.onclick=function(evt){instance.editMode(i);};
    //setMouseOver(this.res.section[i].action[1].node,'black-sm');
    this.res.section[i].action[1].node.onclick=function(evt){instance.updateProductInfo(i);};
    //setMouseOver(this.res.section[i].action[2].node,'black-sm');
    this.res.section[i].action[2].node.onclick=function(evt){instance.viewMode(i);};  
    switch(i){
      case this.CATEGORY:
      case this.IMAGE:
      case this.WEIGHT:
        this.res.section[i].action[1].node.style["display"]="none";
        this.res.section[i].action[2].node.value="Close";
      break;      
    }
    var editor=this.res.section[i].editor[0];
    switch(i){
      case this.CUSTOMER:
        if(editor.customer){        
          for(var j=0; j<editor.customer.length; j++){
            //setMouseOver(editor.customer[j].button[0].node,'red');
            editor.customer[j].button[0].node.onclick=function(evt){instance.removeCustomer(this);};
          }
        }
        //setMouseOver(editor.button[0].node,'green');
        editor.button[0].node.onclick=function(evt){instance.addCustomer();};
      break;
      case this.CATEGORY:
        for(var j=0; j<editor.button.length; j++){      
          //setMouseOver(editor.button[j].node,'green');
          editor.button[j].node.onclick=function(evt){instance.addCategory();};
        }
        if(editor.categories&&editor.categories[0].category){
          for(var j=0; j<editor.categories[0].category.length;j++){
            //setMouseOver(editor.categories[0].category[j].button[0].node,'red');
            editor.categories[0].category[j].button[0].node.onclick=function(evt){instance.removeCategory(this.getAttribute('category'));};
          }
        }
      break;
      case this.IMAGE:
        if(editor.sortdiv[0].image){
          for(var j=0; j<editor.sortdiv[0].image.length; j++){
            //setMouseOver(editor.sortdiv[0].image[j].button[0].node,'green');
            editor.sortdiv[0].image[j].button[0].node.onclick=function(evt){instance.defaultImage(this.getAttribute('imageid'));};
            //setMouseOver(editor.sortdiv[0].image[j].button[1].node,'red');
            editor.sortdiv[0].image[j].button[1].node.onclick=function(evt){instance.removeImage(this.getAttribute('imageid'));};
          }
        }
        //setMouseOver(editor.button[0].node,'green');
        editor.button[0].node.onclick=function(evt){instance.selectImage(this);};
        this.imageSort=new DragDropListObject(editor.sortdiv[0].node,function(){instance.sortImages();});
        if(editor.sortdiv[1].pdf){
          for(var j=0; j<editor.sortdiv[1].pdf.length; j++){
            //setMouseOver(editor.sortdiv[1].pdf[j].button[0].node,'red');
            editor.sortdiv[1].pdf[j].button[0].node.onclick=function(evt){instance.removePDF(this.getAttribute('pdfid'));};
          }
        }
        //setMouseOver(editor.button[1].node,'green');
        editor.button[1].node.onclick=function(evt){instance.addPDF();};
        this.PDFSort=new DragDropListObject(editor.sortdiv[1].node,function(){instance.sortPDF();});
      break;
      case this.INVENTORY:        
      break;      
      case this.PRICING:
        editor.pricing_type[0].node.onclick=function(evt){instance.manualQty();};
        if(editor.pricing_type[0].node.checked) this.manualQty();
        editor.pricing_type[1].node.onclick=function(evt){instance.selectQty();};
        if(editor.pricing_type[1].node.checked) this.selectQty();
        if(editor.pricing_type[2]){
          editor.pricing_type[2].node.onclick=function(evt){instance.globalPricing();};
          if(editor.pricing_type[2].node.checked) this.globalPricing();
        }
        editor.view_with[0].pricing_type[0].node.onclick=function(evt){instance.noPricing();};
        if(editor.view_with[0].pricing_type[0].node.checked) this.noPricing();
        editor.view_with[0].pricing_type[1].node.onclick=function(evt){instance.showPricing();};
        if(editor.view_with[0].pricing_type[1].node.checked) this.showPricing();        
        for(var j=0;j<editor.view_with[0].qty_break[0].row.length;j++){
          editor.view_with[0].qty_break[0].row[j].show_item[0].check[0].node.onclick=function(evt){if(this.checked)this.checked=instance.pricingOkToShow();};
        }        
        //setMouseOver(editor.view_with[0].qty_break[0].more_rows[0].node,'green');
        editor.view_with[0].qty_break[0].more_rows[0].node.onclick=function(evt){instance.showMorePricing();};
        if(editor.view_with[0].qty_break[0].more_rows[0].node.getAttribute('breaks')>6) this.showMorePricing();
        else this.hideMorePricing();
      break;
      case this.SETS:
        for(var j=0; j<editor.button.length; j++){      
          //setMouseOver(editor.button[j].node,'green');
          editor.button[j].node.onclick=function(evt){instance.addSet();};
        }
        if(editor.sets&&editor.sets[0].set){
          for(var j=0; j<editor.sets[0].set.length;j++){
            //setMouseOver(editor.sets[0].set[j].button[0].node,'red');
            editor.sets[0].set[j].button[0].node.onclick=function(evt){instance.removeSet(this.getAttribute('set_id'));};
          }
        }        
        this.viewSets();
      break;
      case this.WEIGHT:
      break;
   }
}

DocumentLibraryObject.prototype.editMode=function(i){
  var instance=this;
  this.res.section[i].node.className="fbElementEdit";
  this.res.section[i].editor[0].node.style["display"]="";
  this.res.section[i].action[0].node.onclick=function(evt){instance.viewMode(i);};
  this.res.section[i].action[0].node.value="Close Without Saving";
  this.res.section[i].content[0].node.style["display"]="none";
  switch(i){
    case this.UDESIGNIT:
       if(!this.pfEditor) this.pfEditor=new PageFlexSettingsEditorObject(this.res.section[i].editor[0].node);
      break;
    case this.CATEGORY:
    case this.IMAGE:
      this.res.section[i].action[0].node.value="Close";
    break;
    case this.INVENTORY:        
      this.res.section[this.INVENTORY].editor[0].logcomment[0].node.value="";
      this.res.section[this.INVENTORY].editor[0].oldinventory[0].node.value=this.res.section[this.INVENTORY].editor[0].newinventory[0].node.value;
    break;     
    case this.WEIGHT:
      this.res.section[i].action[0].node.value="Close";      
      WeightCalcObj.open(this.res.section[i].editor[0].node);
    break;     
  }
 
}


DocumentLibraryObject.prototype.viewMode=function(i){
  var instance=this;
  this.res.section[i].node.className="fbElementHover";
  this.res.section[i].action[0].node.onclick=function(evt){instance.editMode(i);};
  this.res.section[i].action[0].node.value="Edit";  
  this.res.section[i].editor[0].node.style["display"]="none";
  this.res.section[i].content[0].node.style["display"]="";
  var params=new AjaxFormContent();
  params.addNameValue('EDIT_MODE',1);
  switch(i){
    case this.CUSTOMER:  params.addNameValue("mdl","docLib/viewCustomers.aj");     break;
    case this.CATEGORY:  params.addNameValue("mdl","docLib/viewCategory.aj");     break;
    case this.IMAGE:  params.addNameValue("mdl","docLib/viewImages.aj");     break;
    case this.DETAIL:  params.addNameValue("mdl","docLib/viewDetail.aj");     break;
    case this.UDESIGNIT:  params.addNameValue("mdl","docLib/viewuDesignIT.aj");     break;
    case this.INVENTORY: 
      this.res.section[this.INVENTORY].editor[0].logcomment[0].node.value="";
      this.res.section[this.INVENTORY].editor[0].oldinventory[0].node.value=this.res.section[this.INVENTORY].editor[0].newinventory[0].node.value;
      params.addNameValue("mdl","docLib/viewInventory.aj");   
    break;
    case this.PRICING:  params.addNameValue("mdl","docLib/viewPricing.aj");     break;
    case this.SETS: params.addNameValue("mdl","docLib/viewSet.aj");     break;
    case this.WEIGHT: return;
  }
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[i].content[0].node.innerHTML=rt;
       switch(i){
         case instance.INVENTORY: instance.viewInventory();    break;
         case instance.SETS: instance.viewSets(); break;
       }
     },
     "ajax.iml");  
}


DocumentLibraryObject.prototype.updateProductInfo=function(i){
  var params=new AjaxFormContent();
  switch(i){
    case this.CUSTOMER:  params.addNameValue("mdl","docLib/updateCustomers.aj");     break;
    case this.CATEGORY: 
    case this.IMAGE:  this.viewMode(i); return;
    case this.DETAIL:   
	  params.addNameValue("mdl","docLib/updateDetail.aj");     
	  break;
    case this.UDESIGNIT:  params.addNameValue("mdl","docLib/updateuDesignIT.aj");   
   	         if(this.res.section[i].editor[0].PFP){
	             if(this.res.section[i].editor[0].PFP[0].node.selectedIndex!=0&&this.res.section[i].editor[0].PFP[1].node.selectedIndex!=0)    PREFS.Pageflex_Available=true;
              else PREFS.Pageflex_Available=false;      
         	  }
            break;
    case this.INVENTORY:  params.addNameValue("mdl","docLib/updateInventory.aj");     break;
    case this.PRICING:  params.addNameValue("mdl","docLib/updatePricing.aj");     break;
    case this.SETS: this.viewMode(i); return;
    case this.WEIGHT:  this.viewMode(i); return;
    
  }
  params.fromNode(this.res.section[i].editor[0].node);
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
        instance.viewMode(i);
     },
     "ajax.iml");  
}

/******************************* Customers **********************/

DocumentLibraryObject.prototype.removeCustomer=function(button){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/removeCustomer.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('CP_Company_ID',button.getAttribute('company'));
  params.addNameValue('CP_Branch_ID',button.getAttribute('branch'));
  params.addNameValue('CP_Contact_ID',button.getAttribute('contact'));
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.CUSTOMER].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.CUSTOMER].editor[0].node);
     instance.res.section[instance.CUSTOMER].editor[0]=res;
     instance.processEditor(instance.CUSTOMER);
     instance.editMode(instance.CUSTOMER)
     },
     "ajax.iml");  
}
 
DocumentLibraryObject.prototype.addCustomer=function(){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/addCustomer.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.fromNode(this.res.section[this.CUSTOMER].editor[0].node);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.CUSTOMER].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.CUSTOMER].editor[0].node);
     instance.res.section[instance.CUSTOMER].editor[0]=res;
     instance.processEditor(instance.CUSTOMER);
     instance.editMode(instance.CUSTOMER)
    },
     "ajax.iml");  
}

 
 
/***********************  Category *************************/
DocumentLibraryObject.prototype.removeCategory=function(cat){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/removeCategory.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Category',cat);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.CATEGORY].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.CATEGORY].editor[0].node);
     instance.res.section[instance.CATEGORY].editor[0]=res;
     instance.processEditor(instance.CATEGORY);
     instance.editMode(instance.CATEGORY)

     },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.addCategory=function(){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/addCategory.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.fromNode(this.res.section[this.CATEGORY].editor[0].node);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.CATEGORY].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.CATEGORY].editor[0].node);
     instance.res.section[instance.CATEGORY].editor[0]=res;
     instance.processEditor(instance.CATEGORY);
     instance.editMode(instance.CATEGORY)
    },
     "ajax.iml");  
}


/***********************  Images *************************/
DocumentLibraryObject.prototype.removeImage=function(id){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/removeImage.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Image_ID',id);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.IMAGE].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.IMAGE].editor[0].node);
     instance.res.section[instance.IMAGE].editor[0]=res;
     instance.processEditor(instance.IMAGE);
     instance.editMode(instance.IMAGE)
    },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.defaultImage=function(id){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/defaultImage.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Image_ID',id);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.IMAGE].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.IMAGE].editor[0].node);
     instance.res.section[instance.IMAGE].editor[0]=res;
     instance.processEditor(instance.IMAGE);
     instance.editMode(instance.IMAGE)
    },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.selectImage=function(obj){
  var instance=this;
  var category=""; var text=""; var file="";
  var e= Geometry.upperLeftOffset(obj);
//  imageDragger.setPosition(obj);
  imageDragger.setXY(e.x-100,e.y-200);
//  imageDragger.setConstrain(this.res.section[instance.IMAGE].node);
  imagePicker.open(function(img){instance.addImage(img);},category,text,file,'data/');
}
DocumentLibraryObject.prototype.addImage=function(img){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/addImage.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Image_File',img);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.IMAGE].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.IMAGE].editor[0].node);
     instance.res.section[instance.IMAGE].editor[0]=res;
     instance.processEditor(instance.IMAGE);
     instance.editMode(instance.IMAGE)
    },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.sortImages=function(){
  var x=this.res.section[this.IMAGE].editor[0].sortdiv[0].node.childNodes;
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/sortImages.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  
  for(var i=0; i<x.length; i++){
    if(x[i].nodeType==1&&x[i].getAttribute('imageid')>0){
      params.addNameValue('Image_ID',x[i].getAttribute('imageid'));
    }
  }  
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
    },
     "ajax.iml");  
}


DocumentLibraryObject.prototype.removePDF=function(id){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/removePDF.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('PDF_ID',id);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.IMAGE].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.IMAGE].editor[0].node);
     instance.res.section[instance.IMAGE].editor[0]=res;
     instance.processEditor(instance.IMAGE);
     instance.editMode(instance.IMAGE)
    },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.addPDF=function(){
  var editor=this.res.section[this.IMAGE].editor[0];
  add_file_upload_field('SAMPLE_UPLOAD',editor.pdfform[0].node.pdf_PDF,editor.pdfform[0].node.PDF_FILE);
  add_required_field('SAMPLE_UPLOAD',editor.pdfform[0].node.PDF_FILE, 'Please Select a File.', 1, '');
  add_required_field('SAMPLE_UPLOAD',editor.pdfform[0].node.pdf_Name, 'Please Enter a Label.', 1, '');
  if(!check_required_fields('SAMPLE_UPLOAD')) return;
  if(check_file_upload_fields('SAMPLE_UPLOAD')){
     editor.inprogress[0].progress[0].bar[0].node.style.width="0px";
     editor.inprogress[0].node.style["display"]="";
     editor.pdfform[0].node.style["display"]="none";
     var message='Uploading "'+editor.pdfform[0].node.pdf_Name.value+'"';     
     editor.inprogress[0].status[0].node.innerHTML=message;
     var pb=new ProgressBar(editor.inprogress[0].progress[0].bar[0].node);
     editor.pdfform[0].node.submit();
  }
  return;
}
DocumentLibraryObject.prototype.uploadPDFDone=function(){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/editImages.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.IMAGE].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.IMAGE].editor[0].node);
     instance.res.section[instance.IMAGE].editor[0]=res;
     instance.processEditor(instance.IMAGE);
     instance.editMode(instance.IMAGE)
    },
     "ajax.iml");  
} 
DocumentLibraryObject.prototype.sortPDF=function(){
  var x=this.res.section[this.IMAGE].editor[0].sortdiv[1].node.childNodes;
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/sortPDF.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('DEBUG',0);
  for(var i=0; i<x.length; i++){
    if(x[i].nodeType==1&&x[i].getAttribute('pdfid')>0){
      params.addNameValue('PDF_ID',x[i].getAttribute('pdfid'));
    }
  }  
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
    },
     "ajax.iml");  
}


/************************ Inventory ************************/
DocumentLibraryObject.prototype.viewInventory=function(){
  var res=new HTMLParse(this.res.section[this.INVENTORY].content[0].node);
  if(res.inventorylist){
    var total=res.inventorylist[0].node.getAttribute('total');
    var passin=new Array(); passin[0]=new Array(); passin[0][0]="prod_Product_KEY";passin[0][1]=this.productKey;
    this.inentoryList=new ListBoxObject(res.inventorylist[0].node,"inventory/inventory_log2.mdl",10,total,passin,1);
  }
}


DocumentLibraryObject.prototype.removeInventoryNotice=function(button){
  var instance=this;
  $.post('ajax.iml',{mdl:'docLib/removeInventoryNotice.aj', 
                     Product_KEY: this.productKey,
					 IN_Contact_ID: button.getAttribute('contact')}, 
     function(data){
       instance.res.section[instance.INVENTORY].editor[0].node.innerHTML=data;
       var res=new HTMLParse( instance.res.section[instance.INVENTORY].editor[0].node);
       instance.res.section[instance.INVENTORY].editor[0]=res;
       instance.processEditor(instance.INVENTORY);
       instance.editMode(instance.INVENTORY);
	   
     }
   );
}
 
DocumentLibraryObject.prototype.addInventoryNotice=function(){
  var instance=this;
  $.post('ajax.iml',{mdl:'docLib/addInventoryNotice.aj', 
                     Product_KEY: this.productKey,
					 IN_Contact_ID:$(this.res.section[this.INVENTORY].editor[0].node).find('[name=IN_Contact_ID]').val()}, 
     function(data){
       instance.res.section[instance.INVENTORY].editor[0].node.innerHTML=data;
       var res=new HTMLParse( instance.res.section[instance.INVENTORY].editor[0].node);
       instance.res.section[instance.INVENTORY].editor[0]=res;
       instance.processEditor(instance.INVENTORY);
       instance.editMode(instance.INVENTORY);
	   
     }
   );
}





/************************ Pricing **************************/

DocumentLibraryObject.prototype.manualQty=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  editor.view_with[0].node.style["display"]="";
  editor.view_with[0].unit_pricing[0].node.style["display"]="";
  editor.view_with[0].qty_break[0].node.style["display"]="none";
}
DocumentLibraryObject.prototype.selectQty=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  editor.view_with[0].node.style["display"]="";
  editor.view_with[0].unit_pricing[0].node.style["display"]="none";
  editor.view_with[0].qty_break[0].node.style["display"]="";
}
DocumentLibraryObject.prototype.globalPricing=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  editor.view_with[0].node.style["display"]="none";
}
DocumentLibraryObject.prototype.noPricing=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  editor.view_with[0].unit_pricing[0].price[0].node.style["display"]="none";
  editor.view_with[0].qty_break[0].price_col[0].node.style["display"]="none";
  for(var i=0; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].price[0].node.style["display"]="none";
  }
}
DocumentLibraryObject.prototype.showPricing=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  editor.view_with[0].unit_pricing[0].price[0].node.style["display"]="";
  editor.view_with[0].qty_break[0].price_col[0].node.style["display"]="";
  for(var i=0; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].price[0].node.style["display"]="";
  }
}
DocumentLibraryObject.prototype.showMorePricing=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  for(var i=0; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].show_item[0].node.style["display"]="";
  }
  for(var i=6; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].node.style["display"]="";
  }
  editor.view_with[0].qty_break[0].more_rows[0].node.style["display"]="none";
  editor.view_with[0].qty_break[0].default_col[0].node.style["display"]="";
}
DocumentLibraryObject.prototype.hideMorePricing=function(){
  var editor=this.res.section[this.PRICING].editor[0];
  for(var i=0; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].show_item[0].node.style["display"]="none";
  }
  for(var i=6; i<editor.view_with[0].qty_break[0].row.length; i++){
    editor.view_with[0].qty_break[0].row[i].node.style["display"]="none";
  }
  editor.view_with[0].qty_break[0].more_rows[0].node.style["display"]="";
  editor.view_with[0].qty_break[0].default_col[0].node.style["display"]="none";
}
DocumentLibraryObject.prototype.pricingOkToShow=function(){
  var count_items=0;
  var editor=this.res.section[this.PRICING].editor[0];  
  for(var i=0; i<editor.view_with[0].qty_break[0].row.length; i++){
    if(editor.view_with[0].qty_break[0].row[i].show_item[0].check[0].node.checked)count_items++;
  }
  if(count_items>6) alert("Only six quantities can be shown on the product page.");
  return count_items<=6;
}

/****************************** view ************************/

DocumentLibraryObject.prototype.emailPopup=function(){
  url = "popup.iml?mdl=docLib/question_form.mdl&Product_KEY="+this.productKey;
  if(PREFS.cXML_ID!="")url=url+"&cXML_ID="+PREFS.cXML_ID;
  this.emailWindow=window.open(url,"Email","height=550,width=700,resizable=1,scrollbars=1,status=no,toolbar=no,location=no,menubar=no");
  this.emailWindow.focus(); 
}



DocumentLibraryObject.prototype.checkForm=function(){
  if(!check_required_fields('step1')) return false;
  if(!check_required_fields('step2')) return false;
  $('#DOC_SUBMIT').hide();
  $('#DOC_PROGRESS').show();
  if(check_file_upload_fields('step1')||check_file_upload_fields('step2')){
     progress();   
  }else{
     $('body').unbind('click',myDoc.checkClickAway).bind('click',myDoc.checkClickAway);  
  }  
  if(FileUploadUtilityList){
    for(var i=0; i<FileUploadUtilityList.length; i++){
      FileUploadUtilityList[i].closeOut();
    }  
    for(var i=0; i<FileUploadUtilityList.length; i++){
      if(FileUploadUtilityList[i].sending||FileUploadUtilityList[i].waitingToSend){
        FileUploadUtilityNextAction=function(){myDoc.addToCart();};
        FileUploadUtilityCancelAction=function(){myDoc.reOpenCart();};
        //alert("Please wait untill all files have been transfered.");
        return false;
      }
    }
  }  
  if($('form[name=product_order]').length>0){
    $('form[name=product_order]').get(0).submit();
    return false;
  }
  return true;
}

DocumentLibraryObject.prototype.reOpenCart=function(){
  $('#DOC_SUBMIT').show();
  $('#DOC_PROGRESS').hide();
  $('body').unbind('click',myDoc.checkClickAway);
  if(FileUploadUtilityList){
    FileUploadUtilityNextAction=null;
    FileUploadUtilityCancelAction=null;  
    for(var i=0; i<FileUploadUtilityList.length; i++){
      FileUploadUtilityList[i].reOpen();
    }  
  }	  
  
}

DocumentLibraryObject.prototype.checkClickAway=function(event){
   if($(event.target).is('.cancel-icon')) return true;
   if(confirm("Please wait while your file is being transferred. Would you like to end this file transfer session? Click the OK button to end the file transfer session, or click the Cancel button to return to the browser window.")){   
     myDoc.reOpenCart();
     return true;
   }
   return false;
}



DocumentLibraryObject.prototype.thankyou=function(){
  location.replace('index.iml?mdl=orderView/main.mdl'+(this.jobID>0?'&ORDER_Order_ID='+this.orderID:'')+(PREFS.cXML_ID&&PREFS.cXML_ID>0?'&cXML_ID='+PREFS.cXML_ID:''));
}

DocumentLibraryObject.prototype.showPdfInstr=function(){
  if(!check_required_fields('step1')) return;
  hide("Step_1");
  hide("PreviewButton");
  show("PDF_Instructions");
  hide("Step_2");
  hide("OrderButton");
  scroll_to("PDF_Instructions");
}
DocumentLibraryObject.prototype.preview=function(){
  if(!check_required_fields('step1')) return;
  this.previewMode=true;
  hide("Step_1");
  hide("PreviewButton");
  hide("PDF_Instructions"); 
  show("Step_2");
  show("OrderButton");
  if(this.htmlDiv.display[0].PDF)  this.pdfPreview(this.htmlDiv.display[0].PDF[0].node.getAttribute('PDF_ID'));
  scroll_to("Step_2");
}
DocumentLibraryObject.prototype.revise=function(){
  this.previewMode=false;
  show("Step_1");
  show("PreviewButton");
  hide("PDF_Instructions");
  hide("Step_2");
  hide("OrderButton");
  scroll_to("Step_1");
}
DocumentLibraryObject.prototype.addToCart=function(){
  if(outstanding_ajax_calls>0){
    var instance=this;   
    function_waiting_for_ajax=function(){if(instance.addToCart()) $('form[name=product_order]').get(0).submit();};
    return false;  
  }
  document.product_order.action="loadin.iml";
  document.product_order.target="LOADIN_FRAME";
  if(this.jobID>0){
    document.product_order.update_mdl.value="job_ticket/update_product_order.mdl";
  }else{
    document.product_order.update_mdl.value="orderView/add.mdl";
  }
  return this.checkForm();
}
DocumentLibraryObject.prototype.pdfPreview=function(id){
  document.product_order.action="secure_ff_proof.iml";
  document.product_order.target="_self";
  if(document.product_order.turn_off_pdf_instructions.checked)
      document.product_order.update_mdl.value="docLib/turn_off_pdf_directions.mdl";
  else document.product_order.update_mdl.value="";
  document.product_order.PDF_ID.value=id;
  check_file_upload_fields('step1');
  if(check_required_fields('step1')) document.product_order.submit();
}

DocumentLibraryObject.prototype.replaceImage=function(file_name,path){
  this.htmlDiv.display[0].largepic[0].node.src=path+file_name;
  this.htmlDiv.display[0].largepic[0].node.setAttribute('cur_image',file_name);
}
DocumentLibraryObject.prototype.loadImage=function(){
   cur_image=this.htmlDiv.display[0].largepic[0].node.getAttribute('cur_image');
   window.open("full_image.iml?file="+cur_image,"Image","height=350,width=350,resizable=1,scrollbars=1,status=no,toolbar=no,location=no,menubar=no");
 }
 

/***********************  Sets *************************/
DocumentLibraryObject.prototype.viewSets=function(){
        var instance=this;
        this.res.section[this.SETS].content[0]=new HTMLParse(this.res.section[this.SETS].content[0].node);
        var view=this.res.section[this.SETS].content[0];
        if(view.button){
          for(var j=0; j<view.button.length; j++){
            view.button[j].node.onclick=function(evt){instance.openSetSync(this.getAttribute('set_id'));return false;};
          }          
        }
        if(view.sync_set){
          for(var j=0; j<view.sync_set.length; j++){
            view.sync_set[j].button[0].node.onclick=function(evt){instance.syncSet(this.getAttribute('set_id'));};
          }          
        }
}

DocumentLibraryObject.prototype.removeSet=function(set){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/removeSet.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Set_ID',set);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.SETS].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.SETS].editor[0].node);
     instance.res.section[instance.SETS].editor[0]=res;
     instance.processEditor(instance.SETS);
     instance.editMode(instance.SETS)

     },
     "ajax.iml");  
}
DocumentLibraryObject.prototype.addSet=function(){
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/addSet.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.fromNode(this.res.section[this.SETS].editor[0].node);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     instance.res.section[instance.SETS].editor[0].node.innerHTML=rt;
     var res=new HTMLParse( instance.res.section[instance.SETS].editor[0].node);
     instance.res.section[instance.SETS].editor[0]=res;
     instance.processEditor(instance.SETS);
     instance.editMode(instance.SETS)
    },
     "ajax.iml");  
}

DocumentLibraryObject.prototype.openSetSync=function(set){
  var view=this.res.section[this.SETS].content[0];
  var subForm=null;
  for(var j=0; j<view.sync_set.length; j++){
    if(view.sync_set[j].node.getAttribute('set_id')==set){ subForm=view.sync_set[j]; break;}
  }          
  subForm.node.style["display"]="";
}
DocumentLibraryObject.prototype.syncSet=function(set){
  var view=this.res.section[this.SETS].content[0];
  var subForm=null;
  for(var j=0; j<view.sync_set.length; j++){
    if(view.sync_set[j].node.getAttribute('set_id')==set){ subForm=view.sync_set[j]; break;}
  }          
  var params=new AjaxFormContent();
  params.addNameValue("mdl","docLib/syncSet.aj");
  params.addNameValue('Product_KEY',this.productKey);
  params.addNameValue('Set_ID',set);
  params.fromNode(subForm.node);
  params.addNameValue('DEBUG',0);
  var instance=this;
  ajaxPostFunction(params,function(sc,st,rt,rxml){  
     if(getTagValue(rxml,'status')=="ok")   subForm.node.style["display"]="none";
     alert(getTagValue(rxml,'message'));
     },
     "ajax.iml");  
}

