//------------------------------------------------------------------------------------
// Cookie Functions
//------------------------------------------------------------------------------------

//--Conversion----------------------------------------------------------------------------
	function BoolToS(boolVal){
		if (boolVal)
			return("1");
		else
			return("0");
	}

//--Cookies----------------------------------------------------------------------------
	//******************************************************************
	//
	// "Internal" function to return the decoded value of a cookie
	//
	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
		endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}
	//
	//  Function to correct for 2.x Mac date bug.  Call this function to
	//  fix a date object prior to passing it to SetCookie.
	//  IMPORTANT:  This function should only be called *once* for
	//  any given date object!  See example at the end of this document.
	//
	function FixCookieDate (date) {
	  var base = new Date(0);
	  var skew = base.getTime(); // dawn of (Unix) time - should be 0
	  if (skew > 0)  // Except on the Mac - ahead of its time
		date.setTime (date.getTime() - skew);
	}
	//
	//  Function to return the value of the cookie specified by "name".
	//    name - String object containing the cookie name.
	//    returns - String object containing the cookie value, or null if
	//      the cookie does not exist.
	//
	function GetCookieGroup (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		  return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	  }
	  return null;
	}

	function GetCookie(strSection, strCookie){
		var item = GetCookieGroup(strSection);
		if (item!=null) {
			cookies=item.split("&")
			//alert("Cookies: " + item + " Items: "+cookies.length);
			for (j=0; j<cookies.length; j++) {
				cookie=cookies[j];
				cookieName = cookie.substring(0, strCookie.length) + "=";
				cookieNameCheck = strCookie + "=";
				if (cookieName==cookieNameCheck) {
					return cookie.substring(strCookie.length+1, cookie.length);
				}
			}
		} else
			return;

		var str;
		str = document.cookie;

		//alert(str);

		var items = str.split("; ");

		var item;

		for (i=0; i<items.length; i++) {
			item=items[i];
			if (item.substring(0, strSection.length)==strSection){
				item=item.substring(strSection.length+1, item.length);
				cookies=item.split("&")
				for (j=0; j<cookies.length; j++) {
					cookie=cookies[j];
					if (cookie.substring(0, strCookie.length)==strCookie){
						return cookie.substring(strCookie.length+1, cookie.length);
					}
				}
				return;
			}
		}
	}

	function SetCookie(strSection, strCookie, strValue){
		var expires = new Date();
		mon = expires.getUTCMonth();// Set the expiry date date + 6 months
		expires.setUTCMonth(mon + 6);

		SetCookieEx(strSection, strCookie, strValue, expires, null, null, null);
	}

	function SetCookieEx(strSection, strCookie, strValue, expires, path, domain, secure){
		var str;
		str = document.cookie;

		var item;

		var boolFound=false

		//alert(str);

		item = GetCookieGroup(strSection)


		if (item!=null) {
			cookies=item.split("&")
			//alert("Cookies: " + item + " Items: "+cookies.length);
			for (j=0; j<cookies.length && !boolFound; j++) {
				cookie=cookies[j];
				cookieName = cookie.substring(0, strCookie.length) + "=";
				cookieNameCheck = strCookie + "=";
				if (cookieName==cookieNameCheck) {
					boolFound=true;
					cookie=escape(strCookie) + "="+ escape(strValue);
					cookies[j]=cookie;
					item=escape(strSection)+"="+cookies.join("&");
					//alert("Setting Cookie: " + item);
				}
			}
			if (!boolFound) {
				item=escape(strSection)+"="+cookies.join("&")+"&"+escape(strCookie) + "="+escape(strValue);
				//alert("Adding Sub-Cookie: " + item);
			}
		} else {
			item=escape(strSection)+"="+escape(strCookie) + "="+escape(strValue);
			//alert("Adding Cookie: " + item);
		}

		document.cookie = item+
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");

		//alert(document.cookie);
	}

	function SetCookieOldReload(strSection, strCookie, strValue){
		SetCookieOld(strSection, strCookie, strValue);
		location.reload(true)
	}

	function SetCookieOld(strSection, strCookie, strValue){
		var str
		str = strSection + "="
		if (strCookie!="") str += strCookie + "="
		str += strValue

		document.cookie = str
		//document.cookie += "expires=" + cookieDate(24*60*60*1000)
		//alert(str)
	}

	function SetCookieReload(strSection, strCookie, strValue){
		SetCookie(strSection, strCookie, strValue);
		location.reload(true)
	}

	function SetCookieReloadURL(strSection, strCookie, strValue, strURL){
		SetCookie(strSection, strCookie, strValue);
		var arrURL=strURL.split('%0');
		if (arrURL.length>1)
			window.location=arrURL[0]+strValue+arrURL[1];
		else
			window.location=strURL;
	}

