// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;
var IEVersion = 0.0;

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

/* Used in Form.class.php */
// Keep track of mouse x & y for clicking on text
var orig_x = 0;
var orig_y = 0;
// mX and mY come from general.js (mouse coords are recorded constantly in mX and mY)
function track_mouse()
{
	orig_x = mX;
	orig_y = mY;
}

function mouse_was_dragged()
{
	if(orig_x == mX && orig_y == mY)
	{
		return false;
	}
	return true;
}
/* END */

function addslashes(str)
{
	str=str.replace(/'/g, "\\'");
	return str;
}

function textarea_to_str(str)
{
	str=str.replace(/\n/g, "<br>");
	str=str.replace(/&gt;/g, ">");
	str=str.replace(/&lt;/g, "<");
	str=str.replace(/&quot;/g, '"');
	str=str.replace(/&rsquo;/g, "\'");
	
	return str;
}

function str_to_textarea(str)
{
	str=str.replace(/<br>/g, "\n");
	//str=str.replace(/>/g, "&gt;");
	//str=str.replace(/</g, "&lt;");
	//str=str.replace(/"/g, "&quot;");
	//zstr=str.replace(/'/g, "&rsquo;");
	
	return str;
}

if(IE) {
	var temp = navigator.appVersion.split("MSIE");
	IEVersion = parseFloat(temp[1]);
}

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use get_mouse_pos function onmousemove
document.onmousemove = get_mouse_pos;

// Temporary variables to hold mouse x-y pos.s
var mX = 0;
var mY = 0;

// Main function to retrieve mouse x-y pos.s
function get_mouse_pos(e) {
  if(IE) { // grab the x-y pos.s if browser is IE
  	var scrollLeft = 0;
  	var scrollTop = 0;
  
	if(document.documentElement)
	{
		scrollLeft = document.documentElement.scrollLeft;
		scrollTop  = document.documentElement.scrollTop;
	}
  	else if(document.body)
	{
		scrollLeft = document.body.scrollLeft;
		scrollTop  = document.body.scrollTop;
	}
  
    mX = event.clientX + scrollLeft;
    mY = event.clientY + scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    mX = e.pageX;
    mY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (mX < 0){mX = 0}
  if (mY < 0){mY = 0}  
  return true;
}

// function: find_pos
function find_pos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while(obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {"x":curleft,"y":curtop};
}

/* General JS Functions: tick for textarea */
function set_chars_left(name, max_len)
{
	var len = $(name+'_input').value.length;
	if(len > max_len)
	{
		$(name+'_input').value = $(name+'_input').value.substring(0, max_len);
	}
	$(name+'_char_lim').update(max_len-len);
}

var timer = Array();
var lengths = Array();
function tick(name, maxLength)
{
	var length = $(name + '_input').value.length;
	if(lengths[name + '_input'] == length)
	{
		timer[name] = setTimeout("tick('" + name + "', " + maxLength + ")", 500);
		return;
	}
	if($(name + '_input').value.length > maxLength)
	{
		$(name + '_input').value = $(name + '_input').value.substring(0,maxLength);
		length = maxLength;
	}

	$(name + '_char_lim').update(maxLength - length);
	lengths[name + '_input'] = length;

	timer[name] = setTimeout("tick('" + name + "', " + maxLength + ")", 500);
}

/* Set Cookie */
function set_cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
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" : "" );
}

/* Get Cookie */
function get_cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

/* GENERAL CHECKS */
function is_empty(value)
{
	var tmp_val = value;
	tmp_val = tmp_val.replace(/ /ig,"");
	if(tmp_val == '' || tmp_val == null)
	{
		return true;
	}
	return false;
}
function is_len_gt(value, len)
{
	if(value.length > len)
	{
		return true;
	}
	return false;
}
function is_len_gte(value, len)
{
	if(value.length >= len)
	{
		return true;
	}
	return false;
}
function is_len_eq(value, len)
{
	if(value.length == len)
	{
		return true;
	}
	return false;
}
function is_len_lt(value, len)
{
	if(value.length < len)
	{
		return true;
	}
	return false;
}
function is_len_lte(value, len)
{
	if(value.length <= len)
	{
		return true;
	}
	return false;
}
function is_valid_email(value)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(value))
	{
		return true;
	}
	return false;
}
function is_valid_username(value)
{
	var filter = /[^a-zA-Z0-9\-]/;
	if(filter.test(value))
	{
		return false;
	}
	return true;
}
function is_valid_date(field, value)
{
	var date = value.split('/');
	if(date.length != 3)
	{
		return false;
	}

	var filter = /[^0-9\/]/;
	if(filter.test(value))
	{
		return false;
	}

	if(date[2] > 10 && date[2] < 100)
	{
		date[2] = parseInt(date[2]) + 1900;
		$(field).value = date[0] + '/' + date[1] + '/' + date[2];
	}

	var filter  = /^[0-9]{1,2}$/;
	var filter2 = /^[0-9]{4}$/;
	
	if(filter.test(date[0]) && filter.test(date[1]) && filter2.test(date[2]))
	{
		return true;
	}
	return false;
}
function contains_only(value, regex)
{
	var filter = new RegExp("[^" + regex + "]");
	
	if(filter.test(value))
	{
		return false;
	}
	return true;
}
function make_lowercase(field, value)
{
	$(field).value = value.toLowerCase();
	return true;
}

