
// at.js

function at_setup(authorid){
	//document.forms[1].onsubmit="at_form_check()";

	if (authorid){
		authorid = '_' + authorid;
	}
	else{
		authorid = '';
	}

	// look at important elements and decide if they are on or off.
	// if they are off alter the appearance of things...

	var at_trad_books = getByID('at_trad_books' + authorid);

	var at_hardcover = getByID('at_hardcover' + authorid);
	var at_softcover = getByID('at_softcover' + authorid);
	var at_largeprint = getByID('at_largeprint' + authorid);

	var at_trad_font_one = getByID('at_trad_font_1' + authorid);

	if (at_trad_books.checked){
		at_hardcover.disabled = false;
		at_softcover.disabled = false;
		at_largeprint.disabled = false;
		
		at_trad_font_one.color = 'black';
	}
	else{
		at_hardcover.disabled = true;
		at_softcover.disabled = true;
		at_largeprint.disabled = true;

		at_trad_font_one.color = '#7b7b7b';
	}

	var at_audio_books = getByID('at_audio_books' + authorid);

	var at_cassette = getByID('at_cassette' + authorid);
	var at_cd  = getByID('at_cd' + authorid);
	var at_download  = getByID('at_download' + authorid);
	var at_abridge = getByID('at_abridge' + authorid);
	var at_unabridged = getByID('at_unabridged' + authorid);
	var at_all_abridge = getByID('at_all_abridge' + authorid);

	var at_audio_font_one = getByID('at_audio_font_1' + authorid);
	
	if (at_audio_books.checked){
		at_cassette.disabled = false;
		at_cd.disabled = false;
		at_download.disabled = false;
		at_abridge.disabled = false;
		at_unabridged.disabled = false;
		at_all_abridge.disabled = false;
		
		at_audio_font_one.color = 'black';
	}
	else{
		at_cassette.disabled = true;
		at_cd.disabled = true;
		at_download.disabled = true;
		at_abridge.disabled = true;
		at_unabridged.disabled = true;
		at_all_abridge.disabled = true;
		
		at_audio_font_one.color = '#7b7b7b';
	}
}
function at_form_check(authorid){

	if (authorid){
		authorid = '_' + authorid;
	}
	else{
		authorid = '';
	}

	var at_trad_books = getByID('at_trad_books' + authorid);

	var at_hardcover = getByID('at_hardcover' + authorid);
	var at_softcover = getByID('at_softcover' + authorid);
	var at_largeprint = getByID('at_largeprint' + authorid);

	var at_audio_books = getByID('at_audio_books' + authorid);

	var at_cassette = getByID('at_cassette' + authorid);
	var at_cd  = getByID('at_cd' + authorid);
	var at_download  = getByID('at_download' + authorid);

	var at_email = getByID('at_email' + authorid);

	if (at_trad_books.checked){
		if ((! at_hardcover.checked) && (! at_softcover.checked) && (!at_largeprint.checked)){
			alert('We could not process your request.\n\n You have specified an interest in printed books, but have not specified paperback, hardcover or large print.  Please select at least one format, or deselect "Printed Books".');
			return false;
		}
	}
	if (at_audio_books.checked){
		if ((! at_cassette.checked) && (! at_cd.checked) &&(! at_download.checked )){
			alert('We could not process your request.\n\n You have specified an interest in audiobooks, but have not chosen cassette, CD, and/or downloadable.  Please select at least one format, or deselect "Audiobooks".');
			return false;
		}
	}
	if ((authorid.length <1) && (at_email.value.length < 7)){
		alert('It looks like you have not entered a valid Email address.  Please enter your email address.');
		return false;
	}

	var font = getByID('saved' + authorid);
	font.style.textDecoration = 'blink';
	font.style.color = '#FF0000';
	font.innerHTML = '<b>Saving...</b>';
	

	return 1;
}

function textHTMLUpadate(){
	var font = getByID('confirmationText');
	font.style.textDecoration = 'blink';
	font.style.color = '#FF0000';
	font.innerHTML = '<b>Saving...</b>';
	document.forms['texthtml'].submit()
}

function justUpdatedCheck(){
	if (document.location.href.indexOf ('updatedtexthtmlok') > -1){
		//alert ('updated ok');

		var font = getByID('confirmationText');
		font.style.color = '#FF0000';

		if (document.location.href.indexOf ('updatedtexthtmlok=text') > -1){
			font.innerHTML = '<b>Saved</b>';
		}
		else{
			font.innerHTML = '<b>Saved</b>';
		}
		
	}
	else if ((document.location.href.indexOf ('action=update') > -1) && (document.location.href.indexOf ('mode=revise') > -1)){

		var authorid = document.location.href.replace(/.*authorid=(\d+).*/, "$1");

		var font = getByID('saved_' + authorid);
		font.style.color = 'red';
		font.innerHTML = '<b>Saved</b>';
	}
}

function at_delayed_setup(authorid){
	if (window.addEventListener){
		window.addEventListener('load', function (){ at_setup(authorid)}, false);
	}
	else if (window.attachEvent){
		window.attachEvent( "onload", function (){ at_setup(authorid)});
	}
}

if (window.addEventListener){
	window.addEventListener('load', function (){ justUpdatedCheck()}, false);
}
else if (window.attachEvent){
	window.attachEvent( "onload", function (){ justUpdatedCheck()});
}


// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#333333";
		if (!to) to = this.get_bgcolor(id);

		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;

		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);

		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);

		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);

			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.color = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

window.onload = function () 
	{
	Fat.fade_all();
	}

