	function $(elementId)
	{
		return document.getElementById(elementId);
	}

	function in_array(string, array)
	{
		for(var i = 0; i < array.length; i++)
			if(array[i] == string)
				return true;
		return false;
	}

	function changeDocumentLocation(location) {
		setDocumentLocation(location);
	}

	function getDocumentLocation() {
		return document.location.href;
	}

	function setDocumentLocation(location) {
		document.location.href = location;
	}

	function changeElementLocation(elementId, location) {
		if($(elementId))
			$(elementId).src = location;
	}

	function changeParentDocumentLocation(location) {
		parent.document.location.href = location;
	}

	function changeParentElementLocation(elementId, location) {
		if(parent.$(elementId))
			parent.$(elementId).src = location;
	}

	function setCookie( name, value, expires, path, domain, secure ) {
		document.cookie = name + "=" + escape(value) +
			( (expires) ? "; expires=" + expires : "" ) +
			( (path) ? "; path=" + path : "" ) +
			( (domain) ? "; domain=" + domain : "" ) +
			( (secure) ? "; secure" : "" );
	}

	function getCookie( name ) {
		var cookie = " " + document.cookie;
		var search = " " + name + "=";
		var setStr = null;
		var offset = 0;
		var end = 0;
		if( cookie.length > 0 ) {
			offset = cookie.indexOf(search);
			if( offset != -1 ) {
				offset += search.length;
				end = cookie.indexOf( ";", offset )
				if( end == -1 )
					end = cookie.length;
				setStr = unescape( cookie.substring( offset, end ) );
			}
		}
		return(setStr);
	}

	function getFormatedURL(url, param, value)
	{
		var url = new String(url);
		if(url.indexOf("?") == -1) {
			if(url.indexOf("#") != -1) {
				url =  url.substr(0, url.indexOf("#")) + "?" + param + "=" + value;
			} else
				url += "?" + param + "=" + value;
		} else {
			urlLength = url.length;
			pos1 = url.indexOf("?");
			pos2 = url.indexOf("?" + param + "=", pos1);
			pos3 = url.indexOf("&" + param + "=", pos1);
			pos4 = url.indexOf("&amp;" + param + "=", pos1);
			pos5 = urlLength;

			if(pos2 > -1)
				pos5 = Math.min(pos2, pos5);
			if(pos3 > -1)
				pos5 = Math.min(pos3, pos5);
			if(pos4 > -1)
				pos5 = Math.min(pos4, pos5);
			
			if(pos5 == pos1) {
				pos6 = url.indexOf("&", pos5);
				pos7 = url.indexOf("&amp;", pos5);
				pos8 = urlLength;

				if(pos6 > -1)
					pos8 = Math.min(pos6, pos8);
				if(pos7 > -1)
					pos8 = Math.min(pos7, pos8);

				url = url.substr(0, pos5) + "?" + param + "=" + value + url.substr(pos8);
			} else if (pos5 == urlLength) {
				if(url.substr(urlLength-1) == "&" || url.substr(urlLength-5) == "&amp;")
					url = url.substr(0, pos5) + param + "=" + value;
				else
					url = url.substr(0, pos5) + "&" + param + "=" + value;
			} else {
				pos6 = url.indexOf("&", pos5+1);
				pos7 = url.indexOf("&amp;", pos5+1);
				pos8 = urlLength;
				
				pos9 = url.indexOf(param, pos5);

				if(pos6 > -1)
					pos8 = Math.min(pos6, pos8);
				if(pos7 > -1)
					pos8 = Math.min(pos7, pos8);

				url = url.substr(0, pos9) + param + "=" + value + url.substr(pos8);
			}
		}

		return url;
	}

	function getCurrentFormatedURL(param, value) 
	{
		return getFormatedURL(document.location, param, value);
	}
