/* JAVASCRIPT \\\
**************************************************
TITLE: Page Scripts
DESCRIPTION: Scripts used throughout the site.
AUTHOR: David Mingos
CONTACT: http://dmdesigns.com/contact/
///
**************************************************
*/


/* BEHAVIOURS \\\
**************************************************

// The format of the rule definitions is like so:

var myRules = {
	'b.someclass' : function(element){
		element.onclick = function(){
			alert(this.innerHTML);
		}
	},
	'#someid u' : function(element){
		element.onmouseover = function(){
			this.innerHTML = "BLAH!";
		}
	}
};
Behaviour.register(myRules);


// To add an onclick event to every list item <li> 
// in a page - you would write something like this:

var myRules = {
	'li' : function(element){
		element.onclick = function(){
			// Your onclick event goes here - eg;
			// load a page - do an AJAX etc.;
		}
	}
};
Behaviour.register(myRules);

**************************************************
*/

var siteSearchValidation = {
	'#sitesearch' : function(element) {
		element.onsubmit = function() {
			return validateSearch(); 
			//validateSearch() is defined in 
			//FUNCTIONS section below
		}
	}
};

var textSizeChangers = {
	'#textsizer a' : function(element) {
		element.onclick = function() {
			setActiveStyleSheet(this.title);
			return false;
		}
	}
};

/* FUNCTIONS \\\
*************************************************/

function validateSearch() {
   var searchbox = document.getElementById('search');
   var submitbutton = document.getElementById('go');
   if (searchbox.value.length > 0 && searchbox.value != searchbox.defaultValue) {
      submitbutton.disabled = true;
      return true;
      //document.location = '/search/' + escape(searchbox.value).replace('%20','+');
      //return false;
   } else {
      alert('Please enter a word or phrase to search for.');
      searchbox.focus();
      return false;
   }
}

function initSearchForm() {
   var searchbox = document.getElementById('search');
   if (searchbox.value == searchbox.defaultValue)
      searchbox.style.color = '#999999';
   else
      searchbox.style.color = '#000';
}

function init() {
   var cookie = readCookie("style");
   var title = cookie ? cookie : getPreferredStyleSheet();
   alert('setting stylesheet to ' + title);
   setActiveStyleSheet(title);
}

/*************************************************
*/

Behaviour.register(siteSearchValidation);
Behaviour.register(textSizeChangers);

addEvent(window, 'load', loadActiveStylesheet);
addEvent(window, 'load', setInputHandlers);
addEvent(window, 'load', initSearchForm);

addEvent(window, 'unload', unloadActiveStylesheet);
