// JavaScript Document

var dyncontentopc;
var dyncontenthgt;
var dynStatus = false;
var dynCurrentId = false;
var dynAllowResize = true;
var dynPreferredSize = false;
var dynAdvSearch_Pop = false;
var dynOptional = false;
var dynAdvSearch_Exec = false;
var catsfx=new Array();
var catsmd=new Array();
var catsct=new Array();
var FxScrollObject = new Fx.Scroll(window, {duration: 1000});
var FxScrollObjectFast = new Fx.Scroll(window, {duration: 256});
var notifbarStatus = false;
var userdata = false;
var tutratingstatus = false;
var tutratingid = 0;
var tutratingamount = 3;
var tutratingdescriptors = new Array('Bad ( 1/5 )','Mediocre ( 2/5 )','Average ( 3/5 )','Good ( 4/5 )','Excellent ( 5/5 )');
var searchsuggest_isActive = false;
var searchsuggest_pos = 0;
var shareboxStatus = false;
var favePage = 1;

/*----------------------------------------
||| DOM READY LOADER
-----------------------------------------*/

window.addEvent('domready', function(){

	// Tips Layers
	
	var TipsObj = new Tips($$('.TipsLyr'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
	
	// Dyn Content
	
	dyncontentopc = new Fx.Style('dyn_base', 'opacity', {duration:500});
	dyncontenthgt = new Fx.Style('dyn_base', 'height', {duration:500});
	
	// Search Suggest
	
	$('searchq').addEvent('keyup', function(e){
		e = new Event(e).stop();
		if(e.code == 38 || e.code == 40) {
			SearchSuggestNavigate(e.code);
		} else if(e.code == 39) {
			SearchSuggestReplace();
		} else if(e.code == 13) {
			if(searchsuggest_pos > 0) {
				SearchSuggestReplace();
			} else {
				SearchDo(0);
			}
		} else {
			SearchSuggest();
		}
	}).addEvent('blur', function(evt) {
		var evt = new Event(evt);
		if($('header_searchsuggest')) {
			(function() {
				$('header_searchsuggest').remove();
			}).delay(500);
		}
	});
	
});

/*----------------------------------------
||| DYNAMIC HEADER - GLOBAL
-----------------------------------------*/

function dyn_minimize(id, sdata) {
	
	var startpos = 228;
	
	if(dynAllowResize) {
		
		dyn_closeexternals();
		
		dyn_topload_start();
		if(dynStatus) {startpos = 100;}

		dyncontentopc.start(1,0).chain(function() {
			$('dyn_base').setHTML('&nbsp;');
			dyncontenthgt.start(startpos,100).chain(function() {
				if(!id) {
					$('dyn_base').setHTML('<img src="/skin_images/dyn_small.jpg" alt="" border="0" usemap="#dynmap_small" />');
					dyncontentopc.start(0,1).chain(function() {
						displaysetting_dyn(1);
						dynStatus = true;
						dynPreferredSize = true;
						dynCurrentId = false;
						$('locationbar_nav').setHTML('<a href="#" onclick="return dyn_maximize();"><img src="/skin_images/dyn_maximize.gif" alt="Maximize" /></a>');
						dyn_topload_stop();
					});
				} else {
					new Ajax('/xhr/' + id + '/', {
						method: 'post',
						data: sdata,
						update: $('dyn_base'),
						onComplete: function() {
							 dyncontentopc.start(0,1).chain(function() {
								dynStatus = true;
								$('locationbar_nav').setHTML('<a href="#" onclick="return dyn_maximize();"><img src="/skin_images/dyn_maximize.gif" alt="Maximize" /></a>');
								dyn_topload_stop();
							});
						}
					}).request();
				}
			});
		});
	
	} else {
		warningbox_open('You cannot minimize the dynamic header when ' + dynCurrentId + ' is active.');
	}
	
	return false;

}

function dyn_maximize(id, sdata) {
	
	var startpos = 100;
	
	if(dynAllowResize) {
		
		dyn_closeexternals();
		
		dyn_topload_start();
		if(!dynStatus) {startpos = 228;}

		dyncontentopc.start(1,0).chain(function() {
			$('dyn_base').setHTML('&nbsp;');
			dyncontenthgt.start(startpos,228).chain(function() {
				if(!id) {
					$('dyn_base').setHTML('<img src="/skin_images/dyn_home.jpg" alt="" border="0" usemap="#dynmap_big" />');
					dyncontentopc.start(0,1).chain(function() {
						displaysetting_dyn(0);
						dynStatus = false;
						dynPreferredSize = false;
						dynCurrentId = false;
						$('locationbar_nav').setHTML('<a href="#" onclick="return dyn_minimize(false, false);"><img src="/skin_images/dyn_minimize.gif" alt="Minimize" /></a>');
						dyn_topload_stop();
					});
				} else {
					new Ajax('/xhr/' + id + '/', {
						method: 'post',
						data: sdata,
						update: $('dyn_base'),
						onComplete: function() {
							 dyncontentopc.start(0,1).chain(function() {
								dynStatus = false;
								$('locationbar_nav').setHTML('<a href="#" onclick="return dyn_minimize(false, false);"><img src="/skin_images/dyn_minimize.gif" alt="Minimize" /></a>');
								dyn_topload_stop();
							});
						}
					}).request();
				}
			});
		});
		
	} else {
		warningbox_open('You cannot maximize the dynamic header when ' + dynCurrentId + ' is active.');
	}
	
	return false;

}

function dyn_recover() {
	dynAllowResize = true;
	dynCurrentId = false;
	if(dynPreferredSize) {
		dyn_minimize(false, false);
	} else {
		dyn_maximize(false, false);
	}
}

function dyn_closeexternals() {

	if(dynAdvSearch_Pop) {
		$('dyn_advsearch_popoptions').remove();
		dynAdvSearch_Pop = false;
	}

}

function dyn_topload_start(prevent) {
	var tlcenter = new Element('div', {'id': 'dyn_toploading'}).injectInside(document.body);
	tlcenter.setHTML('<img src="/skin_images/toploading.gif" alt="Loading..." />');
	if(prevent) {
		new Element('div', {'id': 'lbBlack'}).injectInside(document.body).setStyles({'top': 0, 'height': window.getScrollHeight(), 'opacity': 0.25});
	}
}

function dyn_topload_stop(prevent) {
	$('dyn_toploading').remove();
	if(prevent) {
		if($('lbBlack')) {
			$('lbBlack').remove();
		}
	}
}

function dyn_topload_active() {
	if($('dyn_toploading')) {return true;} else {return false;}
}

/*----------------------------------------
||| ADVANCED SEARCH
-----------------------------------------*/

function loadAdvSearch() {
	
	  if(dyn_topload_active()) {
		  //warningbox_open('The advanced search is loading. Please wait.');
	  } else if(dynCurrentId == 'Advanced Search') {
		  unloadAdvSearch();
	  } else {
		  dynCurrentId = 'Advanced Search';
		  if(dynOptional) {
			  dyn_topload_start();
			  if(dynAdvSearch_Exec) {
				  dyn_callback();
			  }
			  new Ajax('/xhr/advsearchexternal/', {
				  method: 'post',
				  onComplete: function(response) {
					  var newdyn = new Element('div', {'id': 'dyn_container_super'}).injectBefore('main_container');
					  newdyn.setHTML(response);
					  newdynfx = new Fx.Slide('dyn_container', {duration: 1000});
					  newdynfx.hide();
					  newdynfx.slideIn().chain(function() {
						  $('main_container').setOpacity(0.3);
						  dyn_topload_stop();
					  });
				  }
			  }).request();
		  } else {
			  dyn_maximize('advsearch', false);
		  }
	  }

}

function unloadAdvSearch() {
	if(dynOptional) {
		dyn_topload_start();
		newdynfx = new Fx.Slide('dyn_container', {duration: 1000});
		newdynfx.slideOut().chain(function() {
			$('dyn_container_super').remove();
			dynCurrentId = false;
			$('main_container').setOpacity(1);
			dyn_topload_stop();
		});
	} else {
		dyn_recover();
	}
	return false;
}

function loadAdvSearch_Options(base) {
	
	if(dynAdvSearch_Pop) {
		warningbox_open('The options panel is already opened.');
	} else {
		
		dynAdvSearch_Pop = true;
	
		dyn_topload_start();
		var basepos = $('advs_' + base + 'browse').getPosition();
		
		new Ajax('/xhr/advsearch' + base + '/', {
				method: 'post',
				data: 'currentpos=' + $('advs_' + base).value,
				onComplete: function(response) {
					var asoptions = new Element('div', {'id': 'dyn_advsearch_popoptions'}).injectInside(document.body);
					asoptions.setStyle('left', basepos['x'] + 51);
					asoptions.setStyle('top', basepos['y'] + 13);
					asoptions.setHTML(response);
					dyn_topload_stop();
				}
			}).request();
		
	}
	
	return false;
}

function AdvSearch_time() {
	if($('advs_time2').checked) {
		$('dyn_advsearch_time_status').setText('6 Months');
		$('advs_time').value = 2;
	} else if($('advs_time3').checked) {
		$('dyn_advsearch_time_status').setText('2 Months');
		$('advs_time').value = 3;
	} else if($('advs_time4').checked) {
		$('dyn_advsearch_time_status').setText('30 Days');
		$('advs_time').value = 4;
	} else {
		$('dyn_advsearch_time_status').setText('Anytime');
		$('advs_time').value = 1;
	}
	$('dyn_advsearch_popoptions').remove();
	dynAdvSearch_Pop = false;
	return false;
}

function AdvSearch_cats() {
	var selcats = $('advs_choosecats').getValue();
	if($('advs_catsall').checked || selcats == '') {
		$('dyn_advsearch_cats_status').setText('All Categories');
		$('advs_cats').value = 0;
	} else if(selcats.length == 1) {
		$ES('option','advs_choosecats').each(function(item, index) {
			if(item.value == selcats) {
				$('dyn_advsearch_cats_status').setText(item.getText());
			}
		});
		$('advs_cats').value = selcats;
	} else {
		$('dyn_advsearch_cats_status').setText(selcats.length + ' categories');
		var temp = '0';
		selcats.each(function(item, index){
			temp = temp + ',' + item;
		});
		$('advs_cats').value = temp;
	}
	$('dyn_advsearch_popoptions').remove();
	dynAdvSearch_Pop = false;
	return false;
}

function AdvSearch_init() {

	if($('searchq').value != 'Search' && $('searchq').value != '') {
		$('advs_optional').value = 	$('searchq').value;
	}

}

function SearchDo(from) {
	
	if(from == 0 && ($('searchq').value.length < 3 || $('searchq').value == 'Search')) {
		warningbox_open('Search Error - Your search query is too short. Use at least 3 characters.');
	} else if(from == 1 && ($('advs_optional').value.length < 3 && $('advs_required').value.length < 3 && $('advs_begin').value.length < 3)) {
		warningbox_open('Search Error - Filling out at least one field would be a HUGE help!');
	} else if(from == 1 && !($('advs_statuslive').checked || $('advs_statuspending').checked || $('advs_statusrejected').checked)) {
		warningbox_open('Search Error - You need to check at least 1 tutorial status (Live, Pending or Rejected)!');
	} else {
		dyn_topload_start();
		var formbase = (from == 1) ? 'adv' : 'normal';
	
		new Ajax('/xhr/search/', {
			method: 'post',
			data: $('searchform_' + formbase),
			onComplete: function(response) {
				if(response == 0) {
					dyn_topload_stop();
					warningbox_open('Sorry, no search results were found... please try another query.');
				} else {
					window.location = '/search/' + response + '/';
				}
			}
		}).request();
	}
	
	return false;

}

function SearchSuggest() {

	if($('searchq').value.length >= 3 && $('searchq').value != 'Search') {
		
		if(!searchsuggest_isActive) {
			
			searchsuggest_isActive = true;
			searchsuggest_pos = 0;
			var currentQuery = $('searchq').getValue().clean();
		
			if(!$('header_searchsuggest_load')) {
				var divsuggestanim = new Element('div', {'id': 'header_searchsuggest_load'}).injectInside(document.body);
				divsuggestanim.setStyle('left', $('header_right').getLeft() - 25);
			} else {
				var divsuggestanim = $('header_searchsuggest_load');
			}
			
			new Ajax('/xhr/searchsuggest/', {
			method: 'post',
			data: 'searchq=' + $('searchq').getValue(),
			onComplete: function(response) {
				var resp = Json.evaluate(response);
				if(!$('header_searchsuggest') && resp.error == 0) {
					var divsuggest = new Element('div', {'id': 'header_searchsuggest'}).injectInside(document.body);
					divsuggest.setStyle('left', $('header_right').getLeft());
				} else if(resp.error == 0) {
					var divsuggest = $('header_searchsuggest');
				}
				var divsuggestcontent = '';
				if(resp.error == 0) {
					resp.results.each(function(item, index){
						divsuggestcontent += '<div id="searchsuggest_item' + (index + 1) + '"><a href="#" onclick="return SearchSuggestLink(' + (index + 1) + ');">' + item + '</a></div>';
					});
					divsuggest.setHTML(divsuggestcontent);
				} else if(resp.error == 1 && $('header_searchsuggest')) {
					$('header_searchsuggest').remove();
				}
				(function() {if($('header_searchsuggest_load')) {$('header_searchsuggest_load').remove();}}).delay(1500);
				searchsuggest_isActive = false;
				if($('searchq').getValue().clean() != currentQuery) {
					SearchSuggest();
				}
			}}).request();
			
		}
		
	} else {
		if($('header_searchsuggest')) {$('header_searchsuggest').remove();}
	}

}

function SearchSuggestNavigate(key) {
	if($('header_searchsuggest')) {
		if(key == 40) {
			if(searchsuggest_pos < 5) {
				searchsuggest_pos++;
			}
		} else if(key == 38) {
			if(searchsuggest_pos > 0) {
				searchsuggest_pos--;
			}
		}
		for(var i = 1; i <= 5; i++) {
			if(searchsuggest_pos == i) {
				$('searchsuggest_item' + i).addClass('searchsuggest_itemon');
			} else {
				$('searchsuggest_item' + i).removeClass('searchsuggest_itemon');	
			}
		}
	}
}

function SearchSuggestReplace() {
	if($('header_searchsuggest')) {
		if(searchsuggest_pos > 0 && searchsuggest_pos <= 5) {
			$('searchq').value = $('searchsuggest_item' + searchsuggest_pos).getText();
		}
		searchsuggest_pos = 0;
		SearchSuggestNavigate(0);
	}
}

function SearchSuggestLink(id) {

	searchsuggest_pos = id;
	SearchSuggestReplace();
	return false;

}

function SearchHighlight(state) {

	if(state == 1) {
		$('searchgobutton').src = '/skin_images/header_right_searchgo_on.jpg';
	} else {
		$('searchgobutton').src = '/skin_images/header_right_searchgo.jpg';
	}

}

/*----------------------------------------
||| NOTIFICATION BAR
-----------------------------------------*/

function notifbar_show() {
	if(window.ie) {
		$('notifbar').setStyle('margin-left','-496px');
	}
	$('notifbar').setStyle('visibility','visible');
	
	var nbfx = new Fx.Style('notifbar', 'opacity', {duration:2000});
	nbfx.hide();
	
	nbfx.start(0,1).chain(function() {
		notifbarStatus = true;
		(function() {notifbar_hide();}).delay(5000);
	});
	return false;
}

function notifbar_hide() {
	if(notifbarStatus) {
		notifbarStatus = false;
		var nbfx = new Fx.Style('notifbar', 'opacity', {duration:3000});
		nbfx.start(1,0).chain(function() {
			$('notifbar').remove();
		});
		return false;
	}
}

/*----------------------------------------
||| PODCAST THEATER
-----------------------------------------*/

function podcast_theater(type) {

	if(type == 1) {
		
		var cdgoverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
		cdgoverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});
		
		var cdgcenter = new Element('div', {'id': 'podcastscr_container'}).injectInside(document.body);
		cdgcenter.setStyles({'top': window.getScrollTop() + 100, 'width': 740, 'height':530, 'margin-left': -360});
	
		var cdgoverlay = new Fx.Style('lbBlack', 'opacity', {duration:500});
		cdgoverlay.hide();
		
		var cdgcenterfx = new Fx.Style('podcastscr_container', 'opacity', {duration:250});
		cdgcenterfx.hide();
		
		cdgoverlay.start(0, 0.8).chain(function() {
			cdgcenterfx.start(0, 1).chain(function(){
				cdgcenter.innerHTML = '<div id="podcastsrc_header"><a href="#" onclick="podcast_theater_close(); return false;"><img src="/skin_images/podcastsrc_close.jpg" alt="Close Podcast Theater" /></a></div><br /><embed src="/js/mediaplayer/mediaplayer.swf" width="720" height="405" allowscriptaccess="always" allowfullscreen="true" flashvars="height=405&width=720&file=/podcast/v5intro_720.flv&image=/podcast/01.jpg&id=podcast_01&backcolor=0x530000&frontcolor=0xFFFFFF&lightcolor=0x330033&autostart=true" />';									   
			});
		});		
		
	} else {

		var cdgoverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
		cdgoverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});
		
		var cdgcenter = new Element('div', {'id': 'podcastscr_container'}).injectInside(document.body);
		cdgcenter.setStyles({'top': window.getScrollTop() + 150, 'width': 500, 'height':400, 'margin-left': -250});
	
		var cdgoverlay = new Fx.Style('lbBlack', 'opacity', {duration:500});
		cdgoverlay.hide();
		
		var cdgcenterfx = new Fx.Style('podcastscr_container', 'opacity', {duration:250});
		cdgcenterfx.hide();
		
		cdgoverlay.start(0, 0.8).chain(function() {
			cdgcenterfx.start(0, 1).chain(function(){
				cdgcenter.innerHTML = '<div id="podcastsrc_header"><a href="#" onclick="podcast_theater_close(); return false;"><img src="/skin_images/podcastsrc_close.jpg" alt="Close Podcast Theater" /></a></div><br /><embed src="/js/mediaplayer/mediaplayer.swf" width="480" height="270" allowscriptaccess="always" allowfullscreen="true" flashvars="height=270&width=480&file=/podcast/v5intro_480.flv&image=/podcast/01.jpg&id=podcast_01&backcolor=0x530000&frontcolor=0xFFFFFF&lightcolor=0x330033&autostart=true" />';									   
			});
		});
		
	}

}

