
YAHOO.namespace('housemath');YAHOO.housemath.logotempl=new YAHOO.ext.DomHelper.Template('<div id="logoall"><div id="logoframe"><img src="/images/house2.gif" id="house" width=50 height=50/></div><div id="logosmallpic"><img src="{pic}" id="city" style="" width=0 height=0/></div> </div>');YAHOO.housemath.SwapScenarios=function(pgrid,analysisid){thelayout.pgrid.reload(analysisid);}
YAHOO.housemath.setLogo=function(pgrid,analysisid){YAHOO.housemath.logotempl.overwrite(getEl('logo').dom,{pic:HMLocations.getPicture(analysisid)});thelayout.deallayout.getRegion('center').panels.first().setTitle("<span class='dealpanellabel'>"+HMLocations.getDisplayName(analysisid)+" parameters</span>");swaplogo2();}
YAHOO.namespace('ext.grid');YAHOO.namespace('ext.grid');YAHOO.ext.grid.MoneyEditor=function(){};YAHOO.ext.grid.DollarMoneyRenderer=function(amount){var nf=new NumberFormat(amount);nf.setPlaces(0);nf.setCurrency(true);return nf.toFormatted();};YAHOO.ext.grid.PctRenderer=function(amount){var nf=new NumberFormat(amount);nf.setPlaces(-1);nf.setCurrency(false);return nf.toFormatted();};YAHOO.ext.grid.NumberRenderer=function(amount){var nf=new NumberFormat(amount);nf.setPlaces(0);nf.setCurrency(false);return nf.toFormatted();};YAHOO.ext.grid.YesNoRenderer=function(value){if(value==1)
return"Yes";else
return"No";};YAHOO.ext.bselect=function(){return YAHOO.ext.DomHelper.append(document.body,{tag:'select',cls:'ygrid-editor',children:[{tag:'option',value:1,html:'Yes'},{tag:'option',value:0,html:'No'}]});}
YAHOO.ext.grid.HMJSONParameterDataModel=function(grid){this.grid=grid;YAHOO.ext.grid.HMJSONParameterDataModel.superclass.constructor.call(this);this.callback={success:this.loaded,scope:this};this.setValueAtDelegate=this.setValueAt.createDelegate(this);this.editors=null;this.renderers=null;this.styles=null;this.nexttabs=null;this.prevtabs=null;}
YAHOO.extendX(YAHOO.ext.grid.HMJSONParameterDataModel,YAHOO.ext.grid.LoadableDataModel,{addStyle:function(rowIndex,style)
{if(!this.styles[rowIndex])
{this.styles[rowIndex]=style}
else
{this.styles[rowIndex]+=" "+style}},getStyles:function(rowIndex)
{return this.styles[rowIndex];},setValueAt:function(value,rowIndex,colIndex){this.data[rowIndex][colIndex]=value;this.addStyle(rowIndex,'modified');this.fireCellUpdated(rowIndex,colIndex);},nextTab:function(row)
{return this.nexttabs[row];},prevTab:function(row)
{return this.prevtabs[row];},load:function(analysisid){this.grid.analysisid=analysisid;YAHOO.util.Connect.asyncRequest('GET','/analysis/gridparts?analysisid='+analysisid,this.callback)},loadkey:function(key){YAHOO.util.Connect.asyncRequest('GET','/analysis/gridparts?key='+key,this.callback)},reload:function(analysisid){config=this.grid.config;config.dataModel=new YAHOO.ext.grid.HMJSONParameterDataModel(this);YAHOO.ext.util.Config.apply(this.grid,config);config.dataModel.load(analysisid);return this;},loaded:function(o)
{data=eval(o.responseText);rdata=new Array(data.length);this.editors=new Array(data.length);this.renderers=new Array(data.length);this.styles=new Array(data.length);this.nexttabs=new Array();this.prevtabs=new Array();SECTIONCOL=3;for(var i=0;i<data.length;i++){rdata[i]=(data[i].data);ed=(data[i].editor);if(ed)
{edparams={allowBlak:false};switch(ed.type){case'money':edparams.allowBlank=false;if(ed.min){edparams.minValue=ed.min;}
if(ed.max){edparams.maxValue=ed.max;}
if(ed.neg){edparams.allowNegative=true;}
else
{edparams.allowNegative=false;}
this.editors[i]=new YAHOO.ext.grid.NumberEditor(edparams);break;case'percent':edparams.allowBlank=false;if(ed.min){edparams.minValue=ed.min;}
if(ed.max){edparams.maxValue=ed.max;}
if(ed.neg){edparams.allowNegative=true;}
else
{edparams.allowNegative=false;}
this.editors[i]=new YAHOO.ext.grid.NumberEditor(edparams);break;case'number':edparams.allowBlank=false;if(ed.min){edparams.minValue=ed.min;}
if(ed.max){edparams.maxValue=ed.max;}
if(ed.neg){edparams.allowNegative=true;}
else{edparams.allowNegative=false;}
if(ed.dec){if(ed.dec===0){edparams.allowDecimals=false;}
else
{edparam.allowDecimals=true;edparams.decimalPrecision=ed.dec;}}
this.editors[i]=new YAHOO.ext.grid.NumberEditor(edparams);break;case'yesno':this.editors[i]=new YAHOO.ext.grid.SelectEditor(new YAHOO.ext.bselect());}}
rend=data[i].renderer;switch(rend){case'money':this.renderers[i]=YAHOO.ext.grid.DollarMoneyRenderer;break;case'percent':this.renderers[i]=YAHOO.ext.grid.PctRenderer;break;case'yesno':this.renderers[i]=YAHOO.ext.grid.YesNoRenderer;break;default:this.renderers[i]=YAHOO.ext.grid.NumberRenderer;}}
for(i=0;i<data.length;i++){this.nexttabs[i]=null;if(data[i].data[SECTIONCOL]!='section')
{for(j=i+1;j<data.length;j++){if(data[j].data[SECTIONCOL]!='section')
{this.nexttabs[i]=j;break;}}}}
for(i=data.length-1;i>=0;i--){this.prevtabs[i]=null;if(data[i].data[SECTIONCOL]!='section')
{for(j=i-1;j>=0;j--){if(data[j].data[SECTIONCOL]!='section')
{this.prevtabs[i]=j;break;}}}}
this.data=rdata;thelayout.gridpanel.monitorWindowResize=true;this.grid.loading=false;this.grid.render();YAHOO.housemath.setLogo(this,this.grid.analysisid);}});YAHOO.ext.grid.HMJSONColumnModel=function(config,dataModel){this.dataModel=dataModel;YAHOO.ext.grid.HMJSONColumnModel.superclass.constructor.call(this,config);this.renderCellDelegate=this.renderCell.createDelegate(this);};YAHOO.extendX(YAHOO.ext.grid.HMJSONColumnModel,YAHOO.ext.grid.DefaultColumnModel,{renderCell:function(val,rowIndex,colIndex){if(colIndex==1)
{if(!this.dataModel.renderers[colIndex]){renderedValue=YAHOO.ext.grid.DefaultColumnModel.defaultRenderer(val);}else{if(this.dataModel.renderers[rowIndex]){renderedValue=this.dataModel.renderers[rowIndex](val);}
else
{renderedValue=YAHOO.ext.grid.DefaultColumnModel.defaultRenderer(val);}}
var customstyles="";if(this.dataModel.getStyles(rowIndex))
{customstyles=this.dataModel.getStyles(rowIndex);}
return renderedValue;}
else
{if(!this.config[col].renderer){return YAHOO.ext.grid.DefaultColumnModel.defaultRenderer;}}
return this.config[col].renderer;},isCellEditable:function(colIndex,rowIndex){return(colIndex==1&&this.dataModel.editors[rowIndex])},getCellEditor:function(colIndex,rowIndex){return this.dataModel.editors[rowIndex];},getRenderer:function(col){if(col==1){return this.renderCellDelegate;}
return YAHOO.ext.grid.DefaultColumnModel.defaultRenderer;}});YAHOO.ext.grid.HMJSONGridView=function(grid){YAHOO.ext.grid.HMJSONGridView.superclass.constructor.call(this,grid);this.init(grid);this.headtmpl=new YAHOO.ext.DomHelper.Template('<span class="ygrid-header-col" columIndex=0 tabIndex=0><span class="ygrid-cell-text ygrid-cell-header-text">{sectionname}</span></span>');this.headtmpl.compile();this.celltempl=new YAHOO.ext.DomHelper.Template('<span class="ygrid-col ygrid-col-{col} {lst}"}><span class="ygrid-cell-text">{val}</span></span>');this.dealtmpl=new YAHOO.ext.DomHelper.Template('<div class="ygrid-header-col"><div class="ygrid-cell-text ygrid-cell-header-text" style="height: 100%;"><div class="actionsection">{sectionname}</div><div class="actions"><a onclick="YAHOO.housemath.doSearch(\'parameters-grid\');return;" title="Search for properties on Zillow"><img src="images/zbutton.png" id="{srchid}"></img></a></div></div></div>');};YAHOO.extendX(YAHOO.ext.grid.HMJSONGridView,YAHOO.ext.grid.GridView,{renderRow:function(dataModel,row,rowIndex,colCount,renderers){var headerstyle="";var val;if(dataModel.getValueAt(rowIndex,3)=='section')
{if(dataModel.getValueAt(rowIndex,4)=='deal')
{this.dealtmpl.append(row,{sectionname:dataModel.getValueAt(rowIndex,0),srchid:YAHOO.util.Dom.generateId()});}
else
{this.headtmpl.append(row,{sectionname:dataModel.getValueAt(rowIndex,0)});}}
else
{for(var colIndex=0;colIndex<colCount;colIndex++){var td=document.createElement('span');td.className='ygrid-col ygrid-col-'+colIndex+(colIndex==colCount-1?' ygrid-col-last':'');td.columnIndex=colIndex;var customstyle="";if(dataModel.getStyles(rowIndex))
{customstyle=dataModel.getStyles(rowIndex)}
td.tabIndex=0;var span=document.createElement('span');span.className='ygrid-cell-text '+headerstyle+customstyle;td.appendChild(span);if((dataModel.renderers)&&dataModel.renderers[rowIndex])
{val=renderers[colIndex](dataModel.getValueAt(rowIndex,colIndex),rowIndex,colIndex);if(val===''){val='&nbsp;';}
span.innerHTML=val;}
row.appendChild(td);}}},updateCell:function(dataModel,rowIndex,colIndex,options){var bt=this.getBodyTable();var row=bt.childNodes[rowIndex];var cell=row.childNodes[colIndex];var renderer;if((colIndex==1)&&dataModel.renderers[rowIndex])
{renderer=dataModel.renderers[rowIndex];}
else
{renderer=this.grid.colModel.getRenderer(colIndex);}
var val=renderer(dataModel.getValueAt(rowIndex,colIndex),rowIndex,colIndex);if(val===''){val='&nbsp;';}
cell.firstChild.innerHTML=val;if(dataModel.getStyles(rowIndex))
{getEl(cell.firstChild).addClass(dataModel.getStyles(rowIndex));};if(options&&options.title)
{cell.firstChild.parentNode.title=options.title;}},insertRows:function(dataModel,firstRow,lastRow){this.updateBodyHeight();this.adjustForScroll(true);var renderers=this.getColumnRenderers();var colCount=this.grid.colModel.getColumnCount();var beforeRow=null;var bt=this.getBodyTable();if(firstRow<bt.childNodes.length){beforeRow=bt.childNodes[firstRow];}
for(var rowIndex=firstRow;rowIndex<=lastRow;rowIndex++){var row=document.createElement('span');if(dataModel.getValueAt(rowIndex,3)=='section')
{row.className='ygrid-row row-section';}
else
{row.className='ygrid-row';}
row.style.top=(rowIndex*this.rowHeight)+'px';this.renderRow(dataModel,row,rowIndex,colCount,renderers);if(beforeRow){bt.insertBefore(row,beforeRow);}else{bt.appendChild(row);}}
this.updateRowIndexes(firstRow);this.adjustForScroll();}});YAHOO.ext.grid.NumberEditor.prototype.initEvents=function(){var stopOnEnter=function(e){if(e.browserEvent.keyCode==e.RETURN){this.stopEditing(true);}};var allowed="0123456789\x78\x76\x63\x7A";if(this.allowDecimals){allowed+=this.decimalSeparator;}
if(this.allowNegative){allowed+='-';}
var keyPress=function(e){var c=e.getCharCode();if(c!=e.BACKSPACE&&allowed.indexOf(String.fromCharCode(c))===-1){e.stopEvent();}};this.element.mon('keydown',stopOnEnter,this,true);var vtask=new YAHOO.ext.util.DelayedTask(this.validate,this);this.element.mon('keyup',vtask.delay.createDelegate(vtask,[this.validationDelay]));this.element.mon('keypress',keyPress,this,true);this.element.on('blur',this.stopEditing,this,true);};YAHOO.ext.grid.HMJSONEditorSelectionModel=function(){YAHOO.ext.grid.HMJSONEditorSelectionModel.superclass.constructor.call(this);YAHOO.ext.grid.EditorSelectionModel.prototype.disableArrowNavigation=false;};YAHOO.extendX(YAHOO.ext.grid.HMJSONEditorSelectionModel,YAHOO.ext.grid.EditorSelectionModel,{getEditorCellAfter:function(cell,spanRows){var g=this.grid,dm=g.dataModel;cm=g.colModel;var row=g.getRowFromChild(cell);var rowIndex=row.rowIndex;var next;if(dm.nextTab(rowIndex))
{next=g.getRow(dm.nextTab(rowIndex)).childNodes[cell.columnIndex];}
return next;},getEditorCellBefore:function(cell,spanRows){var g=this.grid,dm=g.dataModel;cm=g.colModel;var row=g.getRowFromChild(cell);var rowIndex=row.rowIndex;var prev;if(dm.prevTab(rowIndex))
{prev=g.getRow(dm.prevTab(rowIndex)).childNodes[cell.columnIndex];}
return prev;},initEvents:function(){this.grid.addListener("cellclick",this.onCellClick,this,true);this.grid.addListener("keydown",this.keyDown,this,true);},keyDown:function(e){var g=this.grid,dm=g.dataModel;cm=g.colModel;cell=g.getEditingCell();dm=g.dataModel;if(!cell){return;}
var newCell;var newRow;var submitThis=false;switch(e.browserEvent.keyCode){case e.TAB:if(e.shiftKey){newCell=this.getEditorCellBefore(cell,true);}else{newCell=this.getEditorCellAfter(cell,true);}
break;case e.RETURN:if(e.shiftKey)
{submitThis=true;}
else
{newCell=this.getEditorCellAfter(cell,true);}
break;case e.DOWN:newCell=this.getEditorCellAfter(cell,true);break;case e.UP:newCell=this.getEditorCellBefore(cell,true);break;case e.RIGHT:newCell=this.getEditorCellAfter(cell);break;case e.LEFT:newCell=this.getEditorCellBefore(cell);break;}
if(newCell){e.stopEvent();row=g.getRowFromChild(newCell);this.grid.startEditing(row.rowIndex,newCell.columnIndex);}
if(submitThis)
{e.stopEvent();sumbitThis=false;this.grid.stopEditing();g.loading=false;var stask=new YAHOO.ext.util.DelayedTask(this.grid.submit,this.grid);stask.delay(200);}}});YAHOO.ext.grid.JSONParameterGrid=function(div,options){this.analysisid=null||options.analysisid;this.key=null||options.key;this.myData=null;this.div=div;this.submiturl=options.submiturl||null;this.outdiv=options.outdiv||null;this.loading=false;this.setup={SECTIONCOL:3};var dataModel=new YAHOO.ext.grid.HMJSONParameterDataModel(this);this.myColumns=[{header:"Variable",width:150,hidden:false},{header:"Value",width:65,hidden:false},{header:"Units",width:40,hidden:false},{header:"secname",width:0,hidden:true},{header:"vname",width:0,hidden:true}];var colModel=new YAHOO.ext.grid.HMJSONColumnModel(this.myColumns,dataModel);var selModel=new YAHOO.ext.grid.HMJSONEditorSelectionModel();this.config={dataModel:dataModel,colModel:colModel,selModel:selModel,autoHeight:true,autoSizeColumns:false};YAHOO.ext.grid.JSONParameterGrid.superclass.constructor.call(this,this.div,this.config);this.view=new YAHOO.ext.grid.HMJSONGridView(this);this.autoHeight=true;};YAHOO.extendX(YAHOO.ext.grid.JSONParameterGrid,YAHOO.ext.grid.Grid,{loadandrender:function(analysisid){this.dataModel.load(analysisid);},load:function(analysisid)
{this.dataModel.load(analysisid);},loadkey:function(key)
{this.dataModel.loadkey(key);},reload:function(analysisid)
{newconfig=this.config;newconfig.dataModel=new YAHOO.ext.grid.HMJSONParameterDataModel(this);newconfig.colModel=new YAHOO.ext.grid.HMJSONColumnModel(this.myColumns,newconfig.dataModel);this.reset(newconfig);this.view=new YAHOO.ext.grid.HMJSONGridView(this);this.load(analysisid);},setConfig:function(vars){this.myData=eval(vars);},getData:function(){return this.myData;},onBodyScroll:function(top,left){if(window.parametertip)
{parametertip.hide();}},getGrid:function(){return this.grid;},gridToPar:function()
{var paramstring="";for(i=0;i<this.dataModel.getRowCount();i++){if(this.dataModel.getRow(i)[this.setup.SECTIONCOL]!="section")
{paramstring+=escape(this.dataModel.getRow(i)[this.setup.SECTIONCOL]+"["+this.dataModel.getRow(i)[4]+"]");paramstring+="="+this.dataModel.getRow(i)[1]+"&";}}
return paramstring+"scenario="+$('scenario').value;},setVariable:function(section,variable,val,options)
{for(i=0;i<this.dataModel.getRowCount();i++){if(this.dataModel.getRow(i)[this.setup.SECTIONCOL]==section)
{if(this.dataModel.getRow(i)[4]==variable)
{this.dataModel.getRow(i)[1]=val;this.dataModel.addStyle(i,'extern');this.view.updateCell(this.dataModel,i,1,options);}}}},findSection:function(sectionname){for(i=0;i<this.rows.length;i++){if(this.dataModel.getRow(i)[4]==sectionname)
{return this.rows[i];}}
return null;},submit:function()
{if(!this.loading)
{this.loading=true;jx=new Ajax.Updater(this.outdiv,this.submiturl,{asynchronous:true,evalScripts:true,parameters:this.gridToPar(),callback:this.gridloaded});}
return false;},gridloaded:function()
{alert('loaded');this.loading=false;},getGridCell:function(row,col)
{var thecell;if(this.dataModel.getRow(row))
thecell=this.dataModel.getRow(row)[col];return thecell;}});