/********************************************************************************/
/***** FULL WINDOW DIMENSIONS AND VALUES ***************************************/
/******************************************************************************/

//Visible window width
	var getWindowWidth = 
		function() {
			return self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
		};
//Visible window height
	var getWindowHeight = 
		function() {
			return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		};
//Visible window width + scroll
	var getTotalWidth = 
		function() {
			return document.documentElement.scrollWidth || document.body.scrollWidth;
		};
//Visible window height + scroll
	var getTotalHeight = 
		function() {
			return document.documentElement.scrollHeight || document.body.scrollHeight;
		};
//Scrollable width
	var getScrollWidth = 
		function() {
			return getTotalWidth() - getWindowWidth();
		};
//Scrollable height
	var getScrollHeight = 
		function() {
			return getTotalHeight() - getWindowHeight();
		};
// Distance scrolled from top
	var getScrollTop = 
		function() {
			return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
		};
// Distance scrolled from top
	var getScrollLeft = 
		function() {
			return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
		};
// Set the top scroll distance
	var setScrollTop = 
		function(value) {
			var y = value;
			var x = getScrollTop();
			window.scrollTo(x,y);
		};
// Set the left scroll distance
	var setScrollLeft = 
		function(value) {
			var y = getScrollLeft();
			var x = value;
			window.scrollTo(x,y);
		};
// Set the left and top scroll distance
	var setScroll = 
		function(x,y) {
			window.scrollTo(x,y);
			return true;
		};
// Get total occupied width of element
	var getOffsetWidth = 
		function(obj) {
			return obj.offsetWidth;
		};
// Get total occupied height of element
	var getOffsetHeight = 
		function(obj) {
			return obj.offsetHeight;
		};
	

/********************************************************************************/
/***** GET ALL MOUSE COORDINATES ***********************************************/
/******************************************************************************/

/***** MOUSE POSITION WITHIN A WINDOW *****/

// X position of mouse
	var getMousePositionX = function(evt) {
		return Event.pointerX(evt);
	}

// Y position of mouse
	var getMousePositionY = function(evt) {
		return Event.pointerY(evt);
	}

/***** MOUSE POSITION WITHIN AN ELEMENT ****/

// X position of mouse
	var getMouseOffsetX = function(obj) {
		var mousePos = getMouseOffset(obj);
		return mousePos.x
		};

// Y position of mouse
	var getMouseOffsetY = function(obj) {
		var mousePos = getMouseOffset(obj);
		return mousePos.y
		};

// Get mouse position within element
	var getMouseOffset = function(obj) {
		var posX = obj.offsetLeft;
		var posY = obj.offsetTop;
		
		while(obj.offsetParent) {
			if(obj == document.getElementsByTagName('body')[0]) {
				break
			} else {
				posX	= posX + obj.offsetParent.offsetLeft;
				posY	= posY + obj.offsetParent.offsetTop;
				obj		= obj.offsetParent;
			}
		}
		var mouseOffset = {
				x: posX,
				y: posY
				};
		return mouseOffset;
	}
		
		
/********************************************************************************/
/***** ERROR MESSAGE SCRIPTS ***************************************************/
/******************************************************************************/

	var Alerting = new Object();

	Alerting.errorMessage = function(element) {
		
		var form 		= $('#' + element);
		var inputList	= $('#' + element + ' *');
		var errorBox	= $(form).find('div.error_message');
		var alertBox;
		var alertText	= new Array();

		for(var i=0; i<inputList.length; i++) {
		// Get the LABEL associated with the element
			var label = $(inputList[i]).prev();

			if($(label).is('label') === true) {
				var labelCheck = $(label).html().toLowerCase();
				if(labelCheck.indexOf('<em>*</em>') != -1) {
				// Get the element value
					var labelVal	= $(label).html().split('<em>*</em>');
						labelVal	= labelVal[0];
						labelVal	= labelVal.split(':');
						labelVal	= labelVal[0];
						labelVal	= labelVal.replace(/^\s*|\s*$/g,'');

					if($(inputList[i]).is('input') === true) {
						if($(inputList[i]).attr('type') != 'button' && 
						$(inputList[i]).attr('type') != 'reset' && 
						$(inputList[i]).attr('type') != 'submit' && 
						$(inputList[i]).attr('type') != 'image') { 
						// Check when text field is empty
							if($(inputList[i]).val() == '') {
								alertText.push(labelVal + ' was not entered.');
							}
						// Validate email address fields
							if($(inputList[i]).attr('id').indexOf('email') != -1 && $(inputList[i]).val() != '') {
								var atPos 	= $(inputList[i]).val().indexOf("@");
								var stopPos	= $(inputList[i]).val().lastIndexOf(".");
								if(atPos == -1 || stopPos == -1) {
									alertText.push('Please enter a valid email address.');
								}
							}
						}
					} else if($(inputList[i]).is('select') === true) {
						if($(inputList[i]).val() == '') {
							alertText.push(labelVal + ' was not selected.');
						}
					} else if($(inputList[i]).is('textarea') === true) {
						if($(inputList[i]).html() == '') {
							alertText.push(labelVal + ' was not entered.');
						}
					}
				}
			}
			if($(inputList[i]).attr('type') == 'button' || 
			$(inputList[i]).attr('type') == 'reset' || 
			$(inputList[i]).attr('type') == 'submit' || 
			$(inputList[i]).attr('type') == 'image') { 
				$(inputList[i]).blur();
			}
		}
	
	// Generate the error box
		if(alertText.length > 0) {
			alertBox = ''
			+ '<p><strong>There was a problem with your submission</strong></p>'
			+ '<ul>';
			for(var i = 0; i < alertText.length; i++) {
				alertBox += '<li>' + alertText[i] + '</li>';
			}
			alertBox += '</ul>';
			
			$(errorBox).show();
			$(errorBox).html(alertBox);
		} else {
			$(form).submit();
		}
	}
	
	

	function addslashes(str) {
		str=str.replace(/\'/g,'\\\'');
		str=str.replace(/\"/g,'\\"');
		str=str.replace(/\\/g,'\\\\');
		str=str.replace(/\0/g,'\\0');
		return str;
	}
	function stripslashes(str) {
		str=str.replace(/\\'/g,'\'');
		str=str.replace(/\\"/g,'"');
		str=str.replace(/\\\\/g,'\\');
		str=str.replace(/\\0/g,'\0');
		return str;
	}