function podcast_theater_close() {
	$('lbBlack').remove();
	$('podcastscr_container').remove();	
}

/*----------------------------------------
||| CATEGORY MENU
-----------------------------------------*/

function category_register(id, state, loaded) {

	catsfx[id] = new Fx.Slide('sdleft_catcontent_' + id, {duration: 500});

	if(state) {
		catsmd[id] = true;
	} else {
		catsmd[id] = false;
		catsfx[id].hide();
	}
	catsct[id] = loaded;

}

function category_toggle(id,eid,pub) {

	catsmd[id] = !catsmd[id];
	if(catsmd[id]) {
		if(catsct[id]) {
			$('sdleft_catcontent_' + id).removeClass('cat_content_empty');	
			$('sdleft_catcontent_' + id).addClass('cat_content');
			$('sdleft_catarrow_' + id).src = '/skin_images/sdleft_cattop_down.gif';
			$('sdleft_cattop_' + id).setStyle('margin-bottom', '1px');
			catsfx[id].slideIn();
		} else {
			dyn_topload_start();
			new Ajax('/xhr/midcats/', {
				method: 'post',
				data: 'topcatid=' + eid + '&ispub=' + pub,
				update: $('sdleft_catcontent_' + id),
				onComplete: function() {
					dyn_topload_stop();
					 catsct[id] = true;
					 if(catsmd[id]) {
						$('sdleft_catcontent_' + id).removeClass('cat_content_empty');	
						$('sdleft_catcontent_' + id).addClass('cat_content');
						$('sdleft_catarrow_' + id).src = '/skin_images/sdleft_cattop_down.gif';
						$('sdleft_cattop_' + id).setStyle('margin-bottom', '1px');
					 	catsfx[id].slideIn();
					 }
				}
			}).request();	
		}
	} else {
		catsfx[id].slideOut().chain(function() {
			$('sdleft_catcontent_' + id).removeClass('cat_content');	
			$('sdleft_catcontent_' + id).addClass('cat_content_empty');
			$('sdleft_catarrow_' + id).src = '/skin_images/sdleft_cattop_tick.gif';
			$('sdleft_cattop_' + id).setStyle('margin-bottom', '0px');
		});
	}
	return false;

}

