if(typeof(afw) === 'undefined')
{
	var afw = {};
}
if(typeof(afw.module) === 'undefined')
{
	afw.module = {};
}
afw.common =
{
	params :
	{
		location : // http://www.alertir.com/index.php?foo=bar&alpha=beta#omega
		{
			hash : window.location.hash // #omega
			,host : window.location.host // www.alertir.com (or www.alertir.com:81 if port is present)
			,hostname : window.location.hostname // www.alertir.com
			,href : window.location.href // complete url
			,pathname : window.location.pathname // /index.php
			,port : window.location.port // 81 (if present)
			,protocol : window.location.protocol // http:
			,search : window.location.search // ?foo=bar&alpha=beta
		}
		,p : ''
		,s : ''
		,t : ''
		,u : ''
		,afw_lang : ''
	}

	,log:
	{
		info : function(msg) {
			if (typeof console !== 'undefined')
				console.info(msg);
		}
	}
	,env :
	{
		isOpera : function()
		{
			return (typeof opera != 'undefined') ? true : false;
		}

		,isSafari : function()
		{
			return (!afw.common.env.isOpera() && (navigator.userAgent.indexOf('WebKit') != -1)) ? true : false;
		}

		,isGecko : function()
		{
			return (!afw.common.env.isOpera() && !afw.common.env.isSafari() && (navigator.product == 'Gecko')) ? true : false;
		}

		,isIE : function()
		{
			return (!afw.common.env.isOpera() && (navigator.userAgent.indexOf('MSIE') != -1)) ? true : false;
		}

	}

	,functions :

	{

		addClass : function(oElement, sClassName)
		{
			if(!oElement || sClassName == undefined)
			{
				return false;
			}
			if(!afw.common.functions.classExists(oElement, sClassName))
			{
				if(oElement.className)
				{
					oElement.className += ' ' + sClassName;
				}
				else
				{
					oElement.className = sClassName;
				}
			}
			return true;
		}
		,addEvent : function(evt, el, fn)
		{
			if(el.addEventListener)
			{
				el.addEventListener(evt, fn, false);
			}
			else if(el.attachEvent)
			{
				return el.attachEvent('on' + evt, fn);
			}
		}
		,classExists : function(oElement, sClassName)
		{
			if(!oElement || sClassName == undefined)
			{
				return false;
			}
			if(oElement.className.indexOf(' ') > -1)
			{
				var i, m, aClasses = oElement.className.split(' ');
				for(i = 0, m = aClasses.length; i < m; ++i)
				{
					if(aClasses[i] == sClassName)
					{
						return true;
					}
				}
			}
			else if(sClassName == oElement.className)
			{
				return true;
			}
			return false;
		}
		,deleteCookie : function( name, path, domain )
		{
			if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
		,getChildren : function(oElement, sNodeName, sClassName)
		{
			if(!afw.common.functions.isDomElement(oElement)
			|| (arguments.length > 1 && ((!afw.common.functions.isString(sNodeName) || afw.common.functions.isEmpty(sNodeName)) && !afw.common.functions.isNull(sNodeName)))
			|| (arguments.length > 2 && ((!afw.common.functions.isString(sClassName) || afw.common.functions.isEmpty(sClassName)) && !afw.common.functions.isNull(sClassName)))
			)
			{
				return false;
			}
			var sCase, iChild, aReturn = [], aChildren = oElement.childNodes;
			if(arguments.length == 1 || (afw.common.functions.isNull(sNodeName) && (arguments.length == 2 || afw.common.functions.isNull(sClassName))))
			{
				sCase = 'element';
			}
			else if(afw.common.functions.isString(sNodeName) && (afw.common.functions.isUndefined(sClassName) || afw.common.functions.isNull(sClassName)))
			{
				sCase = 'node element';
				sNodeName = sNodeName.toUpperCase();
			}
			else if(afw.common.functions.isNull(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'class element';
			}
			else if(afw.common.functions.isString(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'node class element';
				sNodeName = sNodeName.toUpperCase();
			}
			for(iChild in aChildren)
			{
				if(afw.common.functions.isDomElement(aChildren[iChild]))
				{
					switch(sCase)
					{
						case 'element':
						case 'node element':
							if(aChildren[iChild].nodeName != sNodeName && sCase == 'node element')
							{
								break;
							}
						case 'class element':
							if(!afw.common.functions.classExists(aChildren[iChild], sClassName) && sCase == 'class element')
							{
								break;
							}
						case 'node class element':
							if((aChildren[iChild].nodeName != sNodeName || !afw.common.functions.classExists(aChildren[iChild], sClassName)) && sCase == 'node class element')
							{
								break;
							}
							aReturn.push(aChildren[iChild]);
					}
				}
			}
			return aReturn.length ? aReturn : false;
		}
		,getClientDimensions : function()
		{
			var res =
			{
				width : document.documentElement.scrollWidth
				,height : document.documentElement.scrollHeight
			};
			return res;
		}
		,getViewportDimensions : function()
		{
			var mode = document.compatMode;
			var height = self.innerHeight; // Safari, Opera
			if ((mode || afw.common.env.isIE()) && !afw.common.env.isOpera()) { // IE, Gecko
				height = (mode == 'CSS1Compat') ?
						document.documentElement.clientHeight : // Standards
						document.body.clientHeight; // Quirks
			}
			var width = self.innerWidth;  // Safari
			if (mode || afw.common.env.isIE()) { // IE, Gecko, Opera
				width = (mode == 'CSS1Compat') ?
						document.documentElement.clientWidth : // Standards
						document.body.clientWidth; // Quirks
			}
			var top = (mode == 'CSS1Compat') ?
					document.documentElement.scrollTop : // Standards
					document.body.scrollTop; // Quirks
			var left = (mode == 'CSS1Compat') ?
					document.documentElement.scrollLeft : // Standards
					document.body.scrollLeft; // Quirks
			return {width: width, height: height, top: top, left: left};
		}
		,getCookie : function( check_name )
		{
			// first we'll split this cookie up into name/value pairs
			// note: document.cookie only returns name=value, not the other components
			var a_all_cookies = document.cookie.split( ';' );
			var a_temp_cookie = '';
			var cookie_name = '';
			var cookie_value = '';
			var b_cookie_found = false; // set boolean t/f default f

			for ( i = 0; i < a_all_cookies.length; i++ )
			{
				// now we'll split apart each name=value pair
				a_temp_cookie = a_all_cookies[i].split( '=' );


				// and trim left/right whitespace while we're at it
				cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

				// if the extracted name matches passed check_name
				if ( cookie_name == check_name )
				{
					b_cookie_found = true;
					// we need to handle case where cookie has no value but exists (no = sign, that is):
					if ( a_temp_cookie.length > 1 )
					{
						cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
					}
					// note that in cases where cookie is initialized but no value, null is returned
					return cookie_value;
					break;
				}
				a_temp_cookie = null;
				cookie_name = '';
			}
			if ( !b_cookie_found )
			{
				return null;
			}
		}
		,getDimensions : function(oElement)
		{
			if(!afw.common.functions.isDomElement(oElement))
			{
				return false;
			}
			return {width: oElement.offsetWidth, height: oElement.offsetHeight};
		}
		,getElement : function(sId)
		{
			var oReturn = null;
			if(document.getElementById)
			{
				if(document.getElementById(sId))
				{
					oReturn = document.getElementById(sId);
				}
			}
			return oReturn;
		}
		,getElementPositions : function(oElement)
		{
			var left = 0, top = 0;
			if (oElement && oElement.offsetParent) {
				do {
					left += oElement.offsetLeft;
					top += oElement.offsetTop;
				} while (oElement = oElement.offsetParent);
			}
			return { top: top, left: left };
		}
		,getElements : function(oElement, sNodeName, sClassName)
		{
			if(!afw.common.functions.isDomElement(oElement)
			|| (arguments.length > 1 && ((!afw.common.functions.isString(sNodeName) || afw.common.functions.isEmpty(sNodeName)) && !afw.common.functions.isNull(sNodeName)))
			|| (arguments.length > 2 && ((!afw.common.functions.isString(sClassName) || afw.common.functions.isEmpty(sClassName)) && !afw.common.functions.isNull(sClassName)))
			)
			{
				return false;
			}
			var sCase, iElement, aReturn = [], aElements = [];
			if(arguments.length == 1 || (afw.common.functions.isNull(sNodeName) && (arguments.length == 2 || afw.common.functions.isNull(sClassName))))
			{
				sCase = 'element';
			}
			else if(afw.common.functions.isString(sNodeName) && (afw.common.functions.isUndefined(sClassName) || afw.common.functions.isNull(sClassName)))
			{
				sCase = 'node element';
				sNodeName = sNodeName.toUpperCase();
			}
			else if(afw.common.functions.isNull(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'class element';
			}
			else if(afw.common.functions.isString(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'node class element';
				sNodeName = sNodeName.toUpperCase();
			}
			if(!afw.common.functions.isString(sNodeName) && !afw.common.functions.isEmpty(sNodeName))
			{
				sNodeName = '*';
			}
			aElements = oElement.getElementsByTagName(sNodeName);
			for(iElement in aElements)
			{
				if(afw.common.functions.isDomElement(aElements[iElement]))
				{
					switch(sCase)
					{
						case 'element':
						case 'node element':
							if(aElements[iElement].nodeName != sNodeName && sCase == 'node element')
							{
								break;
							}
						case 'class element':
							if(!afw.common.functions.classExists(aElements[iElement], sClassName) && sCase == 'class element')
							{
								break;
							}
						case 'node class element':
							if((aElements[iElement].nodeName != sNodeName || !afw.common.functions.classExists(aElements[iElement], sClassName)) && sCase == 'node class element')
							{
								break;
							}
							aReturn.push(aElements[iElement]);
					}
				}
			}
			return aReturn.length ? aReturn : false;
		}
		,getParent : function(oElement, sNodeName, sClassName)
		{
			if(!afw.common.functions.isDomElement(oElement)
			|| (arguments.length > 1 && ((!afw.common.functions.isString(sNodeName) || afw.common.functions.isEmpty(sNodeName)) && !afw.common.functions.isNull(sNodeName)))
			|| (arguments.length > 2 && ((!afw.common.functions.isString(sClassName) || afw.common.functions.isEmpty(sClassName)) && !afw.common.functions.isNull(sClassName)))
			)
			{
				return false;
			}
			var sCase, bFound = false, i = 0;
			if(arguments.length == 1 || (afw.common.functions.isNull(sNodeName) && (arguments.length == 2 || afw.common.functions.isNull(sClassName))))
			{
				sCase = 'first element';
			}
			else if(afw.common.functions.isString(sNodeName) && (afw.common.functions.isUndefined(sClassName) || afw.common.functions.isNull(sClassName)))
			{
				sCase = 'first node element';
				sNodeName = sNodeName.toUpperCase();
			}
			else if(afw.common.functions.isNull(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'first class element';
			}
			else if(afw.common.functions.isString(sNodeName) && afw.common.functions.isString(sClassName))
			{
				sCase = 'first node class element';
				sNodeName = sNodeName.toUpperCase();
			}
			while(!bFound)
			{
				i++;
				if(oElement.parentNode)
				{
					oElement = oElement.parentNode;
					switch(sCase)
					{
						case 'first element':
						case 'first node element':
							if(oElement.nodeName != sNodeName && sCase == 'first node element')
							{
								break;
							}
						case 'first class element':
							if(!afw.common.functions.classExists(oElement, sClassName) && sCase == 'first class element')
							{
								break;
							}
						case 'first node class element':
							if((oElement.nodeName != sNodeName || !afw.common.functions.classExists(oElement, sClassName)) && sCase == 'first node class element')
							{
								break;
							}
							bFound = true;
					}
				}
				else
				{
					break;
				}
				if(bFound || i > 200)
				{
					break;
				}
			}
			if(bFound)
			{
				return oElement;
			}
			else
			{
				return false;
			}
		}
		,getPrototypeValue : function(oElement, sPrototypeName, defaultReturn)
		{
			if(oElement === undefined || !oElement || sPrototypeName === undefined)
				return false;
			if(defaultReturn === undefined && defaultReturn !== null)
				defaultReturn = false;
			try
			{
				eval('var sValue = oElement.afwobject.' + sPrototypeName + ';');
				if(sValue === undefined && sValue !== null)
					sValue = defaultReturn;
			}
			catch(e)
			{
				var sValue = defaultReturn;
			}
			return sValue;
		}
		,inArray : function(needle, haystack, argStrict)
		{
			if(afw.common.functions.isEmpty(needle)
			|| !afw.common.functions.isArray(haystack)
			|| afw.common.functions.isEmpty(haystack)
			|| (!afw.common.functions.isUndefined(argStrict) && !afw.common.functions.isBoolean(argStrict)))
			{
				return false;
			}

			var found = false, key, strict = !!argStrict;
			for(key in haystack)
			{
				if((strict && haystack[key] === needle) || (!strict && haystack[key] == needle))
				{
					found = true;
					break;
				}
			}

			return found;
		}
		,isArray : function(o)
		{
			return afw.common.functions.isO(o)
			&& !afw.common.functions.isDomElement(o)
			&& !afw.common.functions.isEvent(o)
			&& o.constructor
			&& o.constructor.toString() == Array.toString();
		}
		,isBoolean : function(o)
		{
			return !afw.common.functions.isNull(o)
			&& !afw.common.functions.isUndefined(o)
			&& (typeof o == 'boolean' || (o === 1 || o === 0));
		}
		,isDate : function(o)
		{
			return afw.common.functions.isO(o)
			&& !afw.common.functions.isDomElement(o)
			&& !afw.common.functions.isEvent(o)
			&& o.constructor
			&& o.constructor.toString() == Date.toString();
		}
		,isDomElement : function(o)
		{
			return afw.common.functions.isO(o)
			&& !afw.common.functions.isUndefined(o.childNodes)
			&& !afw.common.functions.isUndefined(o.nodeType)
			&& o.nodeType == 1;
		}
		,isEmpty : function(o)
		{
			if(afw.common.functions.isUndefined(o)
			|| afw.common.functions.isNull(o))
			{
				return true;
			}
			else if(afw.common.functions.isDomElement(o))
			{
				return false;
			}
			else if(afw.common.functions.isObject(o))
			{
				for(var x in o)
				{
					if(!afw.common.functions.isUndefined(o.hasOwnProperty)
					&& o.hasOwnProperty(x))
					{
						return false;
					}
				}
				return true;
			}
			else if(afw.common.functions.isArray(o))
			{
				return (o.length ? false : true);
			}
			else if(afw.common.functions.isString(o))
			{
				return (o == '' ? true : false);
			}
			else if(afw.common.functions.isNumber(o))
			{
				return false;
			}
			else if(afw.common.functions.isDate(o))
			{
				return false;
			}
			else if(afw.common.functions.isFunction(o))
			{
				return false;
			}
			else if(afw.common.functions.isEvent(o))
			{
				return false;
			}
			else if(afw.common.functions.isBoolean(o))
			{
				return false;
			}
			alert('methods::isEmpty isType(typeof argument) isn\'t implemented\nCheck afw.common.functions.isEmpty');
			return true;
		}
		,isEvent : function(o)
		{
			return afw.common.functions.isO(o)
			&& (!afw.common.functions.isUndefined(o.eventPhase) || !afw.common.functions.isUndefined(o.cancelBubble));
		}
		,isFunction : function(o)
		{
			return typeof o == 'function';
		}
		,isNull : function(o)
		{
			return o === null;
		}
		,isNumber : function(o)
		{
			return typeof o == 'number'
			&& isFinite(o);
		}
		,isO : function(o)
		{
			return !afw.common.functions.isNull(o)
			&& !afw.common.functions.isUndefined(o)
			&& typeof o == 'object';
		}
		,isObject : function(o)
		{
			return (o && 'object' == typeof o);
		}
		,isString : function(o)
		{
			return typeof o == 'string'
			|| (afw.common.functions.isO(o) && !afw.common.functions.isDomElement(o) && !afw.common.functions.isEvent(o) && o.constructor && o.constructor.toString() == String.toString());
		}
		,isUndefined : function(o)
		{
			return o === undefined;
		}
		,parseAFWParams : function()
		{
			var i, m, a, o = {}, q = afw.common.params.location.search;
			if(q.length > 0)
			{
				q = q.substring(1);
			}
			q = q.split('&');
			for(i = 0, m = q.length; i < m; ++i)
			{
				a = q[i].split('=');
				if(a.length == 1)
				{
					a.push('');
				}
				o[a[0]] = a[1];
			}
			afw.common.params.p = o.p;
			afw.common.params.s = o.s;
			afw.common.params.t = o.t;
			afw.common.params.u = o.u;
			afw.common.params.afw_lang = (o.afw_lang) ? o.afw_lang : (o.lang) ? o.lang : 'en';
		}
		,randomID : function(sPrefix, iLength)
		{
			if(sPrefix == undefined){ sPrefix = ''; }
			if(iLength == undefined){ iLength = 12; }
			var result = '', i, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), m = chars.length;
			for(i = 0; i < iLength; ++i)
			{
				if(result === '')
				{
					result += chars[afw.common.functions.randomNumber(10, m - 1)];
				}
				else
				{
					result += chars[afw.common.functions.randomNumber(0, m - 1)];
				}
			}
			return sPrefix + result;
		}
		,randomNumber : function(min, max)
		{
			if(min == undefined){ min = 1; }
			if(max == undefined){ max = 100; }
			return Math.floor(Math.random() * ((max - min) + 1)) + min;
		}
		,removeElement : function(oElement)
		{
			if (oElement && oElement.parentNode)
				oElement.parentNode.removeChild(oElement);
		}
		,removeClass : function(oElement, sClassName)
		{
			if(!oElement || sClassName == undefined)
			{
				return false;
			}
			var i, m, sNewClasses = '', sClasses = '' + oElement.className;
			if(sClasses != '' && sClasses.indexOf(' ') > -1)
			{
				var aClasses = sClasses.split(' ');
				for(i = 0, m = aClasses.length; i < m; ++i)
				{
					if(aClasses[i] != sClassName)
					{
						sNewClasses += ' ' + aClasses[i];
					}
				}
				sNewClasses = (sNewClasses.length > 0 ? sNewClasses.substring(1) : '');
			}
			else
			{
				if(sClasses != sClassName)
				{
					sNewClasses = sClasses;
				}
			}
			oElement.className = sNewClasses;
			return true;
		}
		,setCookie : function(name, value, expires, path, domain, secure)
		{
			// set time, it's in milliseconds
			var today = new Date();
			today.setTime( today.getTime() );

			/*
			if the expires variable is set, make the correct
			expires time, the current script below will set
			it for x number of days, to make it for hours,
			delete * 24, for minutes, delete * 60 * 24
			*/
			if ( expires )
			{
			expires = expires * 1000 * 60 * 60 * 24;
			}
			var expires_date = new Date( today.getTime() + (expires) );

			document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );

		}
		,setOpacity : function(o, i)
		{
			o.style.opacity = i / 100;
			o.style.filter = 'alpha(opacity=' + i + ')';
			o.style.zoom = 1;
		}
		,setPrototype : function(oElement, sPrototypeName, oValue)
		{
			if(oElement === undefined || !oElement || sPrototypeName === undefined)
				return false;
			var aNamePath = ('afwobject.' + sPrototypeName).split('.');
			var ref = oElement;
			for(var i = 0, m = aNamePath.length; i < m; ++i)
				if(i + 1 == m)
					ref[aNamePath[i]] = (oValue === undefined && oValue !== null) ? {} : oValue;
				else
				{
					if(ref[aNamePath[i]] === undefined)
						ref[aNamePath[i]] = {};
					ref = ref[aNamePath[i]];
				}
			return true;
		}
		,trim : function(s)
		{
			return s.replace(/^\s+|\s+$/g, '');
		}
	}

	,methods :
	{
		getElement : function(sId){ var oReturn = null; if(document.getElementById){ if(document.getElementById(sId)){ oReturn = document.getElementById(sId); } } return oReturn; }
		,setOpacity : function(o, i){ o.style.opacity = i / 100; o.style.filter = 'alpha(opacity=' + i + ')'; }
		,isEvent : function(o){ return o !== null && typeof o == 'object' && (o.eventPhase !== undefined || o.cancelBubble !== undefined); }
		,addEvent: function(evt, el, fn) { if (el.addEventListener) { el.addEventListener(evt,fn,false); } else if (el.attachEvent) { return el.attachEvent("on"+evt, fn); }}
	}
};
afw.common.functions.parseAFWParams();