/* 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 = {
	'#googlesearch' : 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('q');
   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;
   }
}

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


var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function initPage() {
	loadActiveStylesheet();

}

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


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

addEvent(window, 'unload', unloadActiveStylesheet);
Behaviour.register(siteSearchValidation);
Behaviour.register(textSizeChangers);
