﻿/**
 * streamCaseStudiesMin.js
 * Stream.CaseStudes used to manage the search feature on the case studies pages throughout streamrealty.com
 *
 * @author Jeremy Burton
 * Developed by SohoPros Inc. for Stream Realty Partners
 * Last update: Tuesday, June 23 2009.
 */

Stream.CaseStudies=(function(){var caseStudies=[];var locText=['Dallas','Austin','Houston','San Antonio','Atlanta','Orange County'];var cs=['Advisory Services','Asset Management','Construction Management','Due Diligence','Investment Sales','Marketing','Project Leasing','Property Management','Sustainability Services','Tenant Representation'];function getCsSuccess(result){if((result)&&(result.length>0)){caseStudies=[];caseStudies=result;var tbl=buildTable(result);var numResults=new Element('div').insert(result.length+' Case Studies Found:').setStyle({color:'#807f83',fontSize:'11pt',fontWeight:'bold',marginBottom:'5px'});updateResults(numResults,'#807f83').insert(tbl).setStyle({display:'none'});$j('#caseStudiesResults').slideDown(500,function(){btnSearch.disabled=false;});}else if((result)&&(result.length==0)){updateResults('No results found.','#807f83');btnSearch.disabled=false;}}
function getCsFailure(error){updateResults('Error retrieving data.','red');}
function buildTable(result){var tbl=new Element('table').setStyle({width:'800px',margin:'0',border:'0'});tbl.id='tblCaseStudies';tbl.cellSpacing=0;tbl.cellPadding=0;var tbdy=new Element('tbody');tbl.appendChild(tbdy);var trHead=new Element('tr');var th1=new Element('th').insert('Name');trHead.appendChild(th1);var th2=new Element('th').insert('City');trHead.appendChild(th2);var th3=new Element('th').insert('Type');trHead.appendChild(th3);var th4=new Element('th').insert('Secondary Services');trHead.appendChild(th4);tbdy.appendChild(trHead);for(var i=0;i<result.length;i++){var tr=new Element('tr');i%2==0?tr.addClassName('csResultsTblRowAlt'):tr.addClassName('csResultsTblRow');var td1=new Element('td').addClassName('csResultsTblCell');td1.id=i;var type=result[i].type+' - ';var location=result[i].location;var a=new Element('a',{href:'http://www.streamrealty.com/pdfs/casestudies/'+result[i].url,target:'_blank'}).update('Case Study &#8212; <em>'+location+'</em> (pdf)').setStyle({textDecoration:'none',color:'#807f83'});a.onclick=function(){return false};td1.insert(a);tr.appendChild(td1);var td2=new Element('td').insert(result[i].city).addClassName('csResultsTblCell');tr.appendChild(td2);var td3=new Element('td').insert(result[i].type).addClassName('csResultsTblCell');tr.appendChild(td3);var str='';var services=result[i].secondType.split(',');if(services.length>0){services.each(function(item){if(str.length>0)str+=', ';str+=cs[item-1];});}
var td4=new Element('td').insert(str).addClassName('csResultsTblCell');tr.appendChild(td4);$j(tr).hover(function(){SCS.curClassName=this.className;$(this).toggleClassName('csResultsTblRowHover');},function(){$(this).removeClassName('csResultsTblRowHover');$(this).addClassName(SCS.curClassName);});$j(tr).click(function(){$(this).select('a').each(function(item){window.open(item);});});tbdy.appendChild(tr);}
return tbl;}
function updateResults(text,textColor){if((text)&&(textColor))$('caseStudiesResults').update(text).setStyle({color:textColor});return $('caseStudiesResults');}
return{loc:-1,curClassName:null,init:function(){if(SCS.loc!=-1){ddlCity.length=0;var optn=document.createElement('option');var index=SCS.loc/1000-1;optn.text=locText[index];optn.value=SCS.loc;ddlCity.options.add(optn);}},search:function(){btnSearch.disabled=true;updateResults('Searching...','red');var search=$F(tbLocSearch);var city=$F(ddlCity);var type=$F(ddlTypes);var secondType=$F(ddlServicesSecondTypes);var count=0;var str='';cbCsSecondtypes.select('input').each(function(item){if(item.checked){var index=count+1;if(str.length>0)str+=',';str+=index;}
count++;});if((city==0)&&(type==0)&&(str=='')){wsCaseStudies.getCaseStudies(search,getCsSuccess,getCsFailure);}else if((city>0)&&(type==0)&&(str=='')){wsCaseStudies.getCaseStudiesByCity(city,search,getCsSuccess,getCsFailure);}else if((city>0)&&(type>0)&&(str=='')){wsCaseStudies.getCaseStudiesByCityAndType(city,type,search,getCsSuccess,getCsFailure);}else if((city>0)&&(type==0)&&(str!='')){wsCaseStudies.getCaseStudiesByCityAndSecondType(city,str,search,getCsSuccess,getCsFailure);}else if((city>0)&&(type>0)&&(str!='')){wsCaseStudies.getCaseStudiesByCityAndTypeAndSecondType(city,type,str,search,getCsSuccess,getCsFailure);}else if((city==0)&&(type>0)&&(str=='')){wsCaseStudies.getCaseStudiesByType(type,search,getCsSuccess,getCsFailure);}else if((city==0)&&(type>0)&&(str!='')){wsCaseStudies.getCaseStudiesByTypeAndSecondType(type,str,search,getCsSuccess,getCsFailure);}else if((city==0)&&(type==0)&&(str!='')){wsCaseStudies.getCaseStudiesBySecondType(str,search,getCsSuccess,getCsFailure);}
return false;}};})();