function mycats_reload() {
	
	if($('sdleft_catcontent_my')) {
		$('sdleft_catcontent_my').setHTML('<span class="small">Loading...</span>');
	
		new Ajax('/xhr/mycats/', {
			method: 'get',
			update: $('sdleft_catcontent_my')
		}).request();
	}
	
}

/*----------------------------------------
||| CONFIRM BOX
-----------------------------------------*/

function confirmbox_open(message, actionyes_type, actionyes, actionno_type, actionno, hascancel) {

	var cboverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
	cboverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});
	
	var cbcenter = new Element('div', {'id': 'confirmbox_container'}).injectInside(document.body);
	cbcenter.setStyles({'top': window.getScrollTop() + 150});
	cbcenter.innerHTML = '<div id="confirmbox_message">' + message + '</div>';
	
	if(actionyes_type == 'js') {
		acys = ' onclick="' + actionyes + '"';
		acyu = '#';
	} else {
		acys = '';
		acyu = actionyes;
	}
	
	if(actionno_type == 'js') {
		acns = ' onclick="' + actionno + '"';
		acnu = '#';
	} else {
		acns = '';
		acnu = actionno;
	}
	
	if(hascancel) {
		cbcenter.innerHTML += '<div id="confirmbox_options"><a href="' + acyu + '"' + acys + ' title="Yes"><img src="/skin_images/confirmbox_yes.png" alt="Yes" /></a> <a href="' + acnu + '"' + acns + ' title="No"><img src="/skin_images/confirmbox_no.png" alt="No" /></a> <a href="#" onclick="return confirmbox_close();" title="Cancel"><img src="/skin_images/confirmbox_cancel.png" alt="Cancel" /></a></div>';
	} else {
		cbcenter.innerHTML += '<div id="confirmbox_options"><a href="' + acyu + '"' + acys + ' title="Yes"><img src="/skin_images/confirmbox_yes.png" alt="Yes" /></a> <a href="' + acnu + '"' + acns + ' title="No"><img src="/skin_images/confirmbox_no.png" alt="No" /></a></div>';
	}

	var cboverlayfx = new Fx.Style('lbBlack', 'opacity', {duration:250});
	cboverlayfx.hide();
	
	var cbcenterfx = new Fx.Style('confirmbox_container', 'opacity', {duration:500});
	cbcenterfx.hide();
	
	cboverlayfx.start(0, 0.5).chain(function() {
		cbcenterfx.start(0, 1);
	});
	
	return false;

}

