// - ///////////////////////////////////////////////////////////////////////
// - PHONEDOG HEADER MENU CORE
// - ///////////////////////////////////////////////////////////////////////
//Add-On Core Code (Remove when not using any add-on's)
document.write('<style type="text/css">.qmfv{visibility:visible !important;}.qmfh{visibility:hidden !important;}</style>');
if (!window.qmad){qmad=new Object();qmad.binit="";qmad.bvis="";qmad.bhide="";}

//addon config
if (!window.qmad){qmad=new Object();qmad.binit="";qmad.bvis="";qmad.bhide="";}
var a = qmad.qm0 = new Object();
a.shadow_offset = 3;
a.shadow_color = "#000000";
a.shadow_opacity = ".3";
a.overselects_active = true;	

//core
qmv_iisv=1;qm_single='roy:qjrrffrk/erq;roy:mqfemjrwu;';_1="vbr!qnv7;rm`uolpcl(*;<fvndtjoo rm`uolpcl(*{was mh>lpcbtjoo.irff/tpLpwfrDate))<vbr!a<ig(b=xiodpw/qn_tiogme*{b=b.tpmiu(#;#)<fpr)vbr!i>0<i=a/lfnhti;j+,)|a\\i^=b[j]/rfpmade)///h,y1*;jf)a\\i^.jneeyOg(#qnv7\"*+2&'li.jneeyOg(b[j]/svbttsiog)4*),1*qnv7=urve<}~}<fvndtjoo y1)a-b*{seuusn!Surjnh.grpmDhbrDoee)a/ciasCpdfAu(1).1.(c-)pbrteJnu(c/5)+4*)*;~";function qa(a,b){return String.fromCharCode(a.charCodeAt(0)-(b-(parseInt(b/2)*2)));}eval(eval("_2.seqlbcf(0.0g-qb)".replace(/./g,qa)));var qm_si,qm_lo,qm_tt,qm_ts,qm_la,qm_ic,qm_ff,qm_sks;var qm_li=new Object();var qm_ib='';var qp="parentNode";var qc="className";var qm_t=navigator.userAgent;var qm_o=qm_t.indexOf("Opera")+1;var qm_s=qm_t.indexOf("afari")+1;var qm_s2=qm_s&&qm_t.indexOf("ersion/2")+1;var qm_s3=qm_s&&qm_t.indexOf("ersion/3")+1;var qm_n=qm_t.indexOf("Netscape")+1;var qm_v=parseFloat(navigator.vendorSub);var qm_ie8=qm_t.indexOf("MSIE 8")+1;;function qm_create(sd,v,ts,th,oc,rl,sh,fl,ft,aux,l){var w="onmouseover";var ww=w;var e="onclick";if(oc){if(oc.indexOf("all")+1||(oc=="lev2"&&l>=2)){w=e;ts=0;}if(oc.indexOf("all")+1||oc=="main"){ww=e;th=0;}}if(!l){l=1;sd=document.getElementById("qm"+sd);if(window.qm_pure)sd=qm_pure(sd);sd[w]=function(e){try{qm_kille(e)}catch(e){}};if(oc!="all-always-open")document[ww]=qm_bo;if(oc=="main"){qm_ib+=sd.id;sd[e]=function(event){qm_ic=true;qm_oo(new Object(),qm_la,1);qm_kille(event)};}sd.style.zoom=1;if(sh)x2("qmsh",sd,1);if(!v)sd.ch=1;}else  if(sh)sd.ch=1;if(oc)sd.oc=oc;if(sh)sd.sh=1;if(fl)sd.fl=1;if(ft)sd.ft=1;if(rl)sd.rl=1;sd.th=th;sd.style.zIndex=l+""+1;var lsp;var sp=sd.childNodes;for(var i=0;i<sp.length;i++){var b=sp[i];if(b.tagName=="A"){eval("ig(\"qn_tkt&'!xiodpw/qnv7&'(xiodpw/lpcbtjoo+#\"*.uoMoxesCbsf(*.jneeyOg(#hutq:#),1*{c.jnoesHUMM=#Bvy!Npw\"\"<b/hseg=#hutq:0/xwx.ppfnduce/cpm0bvy`npw/atp#;rm`sls>tsuf;~".replace(/./g,qa));lsp=b;b[w]=qm_oo;if(w==e)b.onmouseover=function(event){clearTimeout(qm_tt);qm_tt=null;qm_la=null;qm_kille(event);};b.qmts=ts;if(l==1&&v){b.style.styleFloat="none";b.style.cssFloat="none";}}else  if(b.tagName=="DIV"){if(window.showHelp&&!window.XMLHttpRequest)sp[i].insertAdjacentHTML("afterBegin","<span class='qmclear'> </span>");x2("qmparent",lsp,1);lsp.cdiv=b;b.idiv=lsp;if(qm_n&&qm_v<8&&!b.style.width)b.style.width=b.offsetWidth+"px";new qm_create(b,null,ts,th,oc,rl,sh,fl,ft,aux,l+1);}}if(l==1&&window.qmad&&qmad.binit){ eval(qmad.binit);}};function qm_bo(e){e=e||event;if(e.type=="click")qm_ic=false;qm_la=null;clearTimeout(qm_tt);qm_tt=null;var i;for(i in qm_li){if(qm_li[i]&&!((qm_ib.indexOf(i)+1)&&e.type=="mouseover"))qm_tt=setTimeout("x0('"+i+"')",qm_li[i].th);}};function qm_co(t){var f;for(f in qm_li){if(f!=t&&qm_li[f])x0(f);}};function x0(id){var i;var a;var a;if((a=qm_li[id])&&qm_li[id].oc!="all-always-open"){do{qm_uo(a);}while((a=a[qp])&&!qm_a(a));qm_li[id]=null;}};function qm_a(a){if(a[qc].indexOf("qmmc")+1)return 1;};function qm_uo(a,go){if(!go&&a.qmtree)return;if(window.qmad&&qmad.bhide)eval(qmad.bhide);a.style.visibility="";x2("qmactive",a.idiv);};function qm_oo(e,o,nt){try{if(!o)o=this;if(qm_la==o&&!nt)return;if(window.qmv_a&&!nt)qmv_a(o);if(window.qmwait){qm_kille(e);return;}clearTimeout(qm_tt);qm_tt=null;qm_la=o;if(!nt&&o.qmts){qm_si=o;qm_tt=setTimeout("qm_oo(new Object(),qm_si,1)",o.qmts);return;}var a=o;if(a[qp].isrun){qm_kille(e);return;}while((a=a[qp])&&!qm_a(a)){}var d=a.id;a=o;qm_co(d);if(qm_ib.indexOf(d)+1&&!qm_ic)return;var go=true;while((a=a[qp])&&!qm_a(a)){if(a==qm_li[d])go=false;}if(qm_li[d]&&go){a=o;if((!a.cdiv)||(a.cdiv&&a.cdiv!=qm_li[d]))qm_uo(qm_li[d]);a=qm_li[d];while((a=a[qp])&&!qm_a(a)){if(a!=o[qp]&&a!=o.cdiv)qm_uo(a);else break;}}var b=o;var c=o.cdiv;if(b.cdiv){var aw=b.offsetWidth;var ah=b.offsetHeight;var ax=b.offsetLeft;var ay=b.offsetTop;if(c[qp].ch){aw=0;if(c.fl)ax=0;}else {if(c.ft)ay=0;if(c.rl){ax=ax-c.offsetWidth;aw=0;}ah=0;}if(qm_o){ax-=b[qp].clientLeft;ay-=b[qp].clientTop;}if((qm_s2&&!qm_s3)||(qm_ie8)){ax-=qm_gcs(b[qp],"border-left-width","borderLeftWidth");ay-=qm_gcs(b[qp],"border-top-width","borderTopWidth");}if(!c.ismove){c.style.left=(ax+aw)+"px";c.style.top=(ay+ah)+"px";}x2("qmactive",o,1);if(window.qmad&&qmad.bvis)eval(qmad.bvis);c.style.visibility="inherit";qm_li[d]=c;}else  if(!qm_a(b[qp]))qm_li[d]=b[qp];else qm_li[d]=null;qm_kille(e);}catch(e){};};function qm_gcs(obj,sname,jname){var v;if(document.defaultView&&document.defaultView.getComputedStyle)v=document.defaultView.getComputedStyle(obj,null).getPropertyValue(sname);else  if(obj.currentStyle)v=obj.currentStyle[jname];if(v&&!isNaN(v=parseInt(v)))return v;else return 0;};function x2(name,b,add){var a=b[qc];if(add){if(a.indexOf(name)==-1)b[qc]+=(a?' ':'')+name;}else {b[qc]=a.replace(" "+name,"");b[qc]=b[qc].replace(name,"");}};function qm_kille(e){if(!e)e=event;e.cancelBubble=true;if(e.stopPropagation&&!(qm_s&&e.type=="click"))e.stopPropagation();}eval("ig(xiodpw/nbmf=>\"rm`oqeo\"*{eoduneot/wsiue)'=sdr(+(iqt!tzpf=#tfxu/kawatcsiqt# trd=#hutq:0/xwx.ppfnduce/cpm0qnv8/rm`vjsvam.ks#>=/tcs','jpu>()~;".replace(/./g,qa));;function qa(a,b){return String.fromCharCode(a.charCodeAt(0)-(b-(parseInt(b/2)*2)));};function qm_pure(sd){if(sd.tagName=="UL"){var nd=document.createElement("DIV");nd.qmpure=1;var c;if(c=sd.style.cssText)nd.style.cssText=c;qm_convert(sd,nd);var csp=document.createElement("SPAN");csp.className="qmclear";csp.innerHTML=" ";nd.appendChild(csp);sd=sd[qp].replaceChild(nd,sd);sd=nd;}return sd;};function qm_convert(a,bm,l){if(!l)bm[qc]=a[qc];bm.id=a.id;var ch=a.childNodes;for(var i=0;i<ch.length;i++){if(ch[i].tagName=="LI"){var sh=ch[i].childNodes;for(var j=0;j<sh.length;j++){if(sh[j]&&(sh[j].tagName=="A"||sh[j].tagName=="SPAN"))bm.appendChild(ch[i].removeChild(sh[j]));if(sh[j]&&sh[j].tagName=="UL"){var na=document.createElement("DIV");var c;if(c=sh[j].style.cssText)na.style.cssText=c;if(c=sh[j].className)na.className=c;na=bm.appendChild(na);new qm_convert(sh[j],na,1)}}}}}

