
function clearField(id){var idVar='#'+id;if(($(idVar).val()=='AaBbCc')||$(idVar).val()=='********'){$(idVar).val('');}}
function facebook_logout()
{window.location='/logout';}
function resetText(id,text){if($(id).val()==""){$(id).val(text);}}
function clearForm(id,value){if($(id).val()==value){$(id).val('');}}
function validateEmail(email){$(".error").hide();var hasError=false;var emailReg=/^([\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4})?$/;if((email=='')||(email=='your email address')){$("#newsLetterBtn").after('<div class="error">You forgot to enter the email address.</span>');hasError=true;}else if(!emailReg.test(email)){$("#newsLetterBtn").after('<div class="error">Please enter a valid email address</span>');hasError=true;}
return false;}
function loginOverlay(headerText,url,xwidth,yheight){if(!headerText){headerText='Sign in to GOOD';}
if(!url){url='/login';}
if(!xwidth){xwidth=550;}
if(!yheight){yheight=430;}
$('<div id=\'overBox\'></div>').html('Form is loading . . .').dialog({autoOpen:false,bgiframe:true,modal:true,resizable:false,closeText:'',closeOnEscape:true,height:yheight,width:xwidth,title:headerText}).load(url).dialog('open');}
var GOOD={domReady:(function(){$(function(){GOOD.domReady=true;});return false;})(),beget:function(o){var F=function(){};F.prototype=o;return new F();},writeCookie:function(name,value,days,path){var date=new Date(),expiry;expiry=(days)?date.setTime(date.getTime()+days*8.64e7).toGMTString():'';path=path||'/';document.cookie=[name+'='+value,'expires='+expiry,'path='+path].join('; ');return this.readCookie(name);},readCookie:function(name){var nameEQ=name+"=",ca=document.cookie.split(';'),c;for(var i=0;i<ca.length;i++){c=ca[i];if(c.charAt(0)===' '){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)===0){return unescape(c.substring(nameEQ.length,c.length));}}
return null;},deleteCookie:function(name){return this.writeCookie(name,'',-1);},user:function(){var cookie=this.readCookie('CakeCookie[good_cookies]'),user;if(cookie){cookie=cookie.split('|');user={link:'/community/'+cookie[0],name:cookie[1]&&cookie[1].replace('+',' '),image:cookie[2]||'http://resource.cloudfront.goodinc.com/v3/images/defaults/avatar135.jpg',fb:cookie[3]>0};}else{user=false;}
return user;},dialog:function(selector,options){var $dialog=$(options&&options.html||'<div/>');function open(url,config){if(url){$.ajax({url:url,success:function(html){var $html=$(html);$(function(){GOOD.form.animateAndReplace($dialog.children(),$html,{hide:($.support.opacity)?['puff',{percent:100},200]:['slide',{},0],show:['slide',{direction:'up'},200],after:function($old,$new){var $dialogContainer=GOOD.form.getAncestor($new,'.ui-dialog');$dialogContainer.animate({top:($(document).scrollTop()+($(window).height()-$dialogContainer.outerHeight())/2)},100);}});});}});$dialog.html('<div class="loading"/>');}
$dialog.dialog(config).parent().find('.ui-dialog-titlebar-close').attr('title','Click here to close this box').end().end().dialog('open');}
options=$.extend({autoOpen:false,bgiframe:true,modal:true,resizable:false,closeText:'',closeOnEscape:true,width:600},options);if(selector){$(selector).each(function(i){options.title=options.title||this.title;$(this).unbind().click(function(e){e.preventDefault();open(options.url||this.href,options);});});}else{open(options.url,options);}
return $dialog;},login:function(postId){GOOD.dialog(null,{url:'/login'+('/'+postId||''),title:'Sign in to GOOD'});},facebookLogin:function(){$.ajax({url:"/users/facebook_login",success:function(userIsNew){if(userIsNew==='1'){var $openDialogs=$('.ui-dialog-content').filter(function(){return $(this).dialog('isOpen');});GOOD.dialog(null,{title:'Facebook',url:'/users/facebook_account',width:900,open:function(){$openDialogs.dialog('close');},close:function(){GOOD.refresh();}});}else{GOOD.refresh();}}});},populateProfile:function($profile){var $loggedInBox=$('<div id="loggedInBox"><div class="profileName floatLeft"><a class="profileLink"></a>&nbsp;<span>(<a style="color:#000" href="/logout" id="logoutLink">logout</a>)</span></div><a class="profileLink"><img id="profileImage" class="floatRight" height="80" width="80" /></a><div class="shareLinks"><a id="shareWindow" class="sharingLinks" href="/posts/add" title="Share Something GOOD">Share</a> something good <br /><a class="sharingLinks" href="/community/">Connect</a> with the community <br /><a class="sharingLinks profileLink">View</a> or <a class="sharingLinks" href="/users/edit">Edit</a> your profile <br /></div></div>'),user=GOOD.user();$profile.hide();if(user){$loggedInBox.find('.profileLink').eq(0).html(user.name).end().attr('href',user.link).end().find('#profileImage').attr({'src':user.image,'alt':user.name,'title':user.name});GOOD.dialog($loggedInBox.find('#shareWindow'));if(user.fb){$loggedInBox.find('#logoutLink').click(function(){FB.Connect.logout(facebook_logout);return false;});}
$profile.empty().append($loggedInBox);}else{GOOD.dialog($profile.find('a[href=/login], a[href=/users/signup]'));}
$profile.show();}};(function(){var partner;if(/ref=msn|msn\.com|bing\.com/.test(document.cookie)||/force=msn/.test(window.location.search)){partner='msn';}
if(/ref=yahoo|yahoo\.com/.test(document.cookie)||/force=yahoo/.test(window.location.search)){partner='yahoo';}
if(partner){document.cookie='ref='+partner+'; path=/;';$.ajax({url:'/ajax/'+partner+'_bar',dataType:'html',success:function(content){var $partnerBar=$('#partnerBar');if($partnerBar.length){$partnerBar.html(content);}else{$('#partnerBar').html(content);}}});}})();