/*
 * GDSL 0.1 - GeoOrbis Developer Script Library
 *
 * Copyright (c) 2007 - Present GeoOrbis, Inc. (geoorbis.com)
 * This software is copyrighted software and is not intended
 * for public distribution.
 *
 * $Date:     2007-10-30 9:43:00 -0400 (Tue, 30 Oct 2007) $
 * $author:   Owan Hunte <ohunte@geoorbis.com>
 * $requires: jQuery JavaScript Library 1.1 or above
 * $Rev:      1 $
 */
var GEOORBIS = window.GEOORBIS || {};

// Namespace for global variables
GEOORBIS.globals = {};

// Widgets namespace
GEOORBIS.widgets = {};

// Utilities namespace
GEOORBIS.util = {};

// Language namespace
GEOORBIS.lang = {};

// Functions namespace
GEOORBIS.functions = {
	array : {
		indexOf : function(arr, element) {
			// Determine the starting index for the search
			var from = (arguments.length > 2) ? arguments[2] : 0;
			if (from >= arr.length)
				return -1;
			if (from < 0) {
				from = arr.length + from;
				if (from < 0) from = 0;
			}
			// Execute the search for searchElement
			for (; from < arr.length; from++)
				if (arr[from] == element)
					return from;

			// Return -1 if element not found
			return -1;
		},
		
		remove : function(arr) {
			var index = (arguments.length > 1) ? arguments[1] : 0;
			var returnArray = new Array();

			// Check for invalid index.
			if (index < 0 || index >= arr.length)
				return returnArray;

			// Remove the element at the specified index from this array.
			if (index == 0) {
				returnArray = arr.slice(0, arr.length);
				returnArray.shift();
			}
			else if (index == (arr.length-1)) {
				returnArray = arr.slice(0, arr.length);
				returnArray.pop();
			}
			else {
				for (var i = 0; i < arr.length; i++)
					if (i != index)
						returnArray.push(arr[i]);
			}
			return returnArray;
		},
		
		trim : function(arr) {
			for (var i in arr) {
				arr[i] = jQuery.trim(arr[i]);
			}
		}
	},
	
	validateEmail : function(value, msg, displayError) {
		var $Lang = GEOORBIS.lang.en;
		var error_msg = (msg == null) ? $Lang.error_msgs.invalidEmail : msg;
		var regExp1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
		var regExp2 = /^[\S]+@(\[?)[A-Za-z0-9\-\.]+\.([A-Za-z0-9]+)(\]?)$/;

		if (value) {
			if (!(regExp1.test(value)) && (regExp2.test(value)))
				return true;    // e-mail address has valid format
		}
		if (displayError) window.alert(error_msg);
		return false;
	}
};

// ------------------------------------------------------------------------------
// GEOORBIS.util.image namespace
// Provides a few commonly needed utility methods
// ------------------------------------------------------------------------------
GEOORBIS.util.image = {
	// Load (pre-cache) an image located at url
	load : function(url) {
		var result = null;
		if (document.images) { result = new Image(); result.src = url; }
		return result;
	},

	// Fix PNG transparency in Win IE 5.5 & 6.
	fixPNG : function(spacer) {
		if (jQuery.browser.msie) {
			var arVersion = navigator.appVersion.split("MSIE");
			var version = parseFloat(arVersion[1]);
			if ((version >= 5.5) && (version < 7) && (document.body.filters))
			{
				var images = jQuery('img[@src*="png"]'), png;
				images.each(
					function() {
						png = this.src;
						this.src = spacer;
						this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + png + "')";
					}
				);
			}
		}
	}
};

// --------------------------------------------------------------------------------
// GEOORBIS.lang.en namespace
//
// This namespace is used to store (English) strings of text. Any text which is
// to be output via JavaScript can be placed within the GEOORBIS.lang.* namespaces
// namespaces, i.e. GEOORBIS.lang.en for English text. This will allow for greater
// flexibility in the application development cycle.
// --------------------------------------------------------------------------------

GEOORBIS.lang.en = {
	error_msgs : {}
};

GEOORBIS.lang.en.error_msgs.invalidEmail = "Invalid e-mail address format!";