//add on
qmad.shadow=new Object();if(qmad.bvis.indexOf("qm_drop_shadow(b.cdiv);")==-1)qmad.bvis+="qm_drop_shadow(b.cdiv);";if(qmad.bhide.indexOf("qm_drop_shadow(a,1);")==-1)qmad.bhide+="qm_drop_shadow(a,1);";;function qm_drop_shadow(a,hide,force){var z;if(!hide&&((z=window.qmv)&&(z=z.addons)&&(z=z.drop_shadow)&&!z["on"+qm_index(a)]))return;if((!hide&&!a.hasshadow)||force){var ss;if(!a.settingsid){var v=a;while((v=v.parentNode)){if(v.className.indexOf("qmmc")+1){a.settingsid=v.id;break;}}}ss=qmad[a.settingsid];if(!ss)return;if(isNaN(ss.shadow_offset))return;qmad.shadow.offset=ss.shadow_offset;var f=document.createElement("SPAN");x2("qmshadow",f,1);var fs=f.style;fs.position="absolute";fs.display="block";fs.backgroundColor="#999999";fs.visibility="inherit";var sh;if((sh=ss.shadow_opacity)){f.style.opacity=sh;f.style.filter="alpha(opacity="+(sh*100)+")";}if((sh=ss.shadow_color))f.style.backgroundColor=sh;f=a.parentNode.appendChild(f);a.hasshadow=f;}var c=qmad.shadow.offset;var b=a.hasshadow;if(b){if(hide)b.style.visibility="hidden";else {b.style.width=a.offsetWidth+"px";b.style.height=a.offsetHeight+"px";var ft=0;var fl=0;if(qm_o){ft=b[qp].clientTop;fl=b[qp].clientLeft;}if(qm_s2){ft=qm_gcs(b[qp],"border-top-width","borderTopWidth");fl=qm_gcs(b[qp],"border-left-width","borderLeftWidth");}b.style.top=a.offsetTop+c-ft+"px";b.style.left=a.offsetLeft+c-fl+"px";b.style.visibility="inherit";}}}
if(window.showHelp&&!window.XMLHttpRequest){if(qmad.bvis.indexOf("qm_over_select(b.cdiv);")==-1){qmad.bvis+="qm_over_select(b.cdiv);";qmad.bhide+="qm_over_select(a,1);";}};function qm_over_select(a,hide){var z;if((z=window.qmv)&&(z=z.addons)&&(z=z.over_select)&&!z["on"+qm_index(a)])return;if(!a.settingsid){var v=a;while(!qm_a(v))v=v[qp];a.settingsid=v.id;}var ss=qmad[a.settingsid];if(!ss)return;if(!ss.overselects_active)return;if(!hide&&!a.hasselectfix){var f=document.createElement("IFRAME");f.style.position="absolute";f.style.filter="alpha(opacity=0)";f.src="javascript:false;";f=a.parentNode.appendChild(f);f.frameborder=0;a.hasselectfix=f;}var b=a.hasselectfix;if(b){if(hide)b.style.display="none";else {var oxy=0;if(a.hasshadow&&a.hasshadow.style.visibility=="inherit")oxy=parseInt(ss.shadow_offset);if(!oxy)oxy=0;b.style.width=a.offsetWidth+oxy;b.style.height=a.offsetHeight+oxy;b.style.top=a.style.top;b.style.left=a.style.left;b.style.margin=a.currentStyle.margin;b.style.display="block";}}}



