
var Message=Class.create({initialize:function(){this.dimensions={width:860,height:440};this.div_id='message_popup';},send:function(form){if(form.warning_checkbox.checked==true){$('send_message_button').disable();var req=new Ajax.Updater(this.div_id,'/messages/send/',{parameters:form.serialize()});}
return false;},show:function(user_id){var params=new Array();params.push('user_id='+user_id);params=params.join('&');var req=new Ajax.Updater(this.div_id,'/messages/show/',{parameters:params,onSuccess:function(t){$(this.div_id).show();this.center();}.bind(this)});return false;},center:function(){visible=document.viewport.getDimensions();scrolled=document.viewport.getScrollOffsets();l=Math.round(scrolled.left+((visible.width-this.dimensions.width)/2));t=Math.round(scrolled.top+((visible.height-this.dimensions.height)/2));l=(l<0)?0:l;t=(t<0)?0:t;$(this.div_id).style.top=t-60+'px';}});var Search=Class.create({initialize:function(){this.prefix='search_';this.formfield='form_search_form';this.fields=['type[]','skill','stars','city'];this.query='/search';this.skill='/skill:';this.useskill=false;this.stars='/stars:';this.usestars=false;this.type='/type:';this.usetype=false;this.city='/city:';this.usecity=false;this.front_page=true;this.designers_page=true;this.developers_page=true;},search:function(){this.initialize();$(this.formfield).getElements().each(function(key,val){this.fields.each(function(f){if($(key).name==this.prefix+f){switch($(key).name){case'search_type[]':if($(key).checked){if($(key).value=='designer'||$(key).value=='developer'){if(this.type!='/type:'){this.usetype=false;}else{this.usetype=true;this.type+=$(key).value;}}}
break;case'search_skill':if($(key).value!=''){this.useskill=true;this.skill+=$(key).value;}
break;case'search_stars':if($(key).value>0){this.usestars=true;this.stars+=$(key).value;this.designers_page=false;this.developers_page=false;}
break;case'search_city':if($(key).value!=''){this.usecity=true;this.city+=$(key).value;this.designers_page=false;this.developers_page=false;}
break;}}}.bind(this));}.bind(this));if(this.useskill==true){this.query+=this.skill;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.usetype==true){this.query+=this.type;this.front_page=false;if(this.type=='/type:designer'){this.developers_page=false;}else if(this.type=='/type:developer'){this.designers_page=false;}}
if(this.usecity==true){this.query+=this.city;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.usestars==true){this.query+=this.stars;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.front_page==true){window.location='/';return false;}else if(this.designers_page==true){window.location='/designers/';return false;}else if(this.developers_page==true){window.location='/developers/';return false;}
window.location=this.query;return false;}});var SearchStars=Class.create({initialize:function(){this.prefix='search_star_';this.postfix='_img';this.overimg='/assets/images/stars_one_black.gif';this.img='/assets/images/stars_one_largeGrey.gif';this.valuefield='search_stars_value';this.stars=$$('.search_stars');this.run();},run:function(){this.stars.each(function(e){e.observe('mouseover',function(){num=this.id.replace(ss.prefix,'');imgEl=$(this.id+ss.postfix);if(imgEl.src!=ss.overimg){imgEl.src=ss.overimg;}
if(num>1){c=1;while(c<=num){newImg=$(ss.prefix+c+ss.postfix);if(newImg){newImg.src=ss.overimg;}
c++;}}});e.observe('mouseout',function(){c=5;while(c>$F(ss.valuefield)){newImg=$(ss.prefix+c+ss.postfix);if(newImg){newImg.src=ss.img;}
c--;}});e.observe('click',function(){if($(ss.valuefield).value==this.id.replace(ss.prefix,'')){$(ss.valuefield).value=0;}else{$(ss.valuefield).value=this.id.replace(ss.prefix,'');}
c=5;while(c>$F(ss.valuefield)){newImg=$(ss.prefix+c+ss.postfix);if(newImg){newImg.src=ss.img;}
c--;}
return false;});});}});var Flag=Class.create({initialize:function(user_id){this.user_id=user_id;this.alert="Are you sure you want to flag this profile as spam?";return this.run();},run:function(){if(confirm(this.alert)){return this.add(this.user_id);}
return false;},add:function(user_id){var params=new Array();params.push('user_id='+user_id);params=params.join('&');var req=new Ajax.Request('/flags/new/',{parameters:params});return false;}});var Follow=Class.create({initialize:function(follow_id){this.parent_id=follow_id;this.follow_id=follow_id.replace('person_','');this.parent_el=follow_id.replace('person_','person_follow_');this.parent_type='users';this.root_id=this.follow_id;this.root_type=this.parent_type;},follow:function(){var params=new Array();params.push('follow_id='+this.follow_id);params.push('parent_type='+this.parent_type);params.push('root_id='+this.root_id);params.push('root_type='+this.root_type);params=params.join('&');var req=new Ajax.Updater(this.parent_el,'/follow/follow/',{parameters:params});return false;},unfollow:function(){var params=new Array();params.push('follow_id='+this.follow_id);params.push('parent_type='+this.parent_type);params.push('root_id='+this.root_id);params.push('root_type='+this.root_type);params=params.join('&');var req=new Ajax.Updater(this.parent_el,'/follow/unfollow/',{parameters:params});return false;}});var FollowCheck=Class.create({initialize:function(id){this.follow_id=id;this.parent_type='users';this.root_id=this.follow_id;this.root_type=this.parent_type;},follow:function(){var params=new Array();params.push('follow_id='+this.follow_id);params.push('parent_type='+this.parent_type);params.push('root_id='+this.root_id);params.push('root_type='+this.root_type);params=params.join('&');var req=new Ajax.Request('/follow/follow/',{parameters:params});$('staff_follow').addClassName('following');return false;},unfollow:function(){var params=new Array();params.push('follow_id='+this.follow_id);params.push('parent_type='+this.parent_type);params.push('root_id='+this.root_id);params.push('root_type='+this.root_type);params=params.join('&');var req=new Ajax.Request('/follow/unfollow/',{parameters:params});$('staff_follow').removeClassName('following');return false;}});var FollowOut=Class.create({initialize:function(follow_id){this.dimensions={width:860,height:440};this.div_id='message_popup';this.parent_id=follow_id;this.follow_id=follow_id.replace('person_','');this.parent_el=follow_id.replace('person_','person_follow_');},show:function(){var params=new Array();params.push('user_id='+this.follow_id);params=params.join('&');var req=new Ajax.Updater(this.div_id,'/follow/show/',{parameters:params,onSuccess:function(t){$(this.div_id).show();this.center();}.bind(this)});return false;},center:function(){visible=document.viewport.getDimensions();scrolled=document.viewport.getScrollOffsets();l=Math.round(scrolled.left+((visible.width-this.dimensions.width)/2));t=Math.round(scrolled.top+((visible.height-this.dimensions.height)/2));l=(l<0)?0:l;t=(t<0)?0:t;$(this.div_id).style.top=t-60+'px';}});var SearchForm=Class.create({initialize:function(){this.prefix='search_form_';this.formfield='form_search_form_form';this.fields=['type[]','skill','stars','city'];this.query='/search';this.skill='/skill:';this.useskill=false;this.stars='/stars:';this.usestars=false;this.type='/type:';this.usetype=false;this.city='/city:';this.usecity=false;this.front_page=true;this.designers_page=true;this.developers_page=true;},search:function(){this.initialize();$(this.formfield).getElements().each(function(key,val){this.fields.each(function(f){if($(key).name==this.prefix+f){switch($(key).name){case'search_form_type[]':if($(key).checked){if($(key).value=='designer'||$(key).value=='developer'){if(this.type!='/type:'){this.usetype=false;}else{this.usetype=true;this.type+=$(key).value;}}}
break;case'search_form_skill':if($(key).value!=''){this.useskill=true;this.skill+=$(key).value;}
break;case'search_form_stars':if($(key).value>0){this.usestars=true;this.stars+=$(key).value;this.designers_page=false;this.developers_page=false;}
break;case'search_form_city':if($(key).value!=''){this.usecity=true;this.city+=$(key).value;this.designers_page=false;this.developers_page=false;}
break;}}}.bind(this));}.bind(this));if(this.useskill==true){this.query+=this.skill;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.usetype==true){this.query+=this.type;this.front_page=false;if(this.type=='/type:designer'){this.developers_page=false;}else if(this.type=='/type:developer'){this.designers_page=false;}}
if(this.usecity==true){this.query+=this.city;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.usestars==true){this.query+=this.stars;this.designers_page=false;this.developers_page=false;this.front_page=false;}
if(this.front_page==true){window.location='/';return false;}else if(this.designers_page==true){window.location='/designers/';return false;}else if(this.developers_page==true){window.location='/developers/';return false;}
window.location=this.query;return false;}});var SearchStarsForm=Class.create({initialize:function(){this.prefix='search_star_form_';this.postfix='_img';this.overimg='/assets/images/stars_one_black.gif';this.img='/assets/images/stars_one_largeGrey.gif';this.valuefield='search_stars_form_value';this.stars=$$('.search_stars_form');this.run();},run:function(){this.stars.each(function(e){e.observe('mouseover',function(){num=this.id.replace(ssf.prefix,'');imgEl=$(this.id+ssf.postfix);if(imgEl.src!=ssf.overimg){imgEl.src=ssf.overimg;}
if(num>1){c=1;while(c<=num){newImg=$(ssf.prefix+c+ssf.postfix);if(newImg){newImg.src=ssf.overimg;}
c++;}}});e.observe('mouseout',function(){c=5;while(c>$F(ssf.valuefield)){newImg=$(ssf.prefix+c+ssf.postfix);if(newImg){newImg.src=ssf.img;}
c--;}});e.observe('click',function(){if($(ssf.valuefield).value==this.id.replace(ssf.prefix,'')){$(ssf.valuefield).value=0;}else{$(ssf.valuefield).value=this.id.replace(ssf.prefix,'');}
c=5;while(c>$F(ssf.valuefield)){newImg=$(ssf.prefix+c+ssf.postfix);if(newImg){newImg.src=ssf.img;}
c--;}
return false;});});}});var Map=Class.create({initialize:function(){this.log=false;this.div_id='map_itself';this.map=null;this.geocoder=new GClientGeocoder();this.markers=new Array();this.bounds=new GLatLngBounds();},load:function(){if(GBrowserIsCompatible()){this.map=new GMap2($(this.div_id));this.map.addControl(new GSmallMapControl());this.map.setCenter(new GLatLng(20,-10),2);}},loadData:function(data){data.each(function(el){this.plot(el);this._log("geocode : "+el);}.bind(this));},plot:function(data){marker=new GMarker(new GLatLng(data.lat,data.lng));this.map.addOverlay(marker);marker.bindInfoWindow(this.buildInfoWindow(data));this.markers.push(marker);},geocode:function(data){this.geocoder.getLatLng(data.city,function(point){if(!point){this._log(data.city+" not found");}else{marker=new GMarker(point);this.map.addOverlay(marker);marker.bindInfoWindow(this.buildInfoWindow(data));this.markers.push(marker);}}.bind(this));},centerAndZoom:function(){this.markers.each(function(marker){this.bounds.extend(marker.getLatLng());}.bind(this));this.map.setCenter(this.bounds.getCenter());zoom=this.map.getBoundsZoomLevel(this.bounds);if(zoom>10){zoom=10;}
this.map.setZoom(zoom);},buildInfoWindow:function(data){tmpl=new Template('<div id="map_city"><h1 class="no_bottom_margin"><a href="/search/city:#{citylink}">#{city}</a></h1> '+'<p class="grey no_bottom_margin"><a href="/search/city:#{citylink}/type:designer/">#{designers} #{designer_label}</a> | <a href="/search/city:#{citylink}/type:developer/">#{developers} #{developer_label}</a></p>'+'</div>');cityData={city:data.city,citylink:data.city.toLowerCase(),designers:data.designers,developers:data.developers,designer_label:data.designer_label,developer_label:data.developer_label};return tmpl.evaluate(cityData);},_log:function(str){if(this.log){if(window.console){console.log(str);}else{alert(str);}}}});var Validator=Class.create();Validator.prototype={initialize:function(className,error,test,options){if(typeof test=='function'){this.options=$H(options);this._test=test;}else{this.options=$H(test);this._test=function(){return true};}
this.error=error||'Validation failed.';this.className=className;},test:function(v,elm){return(this._test(v,elm)&&this.options.all(function(p){return Validator.methods[p.key]?Validator.methods[p.key](v,elm,p.value):true;}));}}
Validator.methods={pattern:function(v,elm,opt){return Validation.get('IsEmpty').test(v)||opt.test(v)},minLength:function(v,elm,opt){return v.length>=opt},maxLength:function(v,elm,opt){return v.length<=opt},min:function(v,elm,opt){return v>=parseFloat(opt)},max:function(v,elm,opt){return v<=parseFloat(opt)},notOneOf:function(v,elm,opt){return $A(opt).all(function(value){return v!=value;})},oneOf:function(v,elm,opt){return $A(opt).any(function(value){return v==value;})},is:function(v,elm,opt){return v==opt},isNot:function(v,elm,opt){return v!=opt},equalToField:function(v,elm,opt){return v==$F(opt)},notEqualToField:function(v,elm,opt){return v!=$F(opt)},include:function(v,elm,opt){return $A(opt).all(function(value){return Validation.get(value).test(v,elm);})}}
var Validation=Class.create();Validation.prototype={initialize:function(form,options){this.options=Object.extend({onSubmit:true,stopOnFirst:false,immediate:false,focusOnError:true,useTitles:false,onFormValidate:function(result,form){},onElementValidate:function(result,elm){}},options||{});this.form=$(form);if(this.options.onSubmit)Event.observe(this.form,'submit',this.onSubmit.bind(this),false);if(this.options.immediate){var useTitles=this.options.useTitles;var callback=this.options.onElementValidate;Form.getElements(this.form).each(function(input){Event.observe(input,'blur',function(ev){Validation.validate(Event.element(ev),{useTitle:useTitles,onElementValidate:callback});});});}},onSubmit:function(ev){if(!this.validate())Event.stop(ev);},validate:function(){var result=false;var useTitles=this.options.useTitles;var callback=this.options.onElementValidate;if(this.options.stopOnFirst){result=Form.getElements(this.form).all(function(elm){return Validation.validate(elm,{useTitle:useTitles,onElementValidate:callback});});}else{result=Form.getElements(this.form).collect(function(elm){return Validation.validate(elm,{useTitle:useTitles,onElementValidate:callback});}).all();}
if(!result&&this.options.focusOnError){Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()}
this.options.onFormValidate(result,this.form);return result;},reset:function(){Form.getElements(this.form).each(Validation.reset);}}
Object.extend(Validation,{validate:function(elm,options){options=Object.extend({useTitle:false,onElementValidate:function(result,elm){}},options||{});elm=$(elm);var cn=elm.classNames();return result=cn.all(function(value){var test=Validation.test(value,elm,options.useTitle);options.onElementValidate(test,elm);return test;});},test:function(name,elm,useTitle){var v=Validation.get(name);var prop='__advice'+name.camelize();try{if(Validation.isVisible(elm)&&!v.test($F(elm),elm)){if(!elm[prop]){var advice=Validation.getAdvice(name,elm);if(advice==null){var errorMsg=useTitle?((elm&&elm.title)?elm.title:v.error):v.error;advice='<div class="validation-advice" id="advice-'+name+'-'+Validation.getElmID(elm)+'" style="display:none">'+errorMsg+'</div>'
switch(elm.type.toLowerCase()){case'checkbox':case'radio':var p=elm.parentNode;if(p){new Insertion.Bottom(p,advice);}else{new Insertion.After(elm,advice);}
break;default:new Insertion.After(elm,advice);}
advice=Validation.getAdvice(name,elm);}
if(typeof Effect=='undefined'){advice.style.display='block';}else{new Effect.Appear(advice,{duration:1});}}
elm[prop]=true;elm.removeClassName('validation-passed');elm.addClassName('validation-failed');return false;}else{var advice=Validation.getAdvice(name,elm);if(advice!=null)advice.hide();elm[prop]='';elm.removeClassName('validation-failed');elm.addClassName('validation-passed');return true;}}catch(e){throw(e)}},isVisible:function(elm){while(elm.tagName!='BODY'){if(!$(elm).visible())return false;elm=elm.parentNode;}
return true;},getAdvice:function(name,elm){return $('advice-'+name+'-'+Validation.getElmID(elm))||$('advice-'+Validation.getElmID(elm));},getElmID:function(elm){return elm.id?elm.id:elm.name;},reset:function(elm){elm=$(elm);var cn=elm.classNames();cn.each(function(value){var prop='__advice'+value.camelize();if(elm[prop]){var advice=Validation.getAdvice(value,elm);advice.hide();elm[prop]='';}
elm.removeClassName('validation-failed');elm.removeClassName('validation-passed');});},add:function(className,error,test,options){var nv={};nv[className]=new Validator(className,error,test,options);Object.extend(Validation.methods,nv);},addAllThese:function(validators){var nv={};$A(validators).each(function(value){nv[value[0]]=new Validator(value[0],value[1],value[2],(value.length>3?value[3]:{}));});Object.extend(Validation.methods,nv);},get:function(name){return Validation.methods[name]?Validation.methods[name]:Validation.methods['_LikeNoIDIEverSaw_'];},methods:{'_LikeNoIDIEverSaw_':new Validator('_LikeNoIDIEverSaw_','',{})}});Validation.add('IsEmpty','',function(v){return((v==null)||(v.length==0));});Validation.addAllThese([['required','This is a required field.',function(v){return!Validation.get('IsEmpty').test(v);}],['validate-number','Please enter a valid number in this field.',function(v){return Validation.get('IsEmpty').test(v)||(!isNaN(v)&&!/^\s+$/.test(v));}],['validate-digits','Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.',function(v){return Validation.get('IsEmpty').test(v)||!/[^\d]/.test(v);}],['validate-alpha','Please use letters only (a-z) in this field.',function(v){return Validation.get('IsEmpty').test(v)||/^[a-zA-Z]+$/.test(v)}],['validate-alphanum','Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.',function(v){return Validation.get('IsEmpty').test(v)||!/\W/.test(v)}],['validate-date','Please enter a valid date.',function(v){var test=new Date(v);return Validation.get('IsEmpty').test(v)||!isNaN(test);}],['validate-email','Please enter a valid email address. For example fred@domain.com .',function(v){return Validation.get('IsEmpty').test(v)||/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)}],['validate-url','Please enter a valid URL.',function(v){return Validation.get('IsEmpty').test(v)||/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)}],['validate-date-au','Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.',function(v){if(Validation.get('IsEmpty').test(v))return true;var regex=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!regex.test(v))return false;var d=new Date(v.replace(regex,'$2/$1/$3'));return(parseInt(RegExp.$2,10)==(1+d.getMonth()))&&(parseInt(RegExp.$1,10)==d.getDate())&&(parseInt(RegExp.$3,10)==d.getFullYear());}],['validate-currency-dollar','Please enter a valid $ amount. For example $100.00 .',function(v){return Validation.get('IsEmpty').test(v)||/^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)}],['validate-selection','Please make a selection',function(v,elm){return elm.options?elm.selectedIndex>0:!Validation.get('IsEmpty').test(v);}],['validate-one-required','Please select one of the above options.',function(v,elm){var p=elm.parentNode;var options=p.getElementsByTagName('INPUT');return $A(options).any(function(elm){return $F(elm);});}]]);