if( typeof VRPG == "undefined" ) {
	VRPG = {};
}

if( typeof VRPG.forums == "undefined" ) {
	VRPG.forums = {};
}

if( typeof VRPG.files == "undefined" ) {
	VRPG.files = {};
}

VRPG.get = YAHOO.util.Dom.get;

if( typeof console == "undefined" ) {
	console = { log : function(a) {} };
}

VRPG.forums.wantToReply = function() {

	if( typeof VRPG.forums._wantToReply == "undefined" ) {
		VRPG.forums._wantToReply = true;
	} else {
		return;
	}
	
	YAHOO.util.Event.onAvailable( 
		'bottomline',
		function() {
			
			var nodes = YAHOO.util.Dom.getElementsByClassName('wantToReply', 'div');
			
			//console.log( 'found: ' + YAHOO.util.Dom.getElementsByClassName('wantToReply', 'div').length + ' elements' );
			//console.log( 'VRPG.getRoot(): ' + VRPG.getRoot() );
			
			for(i in nodes) {
				nodes[i].innerHTML = 'Want to reply?  <a href="'+VRPG.getRoot()+'user/login/">login</a> or <a href="'+VRPG.getRoot()+'user/register/">register</a>!';
			}
		}
	);
}

VRPG.forums.stickyAlertInit = function() {
	VRPG.forums.stickyAlert_dialog = 
		new YAHOO.widget.Dialog(
			"myStickyDialog",
			{
				modal:true,
				fixedcenter:true,
				draggable: false,
				icon: YAHOO.widget.SimpleDialog.ICON_HELP,
				constraintoviewport: true,
				close: false,
				buttons: [ 
					{ 
						text:"Submit", 
						handler: function() {

							var s = YAHOO.util.Dom.get('mega_stickiness')
						
							var myNum = new Number(s.value);
							
							if( s.value.length == 0 ) {
								myNum = Number.NaN;
							}
							
							if( !isNaN(myNum) ) {
								document.location = VRPG.forums.stickyAlert_target+'/'+myNum.valueOf();
							} else {
								alert( "That stickiness is invalid." )
							}
						}, 
						isDefault:true 
					},
					
					{ 
						text:"Cancel",  
						handler: function() {
							VRPG.forums.stickyAlert_dialog.hide();
						} 
					}
				]
			}
		); 
	VRPG.forums.stickyAlert_dialog.render("doc2"); 
	VRPG.forums.stickyAlert_dialog.hide(); 
}

VRPG.forums.stickyAlert = function(evt, argObj) {

	YAHOO.util.Event.preventDefault( evt );
	
	VRPG.forums.stickyAlert_target = evt.target;
	
	VRPG.forums.stickyAlert_dialog.show(); 
	
	return;
};


VRPG.forums.deleteAlert = function(evt, argObj) {
	YAHOO.util.Event.preventDefault( evt );
	
	var myOriginalTarget = evt.target;
		
	var myText = 'Are you sure you want to '+(argObj.is_deleted?'undelete':'delete')+' this message?';
	
	// Instantiate the Dialog
	VRPG.forums.deleteAlert_SimpleDialog = 
		new YAHOO.widget.SimpleDialog(
			"deleteAlert_SimpleDialog", 
			{ width: "300px",
				fixedcenter: true,
				visible: false,
				modal: true,

				draggable: false,
				close: false,
				text: myText,
				icon: YAHOO.widget.SimpleDialog.ICON_HELP,
				constraintoviewport: true,
				buttons: [ 
					{ 
						text:"Yes", 
						handler: function() {
							document.location = myOriginalTarget;
						}, 
						isDefault:true 
					},
					
					{ 
						text:"No",  
						handler: function() {
							VRPG.forums.deleteAlert_SimpleDialog.hide();
						} 
					}
				]
			} 
		);
	VRPG.forums.deleteAlert_SimpleDialog.render("doc2");
	VRPG.forums.deleteAlert_SimpleDialog.show();	
};

if( typeof VRPG.util == "undefined" ) {
	VRPG.util = {};
}

VRPG.util.urlencode = function (str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

VRPG.util.forms = {};
VRPG.util.forms.select = {};

VRPG.util.forms.select.enable = function(e) {
	sel = VRPG.get(e);
	sel.disabled = false;
	YAHOO.util.Dom.removeClass(sel, 'disabledSelect'); 
};

VRPG.util.forms.select.disable = function(e) {
	sel = VRPG.get(e);
	sel.disabled = true;
	YAHOO.util.Dom.addClass(sel, 'disabledSelect'); 
}