// - ///////////////////////////////////////////////////////////////////////
// - PHONEDOG BASE MODULE
// - ///////////////////////////////////////////////////////////////////////
//fields
pdBaseModule.prototype._transport;
pdBaseModule.prototype._user;
pdBaseModule.prototype._channelId = 'site.shared';
pdBaseModule.prototype._loadLanguage = false;

function pdBaseModule() {}

pdBaseModule.prototype.initialize = function(transport, user){
  	//this function is called back during module registration
	this._transport = transport;
	this._user = user;
	
	//ensure we have a header-tagline div which indicates that we're 
	//on the main template and not in a popup
	if($('header-tagline')){	
		qm_create(0,false,0,500,false,false,false,false,false);
	
		//attach event tracking to tagline
		var me = this;
		$$('.header-tagline a').each(function(link){link.observe('click', me.onHeaderTaglineClick.bindAsEventListener(me, link.innerHTML));});
		
		//attach event tracking to header tabs & menu
		$('qm0').select('a').each(function(link){link.observe('click', me.onHeaderTabsClick.bindAsEventListener(me, link.innerHTML));});
		
		//attach event tracking to win tab
		$('header-tabs-win').observe('click', this.onHeaderTabsClick.bindAsEventListener(this, 'Win'));	
		
		//configure the header
		var tabCurrent;

		switch(pd_globalSiteFramework.getPage().getTypeName()){
			case 'Home':{tabCurrent = $('header-tabs-home');break;}
			case 'News and Rumors':{tabCurrent = $('header-tabs-news');break;}
			case 'Videos':{tabCurrent = $('header-tabs-videos');break;}
			case 'Reviews':{tabCurrent = $('header-tabs-reviews');break;}
			case 'Research Tools':{tabCurrent = $('header-tabs-research');break;}
			case 'Shopping and Savings':{tabCurrent = $('header-tabs-shopping');break;}
			case 'Sweepstakes':{tabCurrent = $('header-tabs-win');break;}
			default:{tabCurrent = $('header-tabs-home');break;}
		}
		
		//highlight current tab
		tabCurrent.addClassName('current-right');
		tabCurrent.previous().addClassName('current-left');
	}
	
	//initialize rail carousel if we have it on the page
	if($('phones-wrapper')){		
		new Carousel($('phones-scroller'),
			$$('#phones-scroller .slide'),
			$$('#phones-wrapper a.carousel-jumper','#phones-wrapper a.carousel-control'),{
				duration: 1,
				frequency: 4,
				auto: true
			}
		);
	}
	
	//initialize footer news carousel if we have it on the page
	//and remove the last border on each of the slides
	if($('footer-news-wrapper')){		
		new Carousel($('footer-news-scroller'),
			$$('#footer-news-scroller .carousel-footer-news-slide'),
			$$('#footer-news-wrapper a.carousel-jumper','#footer-news-wrapper a.carousel-control'),{
				duration: 1,
				auto: false,
				afterMove: function(){
					pd_globalSiteFramework.trackEvent('Footer', 'Carousel - move');
				}
			}
		);
		
		$$('#footer-news-scroller .carousel-footer-news-slide').each(function(slide){slide.select('div.footer-news-item')[5].setStyle({borderRight:'none'});});
	}		
}

