 /*
Name    : Styles On the Fly
Author  : Fabián Ruiz
Version : 1.00.A Beta
Website : http://www.poemasdeamor.com.ar
This code is Copyright (c) 2009 Fabián Ruiz
License is granted to user to reuse this code on other Web site
if, and only if, this entire copyright notice is included. The Web Site
containing this script must be a not-for-profit(non-commercial) web site 
unless I gave permission for the use of the script.
End copyright - This must be retained and posted as is to use this script
along with a link to the original location.
*/


var active_stylesheet="style1";	  // The stylesheet by default.

//////////////////////////////////// Cookie Functions //////////////////////////////// 

function setCookie(name, value) {
	var today = new Date();
	today.setTime( today.getTime() );
	var expires = 28;
	expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" )
} 

function getCookie(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 ) );
}

//////////////////////////////////// Styles Functions //////////////////////////////// 

//Changes the style sheet that is in use.

function selectStyleSheet() {
	$(active_stylesheet).disabled=true;
	active_stylesheet = $("style-selector").value;
	$(active_stylesheet).disabled=false;
}
function $(id) { return document.getElementById(id); }
 
 
//Load last selected stylesheet.
function init() {

	var new_style_sheet = getCookie("pda_options_stylesheet");
	if($(new_style_sheet)) {
		$(active_stylesheet).disabled=true;
		active_stylesheet = new_style_sheet;
		$(active_stylesheet).disabled=false;
		$("style-selector").value = new_style_sheet;
	}

}	
	
//Saves the chosen options when the user leaves the page.
function exit() {
	setCookie("pda_options_stylesheet",active_stylesheet);
}
window.onload=init;
window.onunload=exit;