


//to disable community, uncomment the following line, and flush the cache on this file
/*
SetCookieUtil("cCommunityAccess", "false");
*/

//to re-enable community, uncomment the following line and flush the cache on this file
/* */
if (GetCookieUtil("cCommunityAccess")=="false"){ SetCookieUtil("cCommunityAccess", ""); }

/**
function injectFluxWidget(widgetName, options){
	var showWidget = "false";
	
	if (widgetName=="Comments2" && GetCookieUtil("cCommunityComments")=="true"){ showWidget = "true"; }
	if (widgetName=="Rating" && GetCookieUtil("cCommunityRating")=="true"){ showWidget = "true"; }
	if (widgetName=="Usage" && GetCookieUtil("cCommunityUsage")=="true"){ showWidget = "true"; }
	if (widgetName=="QuickMenu" && GetCookieUtil("cCommunityPhase")=="2"){ showWidget = "true"; }
	
	if (showWidget=="true" && GetCookieUtil("cCommunityAccess")=="true"){
		if (Flux && Flux.Utils.WidgetsLoader) {
			Flux.Utils.WidgetsLoader.createWidget(widgetName, options);
		}
	}
}

**/

function injectFluxWidget(widgetName, options){

			if (widgetName=="Comments2") { 
			options.displayUserName = true;
			options.customize = {markupUrl: '/sitewide/scripts/community/widgets/CustomComments.js'};
			}
			if (widgetName=="CommunityMembers") { 
			options.customize = {markupUrl: '/sitewide/scripts/community/widgets/CustomMembers.js'};
			}
			if (Flux && Flux.Utils.WidgetsLoader) {
			Flux.Utils.WidgetsLoader.createWidget(widgetName, options);
		}
}

function fluxWidgetError(errorCode){
	community.open(errorCode);
}