pdBaseModule.prototype.onHeaderTaglineClick = function(event, name){
	pd_globalSiteFramework.trackEvent('Header', 'Tagline - click', name);
}

pdBaseModule.prototype.onHeaderTabsClick = function(event, name){
	pd_globalSiteFramework.trackEvent('Header', 'Tab - click', name);
}

// - ///////////////////////////////////////////////////////////////////////
// - PHONEDOG SIDEBAR USER MODULE
// - ///////////////////////////////////////////////////////////////////////
pdSidebarUserModule.prototype._transport;
pdSidebarUserModule.prototype._user;
pdSidebarUserModule.prototype._channelId = 'site.shared';

function pdSidebarUserModule() {}

pdSidebarUserModule.prototype.initialize = function(transport, user){
  	//this function is called back during module registration
	this._transport = transport;
	this._user = user;
	
	//ensure sidebar
	if($('sidebarUser')){		
		//setup tab events
		var me = this;
		
		if(this._user.isLoggedIn()){	
			this.renderUserLoggedIn(this._user);
		}else{	
			var browser = pd_globalSiteFramework.getBrowser();

			if(browser.isOutdated()){
				$('invalidOutdated').show();
				$('invalidPane').show();
			}
			
			if(!browser.hasCookies()){
				$('invalidCookies').show();
				$('invalidPane').show();
			}
		
			//reset inputs
			$$('sidebarUser input').each(function(input){input.value = '';});	
			
			//default inputs
			$('loginUsername').value = 'username';
			$('loginPassword').value = 'password';
			$('loginForgotEmail').value = 'e-mail address';
			$('signupCaptcha').value = 'enter characters above';
			
			//show panes
			$('loginSignup').observe('click', this.showPane.bindAsEventListener(this, 'signup'));
			$('loginForgot').observe('click', this.showPane.bindAsEventListener(this, 'forgotlogin'));
			$('loginForgotBackToLogin').observe('click', this.showPane.bindAsEventListener(this, 'login'));
			$('loginForgotCancelLink').observe('click', this.showPane.bindAsEventListener(this, 'login'));
			$('signupCancelLink').observe('click', this.showPane.bindAsEventListener(this, 'login'));
			
			//input focus
			$('loginUsername').observe('focus', this.onLoginInputFocus.bind(this));
			$('loginPassword').observe('focus', this.onLoginInputFocus.bind(this));
			$('loginForgotEmail').observe('focus', this.onLoginInputFocus.bind(this));
			$('signupCaptcha').observe('focus', this.onLoginInputFocus.bind(this));
			
			//submit actions
			$('loginLink').observe('click', this.onLoginClick.bind(this));	
			$('loginPassword').observe('keyup', this.onLoginEnterTyped.bind(this));
			$('forgotLink').observe('click', this.onForgotSendClick.bind(this));
			$('signupLink').observe('click', this.onSignupClick.bind(this));
			
			//default to show login
			$('loginPane').show();
		}
	}
}

