String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/* newsletter */
function check_newsletter() {
	if ($('email').value == 'yourname@domain.com') return false;
	if ($('email').value.indexOf('@') == -1) return false;
	return true;
}


/* print */

function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	}else{
	 	//if (navigator.appName.indexOf("Microsoft")!=-1) {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}

function print_me(path) {
	uri = path
	wwidth = 616;
	wheight = 580;
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, 'print', "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=yes, resizable=no, directories=no");
}

/* form functions */

function clear_input(obj) {
	
	if  (typeof(obj.old_value) == "undefined") {
		obj.old_value = obj.value;
		obj.value = '';
	} else if (obj.value.trim() == '') {
		obj.value = obj.old_value;
		delete obj.old_value;
	}
}

/* toggle font / line size */
/* set cookie */
//function setCookie(name, value, expires, path, domain, secure) {
function setCookie(name, value, days) {
  if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var text_sizes		= [1, 1.2, 1.4];
var line_heights	= [1.4, 1.6, 1.8];

var def_text_size = 0;
var def_line_height = 0;

var content_placeholder = 'content';


function change_line_height() {
	current_lh = getCookie('line_height');

	if (!current_lh) current_lh = def_line_height;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;

	setCookie('line_height', current_lh, 365);
	
	document.getElementById(content_placeholder).style.lineHeight = line_heights[current_lh] + "em";
}

function change_text_size() {
	current_ts = getCookie('text_size');
	if (!current_ts) current_ts = def_text_size;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	setCookie('text_size', current_ts, 365);
	document.getElementById(content_placeholder).style.fontSize = text_sizes[current_ts] + "em";
}

function init_text_properties() {
	current_text_size = getCookie('text_size');
	current_line_height = getCookie('line_height');
	
	if (current_text_size && (s = document.getElementById(content_placeholder)) != null) {
		s.style.fontSize = text_sizes[current_text_size] + "em";
	}	
	if (current_line_height && (s = document.getElementById(content_placeholder)) != null) {
		s.style.lineHeight = line_heights[current_line_height] + "em";
	}
	
}

window.addEvent('load', function() {
	init_text_properties();
}	
);