var tab_timer = Object();
var tab_opened = Object();
function show_over_box(container_id, box_id, bg_color, font_color)
{
	if(!bg_color)
	{
		bg_color = 'FFFFFF';
	}
	if(!font_color)
	{
		font_color = '000000';
	}

	$(container_id).onmouseout = function() {
		clearTimeout(tab_timer[box_id]);
		tab_timer[box_id] = setTimeout("hide_over_box('"+box_id+"');", 1);
	};
	$(box_id).onmouseout = function() {
		clearTimeout(tab_timer[box_id]);
		tab_timer[box_id] = setTimeout("hide_over_box('"+box_id+"');", 1);
	};
	$(container_id).onmouseover = function() {
		clearTimeout(tab_timer[box_id]);
		if(tab_opened[box_id] == false)
			show_over_box(container_id, box_id, bg_color, font_color);
	};
	$(box_id).onmouseover = function() {
		clearTimeout(tab_timer[box_id]);
		if(tab_opened[box_id] == false)
			show_over_box(container_id, box_id, bg_color, font_color);
	};

	// Get position of the container
	var pos = find_pos(document.getElementById(container_id));
	var container_dim = $(container_id).getDimensions();
	pos.y += container_dim.height;

	$(box_id).style.backgroundColor='#'+bg_color;
	$(box_id).style.color='#'+font_color;
	$(box_id).style.zIndex=999999;
	$(box_id).style.position='absolute';
	$(box_id).style.left=pos.x+'px';
	$(box_id).style.top=pos.y+'px';
	$(box_id).style.display='';
	
	tab_opened[box_id] = true;
}

function hide_over_box(box_id)
{
	$(box_id).style.display='none';
	tab_opened[box_id] = false;
}










var is_bubble_created = false;
function post_new_event(type, message, container_id)
{
	if(!is_bubble_created) create_bubble();
	
	// Set the bubble message
	set_event_bubble_message(type, message);

	// Handle bubble (appear, disappear, etc.)
	create_event_bubble(message, container_id);
}