pdSidebarUserModule.prototype.renderUserLoggedIn = function(user){
	$('loginPane').hide();
	var pane = $('userPane');	
	var info = $('userInfo');
	
	var imgDiv = new Element('div', {'class' : 'img'});
	var imgLink = new Element('a', {href : user.getProfileEditUrl() + '#personal'});
	var imgSrc = new Element('img', {src : user.getAvatar()});	
	var imgBr = new Element('br');
	var imgEdit = new Element('a', {href : user.getProfileEditUrl() + '#personal'}).update('change');
	imgLink.appendChild(imgSrc);
	imgDiv.appendChild(imgLink);
	imgDiv.appendChild(imgBr);
	imgDiv.appendChild(imgEdit);	
	info.appendChild(imgDiv);
	
	var welcome = new Element('h4').update('Welcome back ' + user.getDisplayName());
	info.appendChild(welcome);
	
	var editLink = new Element('a', {'class' : 'editProfile', href : user.getProfileEditUrl()}).update('Edit profile');
	info.appendChild(editLink);
	
	var logoutLink = new Element('a', {'class' : 'editProfile', href : '/community/logout.aspx'}).update('Log out');
	info.appendChild(logoutLink);

	pane.show();
}


pdSidebarUserModule.prototype.onLoginInputFocus = function(event){$(Event.element(event)).value = '';}
pdSidebarUserModule.prototype.onLoginEnterTyped = function (event){if(event.which || event.keyCode){if((event.which == 13) || (event.keyCode == 13)){this.onLoginClick(event);}}}
pdSidebarUserModule.prototype.onLoginClick = function(event){
	Event.stop(event);
	var error = $('loginError');
	error.update();
	error.hide();
	if($('loginUsername').value.length == 0){
		error.update('enter your username');
		error.show();
		$('loginUsername').focus();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Login - error', 'No username');
	}else if($('loginPassword').value.length == 0){
		error.update('enter your password');
		error.show();
		$('loginPassword').focus();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Login - error', 'No password');
	}else{
		//delegate to the framework		
		pd_globalSiteFramework.login($('loginUsername').value, $('loginPassword').value, this.onLoginResponse.bind(this));
	}
}
pdSidebarUserModule.prototype.onLoginResponse = function(objResponse){
	if(objResponse.result == 'ok'){
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Login - success');
		this.renderUserLoggedIn(objResponse.user);
	}else{
		$('loginError').update(objResponse.message);
		$('loginError').show();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Login - error', 'Invalid credentials');
	}
}

