window.jsboxed = {};
(window.jsboxed['dom/tool/css/preload'] = new function() { var self = this;
(window.jsboxed['base/extension/function'] = new function() { var self = this;

/**
 * Creates a new function that will execute the current function
 * in the context of the passed argument.
 * @param object context
 */
Function.prototype.bind = function(object) {
	var self = this;
	return function() {
		self.apply(object, arguments);
	}
}


/**
 * Instead of executing a function, it returns a new function
 * that will execute with the same arguments and context.
 */
Function.prototype.callback = function() {
	var self = this;
	var _arguments = arguments;
	return function() {
		self.apply(self, _arguments);
	}
}

});
var e = (window.jsboxed['event/add-event'] = new function() {
/**
 * @author Dean Edwards, 2005 with input from Tino Zijdel
 * @link http://dean.edwards.name/weblog/2005/10/add-event/
 */

/**
 * a counter used to create unique IDs
 */
var guid = 1;

this.addEvent = function(element, type, handler) {
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = guid++;
	// create a hash table of event types for the element
	if (!element.events) element.events = {};
	// create a hash table of event handlers for each element/event pair
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		// store the existing event handler (if there is one)
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}

	// store the event handler in the hash table
	handlers[handler.$$guid] = handler;
	// assign a global event handler to do all the work
	element["on" + type] = handleEvent;
}

this.removeEvent = function(element, type, handler) {
	// delete the event handler from the hash table
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
}

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(window.event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler

	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
}

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
}
fixEvent.preventDefault = function() {
	this.returnValue = false;
}
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
}
});

this.preloaded = [];


/**
 * Uses css level 1 pseudo-class and properties that
 * takes url to assure preloading.
 */
e.addEvent(window, "load", function() {
	var props = ["background", "backgroundImage", "listStyle", "listStyleImage"];
	var pseudos = /:(active|hover|link|visited)/;
	var sheet, rules, matched;

	for (var i = 0; i < document.styleSheets.length; i++) {
		sheet = document.styleSheets[i];
		rules = sheet.cssRules || sheet.rules;

		for (j = 0; j < rules.length; j++) {
			if (rules[j].selectorText && rules[j].selectorText.match(pseudos)) {

				for (var k = 0; k < props.length; k++) {
					matched = rules[j].style[props[k]].match(/url\([\'\"]?(.*)[\'\"]?\)/);
					if (matched) {
						self.preloaded.push(new Image().src = matched[1]);
					}
				}
			}
		}
	}
});

})

function isValidEmail(email, errorMessage)
{
	if (/^.{1,80}@.{1,80}$/.test(email.value) == false) {
		alert(errorMessage);
		email.focus();
		return false;
	}
	return true;
}