function create_bubble()
{
	var bubble_html = '<div id="event_bubble_container" style="width: 200px; display: none;">'+
		''+
		'<!-- top -->'+
		'<div style="overflow: hidden; height: 25px;">'+
			'<div style="float: left; width: 10px; height: 25px;">';
			if(IE)
			{
				bubble_html += '<div style="width: 10px; height: 25px; float: left; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/event_bubble/tlc.png\', sizingMethod=\'image\');"></div>';
			}
			else
			{
				bubble_html += '<img src="/images/event_bubble/tlc.png" />';
			}
			bubble_html += '</div>'+
			'<div id="event_bubble_top_bg" style="float: left; height: 25px; background: url(\'/images/event_bubble/top_bg.png\') bottom repeat-x;">&nbsp;</div>'+
			'<div id="trc_image_container" style="float: right; width: 10px; height: 25px;">';
			if(IE)
			{
				bubble_html += '<div id="trc_image" style="width: 10px; height: 25px; float: left; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/event_bubble/trc.png\', sizingMethod=\'image\');"></div>';
			}
			else
			{
				bubble_html += '<img id="trc_image" src="images/event_bubble/trc.png" />';
			}
			bubble_html += '</div>'+
			'<div class="spacer">&nbsp;</div>'+
		'</div>'+
		'<!-- end top -->'+
		''+
		'<!-- center container -->'+
		'<div>'+
		''+
			'<!-- left -->'+
			'<div id="event_bubble_left_bg" style="padding-left: 10px; background: url(\'/images/event_bubble/left_bg.png\') left repeat-y;">'+
		''+
				'<!-- right -->'+
				'<div id="event_bubble_right_bg" style="padding-right: 10px; background: url(\'/images/event_bubble/right_bg.png\') right repeat-y;">'+
		''+
					'<!-- message -->'+
					'<div id="event_bubble_message_container">'+
						'<div id="event_message"></div>'+
						'<div style="text-align: right; color: #000000;"><a href="#" onClick="$(\'event_bubble_container\').hide(); return false;">close</a></div>'+
					'</div>'+
					'<!-- end message -->'+
		''+
				'</div>'+
				'<!-- end right -->'+
		''+
			'</div>'+
			'<!-- end left -->'+
		''+
		'</div>'+
		'<!-- end center container -->'+
		''+
		'<!-- bot -->'+
		'<div style="overflow: hidden; height: 25px;">'+
			'<div style="float: left; width: 10px; height: 25px;">';
			if(IE)
			{
				bubble_html += '<div style="width: 10px; height: 25px; float: left; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/event_bubble/blc.png\', sizingMethod=\'image\');"></div>';
			}
			else
			{
				bubble_html += '<img src="images/event_bubble/blc.png" />';
			}
			bubble_html += '</div>'+
			'<div id="event_bubble_bot_bg" style="float: left; height: 25px; background: url(\'/images/event_bubble/bot_bg.png\') top repeat-x;">&nbsp;</div>'+
			'<div id="brc_image_container" style="float: right; width: 58px; height: 25px;">';
			if(IE)
			{
				bubble_html += '<div id="brc_image" style="width: 58px; height: 25px; float: left; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/event_bubble/brs.png\', sizingMethod=\'image\');"></div>';
			}
			else
			{
				bubble_html += '<img id="brc_image" src="images/event_bubble/brs.png" />';
			}
			bubble_html += '</div>'+
			'<div class="spacer">&nbsp;</div>'+
		'</div>'+
		'<!-- end bot -->'+
		''+
	'</div>';
	
	new Insertion.Bottom(document.body, bubble_html);
	is_bubble_created = true;
}

