/* Metacafe Copyright - http://www.metacafe.com/ */
/* Files included: AgeGateway.js.tmp */

var AgeGateway=new Class({Implements:[Options],options:{pageName:'redBand',ageLimit:18,redirect:'/',overlayOpacity:0.9,removeFF:false,pausePlayer:false,perSession:false},initialize:function(options){this.setOptions(options);this.hashCookie=new Hash.Cookie('User',{domain:headerObj.cookieDomain,path:'/',duration:362});this.ageCookieName=this.options.pageName+'_age';this.sessIDCookieName=this.options.pageName+'_sessid';this.boolSessionCookieName=this.options.pageName+'_ok';this.getAgeLimitCookie();},getAgeLimitCookie:function(){this.savedAge=this.hashCookie.get(this.ageCookieName);if(this.options.perSession&&!(this.isSameSession())){this.showAgeGateway();}else if(this.savedAge&&this.savedAge>=this.options.ageLimit){return;}else{this.showAgeGateway();}},isSameSession:function(){return(Cookie.get('PHPSESSID')==this.hashCookie.get(this.sessIDCookieName));},showAgeGateway:function(banned){window.showAgeGateFlg=true;var url='/index.php?pageToLoad=static&displayMode=ageGateway&isFramed=0';if(banned){url+='blocked=1';}
if(this.options.pausePlayer){VideoStateManager.states.set('playing',function(){var player=document.getElementById('fpObj');player.style.visibility='hidden';if(player&&typeof player.pause=='function'){try{player.pause();}catch(err){}}});}
if($("Billboard")){$("Billboard").remove();}
this.mbox=new Moobox({showOverlay:true,classes:{closer:'Hidden',window:'MbxContainer AgeGateway'}});this.mbox.addEvent('onUpdate',this.initAgeGatewayForm.bind(this));this.mbox.getContent(url);},initAgeGatewayForm:function(){if(this.options.perSession&&!(this.isSameSession())){this.showAgeGatewayForm();}else if(this.savedAge&&this.savedAge.toInt()<this.options.ageLimit){this.toggleUnderageWarning();}},showAgeGatewayForm:function(){$('AgeGatewayForm').setStyle('visibility','visible');$('VerifyAge').addEvent('click',this.onAgeSubmit.bindWithEvent(this));},onAgeSubmit:function(ev){ev.preventDefault();var d=$('rBDateDay').value,m=$('rBDateMonth').value,y=$('rBDateYear').value;if(d=='DD'||m=='MM'||y=='YYYY'){return;}
var curDate=new Date();var minDate=new Date(curDate.getYear()-this.options.ageLimit,curDate.getMonth(),curDate.getDate(),0,0,0,0);var inputDate=new Date(y,m-1,d,0,0,0,0);var diff=minDate-inputDate;var valid=isNaN(diff)||diff<0?false:true;var age=curDate.getFullYear()-inputDate.getFullYear();if(age==this.options.ageLimit)age-=1;this.hashCookie.set(this.ageCookieName,age);if(this.options.perSession){this.hashCookie.set(this.sessIDCookieName,Cookie.get('PHPSESSID'));}
if(!valid){if(this.options.perSession){this.hashCookie.set(this.boolSessionCookieName,'');}
this.toggleUnderageWarning();}else{if(this.options.perSession){this.hashCookie.set(this.boolSessionCookieName,1);}
if(this.options.removeFF){self.location.href='/f/index.php?inputType=filter&controllerGroup=user&filters=0&prevURL='+self.location.href;}else{if(this.pausePlayer){window.location.reload();}else{this.mbox.close();}}}},toggleUnderageWarning:function(){$('AgeGatewayForm').addClass('Hidden');$('UnderageWarning').removeClass('Hidden');this.redirect.delay(5000,this);},redirect:function(){self.location.href=this.options.redirect;}});