// Copyright 2012-2014 Laserfiche. All rights reserved var LaserficheForms=(function(){"use strict";return{Form:function(formDiv,opts){var that=this,options={host:'',bpid:'',formid:'',height:'',formName:'',hideheader:true,autoheight:true,params:'',width:'auto',onloadCallback:null},myopt=options,formapi={};formapi.getDiv=function(){return myopt.formDiv;};formapi.getFrm=function(){return myopt.formFrm;};formapi.getFrmDocument=function(){try {return formapi.getFrm().contentWindow.document;} catch(error) {return null;}};myopt.formDiv=formDiv;for(var key in opts){myopt[key]=opts[key];} myopt.objectName="object"+(myopt.bpid==''?myopt.formid:myopt.bpid);var ifrm=document.createElement("iframe");ifrm.setAttribute("id",myopt.objectName);ifrm.setAttribute("name",myopt.objectName);ifrm.setAttribute("frameborder","0");ifrm.setAttribute("position","relative");if(myopt.width=='auto'){var w='100%';if(myopt.formDiv!==null) w=myopt.formDiv.clientWidth-1;ifrm.style.width=w;ifrm.setAttribute("width",w);} else{ifrm.style.width=myopt.width;ifrm.setAttribute("width",myopt.width);} if(myopt.height!=''){ifrm.style.height=myopt.height;ifrm.setAttribute("height",myopt.height);} var path=(myopt.bpid=='')?("/form/embed/"+myopt.formid):("/form/new/"+myopt.bpid);path+="?HideHeader="+myopt.hideheader;if(myopt.params!='') path+="&"+myopt.params;ifrm.setAttribute("src",myopt.host+path);if(myopt.formDiv!==null){myopt.formDiv.appendChild(ifrm);} else{document.body.appendChild(ifrm);} myopt.formFrm=ifrm;function adjustHeight(callback){setTimeout(function(){var doc=formapi.getFrmDocument();if(!doc) return;if(callback) callback();var p=doc.body;myopt.formFrm.style.height=p.clientHeight+90+'px';},0);} if(myopt.autoheight){myopt.formFrm.style.height='0px';} myopt.formFrm.onload=function(){if(myopt.autoheight){var doc=formapi.getFrmDocument();if(doc==null){myopt.formFrm.style.height='90%';} else{adjustHeight();doc.body.onclick=function(){adjustHeight();};doc.body.onkeypress=function(){adjustHeight();};}} if(myopt.onloadCallback) myopt.onloadCallback();};return formapi;},trigger:function(instance,eventName){instance.trigger(eventName);}};}());