var bubble_message = '';
var bubble_status = 'closed';
var max_bubble_width = 200;
// Every time this is called, we'll try to bring down the fader if
// it's not down and set a timer to bring it back up.  However, we
// may lock the fader so that it can't get a down call while going
// up or vice-versa
function create_event_bubble(message, container_id)
{
	// Calculate the width of the bubble
	var bubble_width = message.length * 7;
	if(bubble_width > max_bubble_width)
	{
		var words = message.split(" ");
		var char_count = 0;
		var first = true;
		for(var i = 0; i < words.length; i++)
		{
			var count = words[i].length;
			if(first == true)
			{
				first = false;
			}
			else
			{
				count++;
			}

			// If this word puts the width over the max, stay with char_count as the width
			if((char_count + count)*7 > max_bubble_width)
			{
				break;
			}
			char_count += count;
		}
		bubble_width = char_count*7;
	}

	if(container_id == null || $(container_id) == null)
	{
		container_id = 'content';
	}
	
	var is_generic = true;
	if(container_id != 'content' && container_id.indexOf('_input') != -1)
	{
		is_generic = false;
	}
	
	// Get container dimensions and position
	var container_dim = $(container_id).getDimensions();
	var container_pos = find_pos($(container_id));
	
	if(container_dim.width == 0)
	{
		// Default to this so the bubble doesn't go off the screen
		container_dim.width = 800;
	}

	if(is_generic)
	{
		// Calculate the position for the bubble to be in the exact middle of the container
		var bubble_x = container_pos.x + container_dim.width/2 + bubble_width/2;
		var	bubble_y = container_pos.y - 10;
	}
	else
	{
		// Calculate the position for the bubble to be just above the container to the left
		var bubble_x = container_pos.x+5;
		var	bubble_y = container_pos.y+5;
	}

	// Set the bubble widths
	$('event_bubble_message_container').style.width = bubble_width + 'px';
	$('event_bubble_container').style.width = (bubble_width + 20) + 'px';

	// Set the bubble position
	var bubble_dim = $('event_bubble_container').getDimensions();
	// Move the bubble left and up equal to its width and height
	bubble_y -= bubble_dim.height;
	bubble_x -= bubble_dim.width;
	// If the bubble y position is negative (off the screen), let's reposition it
	if(!is_generic)
	{
		if(bubble_y < 0)
		{
			bubble_y += bubble_dim.height+container_dim.height-10;
			// Make the speach on the top
			$('event_bubble_top_bg').style.width = (bubble_width-48) + 'px';
			$('event_bubble_bot_bg').style.width = bubble_width + 'px';
			$('trc_image_container').style.width = '58px';
			$('brc_image_container').style.width = '10px';
			if(IE)
			{
				$('trc_image').style.filter=$('trc_image').style.filter.replace('trc', 'trs');
				$('brc_image').style.filter=$('brc_image').style.filter.replace('brs', 'brc');
			}
			else
			{
				$('trc_image').src=$('trc_image').src.replace('trc', 'trs');
				$('brc_image').src=$('brc_image').src.replace('brs', 'brc');
			}
		}
		else
		{
			// Make the speach on the bot
			$('event_bubble_top_bg').style.width = bubble_width + 'px';
			$('event_bubble_bot_bg').style.width = (bubble_width-48) + 'px';
			$('trc_image_container').style.width = '10px';
			$('brc_image_container').style.width = '58px';
			if(IE)
			{
				$('trc_image').style.filter=$('trc_image').style.filter.replace('trs', 'trc');
				$('brc_image').style.filter=$('brc_image').style.filter.replace('brc', 'brs');
			}
			else
			{
				$('trc_image').src=$('trc_image').src.replace('trs', 'trc');
				$('brc_image').src=$('brc_image').src.replace('brc', 'brs');
			}
		}
	}
	else
	{
		if(bubble_y < 0)
		{
			bubble_y += bubble_dim.height+container_dim.height+10;
		}

		// Make no speach
		$('event_bubble_top_bg').style.width = bubble_width + 'px';
		$('event_bubble_bot_bg').style.width = bubble_width + 'px';
		$('trc_image_container').style.width = '10px';
		$('brc_image_container').style.width = '10px';
		if(IE)
		{
			$('trc_image').style.filter=$('trc_image').style.filter.replace('trs', 'trc');
			$('brc_image').style.filter=$('brc_image').style.filter.replace('brs', 'brc');
		}
		else
		{
			$('trc_image').src=$('trc_image').src.replace('trs', 'trc');
			$('brc_image').src=$('brc_image').src.replace('brs', 'brc');
		}
	}
	$('event_bubble_container').style.top = bubble_y + 'px';
	$('event_bubble_container').style.left = bubble_x + 'px';

	if(bubble_status == 'closed')
	{
		$('event_bubble_container').show();
	}
	
	Effect.Shake('event_bubble_container', 1);
}

