function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function report(type, id){
	clearInterval(refreshIntervalId);
	$('black_underlay').show();
	var arrayPageSize = getPageSize();
	$('black_underlay').setStyle({height: arrayPageSize[1] + 'px'});
	$('white_overlay').show();
	
	var reportLink = '<a href="#" onclick="reportSend(\''+type+'\', \''+id+'\', document.getElementById(\'reportmessage\').value); return false;">Send Report</a>';
	$('white_overlay').innerHTML = '<div class="box"><div class="title"><span class="float-right"><img src="/images/icons/cross.png" alt="Close" title="Close" class="pointer" onclick="reportClose();" /></span>Report Content</div><div class="content">Please enter why you are reporting this?<br /><br /><form method="post" id="reportForm"><textarea name="reportmessage" id="reportmessage"></textarea><br /><br />'+reportLink+'</form></div></div>';
}

function reportClose(){
	$('black_underlay').hide();
	$('white_overlay').hide();
	
	var refreshIntervalId = setInterval("Alert.get();", 3000);
}

function reportSend(type, id, value){
	reportClose();
	var newvalue = value.strip();
	newvalue = newvalue.stripTags();
	newvalue = newvalue.escapeHTML();
	newvalue = encodeURIComponent(newvalue);

	new Ajax.Request('/ajax.php/report/'+ type + '/' + id + '/' + newvalue,{
		method: 'get',
		onComplete: function(obj){
			if(obj.responseText == 1){
				alert('This post has been sent to our community moderators for review!');
			}
			
			if(obj.responseText == 2){
				alert('Please login to report this post.');
			}
			
			if(obj.responseText == 3){
				alert('You must enter a reason for this report!');
			}
		}
	});
}

function like(section, sid, like){
	new Ajax.Request('/ajax.php/like/'+ section + '/' + sid + '/' + like,{
		method: 'get',
		onComplete: function(obj){
			$(section + '_' + sid).innerHTML = obj.responseText;
		}
	});
}

function menu(id){
    var call = id + '_menu';
    var dropdown = $(call);
		
    $(id).addClassName('selectedb');
    dropdown.setStyle({width: '200px'});
    dropdown.show();
}

function menu_off(id){
    var call = id + '_menu';
    $(id).removeClassName('selectedb');
    $(call).hide();
}

function toggle_hidden(id){
    var hidden = $(id);

    if(hidden.getStyle('display') != 'block'){
        $(id).show();
    }
}

function clearin(id){
	var input = $(id);
	input.value = '';
}

function input(id,def){
	var input = $(id);
	input.value = (input.value == def) ? '' : input.value;
}

function toggle_content(current, next){
	var cur = $(current);
	var next = $(next);
	
	cur.innerHTML = next.innerHTML;
}

function check_all(id, type, field){
	var boxes = $$("[id^='"+id+"_']");
	switch(type){
		case 'invert':
			for (i = 0; i < boxes.length; i++){
				var chk = boxes[i];
				chk.checked = (chk.checked == true) ? false : true;
			}
		break;
		
		case 'all':
			for (i = 0; i < boxes.length; i++){
				boxes[i].checked = true;
			}
		break;
		
		case 'none':
			for (i = 0; i < boxes.length; i++){
				boxes[i].checked = false;
			}
		break;
		
		case 'class':
			check_all(id, 'none');
		
			boxes = $$("[class~='"+field+"']");
			for (i = 0; i < boxes.length; i++){
				boxes[i].checked = true;
			}
		break;
		
		default:
	}	
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function collapsible(sname, id){
	var name = sname + '_' + id;
	Delete_Cookie(name, '/');

	var c = $(name);
	var i = $(sname + '_collapse_' + id);
	var block = (c.getStyle('display') == 'block') ? 'none' : 'block';
	var expand = (block == 'block') ? 'collapse' : 'expand';
	var expandb = (block == 'block') ? 'bullet_toggle_minus' : 'bullet_toggle_plus';
	
	i.src = (sname == 'housekeeping' || sname == 'home') ? '/images/icons/'+ expandb +'.png' : '/images/layout/'+ expand +'.png';
	c.setStyle({display: block});
	
	Set_Cookie(name, block, 30, '/');
}

function init_collapsibles(sname){
	var collapsibles = $$("[class^='forumcollapsible']");

	for (ib = 0; ib < collapsibles.length; ib++){
		var name = sname + '_' + ib;
		var c = $(name);
		var img = $(sname + '_collapse_' + ib);
		
		var cookie = Get_Cookie(name);
		var expand = (cookie == 'block') ? 'collapse' : 'expand';
		var expandb = (cookie == 'block') ? 'bullet_toggle_minus' : 'bullet_toggle_plus';
		 
		img.src = (sname == 'housekeeping' || sname == 'home') ? '/images/icons/'+ expandb +'.png' : '/images/layout/'+ expand +'.png';
		c.setStyle({display: cookie});
	}
}