function getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else{if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(xScroll<windowWidth){pageWidth=xScroll}else{pageWidth=windowWidth}return[pageWidth,pageHeight]}function getViewportHeight(){if(window.innerHeight!=window.undefined){return window.innerHeight}if(document.compatMode=="CSS1Compat"){return document.documentElement.clientHeight}if(document.body){return document.body.clientHeight}return window.undefined}function getViewportWidth(){if(window.innerWidth!=window.undefined){return window.innerWidth}if(document.compatMode=="CSS1Compat"){return document.documentElement.clientWidth}if(document.body){return document.body.clientWidth}return window.undefined}function getDocumentHeight(){if(document.compatMode=="CSS1Compat"){return(navigator.appName.indexOf("Explorer")>-1)?document.documentElement.scrollHeight:document.documentElement.offsetHeight}if(document.body){return(navigator.appName.indexOf("Explorer")>-1)?document.body.scrollHeight:document.body.offsetHeight}return window.undefined}function getDocumentWidth(){if(document.compatMode=="CSS1Compat"){return(navigator.appName.indexOf("Explorer")>-1)?document.documentElement.scrollWidth:document.documentElement.offsetWidth}if(document.body){return(navigator.appName.indexOf("Explorer")>-1)?document.body.scrollWidth:document.body.offsetWidth}return window.undefined}function scrollDocument(dialogID){dialogElement=document.getElementById(dialogID)}function handleFunction(dialogObject){if(dialogObject.functionHandler){dialogObject.functionHandler(dialogObject)}}function padLeft(value,charCount,charValue){while(value.length<charCount){value=charValue+value}return value}function padRight(value,charCount,charValue){while(value.length<charCount){value=value+charValue}return value}function padCenter(value,charCount,charValue){if((charCount>value.length)&&((charCount-value.length)>=2)){offset=(((charCount-value.length)%2)==0)?((charCount-value.length)/2):(((charCount-value.length)-1)/2);value=padLeft(value,(value.length+offset),charValue);value=padRight(value,(value.length+offset),charValue)}return value}function DialogConstants(){this.DIALOG_ID_DIV_DIALOG="divDialog";this.DIALOG_ID_DIV_MASK="";this.DIALOG_ID_TABLE_DIALOG="tableDialog";this.DIALOG_ID_CELL_TITLE="cellTitle";this.DIALOG_ID_CELL_MESSAGE="cellMessage";this.DIALOG_ID_CELL_OPTION="cellOption";this.DIALOG_ID_CELL_FRAME="cellFrame";this.DIALOG_TYPE_MESSAGE=0;this.DIALOG_TYPE_CONFIRM=1;this.DIALOG_TYPE_INPUT=2;this.DIALOG_OPTION_OK=0;this.DIALOG_OPTION_YES=1;this.DIALOG_OPTION_NO=2;this.DIALOG_OPTION_CANCEL=3;this.DIALOG_OPTION_TYPE_DEFAULT=0;this.DIALOG_OPTION_TYPE_YES_NO=1;this.DIALOG_OPTION_TYPE_YES_NO_CANCEL=2;this.DIALOG_OPTION_TYPE_OK_CANCEL=3}function Dialog(){this.dialog=null;this.mask=null;this.dialogTable=null;this.tableBody=null;this.textField=null;this.constants=(new DialogConstants());this.message="";this.title="";this.bgColor="#FFFFFF";this.optionResult=-1;this.inputResult="";this.functionHandler=null;this.positionTop=-1;this.positionLeft=-1;this.resizeFuntion;this.layer=null;this.parent=null;this.closeButton=null;this.initIndex=(new Date()).getTime();this.dialogType=this.constants.DIALOG_TYPE_MESSAGE;this.optionType=this.constants.DIALOG_OPTION_TYPE_DEFAULT;this.effect=false}Dialog.prototype.cleanDialog=function(){while(this.dialog.childNodes[0]){this.dialog.removeChild(this.dialog.childNodes[0])}};Dialog.prototype.getMaskHeight=function(){return Math.max(getDocumentHeight()+150,getViewportHeight()+150)};Dialog.prototype.getMaskWidth=function(){return Math.max(getDocumentWidth(),getViewportWidth())};Dialog.prototype.closeDialog=function(optionButton,dialogObject){var dialog=document.getElementById(dialogObject.dialog.id);var mask=document.getElementById(dialogObject.mask.id);var body=document.getElementsByTagName("body")[0];if(dialog&&body&&mask){body.removeChild(mask);body.removeChild(dialog)}if(dialogObject.parent&&dialogObject.layer){dialogObject.layer.style.visibility="hidden";dialogObject.parent.appendChild(dialogObject.layer)}if(optionButton){dialogObject.optionResult=optionButton;if(dialogObject.textField){dialogObject.inputResult=dialogObject.textField.value}}if(dialogObject.functionHandler){dialogObject.functionHandler(dialogObject)}};Dialog.prototype.prepareMask=function(){this.mask=document.getElementById(this.constants.DIALOG_ID_DIV_MASK+this.identifier);if(!this.mask){body=document.getElementsByTagName("body")[0];html=document.getElementsByTagName("html")[0];this.mask=document.createElement("div");this.mask.id=this.constants.DIALOG_ID_DIV_MASK+this.identifier;this.mask.className="overlay";this.mask.style.zIndex=Math.ceil(this.initIndex/1024);body.appendChild(this.mask)}var pageSize=getPageSize();this.mask.style.width=pageSize[0]+"px";this.mask.style.height=pageSize[1]+"px";if(!this.effect){this.mask.style.backgroundColor="#000000";this.mask.style.visibility="visible";if((navigator.appName.indexOf("Explorer")>-1)){this.mask.style.filter="alpha(opacity=50)"}else{this.mask.style.filter="alpha(0.5)";this.mask.style.MozOpacity=0.5;this.mask.style.KhtmOpacity=0.5;this.mask.style.opacity=0.5}}};Dialog.prototype.createTextField=function(){this.textField=document.createElement("INPUT");this.textField.className=".inputText";this.textField.type="text";this.textField.style.width="100%";return this.textField};Dialog.prototype.createRowTitle=function(){var rowTitle=document.createElement("TR");var cellTitle=document.createElement("TD");cellTitle.id=this.constants.DIALOG_ID_CELL_TITLE+this.identifier;cellTitle.className=this.constants.DIALOG_ID_CELL_TITLE;cellTitle.appendChild(document.createTextNode(this.title));rowTitle.appendChild(cellTitle);return rowTitle};Dialog.prototype.createRowMessage=function(){var rowMessage=document.createElement("TR");var cellMessage=document.createElement("TD");cellMessage.id=this.constants.DIALOG_ID_CELL_MESSAGE+this.identifier;cellMessage.className=this.constants.DIALOG_ID_CELL_MESSAGE;var messageText=document.createElement("span");messageText.innerHTML=padRight(this.message,50,"&nbsp;");cellMessage.appendChild(messageText);if(this.dialogType==this.constants.DIALOG_TYPE_INPUT){cellMessage.appendChild(document.createElement("br"));cellMessage.appendChild(this.createTextField());cellMessage.appendChild(document.createElement("br"))}rowMessage.appendChild(cellMessage);return rowMessage};Dialog.prototype.createOption=function(caption,actionFunction,optionButton){var option=document.createElement("LI");var optionLink=document.createElement("A");optionLink.href="javascript:void(0);";var dialogObject=this;optionLink.appendChild(document.createTextNode(padCenter(caption,23,"\u00a0")));option.appendChild(optionLink);option.onclick=function(){actionFunction(optionButton,dialogObject)};return option};Dialog.prototype.createRowOption=function(){var rowOption=document.createElement("TR");var cellOption=document.createElement("TD");cellOption.id=this.constants.DIALOG_ID_CELL_OPTION+this.identifier;cellOption.className=this.constants.DIALOG_ID_CELL_OPTION;cellOption.align="center";cellOption.appendChild(document.createElement("br"));var listOption=document.createElement("UL");listOption.className="listOption";switch(this.dialogType){case this.constants.DIALOG_TYPE_MESSAGE:listOption.appendChild(this.createOption("OK",this.closeDialog,this.constants.DIALOG_OPTION_OK));break;case this.constants.DIALOG_TYPE_CONFIRM:switch(this.optionType){case this.constants.DIALOG_OPTION_TYPE_DEFAULT:listOption.appendChild(this.createOption("OK",this.closeDialog,this.constants.DIALOG_OPTION_OK));break;case this.constants.DIALOG_OPTION_TYPE_YES_NO:listOption.appendChild(this.createOption("Sim",this.closeDialog,this.constants.DIALOG_OPTION_YES));listOption.appendChild(this.createOption("Não",this.closeDialog,this.constants.DIALOG_OPTION_NO));break;case this.constants.DIALOG_OPTION_TYPE_YES_NO_CANCEL:listOption.appendChild(this.createOption("Sim",this.closeDialog,this.constants.DIALOG_OPTION_YES));listOption.appendChild(this.createOption("Não",this.closeDialog,this.constants.DIALOG_OPTION_NO));listOption.appendChild(this.createOption("Cancelar",this.closeDialog,this.constants.DIALOG_OPTION_CANCEL));break;case this.constants.DIALOG_OPTION_TYPE_OK_CANCEL:listOption.appendChild(this.createOption("OK",this.closeDialog,this.constants.DIALOG_OPTION_OK));listOption.appendChild(this.createOption("Cancelar",this.closeDialog,this.constants.DIALOG_OPTION_CANCEL));break}break;case this.constants.DIALOG_TYPE_INPUT:listOption.appendChild(this.createOption("OK",this.closeDialog,this.constants.DIALOG_OPTION_OK));listOption.appendChild(this.createOption("Cancelar",this.closeDialog,this.constants.DIALOG_OPTION_CANCEL));break}cellOption.appendChild(listOption);cellOption.appendChild(document.createElement("br"));cellOption.appendChild(document.createElement("br"));rowOption.appendChild(cellOption);return rowOption};Dialog.prototype.createRowLayer=function(){var rowLayer=document.createElement("TR");var cellLayer=document.createElement("TD");cellLayer.id=this.constants.DIALOG_ID_CELL_FRAME+this.identifier;if(this.closeButton){var closeFunction=this.closeDialog;var dialogObject=this;this.closeButton.onclick=function(){closeFunction(null,dialogObject)}}cellLayer.appendChild(this.layer);rowLayer.appendChild(cellLayer);return rowLayer};Dialog.prototype.createDialogTable=function(isLayer){this.dialogTable=document.createElement("TABLE");if(!isLayer){this.dialogTable.id=this.constants.DIALOG_ID_TABLE_DIALOG+this.identifier;this.dialogTable.className=this.constants.DIALOG_ID_TABLE_DIALOG}this.dialogTable.cellSpacing=0;this.dialogTable.cellPadding=0;this.tableBody=document.createElement("TBODY");if(isLayer){this.tableBody.appendChild(this.createRowLayer())}else{this.tableBody.appendChild(this.createRowTitle());this.tableBody.appendChild(this.createRowMessage());this.tableBody.appendChild(this.createRowOption())}this.dialogTable.appendChild(this.tableBody)};Dialog.prototype.adjustDialogPosition=function(){if(this.positionTop==-1){var scrollTop=parseInt(document.documentElement.scrollTop,10);var scrollLeft=parseInt(document.documentElement.scrollLeft,10);this.dialog.style.top=scrollTop+((getViewportHeight()-this.dialog.offsetHeight)/2)+"px";this.dialog.style.left=scrollLeft+((getViewportWidth()-this.dialog.offsetWidth)/2)+"px"}else{this.dialog.style.top=this.positionTop+"px";this.dialog.style.left=this.positionLeft+"px"}};Dialog.prototype.prepareDialog=function(isLayer){var random=Math.floor(Math.random()*11);this.identifier=(new Date()).getTime()*(random==0?1:random);this.prepareMask();this.dialog=document.getElementById(this.constants.DIALOG_ID_DIV_DIALOG);if(!this.dialog){body=document.getElementsByTagName("body")[0];this.dialog=document.createElement("DIV");this.dialog.className="divDialog";this.dialog.id=this.constants.DIALOG_ID_DIV_DIALOG+this.identifier;this.dialog.style.zIndex=(Math.ceil(this.initIndex/1024)+1);body.appendChild(this.dialog);var dialogID=this.dialog.id;var maskID=this.dialog.id;if(this.functionHandler){var dialogObject=this;window.onresize=function(){handleFunction(dialogObject)}}this.dialog.style.display="block";this.dialog.style.position="absolute";this.dialog.style.backgroundColor=this.bgColor;this.createDialogTable(isLayer);this.dialog.appendChild(this.dialogTable);this.adjustDialogPosition(isLayer)}};Dialog.prototype.showMessageDialog=function(title,message){this.title=title;this.message=message;this.prepareDialog(false)};Dialog.prototype.showConfirmDialog=function(title,message,optionType,functionHandler){this.title=title;this.message=message;this.dialogType=this.constants.DIALOG_TYPE_CONFIRM;this.optionType=optionType;this.functionHandler=functionHandler;this.prepareDialog(false)};Dialog.prototype.showInputDialog=function(title,message,functionHandler){this.title=title;this.message=message;this.dialogType=this.constants.DIALOG_TYPE_INPUT;this.functionHandler=functionHandler;this.prepareDialog(false)};Dialog.prototype.showLayerDialog=function(layer,parent,closeButton,effect,positionTop,positionLeft,functionHandler){this.layer=layer;if(layer){layer.style.height="";layer.style.position="relative"}this.parent=parent;this.bgColor="";this.closeButton=closeButton;this.effect=effect;if((positionTop)&&(positionLeft)){this.positionTop=positionTop;this.positionLeft=positionLeft}this.functionHandler=functionHandler;this.prepareDialog(true);if(this.effect==true){var dialogObject=this}else{this.layer.style.visibility="visible"}};