function set_event_bubble_message(type, message)
{
	if(bubble_message != message)
	{
		$('event_message').innerHTML = message;
		bubble_message = message;
	}
}






function post_new_event2(type, message, container_id)
{
	if(ip == '68.96.77.116' || ip == '66.27.212.60')
	{
		post_new_event2(type, message, container_id);
		return;
	}

	if(IE && IEVersion < 7.0)
	{
		alert(message);
	}
	else
	{
		// Handle the event (insert, swap, fade, update, etc.)
		handle_event(type, message);
	
		// Handle fader (go up, go down, etc.)
		handle_fader();
	}
}

var slide_up_timer = null;
var fader_status = 'up';
// Every time this is called, we'll try to bring down the fader if
// it's not down and set a timer to bring it back up.  However, we
// may lock the fader so that it can't get a down call while going
// up or vice-versa
function handle_fader()
{
	// If handle_fader is locked, then try again in .1 sec
	if(lock_array['handle_fader'])
	{
		setTimeout("handle_fader();", 100);
		return;
	}

	// Reset the slide_up_timer
	clearTimeout(slide_up_timer);

	// Try to slide the fader down
	// Lock the handle_fader function for .5 sec
	if(fader_status == 'up')
	{
		Effect.SlideDown('event_fader', {duration:.5});
		fader_status = 'down';
		setTimeout("lock_func('handle_fader', .5);", 3000);
	}
	
	// Set the event_fader to slide up in 10 sec
	// Once it's sliding up, lock the handle_fader function for .5 sec
	slide_up_timer = setTimeout("Effect.SlideUp('event_fader', {duration:.5}); lock_func('handle_fader', .5); fader_status = 'up';", 10000);
}

var event_msg = '';
var event_exists = false;
var event_fade_timer = null;
var lock_handle_event = false;
function handle_event(type, message)
{
	// If handle_event is locked, then try again in .1 sec
	if(lock_array['handle_event'])
	{
		setTimeout("handle_event('"+type+"', '"+addslashes(message)+"');", 100);
		return;
	}

	// Reset the event_fade_timer
	clearTimeout(event_fade_timer);

	// If we enounter the same message and the event exists, then let's not give it again
	// (spam protection!)
	if(!event_exists || event_msg != message)
	{
		if(type == 'error')
		{
			error_issued = true;
		}
		
		if(event_exists)
		{
			// If there is currently an event, then fade it out
			Effect.Fade('fader_event', { duration: .5 });
		}
		
		// Replace content with new message in .5 sec
		// Also, toggle the class name so it appears correctly (colors, style, etc.)
		//message.evalScripts();
		//message = message.stripScripts();
		setTimeout("$('fader_event').innerHTML='"+addslashes(message)+"'; $('fader_event').className='"+type+"'; event_exists=true;", 500);

		// Fade in event in .5 sec
		setTimeout("Effect.Appear('fader_event', { duration: .5 });", 500);

		// Store the event message for later comparison
		event_msg = message;
	}

	// Set the event to fade out (slow 1 sec fade) automatically in 9 sec
	// and lock this function for 1 sec
	event_fade_timer = setTimeout("Effect.Fade('fader_event', { duration: 1 }); lock_func('handle_event', 1); event_exists=false;", 9000);
}

var lock_array = Array();
function lock_func(name, lock_time)
{
	// Multiply lock time to convert from sec to milisec
	lock_time = lock_time * 1000;

	// Set the lock status for the function to true
	lock_array[name] = true;

	// Unlock the function after the lock_time has expired
	setTimeout("unlock_func('"+name+"')", lock_time);
}

function unlock_func(name)
{
	lock_array[name] = false;
}


/* Slider functions */
function get_page_y_offset()
{
	if(IE)
	{
		if (document.documentElement && document.documentElement.scrollTop)
		{
			page_y_offset = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			page_y_offset = document.body.scrollTop;
		}
	}
	else
	{
		page_y_offset = window.pageYOffset;
	}
	return page_y_offset;
}

