
function get_page_size() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

function expand_page() {
	var content_dimesions=get_page_size();
	document.getElementById('outer_container_id').style.height=content_dimesions[1]+'px';
	document.getElementById('inner_container_id').style.height='100%';
}

function show_gb_form() {
	document.getElementById('form').style.display='';
	document.getElementById('link').style.display='none';
	expand_page();
}

function show_form (form_id) {
	$(form_id).style.display='block';
	expand_page();
}

function character_count(max_count, element, target) {
	var used=$(element).value.length;
	if (used>max_count) {
		$(element).value=$(element).value.substring(0,max_count);
	}
	var remaining=max_count-$(element).value.length;
	$(target).innerHTML=remaining+' charaters remaining';
}

function sms_character_count(max_count) {
	var used=$('content1').value.length;
	//console.log(max_count);
	var remaining=max_count-used;
	var output;
	if (used>max_count) {
		$('character_display').addClassName('alert');
		output='The last '+(Math.abs(used)-max_count)+' characters will not be visible in text messages';
	} else {
		$('character_display').removeClassName('alert');
		output=remaining+' characters remaining for text messages.<br/>Characters after '+max_count+' will still be sent via email';
	}
	$('character_display').innerHTML=output;
}

var fade_ready=true;
function fade (element, field_value, direction) {
	var speed=100;
	var step=10;


	if (direction=='') {
		direction='out';
	}

	if (direction=='out') {
		step=step-step*2;
	}

	var current_opacity=$(element).getStyle('opacity');
	current_opacity+=(step/100);
	$(element).setStyle({opacity:current_opacity});

	if (current_opacity>=1) {
		clearTimeout(timer_in);
		$(element).setStyle({opacity:1});
		fade_ready=true;
	} else if (current_opacity<=0) {
		clearTimeout(timer_out);
		var timer_in=setTimeout("fade('"+element+"','"+field_value+"',\"in\")",speed);
		$('birthday').innerHTML=field_value;
		fade_ready=false;
	} else {
		var timer_out=setTimeout("fade('"+element+"','"+field_value+"','"+direction+"')",speed);
		fade_ready=false;
	}
}

function transition (array_position, first_iteration) {
	var duration=5000;
	var array_count=birthdays.length;
	array_position=(array_position=='')?1:array_position;
	first_iteration=(first_iteration===undefined)?'true':'false';

	if (fade_ready) {
		if (++array_position>=array_count) {
			array_position=0;
		}
	}

	if (first_iteration!='true') {
		fade('birthday',birthdays[array_position],'out');
	}

	var transition_timer=setTimeout("transition('"+array_position+"','false')",duration);
}

function carrier_toggle() {
	if ($F('sms')=='yes') {
		$('sms_provider').removeClassName('hidden');
	} else {
		$('sms_provider').addClassName('hidden');
	}
}

function asteroids() {
	//Asteroids created by http://github.com/erkie/erkie.github.com
	alert ("Well, isn't this just great. You found the ship that we had hidden in case we were invaded by another website. Try not to do too much damage.\n\nControls:\n-----------\nLeft\t\t=\tRotate ship to the left\nRight\t=\tRotate ship to the right\nUp\t\t=\tMove ship forward\nSpace\t=\tFIRE!!\nB\t\t=\tHighlight remaining targets\nEsc\t\t=\tExit game and return to the site\n\nWhen you're done playing you will have to refresh the page to get back any parts of the page you destroyed.");
	var asteroids=document.createElement('script');
	asteroids.type='text/javascript';
	document.body.appendChild(asteroids);
	asteroids.src='http://erkie.github.com/asteroids.min.js';void(0);
}