//------------------------------------------------------------------------------------
// Open Window Functions
//------------------------------------------------------------------------------------

	function OpenWindow(strUrl, intWidth, intHeight) {
		OpenWindowEx(strUrl, intWidth, intHeight, 0, "floating_window")
	}
	function OpenWindowEx(strUrl, intWidth, intHeight, intBorder, strName) {
		intWidth += intBorder*2;
		intHeight += intBorder*2;
		if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
			isNav4 = (navigator.appName == "Netscape") ? true : false;
			isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
		}
		floatingWindow = window.open(strUrl, strName, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width="+intWidth+",height="+intHeight);
		if (floatingWindow!=null) {
			if(isIE4) {
				if ((intHeight>0) && (intWidth>0))
					floatingWindow.resizeTo(intWidth,intHeight);
				//else if (intWidth>0)
				//	floatingWindow.resizeTo(intWidth,floatingWindow.height);
				//else if (intHeight>0)
				//	floatingWindow.resizeTo(floatingWindow.width,intHeight);
				//floatingWindow.moveTo(((800-intWidth)/2),((580-intHeight)/2));
			} else {
				if (intHeight>0) floatingWindow.window.outerHeight = intHeight;
				if (intWidth>0) floatingWindow.window.outerWidth = intWidth;
				//floatingWindow.window.moveTo(((top.window.outerWidth-intWidth)/2),((top.window.outerHeight-intHeight)/2));
			}
			floatingWindow.focus();
		}
	}

	function Format(fmt, arr) {
		var result=fmt;
		if (isArray(arr))
		{
			for (i=arr.length-1; i>=0; i--)
			{
				result = result.split("%"+i).join(arr[i]);
			}
		} else
			result = result.split("%0").join(arr);

		return result;
	}

	function isAlien(a) {
	   return isObject(a) && typeof a.constructor != 'function';
	}
	function isArray(a) {
		return isObject(a) && a.constructor == Array;
	}
	function isBoolean(a) {
		return typeof a == 'boolean';
	}
	function isEmpty(o) {
		var i, v;
		if (isObject(o)) {
			for (i in o) {
				v = o[i];
				if (isUndefined(v) && isFunction(v)) {
					return false;
				}
			}
		}
		return true;
	}
	function isFunction(a) {
		return typeof a == 'function';
	}
	function isNull(a) {
		return typeof a == 'object' && !a;
	}
	function isNumber(a) {
		return typeof a == 'number' && isFinite(a);
	}
	function isObject(a) {
		return (a && typeof a == 'object') || isFunction(a);
	}
	function isString(a) {
		return typeof a == 'string';
	}
	function isUndefined(a) {
		return typeof a == 'undefined';
	} 

	function Is() {
		var agent = navigator.userAgent.toLowerCase();
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
		this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
		this.ns2 = (this.ns && (this.major == 2));
		this.ns3 = (this.ns && (this.major == 3));
		this.ns4b = (this.ns && (this.minor < 4.04));
		this.ns4 = (this.ns && (this.major >= 4));
		this.ie = (agent.indexOf("msie")!= -1);
		this.ie3 = (this.ie && (this.major == 2));
		this.ie4 = (this.ie && (this.major >= 4));
		this.op3 = (agent.indexOf("opera")!= -1);
		this.win = (agent.indexOf("win")!=-1);
		this.mac = (agent.indexOf("mac")!=-1);
		this.unix = (agent.indexOf("x11")!=-1);
	}
	var is = new Is(); 


function getElementTop(el) {
	if (el.offsetParent==null)
		return 0;
	else
		return (el.offsetTop + getElementTop(el.offsetParent));
}

function getElementLeft(el) {
	if (el.offsetParent==null)
		return 0;
	else
		return (el.offsetLeft + getElementLeft(el.offsetParent));
}

function getElementWidth(el) {
	return el.offsetWidth;
}

function getElementHeight(el) {
	return el.offsetHeight;
}

function LimitMultiLineLength(obj)
{
	var iKey;
	var eAny_Event = window.event;
	iKey = eAny_Event.keyCode;
	var re
	re = new RegExp("\r\n","g")  
	x = obj.value.replace(re,"").length ;
	if ((x >= obj.maxLength) && ((iKey > 33 && iKey < 255) || (iKey > 95 && iKey < 106)) && (iKey != 13))
	{
		if (obj.ErrorMessage )
		{
			alert(obj.ErrorMessage);
		}
		window.event.returnValue=false;      
	}
} 

function imposeMaxLength(event, Object, MaxLen)
{
  //8 - backslash, 37 - left, 38 - up, 39 - right, 40 - bottom, 46 - delete, 9 - tab
  if (event.keyCode==8 || event.keyCode==9 || (event.keyCode>=37 && event.keyCode<=46) || event.keyCode==46)
	return true;
  return (Object.value.length <= MaxLen);
}