slider = Class.create();
slider.prototype.initialize = function(id, option)
{
	this.self = $(id);

	if(option.margin_top) { this.margin_top = option.margin_top; }
	else { this.margin_top = 0; }

	if(option.type == 'fixed') { this.type = option.type; }
	else { this.type = 'normal'; }

	this.self.style.position = 'relative';

	var pos = find_pos(this.self);
	this.orig_y_pos = pos.y;
	this.cur_y_pos = pos.y;

	this.self.style.top = '0px';
	this.self.style.left = '0px';
}
slider.prototype.check_y_pos = function()
{
	// Get page_y_offset
	var page_y_offset = get_page_y_offset()+this.margin_top;

	// If the type is fixed, once it reaches a scroll point, make it fixed
	if(this.type == 'fixed')
	{
		if(page_y_offset > this.orig_y_pos)
		{
			this.self.style.position = 'fixed';
			this.self.style.top = this.margin_top + 'px';
			return;
		}
		else
		{
			this.self.style.position = 'relative';
			this.self.style.top = '0px';
			return;
		}
	}

	// Slow down as we reach the origin, or the top of the page
	if(page_y_offset < this.orig_y_pos)
	{
		var y_dif = Math.abs(this.orig_y_pos-this.cur_y_pos);
	}
	else
	{
		var y_dif = Math.abs(page_y_offset-this.cur_y_pos);
	}
	var y_move = parseInt(y_dif/10)+10;

	// Moving down
	if(page_y_offset > this.cur_y_pos)
	{
		if(this.cur_y_pos + y_move > page_y_offset)
		{
			this.self.style.top = page_y_offset - this.orig_y_pos + 'px';
			this.cur_y_pos = page_y_offset;
		}
		else
		{
			this.self.style.top = parseInt(this.self.style.top) + y_move + 'px';
			this.cur_y_pos += y_move;
		}
	}
	// Moving up
	else if(page_y_offset < this.cur_y_pos && this.cur_y_pos > this.orig_y_pos)
	{
		if(this.cur_y_pos - y_move < this.orig_y_pos)
		{
			this.self.style.top = '0px';
			this.cur_y_pos = this.orig_y_pos;
		}
		else
		{
			this.self.style.top = parseInt(this.self.style.top) - y_move + 'px';
			this.cur_y_pos -= y_move;
		}
	}
}
/* END Slider functions */

/* ajax methods */
function ajax_update(container, serv, page, action, pars)
{
	pars['tb'] = 1;
	pars['serv'] = serv;
	pars['page'] = page;
	pars['action'] = action;

	new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: pars,
			onSuccess: function(t)
			{
				var r = t.responseText.replace("while(1);", "").evalJSON();
				var e = r.error;
				var content = r.content;
				if(e != null) post_new_event('error', e);
				if(content == null) return;
				$(container).innerHTML = content.stripScripts();
				content.evalScripts();
			},
			onFailure: function(t)
			{
				post_new_event('error', 'Error ' + t.status + ' - ' + t.statusText);
			}
		});
}

function ajax_request(serv, page, action, pars, func)
{
	pars['tb'] = 1;
	pars['serv'] = serv;
	pars['page'] = page;
	pars['action'] = action;

	new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: pars,
			onSuccess: function(t)
			{
				var r = t.responseText.replace("while(1);", "").evalJSON();
				var s = r.success;
				var e = r.error;
				var content = r.content;
				if(content == null) content = '';
				if(e != null) post_new_event('error', e);
				if(s != null && s != 1) post_new_event('success', s);
				if(typeof func == 'function')
				{
					func.apply(this, [content.stripScripts()]);
				}
				content.evalScripts();
			},
			onFailure: function(t)
			{
				post_new_event('error', 'Error ' + t.status + ' - ' + t.statusText);
			}
		});
}
/* end ajax methods */