function confirmbox_close() {
	$('lbBlack').remove();
	$('confirmbox_container').remove();	
	
	return false;
	
}

/*----------------------------------------
||| WARNING/SUCCESS BOX
-----------------------------------------*/

function warningbox_open(message) {
	
	var wbcenter = new Element('div', {'id': 'warningbox_container'}).injectInside(document.body);
	wbcenter.setHTML('<div>' + message + '</div>');
	
	var wbcenterfx = new Fx.Slide(wbcenter, {duration: 500});
	wbcenterfx.hide();
	
	wbcenterfx.slideIn().chain(function() {
		(function() {
			wbcenterfx.slideOut().chain(function() {wbcenter.remove();});		
		}).delay(3000);									
	});
	
	return false;
	
}

function successbox_open(message) {
	
	var wbcenter = new Element('div', {'id': 'successbox_container'}).injectInside(document.body);
	wbcenter.innerHTML = '<div>' + message + '</div>';
	
	var wbcenterfx = new Fx.Slide(wbcenter, {duration: 500});
	wbcenterfx.hide();
	
	wbcenterfx.slideIn().chain(function() {
		(function() {
			wbcenterfx.slideOut().chain(function() {wbcenter.remove();});		
		}).delay(3000);									
	});
	
	return false;
	
}

/*----------------------------------------
||| LOGIN BOX
-----------------------------------------*/

function loginbox_open() {

	var cboverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
	cboverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});
	
	var cbcenter = new Element('div', {'id': 'loginbox_container'}).injectInside(document.body);
	cbcenter.setStyles({'top': window.getScrollTop() + 150});

	var cboverlayfx = new Fx.Style('lbBlack', 'opacity', {duration:250});
	cboverlayfx.hide();
	
	var cbcenterfx = new Fx.Style('loginbox_container', 'opacity', {duration:500});
	cbcenterfx.hide();
	
	cboverlayfx.start(0, 0.5).chain(function() {
		new Ajax('/xhr/loginbox/', {
			method: 'get',
			update: $('loginbox_container'),
			onComplete: function() {
				 cbcenterfx.start(0, 1);
			}
		}).request();
	});
	
	return false;

}