function Community() {
	var communityHostname = 'http://community.mtvtr3s.com';	
	var onFinish = "";
	
	/* dialogue open and close */
	this.open = function(page){
		if (page=="register" || page=="login" || page=="join" || "notLoggedIn"){ 
				this.hostedPageLink(page);
			}
			else{
				overlayOpen();
				window.scrollTo(0,0);
				this.link(page);
			}
	}
	
	this.close = function(){
		overlayClose();
		this.link('clear');
	}
	
	this.finish = function(){
		this.close();		
		if (this.onFinish != undefined){
			switch(this.onFinish){
				case 'reload': window.location.reload(); break;
				default: window.location.href = this.onFinish; break;
			}
		}
	}
	
	/* links */
	this.hostedPageLink = function(page, id){
		var hostedPage = "/";
		switch(page){
			case 'discussion': hostedPage = '/-/Content/Discussions/DiscussionBoard.aspx?catId=' + id; break;
			case 'join': hostedPage = '/-/JoinInterim.aspx?returnPath=' + window.location.href; break;
			case 'login': hostedPage = '/-/SignUp.aspx?returnPath=' + window.location.href; break;
			case 'notLoggedIn': hostedPage = '/-/SignUp.aspx?returnPath=' + window.location.href; break;
			case 'register': hostedPage = '/-/SignUp.aspx?returnPath=' + window.location.href; break;
			case 'notVerified': hostedPage = '/EmailInterim.aspx'; break;
			case 'sendValidation': hostedPage = '/EmailInterim.aspx'; break;
			default: break;
		}		
				
		window.location.href=communityHostname + hostedPage;
	}
	
	this.link = function(page){
		if (page=="register" || page=="login" || page=="join"){ 
			this.hostedPageLink(page);
		}
		else{
			/* temporary iframe fix */
			this.hide(document.getElementById('communityUpload'));
		
			switch(page){
				case 'clear': submit('/sitewide/community/forms/clear.jhtml'); break;
				case 'join': submit('/sitewide/community/forms/join.jhtml'); break;
				case 'login': submit('/sitewide/community/forms/login.jhtml'); break;
				case 'loginFromReg': submit('/sitewide/community/forms/login.jhtml?event=loginFromRegLink'); break;
				case 'notJoined': submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
				case 'notLoggedIn': submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
				case 'notVerified':	submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
				case 'passwordReminder': submit('/sitewide/community/forms/passwordReminder.jhtml'); break;
				case 'problems': submit('/sitewide/community/forms/problems.jhtml'); break;
				case 'register': submit('/sitewide/community/forms/register.jhtml'); break;
				case 'sendValidation': submit('/sitewide/community/forms/sendValidation.jhtml'); break;
				case 'updateAccount': submit('/sitewide/community/forms/updateAccount.jhtml'); break;
				case 'updatePassword': submit('/sitewide/community/forms/updatePassword.jhtml'); break;
				case 'uploadPhoto': submit('/sitewide/community/forms/uploadPhoto.jhtml'); break;
				case 'uploadSuccess': submit('/sitewide/community/forms/updateAccount.jhtml?action=uploadSuccess'); break;
				case 'uploadSkip': submit('/sitewide/community/forms/welcome.jhtml?action=register&event=uploadSkip'); break;
				case 'quit': submit('/sitewide/community/forms/quit.jhtml'); break;
				case 'welcomeRegister': submit('/sitewide/community/forms/welcome.jhtml?action=register'); break;
				default: submit(page); break;
			}
		}
	}
	
	
	/* form handlers */
	this.handle = function(form, elements){
		switch(form){
			case 'deactivate': submit('/sitewide/community/forms/do_deactivate.jhtml'); break;
			case 'join': submit('/sitewide/community/forms/do_join.jhtml', ['firstName', 'lastName', 'username', 'agreeToTerms']); break;
			case 'login': submit('/sitewide/community/forms/do_login.jhtml', ['loginName', 'password']); break;
			case 'logout': submit('/sitewide/community/forms/logout.jhtml'); break;
			case 'passwordReminder': submit('/sitewide/community/forms/do_passwordReminder.jhtml', ['email']); break;
			case 'register': submit('/sitewide/community/forms/do_register.jhtml', ['email', 'emailConfirm', 'password', 'passwordConfirm', 'loginName', 'firstName', 'lastName', 'birthDateMonth', 'birthDateDay', 'birthDateYear', 'postalCode', 'agreeToTerms']); break;
			case 'updateAccount': submit('/sitewide/community/forms/do_updateAccount.jhtml', elements); break;			
			case 'updatePassword': submit('/sitewide/community/forms/do_updatePassword.jhtml', ['currentPassword', 'newPassword', 'newPasswordConfirm']); break;
			case 'unjoin': submit('/sitewide/community/forms/do_unjoin.jhtml'); break;
			case 'sendValidation': submit('/sitewide/community/forms/do_sendValidation.jhtml', ['email']); break;
			default: break;
		}
	}
	
	this.updateWidgets = function(){
		submit('/sitewide/community/forms/updateWidgets.jhtml');
	}
	
	this.pop = function(url, type){
		var features;
		if (type=='legal') features = "width=620,height=600,scrollbars";
		if (url=='faq'){
			url = "/sitewide/mtvinfo/social_project_faq.jhtml";
			features = "width=620,height=600,scrollbars";
		}
		if (url=='betaInvite'){
			url = "/community/invite/index.jhtml";
			features = "width=344,height=320,menubar=no,status=yes,scrollbars=no";
		}
		window.open(url, '', features);
	}
	
	/* utils */
	this.getQuickmenu = function(){
		this.show(document.getElementById("quickmenu"));
	}
	
	
	
	
	
	this.show = function(element){
		show(element);
	}
	
	this.hide = function(element){
		hide(element);
	}
	
	function show(element){
		if (element!=null && element.className.indexOf('hide') >= 0){
			element.className = element.className.substring(0, element.className.indexOf('hide'));
		}
	}
	
	function hide(element){
		if (element!=null){
			element.className = element.className + " hide";
		}
	}
	

this.setReportingVars = function(){
		var vars = "";
		var numkeys = 1;
		var keyvals = new Array(2);
		var keynames = new Array(2);
		
		/* PHASE 2 */
		keynames[0] = "siteFormat";		//prop31 - logged in
		keyvals[0] = (Flux.Context.isUserAuthenticated()==true) ? 'logged-in' : 'not-logged-in';
		
		for (var i=0; i<numkeys; i++){
			if (keyvals[i].length != 0){
				vars = vars + keynames[i] + "=" + keyvals[i] + ";";
			}
		}
		return vars;
	}

	
}
var community = new Community();