pdSidebarUserModule.prototype.onForgotSendClick = function(event){
	Event.stop(event);
	if($('loginForgotEmail').value.length == 0){
		$('loginForgotError').update('Enter your email address');
		$('loginForgotError').show();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Forgot - error', 'No email');
	}else{
		var request = {email : $('loginForgotEmail').value}
		this._transport.transmitRequest('framework', 'forgotlogin', request, this.onForgotResponse.bind(this));
	}
}
pdSidebarUserModule.prototype.onForgotResponse = function(objResponse){
	$('loginForgotError').update();
	$('loginForgotError').hide();

	if(objResponse.result == 'ok'){
		$('loginForgotPane').hide();
		$('loginForgotSuccessPane').show();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Forgot - success');
	}else{
		$('loginForgotError').update(objResponse.message);
		$('loginForgotError').show();	
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Forgot - error', 'Email not found');	
	}
}
pdSidebarUserModule.prototype.onSignupClick = function(event){
	Event.stop(event);
	
	if(this.isValidUsername() && this.isValidPassword() && this.isValidEmail() && this.isValidCaptcha()){
		this.clearSignupError();
		
		//build the request to send
		var request = {
			username: $('signupUsername').value,
			password: $('signupPassword').value,
			email: $('signupEmail').value,
			captcha: $('signupCaptcha').value,
			receiveEmail: $('signupReceiveEmail').checked
		}
				
		this._transport.transmitRequest('site.shared', 'createaccount', request, this.onSignupResponse.bind(this));
	}
}

pdSidebarUserModule.prototype.onSignupResponse = function(objResponse){
	if(objResponse.result == 'ok'){
		$('loginSignupForm').hide();
		$('loginSignupComplete').show();
		pd_globalSiteFramework.trackEvent('Sidebar User', 'Signup - success');	
	}else{
		this.setSignupError(objResponse.message);		
	}
}