function loginbox_do() {

	var loginuser = $('login_user').value.clean();
	var loginpass = $('login_pass').value.clean();

	$('loginbox_container').remove();
	var cboverlayfx = new Fx.Style('lbBlack', 'opacity', {duration:500});

	var cbcenter = new Element('div', {'id': 'loginbox_loadcontainer'}).injectInside(document.body);
	cbcenter.setStyles({'top': window.getScrollTop() + 250});
	cbcenter.innerHTML = '<div class="lbBigText">Processing...</div>';
	
	var cbcenterfx = new Fx.Style('loginbox_loadcontainer', 'opacity', {duration:500});
	cbcenterfx.hide();
	
	cboverlayfx.start(0.5, 0.8).chain(function() {
		cbcenterfx.start(0, 1).chain(function() {
			(function(){
				new Ajax('/xhr/login/', {
					method: 'post',
					data: Object.toQueryString({user: loginuser, pass: loginpass}),
					onComplete: function(response) {
						 resp = response.split("|");
						 if(resp[0] == 1) {
							 userdata = Json.evaluate(resp[1]);
							 cbcenter.innerHTML = '<div class="lbBigText">Welcome back ' + userdata['username'] + '</div><div class="lbSmallText">Loading your account data...</div>';
							 // Loading these files without an admin session will fail!
							 if(userdata['admin']) {
							 	new Asset.javascript('/js/admin.js');
								new Asset.css('/admin.css');
								(function() {
									adm_initPanel();
									adm_launchfx.slideIn();
								}).delay(3000);
							 }
							 // User bar
							 if($('userbar_user')) {
								 $('userbar_user').setHTML('Welcome <strong>' + userdata['username'] + '</strong>');
								 $('userbar_inbox').setHTML('<a href="/inbox/">Inbox</a> (<strong>' + userdata['newmsg'] + '</strong>)');
								 $('userbar_adcredits').setHTML('<a href="/credits/">P2L Credits</a> (<strong>' + userdata['credits'] +'</strong>)');
								 $('userbar_mytuts').setHTML('<a href="/mytuts/">My Tutorials</a> (<strong>' + userdata['mytuts'] +'</strong>)');
								 $('userbar_myfaves').setHTML('<a href="#favorites" onclick="return faves_open();">Faves</a> (<strong id="fave_amount">' + userdata['faves'] +'</strong>)');
								 $('userbar_settings').setHTML('<a href="/settings/">Settings</a>');
								 $('userbar_logout').setHTML('<a href="#" onclick="return logout();">Logout</a>');
							 }
							 login_callback();
							 (function() {loginload_close();}).delay(2500);
						 } else {
							 cbcenter.innerHTML = '<div class="lbBigText">Login Failed</div><div class="lbSmallText">' + resp[1] + '</div>';
							 (function() {loginload_close(); loginbox_open();}).delay(2500);
						 }
					}
				}).request();
			}).delay(500);
		});
	});
	
	return false;

}

function logout() {

	var cboverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
	cboverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});

	var cboverlayfx = new Fx.Style('lbBlack', 'opacity', {duration:250});
	cboverlayfx.hide();
	
	var cbcenter = new Element('div', {'id': 'loginbox_loadcontainer'}).injectInside(document.body);
	cbcenter.setStyles({'top': window.getScrollTop() + 250});
	cbcenter.innerHTML = '<div class="lbBigText">Disconnecting...</div>';
	
	var cbcenterfx = new Fx.Style('loginbox_loadcontainer', 'opacity', {duration:500});
	cbcenterfx.hide();
	
	cboverlayfx.start(0, 0.8).chain(function() {
		cbcenterfx.start(0, 1).chain(function() {
			(function(){
				new Ajax('/xhr/logout/', {
					method: 'get',
					onComplete: function() {
						cbcenter.innerHTML = '<div class="lbBigText">You\'ve been logged out</div><div class="lbSmallText">Please Wait...</div>';
						$('container').empty();
						(function() {window.location = '/';}).delay(2500);
					}
				}).request();
			}).delay(500);
		});
	});
	
	return false;

}

function loginbox_close() {
	$('lbBlack').remove();
	$('loginbox_container').remove();	
	return false;
}

function loginload_close() {
	$('lbBlack').remove();
	$('loginbox_loadcontainer').remove();	
	return false;
}

/*----------------------------------------
||| MY CATEGORIES - ADD/REMOVE
-----------------------------------------*/

function mycats_add(id) {
	dyn_topload_start();
	new Ajax('/xhr/mycatschange/', {
		method: 'post',
		data: 'catid=' + id + '&catact=add', 
		onComplete: function(response) {
			dyn_topload_stop();
			resp = response.split("|");
			if(resp[0] == 1) {
				successbox_open(resp[1]);
				mycats_reload();
				$('sdleft_subcategories_fave').setHTML('<a href="#" onclick="return mycats_remove(' + id + ');" title="Remove from My Categories"><img src="/skin_images/sdleft_subcat_faveminus.gif" alt="Remove from My Categories" height="16" /></a>');
			} else {
				warningbox_open(resp[1]);
			}
		}
	}).request();
	return false;
}

function mycats_remove(id) {
	dyn_topload_start();
	new Ajax('/xhr/mycatschange/', {
		method: 'post',
		data: 'catid=' + id + '&catact=del', 
		onComplete: function(response) {
			dyn_topload_stop();
			resp = response.split("|");
			if(resp[0] == 1) {
				successbox_open(resp[1]);
				mycats_reload();
				$('sdleft_subcategories_fave').setHTML('<a href="#" onclick="return mycats_add(' + id + ');" title="Add to My Categories"><img src="/skin_images/sdleft_subcat_faveplus.gif" alt="Add to My Categories" height="16" /></a>');
			} else {
				warningbox_open(resp[1]);
			}
		}
	}).request();
	return false;
}

/*----------------------------------------
||| NEWSLETTER
-----------------------------------------*/

function newsletterclient_open() {
	
	if(dynCurrentId == 'Newsletter') {
		warningbox_open('Newsletter Pane is already opened');
	} else {
		FxScrollObjectFast.toElement(document.body).chain(function() {
			dynCurrentId = 'Newsletter';
			dyn_maximize('newsletter', false);
		});
	}
	
}

function newsletterclient_do() {
	if(dynCurrentId == 'Newsletter') {
		dyn_topload_start();
		new Ajax('/xhr/newsletterdo/', {
			method: 'post',
			data: 'email=' + $('newsletter_email').getValue(), 
			onComplete: function(response) {
				dyn_topload_stop();
				if(response == 1) {
					dyn_recover();
					successbox_open('You are now subscribed to our newsletter!');
				} else {
					warningbox_open('Your email address is invalid or you are already registered to our newsletter.');
				}
			}
		}).request();
	} else {
		alert('Error: Newsletter pane is not active.');
	}
}

/*----------------------------------------
||| DISPLAY SETTINGS
-----------------------------------------*/

function displaysetting_mycats(opt) {
	new Ajax('/xhr/displaysettings/', {
		method: 'post',
		data: Object.toQueryString({setting: 'mycats', value: opt})
	}).request();
	confirmbox_close();
	if((opt == 0 && !catsmd['my']) || (opt == 1 && catsmd['my'])) {
		category_toggle('my',0);
	}
	return false;
}
function displaysetting_popcats(opt) {
	new Ajax('/xhr/displaysettings/', {
		method: 'post',
		data: Object.toQueryString({setting: 'popcats', value: opt})
	}).request();
	confirmbox_close();
	if((opt == 0 && !catsmd['pop']) || (opt == 1 && catsmd['pop'])) {
		category_toggle('pop',0);
	}
	return false;
}
function displaysetting_dyn(opt) {
	new Ajax('/xhr/displaysettings/', {
		method: 'post',
		data: Object.toQueryString({setting: 'dyn', value: opt})
	}).request();
	return false;
}
function displaysetting_show() {
	
	var dscenter = new Element('div', {'id': 'dsettingsbox_container'}).injectInside(document.body);
	dscenter.setStyles({'top': window.getHeight() - 175});
	//window.addEvent('scroll', function(){dscenter.setStyles({'top': window.getScrollTop() + window.getHeight() - 175});});
	
	var dscenterfx = new Fx.Style('dsettingsbox_container', 'opacity', {duration:500});
	dscenterfx.hide();
	 
	new Ajax('/xhr/displaysettings/', {
		method: 'get',
		onComplete: function(response) {
			dscenter.setHTML(response);
			dscenterfx.start(0,1);
		}
	}).request();
	return false;
}

