/*
* Javascript implementations for WhatAMan 2008 website
* (c) Papercut Media. No reproduction without permission. Feel free to ask.
* Author: Patrick Pittman
* Date: October 2007
* Version: 1.0
* Requires: Prototype.js framework, ufo.js for flash loading, Dreamgirl on the other end for AJAXy JSON communication
*/


function $RC(form, name) { 
        return $(form).getInputs('radio', name).find(function(radio) { 
                if (radio.checked) { 
                        return radio; 
                } 
        }); 
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
//	alert(document.cookie.inspect());
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};



function Papercut() {
	this.loaderlock = false;
	this.baseHref = "http://www.fostercareconference.com/";
	this.ajaxBase = this.baseHref+"js/ajax/";
	this.ajaxProgress = document.createElement('img');
	this.ajaxProgress.src = this.baseHref+"images/icons/ajax-loader.gif";
	this.anchors = $H({});
}

Papercut.prototype.init = function(e) {

		Element.extend(document.body);
		if ($('Registrations')) {
			this.setupRegForm();
		}
		
	
}

Papercut.prototype.toggleForm = function() {
	$$('.hideSet').each(function(el){
		el.hide();
		$('Registrations_EmploymentOther').up('div').hide();
	});
	$$('.carerSet').each(function(el){
		if (el.visible()) {
				el.hide();
		}
	});
	book = $RC('Registrations','Registrations[BookingTypeID]');
	if (book) {
		if ($F(book) == 5) {
			Effect.Appear($('Registrations_EmploymentOther').up('div'));
			$('Registrations_EmploymentOther').focus();
		} else if ($F(book) == 4) {
			$$('.carerSet').each(function(el){
				if (!el.visible()) {
						Effect.Appear(el);
				}
			});	
			$$('.hideSet').each(function(el){
				if (el.visible()) {
						el.hide();
				}
			});		
		} else if ($F(book)) {
			$$('.hideSet').each(function(el){
				if (!el.visible()) {
						Effect.Appear(el);
				}
			});	
			$$('.carerSet').each(function(el){
				if (el.visible()) {
						el.hide();
				}
			});	
		}
	}
}

Papercut.prototype.setupRegForm = function(e) {
	Papercut.toggleForm();
	$$('.bookingType').each(function(el){
		el.observe('click',Papercut.setupRegForm);
	});
}

function cleanupFP9IELeaks() {
  __flash_unloadHandler = function() {};
  __flash_savedUnloadHandler = function() {};
}

function initPapercut() {
	Papercut.init();
}
var Papercut = new Papercut();
document.observe('dom:loaded',initPapercut);