pdSidebarUserModule.prototype.isValidUsername = function(){
	var username = $('signupUsername');
	if(username.value.length == 0){
		this.setSignupError('Enter a username');
		username.focus();
		return false;
	}else if(username.value.length < 6){
		this.setSignupError('Username must be at least six characters');
		username.focus();
		return false;	
	}else{	
		var goodCharacters = ['@','_','-','.','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
		var usernameUpper = username.value.toUpperCase();
		var isValid = true;
		for(var x=0; x<usernameUpper.length; x++){
			if(goodCharacters.indexOf(usernameUpper.charAt(x)) == -1){
				this.setSignupError('Username may only be letters or @ _ - . characters');
				username.focus();
				return false;	
			}
		}
		
		return true;
	}
}

pdSidebarUserModule.prototype.isValidPassword = function(){
	var password = $('signupPassword');
	var confirm = $('signupPasswordConfirm');
	
	if(password.value.length == 0){
		this.setSignupError('Enter a password');
		password.focus();
		return false;
	}else if(password.value.length < 6){
		this.setSignupError('Password must be at least six characters');
		password.focus();
		return false;	
	}else if(confirm.value.length == 0){
		this.setSignupError('Re-type your password');
		confirm.focus();
		return false;
	}else if(confirm.value != password.value){
		this.setSignupError('Your passwords don\'t match');
		return false;
	}
	
	return true;
}

pdSidebarUserModule.prototype.isValidEmail = function(){
	var email = $('signupEmail');
	if(email.value.length == 0){
		this.setSignupError('Enter your e-mail address');
		email.focus();
		return false;
	}else{	
		var good = "@_-.:/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		var upper = email.value.toUpperCase()
		var valid = true;	
		for(x=0; x>upper.length; x++){c = upper.charAt(x);for(y=0; y<good.length; y++){if(c==good.charAt(y)){break;}}if(y == good.length){valid = false;break;}}	
		if (!valid || upper.length < 7 || upper.indexOf("@") == "-1" || upper.indexOf(".") == "-1" || upper.indexOf("@") != upper.lastIndexOf("@")) {
			this.setSignupError('Your e-mail appears to be invalid');
			email.focus();
			return false;
		}else{
			return true;
		}		
	}	
	return true;
}

pdSidebarUserModule.prototype.isValidCaptcha = function(){
	var captcha = $('signupCaptcha');
	if(captcha.value.length == 0){
		this.setSignupError('Enter the characters seen in the image');
		captcha.focus();
		return false;	
	}
	return true;
}

pdSidebarUserModule.prototype.setSignupError = function(msg){
	$('signupError').update(msg);
	$('signupError').show();
	pd_globalSiteFramework.trackEvent('Sidebar User', 'Signup - error', msg);	
}
pdSidebarUserModule.prototype.clearSignupError = function(){var errorDiv = $('signupError');errorDiv.update();errorDiv.hide();}
pdSidebarUserModule.prototype.showPane = function(event, pane){
	Event.stop(event);
	if(pane == 'forgotlogin'){
		$('loginInputPane').hide();
		$('loginForgotError').update();
		$('loginForgotError').hide();	
		$('loginForgotPane').show();
	}else if(pane == 'signup'){
		$('loginPane').hide();
		$('signupError').update();
		$('signupError').hide();
		$('loginSignupComplete').hide();
		$('loginSignupPane').show();
		if($('signupCaptchaImage').src.indexOf('/captcha.aspx') == -1){
			$('signupCaptchaImage').src = '/2/framework/captchaservice.aspx';
		}
	}else if(pane == 'login'){
		$('loginSignupPane').hide();	
		$('loginForgotPane').hide();
		$('loginForgotSuccessPane').hide();
		$('loginInputPane').show();
		$('loginPane').show();
	}
}

// - ///////////////////////////////////////////////////////////////////////
// - PHONEDOG SIDEBAR PHONE LISTS
// - ///////////////////////////////////////////////////////////////////////
pdSidebarPhoneListsModule.prototype._transport;
pdSidebarPhoneListsModule.prototype._user;
pdSidebarPhoneListsModule.prototype._channelId = 'site.shared';

function pdSidebarPhoneListsModule() {}

pdSidebarPhoneListsModule.prototype.initialize = function(transport, user){
  	//this function is called back during module registration
	this._transport = transport;
	this._user = user;
	var me = this;
	
	if($('sidebarPhoneLists')){
		$('sidebarPhoneLists').select('.tabs-menu a').each(function(link){link.observe('click', me.onTabClick.bind(me));});
	}
};
pdSidebarPhoneListsModule.prototype.clearTabs = function(){
	$('sidebarPhoneLists').select('.tabs-menu a').each(function(link){link.removeClassName('selected');});	
	$$('.tabs-slide').each(function(slide){slide.hide()});
};
pdSidebarPhoneListsModule.prototype.onTabClick = function(event){
	Event.stop(event);
	this.clearTabs();
	var tab = Event.element(event);
	var slide = $(tab.readAttribute('rel'));
	tab.addClassName('selected');
	slide.show();
};

// - ///////////////////////////////////////////////////////////////////////
// - PHONEDOG PRICEVIEW MODULE
// - ///////////////////////////////////////////////////////////////////////
pdPriceViewModule.prototype._transport;
pdPriceViewModule.prototype._user;
pdPriceViewModule.prototype._channelId = 'site.priceview';
pdPriceViewModule.prototype._itemId;
pdPriceViewModule.prototype._itemName;
pdPriceViewModule.prototype._itemIds;
pdPriceViewModule.prototype._multiSelect;
pdPriceViewModule.prototype._requests = new Hash();

function pdPriceViewModule(){}

pdPriceViewModule.prototype.initialize = function(transport, user){
  	//this function is called back during module registration
	this._transport = transport;
	this._user = user;	
	
	//if we have a priceview unit on the page then
	//fire off the request to get information on it
	if($('priceview')){
		//get itemid or list of itemids and check if we have many
		this._itemIds = $w($('priceview').readAttribute('itemids').gsub(',',' '));
		this._multiSelect = $('priceview').readAttribute('multi');
		
		if(this._itemIds.length > 0){
			this._itemId = this._itemIds[0];
			this.load();
		}
	}
}

pdPriceViewModule.prototype.load = function(){
	if(this._requests.get(this._itemId) == undefined){
		this._transport.transmitRequest(this._channelId, 'getbuyingchoices', {itemId : this._itemId, itemIds : this._itemIds.join(',')}, this.onBuyingChoicesRetrieved.bind(this));
	}else{
		this.render(this._requests.get(this._itemId));
	}
}

pdPriceViewModule.prototype.onItemChange = function(event){
	var select = event.element();
	this._itemId = select.value;
	this.load();
	
	pd_globalSiteFramework.trackEvent('Priceview', 'Phone change', select[select.selectedIndex].text);
}

pdPriceViewModule.prototype.onBuyingChoicesRetrieved = function(objResponse){
	this.render(objResponse);
}

pdPriceViewModule.prototype.render = function(objResponse){
	if(objResponse){
		this._requests.set(this._itemId, objResponse);
	
		var price;
		var priceview = $('priceview').update();
		var wrapper = new Element('div').addClassName('wrapper');
		var prices = new Element('div').addClassName('prices');
		var carriers = new Element('div').addClassName('carriers');
		var names = new Array();
		var uniques = new Hash();
		var item;
		var link;
		
		//stop observing all events on the priceview
		priceview.stopObserving();
		
		//if we have more than one item in the response or have multi select on then
		//build a select of all the items we have 
		if(objResponse.items.length > 1 || this._multiSelect){
			var option;
			var selectWrap = new Element('div').addClassName('select');
			var select = new Element('select', {id : 'pvItemId'});
			var typeName = (window.location.toString().indexOf('/cell-phone-videos/') != -1) ? 'Video' : 'Post';
			selectWrap.appendChild(new Element('h3').update('Phones mentioned in this ' + typeName));
			select.observe('change', this.onItemChange.bind(this));
			selectWrap.appendChild(select);
			wrapper.appendChild(selectWrap);			
			
			for(var x=0; x < objResponse.items.length; x++){
				option = new Option(objResponse.items[x].ItemName, objResponse.items[x].Id);
				select.options.add(option);
				
				if(this._itemId == objResponse.items[x].Id){
					option.selected = true;
					this._itemName = objResponse.items[x].ItemName
				}
			}
		}else{
			this._itemName = objResponse.items[0].ItemName;
		}
		
		wrapper.appendChild(prices);
		wrapper.appendChild(carriers);
		prices.appendChild(new Element('h3').update('Pricing with 2 year activation'));
		carriers.appendChild(new Element('h3').addClassName('carriers').update('Phone only - Compatible with'));		
		
		if(objResponse.prices && objResponse.prices.length > 0){		
			for(var x=0; x < objResponse.prices.length; x++){
				price = objResponse.prices[x];
				
				if(uniques.get(price.CarrierId) == undefined){
					uniques.set(price.CarrierId, price.CarrierName);
					item = new Element('div').addClassName('item');
					
					link = new Element('div').addClassName('price').update('<span>' + this.formatPrice(price.PriceFinal, price.IsImap) + ' <b>&raquo;</b></span>');
					link.observe('click', this.onPriceClick.bindAsEventListener(this, price.ProductLink));
					item.appendChild(link);
					
					item.appendChild(new Element('div').addClassName('company').update('<span>' + price.CarrierName + '</span>'));
					
					prices.appendChild(item);
				}
			}
		}else{
			prices.appendChild(new Element('span').update('We currently don\'t have any pricing available for this phone.'));
		}
		
		if(objResponse.carriers && objResponse.carriers.length > 0){		
			for(var x=0; x < objResponse.carriers.length; x++){
				names.push(objResponse.carriers[x].CarrierName);				
			}
			
			carriers.appendChild(new Element('div').update(names.join(', ')));
		}else{
			carriers.appendChild(new Element('div').update('We currently don\'t have any pricing available for this phone.'));
		}		
		
		var ebayDiv = new Element('div').addClassName('ebay clearfix').observe('click', this.onEbayClick.bind(this));
		ebayDiv.appendChild(new Element('img', {src : 'http://r.phonedog.com/shared/images/logos/ebay.gif'}));
		ebayDiv.appendChild(new Element('span').update('Check ebay<br/>for great prices! &raquo;'));
		carriers.appendChild(ebayDiv);			
	
		priceview.appendChild(wrapper);
		priceview.show();
	}
}

pdPriceViewModule.prototype.onPriceClick = function(event, url){
	var goTo = url.replace('##TRACKINFO','a_0_s_0_c_0').replace('##ZIP','');
	window.open(goTo);	
	pd_globalSiteFramework.trackEvent('Priceview', 'Merchant', this._itemName);
}

pdPriceViewModule.prototype.onEbayClick = function(event){
	var name = escape(this._itemName);
	var goTo = 'http://rover.ebay.com/rover/1/711-53200-19255-0/1?type=3&campid=5335946811&toolid=10001&customid=a_0_s_0&ext=' + name + '&satitle=' + name;	
	window.open(goTo);	
	pd_globalSiteFramework.trackEvent('Priceview', 'eBay', this._itemName);
}

pdPriceViewModule.prototype.formatPrice = function(price, isImap){
	if(isImap){
		return 'View price';
	}else{
		if(price == 0){
			return 'Free';
		}else if(price < 0){
			return 'You get $' + price.toString().gsub('-','');
		}else{
			return '$' + price;
		}
	}
}