function displaysetting_close() {
	
	var dscenterfx = new Fx.Style('dsettingsbox_container', 'opacity', {duration:500});
	dscenterfx.start(1,0).chain(function() {
		$('dsettingsbox_container').remove();
	});
	
	return false;
	
}

		/*rbcenterfx.slideIn().chain(function() {
			/*(function() {
						
			}).delay(3000);
			
				if(opt == 1) {
					$$('.tutorialicon').each(function(item){
						item.src = 'http://www.pixel2life.com/images/no_av.gif';					   
					});
				} else {
					alert('---');
				}												
		});*/

/*----------------------------------------
||| TUTORIALS LISTING
-----------------------------------------*/

function tutorialClick(id) {
	$('tutorial_views_' + id).setText($('tutorial_views_' + id).getText().toInt() + 1);
}

function tutorialRate(id) {
	
	if(tutratingstatus) {
		
		warningbox_open('Sorry, you can only rate one tutorial at a time.');
		
	} else {
		
		tutratingstatus = true;
		tutratingid = id;
		tutratingamount = 3;
		
		new Ajax('/xhr/rating/', {
			method: 'post',
			data: 'tutid=' + id,
			onComplete: function(response) {
				if(response == 1) { 
					warningbox_open('Sorry, you must be registered to vote or leave comments on tutorials. ( <a href="#" onclick="return loginbox_open();">Login</a> )');
					tutratingstatus = false;
					tutratingid = 0;
				} else if(response == 2) { 
					warningbox_open('Sorry, you can only vote for this tutorial once!');
					tutratingstatus = false;
					tutratingid = 0;
				} else if(response == 3) { 
					warningbox_open('Sorry, this tutorial does not exist!');
					tutratingstatus = false;
					tutratingid = 0;
				} else {
					var rbcenter = new Element('div', {'id': 'ratingbox_container'}).injectInside(document.body);
					rbcenter.setHTML(response);
					//rbcenter.setStyles({'top': window.getScrollTop()});
					//window.addEvent('scroll', function(){rbcenter.setStyles({'top': window.getScrollTop()});});
					var rbcenterfx = new Fx.Slide(rbcenter, {duration: 500});
					rbcenterfx.hide();
					rbcenterfx.slideIn();
				}
			}
		}).request();
		
	}
	
	return false;
	
}

function tutorialRateHover(sid) {
	tutratingamount = sid;
	$('ratingbox_descriptor').setText(tutratingdescriptors[sid - 1]);
	for(i = 1; i <= 5; i++) {
		if(i <= sid) {
			$('ratingbox_star' + i).src = '/skin_images/ratingbox_starfill.png';
		} else {
			$('ratingbox_star' + i).src = '/skin_images/ratingbox_starempty.png';
		}
	}
}

function tutorialRateSend() {
	new Ajax('/xhr/rating/', {
		method: 'post',
		data: 'tutid=' + tutratingid + '&tutrating=' + tutratingamount,
		onComplete: function(response) {
			if(response == 0) {
				warningbox_open('Sorry, you can only vote for this tutorial once!');
			} else {
				if($('ratingimg_' + tutratingid)) {
					$('ratingimg_' + tutratingid).src = '/images/listingicons/rating_' + response + '.jpg';
				} else if($('publish_view_ratingimg')) {
					$('publish_view_ratingimg').src = '/images/listingicons/rating_' + response + '.gif';	  
				}
				successbox_open('Thanks for your vote!');
			}
			tutorialRateClose();
		}
	}).request();
	return false;
}

function tutorialRateClose() {
	var rbcenterfx = new Fx.Style('ratingbox_container', 'opacity', {duration:500});
	rbcenterfx.start(1,0).chain(function() {
		$('ratingbox_container').remove();
		tutratingstatus = false;
		tutratingid = 0;
	});
	return false;
}

function tutorialFaveHover(el, mode) {
	var curitem = $(el);
	if(curitem.getProperty('name') == 'foff') {
		if(mode == 1) {
			curitem.setProperty('src', '/images/listingicons/fav_on.gif');
		} else {
			curitem.setProperty('src', '/images/listingicons/fav_off.gif');
		}
	}
	return false;
}

function tutorialFave(el, tutid) {
	
	new Ajax('/xhr/favesact/toggle/', {
		method: 'post',
		data: 'tutid=' + tutid,
		onComplete: function(resp) {
			response = resp.split('|');
			if(response[0] == 1) {
				if($(el)) {
					if(response[1] == 1) {
						$(el).setProperty('name', 'foffsticky');
						$(el).setProperty('src', '/images/listingicons/fav_on.gif');
						$('fave_amount').setText($('fave_amount').getText().toInt() + 1);
					} else {
						$(el).setProperty('src', '/images/listingicons/fav_off.gif');
						$(el).setProperty('name', 'foff');
						if($('fave_amount').getText().toInt() > 0) {
							$('fave_amount').setText($('fave_amount').getText().toInt() - 1);
						}
					}
				}
				successbox_open(response[2]);
			} else {
				warningbox_open(response[1]);
			}
		}
	}).request();
	
	return false;
	
}

function tutorialReportHover(el) {
	var curitem = $(el);
	if(curitem.getProperty('name') == 'roff') {
		if(curitem.getProperty('src') == '/images/listingicons/report_off.gif') {
			curitem.setProperty('src', '/images/listingicons/report_on.gif');
		} else {
			curitem.setProperty('src', '/images/listingicons/report_off.gif');
		}
	}
	return false;
}

function tutorialReport(id) {
	confirmbox_open(msglib[50],'js','return tutorialReport_do(' + id + ');','js','return confirmbox_close();',false);
	return false;
}

function tutorialReport_do(id) {
	confirmbox_close();
	new Ajax('/xhr/report/', {
		method: 'post',
		data: 'tutid=' + id,
		onComplete: function(response) {
			var resp = response.split('|');
			if(resp[0] == '1') {
				if($('midtut_report_' + id)) {
					$('midtut_report_' + id).setProperty('src', '/images/listingicons/report_on.gif');
				}
				successbox_open('The tutorial has been flagged for review. Thanks.');
			} else {
				warningbox_open(resp[1]);
			}
		}
	}).request();
	return false;
}

function tutorialShare(id, el) {
	
	var startpt = $(el);
	
	if(shareboxStatus) {
		$('midtut_sharebox').remove();
	}
	
	var sharebox = new Element('div', {'id': 'midtut_sharebox'}).injectInside(document.body);
	sharebox.setHTML('<img src="/skin_images/sharewindow.png" alt="Share!" border="0" usemap="#sharebox_map" /><map name="sharebox_map" id="sharebox_map"><area shape="rect" coords="198,29,288,68" href="/sharetutorial/' + id + '/digg/" alt="Digg it!" title="Digg it!" target="_blank" /><area shape="circle" coords="296,18,13" href="#Close" alt="Close" title="Close" onclick="return tutorialShare_close();" /><area shape="rect" coords="40,67,126,92" href="/sharetutorial/' + id + '/blinklist/" alt="Blinklist" title="Blinklist" target="_blank" /><area shape="rect" coords="40,98,134,124" href="/sharetutorial/' + id + '/delicious/" alt="Del.icio.us" title="Del.icio.us" target="_blank" /><area shape="rect" coords="40,130,149,155" href="/sharetutorial/' + id + '/stumbleupon/" alt="StumbleUpon" title="StumbleUpon" target="_blank" /><area shape="rect" coords="41,160,120,186" href="/sharetutorial/' + id + '/google/" alt="Google Bookmarks" title="Google Bookmarks" target="_blank" /><area shape="rect" coords="41,190,159,215" href="/sharetutorial/' + id + '/yahoo/" alt="Yahoo! My Web" title="Yahoo! My Web" target="_blank" /><area shape="rect" coords="161,68,253,93" href="/sharetutorial/' + id + '/facebook/" alt="Facebook" title="Facebook" target="_blank" /><area shape="rect" coords="163,98,234,123" href="/sharetutorial/' + id + '/reedit/" alt="reedit" title="reedit" target="_blank" /><area shape="rect" coords="163,129,260,155" href="/sharetutorial/' + id + '/technorati/" alt="Technorati" title="Technorati" target="_blank" /><area shape="rect" coords="162,160,274,186" href="/sharetutorial/' + id + '/windowslive/" alt="Windows Live" title="Windows Live" target="_blank" /><area shape="rect" coords="163,188,223,215" href="/sharetutorial/' + id + '/furl/" alt="Furl" title="Furl" target="_blank" /></map>');
	sharebox.setStyles({'top': startpt.getTop(), 'left': startpt.getLeft()});
	
	shareboxStatus = true;
	
	return false;

}

function tutorialShare_close() {
	$('midtut_sharebox').remove();
	shareboxStatus = false;
	return false;
}

function tutorialShareHover(el) {
	var curitem = $(el);
	if(curitem.getProperty('name') == 'soff') {
		if(curitem.getProperty('src') == '/images/listingicons/share_off.gif') {
			curitem.setProperty('src', '/images/listingicons/share_on.gif');
		} else {
			curitem.setProperty('src', '/images/listingicons/share_off.gif');
		}
	}
	return false;
}

function quickbar_set(mode,catid,subid) {
	dyn_topload_start();
	var quickbarfx = new Fx.Style('quickbar_img', 'opacity', {duration:500});
	var midtutfx = new Fx.Style('midtut_listing', 'opacity', {duration:500});
	new Ajax('/xhr/quickbarload/', {
		method: 'post',
		data: 'mode=' + mode + '&catid=' + catid + '&subid=' + subid,
		onComplete: function(resp) {
			quickbarfx.hide();
			$('quickbar_img').setProperty('src', '/skin_images/midcat_quickbar_' + mode + '.jpg');
			quickbarfx.start(0,1);
			midtutfx.hide();
			$('midtut_listing').setHTML(resp);
			midtutfx.start(0,1).chain(function() {
				dyn_topload_stop();
			});
		}
	}).request();
	
	return false;
}

/*----------------------------------------
||| FAVORITES
-----------------------------------------*/

function faves_open() {

	dyn_topload_start();

	var cboverlay = new Element('div', {'id': 'lbBlack'}).injectInside(document.body);
	cboverlay.setStyles({'top': 0, 'height': window.getScrollHeight()});
	
	var cbcenter = new Element('div', {'id': 'faves_container'}).injectInside(document.body);
	
	var cboverlayfx = new Fx.Style(cboverlay, 'opacity', {duration:500});
	cboverlayfx.hide();
	
	var cbcenterfx = new Fx.Style(cbcenter,'opacity', {duration:500});
	cbcenterfx.hide();
	
	cboverlayfx.start(0, 0.75).chain(function() {
		new Ajax('/xhr/faves/', {
			method: 'get',
			update: cbcenter,
			evalScripts: true,
			onComplete: function() {
				cbcenterfx.start(0,1).chain(function() {
					dyn_topload_stop();				 
				});
			}
		}).request();
	});
	
	return false;

}

function faves_search_hover(mode) {
	if(mode == 1) {
		$('faves_search').setStyle('background-image','url(/skin_images/faves_search_bgon.jpg)');
		$('faves_searchq').setStyle('color','#72882F');
		if($('faves_searchq').getValue() == 'Search') {
			$('faves_searchq').value = '';		
		}
	} else {
		$('faves_search').setStyle('background-image','url(/skin_images/faves_search_bg.jpg)');
		$('faves_searchq').setStyle('color','#CCCCCC');
		if($('faves_searchq').getValue() == '') {
			$('faves_searchq').value = 'Search';
		}
	}
}

function faves_close() {
	favePage = 1;
	$('lbBlack').remove();
	$('faves_container').remove();
	return false;
}

function faves_navigate(mv) {
	
	favePage += mv;
	
	dyn_topload_start();
	
	var cbcenterfx = new Fx.Style('faves_main', 'opacity', {duration:500});
	
	cbcenterfx.start(1,0).chain(function() {
		new Ajax('/xhr/faves/', {
			method: 'post',
			data: 'favespage=' + favePage,
			update: $('faves_main'),
			evalScripts: true,
			onComplete: function() {
				cbcenterfx.start(0,1).chain(function() {
					dyn_topload_stop();				 
				});
			}
		}).request();
	});
}

function faves_navmode(md) {
	
	dyn_topload_start();
	
	$('faves_menumode').src = '/skin_images/faves_menu_mode' + md + '.jpg';
	var cbcenterfx = new Fx.Style('faves_main', 'opacity', {duration:500});
	
	cbcenterfx.start(1,0).chain(function() {
		new Ajax('/xhr/faves/', {
			method: 'post',
			data: 'favesmode=' + md,
			update: $('faves_main'),
			evalScripts: true,
			onComplete: function() {
				cbcenterfx.start(0,1).chain(function() {
					dyn_topload_stop();				 
				});
			}
		}).request();
	});
	
	return false;
}

function faves_reinit(page,perPage,startAm,totalAm) {
	
	favePage = page;
	for(i = 1; i <= favesusualtotal; i++) {
		if($('faves_doti' + i)) {
			if(i > Math.ceil(totalAm / 12)) {
				$('faves_doti' + i).setStyle('display','none');
			} else {
				$('faves_doti' + i).setStyle('display','');
				$('faves_doti' + i).setProperty('src','/skin_images/faves_dot_' + ((i == page) ? 'on' : 'off') + '.gif');
			}
		}
	}
	$('fave_lblpp').setText(perPage);
	$('fave_lbltt').setText(totalAm);
	$('fave_lblsa').setText(startAm);
	$('fave_lblea').setText(startAm + perPage - 1);
	$('faves_nav_previous').setProperty('src','/skin_images/faves_nav_previous' + ((favePage > 1) ? '' : 'off') + '.jpg');
	$('faves_nav_next').setProperty('src','/skin_images/faves_nav_next' + ((favePage < Math.ceil(totalAm / 12)) ? '' : 'off') + '.jpg');
	
}

function faves_search() {
	
	if($('faves_searchq').getValue().clean() != '' && $('faves_searchq').getValue().clean() != 'Search') {
	
		dyn_topload_start();
		
		$('faves_menumode').src = '/skin_images/faves_menu_mode0.jpg';
		var cbcenterfx = new Fx.Style('faves_main', 'opacity', {duration:500});
		
		cbcenterfx.start(1,0).chain(function() {
			new Ajax('/xhr/faves/', {
				method: 'post',
				data: 'favesmode=0&favesqry=' + escape($('faves_searchq').getValue().clean()),
				update: $('faves_main'),
				evalScripts: true,
				onComplete: function() {
					cbcenterfx.start(0,1).chain(function() {
						dyn_topload_stop();				 
					});
				}
			}).request();
		});
		
	} else {
		faves_navmode(1);
	}
	
	return false;
	
}

/*----------------------------------------
||| USERS
-----------------------------------------*/

// Switch Tab

function users_switchtab(tabid, userid) {

	dyn_topload_start();
	$('users_mainright').setHTML('<div style="padding:15px; color:#AAAAAA;">Loading...</div>');
	usersleftmenu.each(function(item, index){
		if(item == tabid) {
			$('usersm_' + item).src = '/skin_images/users_leftmenu_' + item + '_on.jpg';
		} else {
			$('usersm_' + item).src = '/skin_images/users_leftmenu_' + item + '_off.jpg';
		}
	});
	new Ajax('/xhr/users/', {
		method: 'post',
		data: 'userid=' + userid + '&userstab=' + tabid,
		update: $('users_mainright'),
		onComplete: function() {
			dyn_topload_stop();
			if(userscommentlocate) {
				userscommentlocate = false;
				FxScrollObjectFast.toElement('users_comments_post');
				$('users_newcomment').focus();
			}
		}
	}).request();
	
	return false;

}

// Switch Tab to Post Comment Screen

function users_switchtab_postscreen(userid) {
	userscommentlocate = true;
	users_switchtab('comments', userid);
	return false;
}

// View More Tutorials

function users_switchtab_more(tabid, userid, pageid) {
	dyn_topload_start();
	FxScrollObjectFast.toElement($('users_mainright')).chain(function() {
		$('users_mainright').setHTML('<div style="padding:15px; color:#AAAAAA;">Loading...</div>');
		new Ajax('/xhr/users/', {
			method: 'post',
			data: 'userid=' + userid + '&userstab=' + tabid + '&userpage=' + pageid,
			update: $('users_mainright'),
			onComplete: function() {
				dyn_topload_stop();
			}
		}).request();
	});
}

// Add as friend

function users_addfriend(userid) {
	confirmbox_close();
	dyn_topload_start();
	new Ajax('/xhr/usersaddfriend/', {
		method: 'post',
		data: 'userid=' + userid,
		onComplete: function(response) {
			dyn_topload_stop();
			resp = response.split('|');
			if(resp[0] == '1') {
				successbox_open(resp[1]);
			} else {
				warningbox_open(resp[1]);
			}
		}
	}).request();
}

// Post a comment

function users_postcomment() {

	var content = $('users_newcomment').getValue();
	
	if(content.length < 10) {
		warningbox_open('The comment is too short!');
	} else {
		dyn_topload_start();
		new Ajax('/xhr/userspostcomment/', {
			method: 'post',
			data: $('users_postcomment_form'),
			onComplete: function(response) {
				dyn_topload_stop();
				if(response == '0') {
					warningbox_open('The comment could not be posted. An error occured.');
				} else if(response == '1') {
					warningbox_open('Please wait 15 seconds before posting a new comment.');
				} else {
					$('users_newcomment').value = '';
					if($('userhasnocomments')) {$('userhasnocomments').remove();}
					var newcomment = new Element('div', {'class': 'users_comment'}).setHTML(response).injectTop('users_comments_all');
					var newcommentfx = new Fx.Slide(newcomment, {duration: 1000});
					newcommentfx.hide();
					FxScrollObjectFast.toElement('main_container').chain(function() {
						newcommentfx.slideIn().chain(function() {
							successbox_open('Your comment was posted successfully!');
						});
					});
				}
			}
		}).request();
	}

}

/*----------------------------------------
||| ADVERTISING
-----------------------------------------*/

function ad_delete_campaign(id) {
	confirmbox_open(msglib[250],'js','return ad_delete_campaign_do(' + id + ');','js','return confirmbox_close();',false);
	return false;
}
function ad_delete_campaign_do(id) {
	confirmbox_close();
	dyn_topload_start();
	new Ajax('/xhr/addelete/', {
			method: 'post',
			data: 'adid=' + id,
			onComplete: function(response) {
				dyn_topload_stop();
				if(response == '0') {
					warningbox_open(msglib[251]);
				} else {
					window.location.reload();
				}
			}
		}).request();
	return false;
}

function ad_globalswitch(mode) {

	dyn_topload_start();
	new Ajax('/xhr/adglobalswitch/', {
			method: 'post',
			data: 'mode=' + mode,
			onComplete: function(response) {
				dyn_topload_stop();
				if(response == '0') {
					warningbox_open('An error occured.');
				} else {
					if(mode == 0) {
						successbox_open(msglib[252]);
					} else {
						successbox_open(msglib[253]);
					}
				}
			}
		}).request();
	return false;


}

function ad_setnotif() {

	var adnotlow = $('adsetting_notlow').getValue().toInt();
	if(adnotlow >= 0) {
	
		dyn_topload_start();
		new Ajax('/xhr/adnotlow/', {
			method: 'post',
			data: 'adnotlow=' + adnotlow ,
			onComplete: function(response) {
				dyn_topload_stop();
				successbox_open(msglib[254]);
			}
		}).request();
			
	}
	return false;
	
}