/* JavaScript Document */

isDOM = (typeof(document.getElementById('foo')) == undefined) ? false: true;
isOpera = isOpera5 = window.opera && isDOM;
isOpera6 = isOpera && window.print;
isOpera7 = isOpera && document.readyState;
isMSIE = isIE = document.all && document.all.item && !isOpera;
isStrict = document.compatMode == 'CSS1Compat';
isNN = isNC = navigator.appName == "Netscape";
isNN4 = isNC4 = isNN && !isDOM;
isMozilla = isNN6 = isNN && isDOM;

/*фактический размер документа по вертикали*/
function aliteGetDocumentRealHeight(doc) {
	return (doc.body.scrollHeight > doc.body.offsetHeight) ? doc.body.scrollHeight : doc.body.offsetHeight;
}

/*фактический размер документа по горизонтали*/
function aliteGetDocumentRealWidth(doc) {
	return (doc.body.scrollWidth > doc.body.offsetWidth) ? doc.body.scrollWidth : doc.body.offsetWidth;
}

function aliteGetWindowRealHeight() {
	return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}

function aliteGetWindowRealWidth() {
	return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function aliteGetElementComputedStyle(elem, prop) {
	if (typeof elem != 'object') elem = document.getElementById(elem);
	/*external stylesheet for Mozilla, Opera 7+ and Safari 1.3+*/
	if (document.defaultView && document.defaultView.getComputedStyle) {
		if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
		return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
	}
	/*external stylesheet for Explorer and Opera 9*/
	if (elem.currentStyle) {
		var i;
		while ((i=prop.indexOf("-")) != -1) prop = prop.substr(0, i) + prop.substr(i + 1, 1).toUpperCase() + prop.substr(i + 2);
		return elem.currentStyle[prop];
	}
	return "";
}

function aliteMouseLayerXY(e) {
	if (!e) e = window.event;
	var x = 0;
	var y = 0;
	if (!document.attachEvent && document.addEventListener) {
		x = e.layerX - parseInt(aliteGetElementComputedStyle(e.target, "border-left-width"));
		y = e.layerY - parseInt(aliteGetElementComputedStyle(e.target, "border-top-width"));
	} else if (document.attachEvent != null) {
		x = e.offsetX;
		y = e.offsetY;
	}
	var elm = (e.target) ? e.target : e.srcElement;
	return {"elm":elm, "x":x, "y":y};
}

function aliteMouseDocumentXY(e) {
	var x = 0;
	var y = 0;
	if (document.attachEvent && window.event) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	} else if (!document.attachEvent && document.addEventListener && e) {
		x = e.clientX + window.scrollX;
		y = e.clientY + window.scrollY;
	}
	return {"x":x, "y":y};
}

function aliteScrollToElement(theElement, useX) {
	var selectedPosX = 0;
	var selectedPosY = 0;
	while (theElement != null) {
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
	if (useX) {
		window.scrollTo(0, selectedPosY);
	} else {
		window.scrollTo(selectedPosX, selectedPosY);
	}
}

function aliteSetSizeAttahedIframe(frameId, doc, addh) {
	if (!doc || doc == null || typeof doc == 'undefined') doc = document;
	var frame = doc.getElementById(frameId);
	if (frame && typeof frame != 'undefined') {
		var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		if (innerDoc && typeof innerDoc != 'undefined') {
			var acntr = innerDoc.getElementById('attahedContainer');
			if (acntr && typeof acntr != 'undefined') {
				var h = acntr.scrollHeight + Number(addh);
				if (frame.height != h) frame.height = h;
				if (frame.width != '100%') frame.width = '100%';
			}
		}
	}
}

function aliteMarkImgRubric(type) {
	var aItem;
	switch (type) {
		case 'news':
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '';
			break;
		case 'articles':
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '';
			break;
		case 'gallerys':
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '';
			break;
		case 'catalogs':
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '';
			break;
		case 'votings':
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '';
			break;
		case 'brands':
			aItem = document.getElementById('imgRubBrands'); if (aItem) aItem.style.backgroundColor = '#EBEBEB';
			aItem = document.getElementById('imgRubNews'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubArticles'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubGallerys'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubCatalogs'); if (aItem) aItem.style.backgroundColor = '';
			aItem = document.getElementById('imgRubVotings'); if (aItem) aItem.style.backgroundColor = '';
			break;
	}
}

function aliteConfirmationAndGotoUrl(text, url) {
	if (confirm(text)) document.location.href = url;
}

function aliteUserCorrectTdForInput(_this) {
	if (!_this) return;
	if (isMSIE || isMozilla) {
		var items_tdForInput = _this.getElementsByTagName("td");
		var old_paddingRight;
		for (var i =0; i < items_tdForInput.length; i++) {
			if (items_tdForInput[i].id == "tdForInput") {
				old_paddingRight = 0;
				if (items_tdForInput[i].style.paddingRight) old_paddingRight = parseInt(items_tdForInput[i].style.paddingRight);
				if (isMSIE) items_tdForInput[i].style.paddingRight = old_paddingRight + 6 + "px";
				else if (isMozilla) items_tdForInput[i].style.paddingRight = old_paddingRight + 4 + "px";
			} else if (items_tdForInput[i].id == "tdForTextArea") {
				old_paddingRight = 0;
				if (items_tdForInput[i].style.paddingRight) old_paddingRight = parseInt(items_tdForInput[i].style.paddingRight);
				if (isMSIE) items_tdForInput[i].style.paddingRight = old_paddingRight + 6 + "px";
				else if (isMozilla) items_tdForInput[i].style.paddingRight = old_paddingRight + 4 + "px";
			}
		}
	}
}

function aliteAdminCorrectTdForInput() {
	if (isMozilla) {
		var ac = document.getElementById("attahedContainer");
		if (ac) document.getElementById("attahedContainer").style.paddingLeft = "1px";
	}
	if (isMSIE || isMozilla || isOpera) {
		var items_tdForInput = document.getElementsByTagName("td");
		/*var items_tdForInput = document.all["tdForInput"];*/
		var old_paddingRight;
		for (var i =0; i < items_tdForInput.length; i++) {
			if (items_tdForInput[i].id == "tdForInput") {
				old_paddingRight = 0;
				if (items_tdForInput[i].style.paddingRight) old_paddingRight = parseInt(items_tdForInput[i].style.paddingRight);
				if (isMSIE) items_tdForInput[i].style.paddingRight = old_paddingRight + 22 + "px";
				if (isOpera) items_tdForInput[i].style.paddingRight = old_paddingRight + 22 + "px";
				if (isMozilla) items_tdForInput[i].style.paddingRight = old_paddingRight + 22 + "px";
			} else if (items_tdForInput[i].id == "tdForTextArea") {
				old_paddingRight = 0;
				if (items_tdForInput[i].style.paddingRight) old_paddingRight = parseInt(items_tdForInput[i].style.paddingRight);
				if (isMSIE) items_tdForInput[i].style.paddingRight = old_paddingRight + 20 + "px";
				if (isOpera) items_tdForInput[i].style.paddingRight = old_paddingRight + 22 + "px";
				if (isMozilla) items_tdForInput[i].style.paddingRight = old_paddingRight + 22 + "px";
			} else if (items_tdForInput[i].id == "tdForTextAreaTinyMce") {
				old_paddingRight = 0;
				if (items_tdForInput[i].style.paddingRight) old_paddingRight = parseInt(items_tdForInput[i].style.paddingRight);
				if (isMSIE) items_tdForInput[i].style.paddingRight = old_paddingRight + 12 + "px";
				if (isOpera) items_tdForInput[i].style.paddingRight = old_paddingRight + 12 + "px";
				if (isMozilla) items_tdForInput[i].style.paddingRight = old_paddingRight + 12 + "px";
			}
		}
	}
}

function aliteOpenNewWindow(url, width, heigth, scrollbars, winName) {
	if (typeof winName == 'undefined' || !winName) winName = 'MyWinName';
	var leftPosition = (screen) ? (screen.width - width) / 2 : 20;
	var topPosition = (screen) ? (screen.height - heigth) / 2 : 20;
	var w = window.open(url ? url.toString() : "", winName, "width=" + width.toString() + ",height=" + heigth.toString() + ",resizable=yes,scrollbars=" + scrollbars + ",status=no,menubar=no,location=no,toolbar=no,left=" + leftPosition.toString() + ",top=" + topPosition.toString());
	if (w && w != 'undefined') w.focus();
}

function aliteOpenNewWindowDefault(url, winName) {
	if (typeof winName == 'undefined' || !winName) winName = 'DefaultWinName';
	var w = window.open(url ? url.toString() : '', winName);
	if (w && w != 'undefined') w.focus();
}

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

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

function aliteGetObjectRect(curObj, useSelf) {
	var elmt;
	var y = 0;
	var x = 0;
	var h = 0;
	var w = 0;
	if (useSelf) {
		elmt = curObj;
	} else {
		elmt = curObj.offsetParent; /*parentNode*/
	}
	if (elmt != null) {
		h = elmt.offsetHeight;
		w = elmt.offsetWidth;
		while (elmt != null) {
			y += elmt.offsetTop;
			x += elmt.offsetLeft;
			elmt = elmt.offsetParent;
		}
	}
	if (isNaN(y)) y = 0;
	if (isNaN(x)) x = 0;
	if (isNaN(h)) h = 0;
	if (isNaN(w)) w = 0;
	return {"x":x, "y":y, "w":w, "h":h};
}

function aliteLoadXMLDoc(url, destElm, sendMethod) {
	var dest = null;
	if (!sendMethod || sendMethod == null || typeof sendMethod == 'undefined') sendMethod = 'GET'
	if (destElm) var dest = document.getElementById(destElm);
	if (dest) dest.innerHTML = '';
	if (url) {
		if (dest) dest.innerHTML = 'ajax ...';
		var req = null;
		if (window.XMLHttpRequest) {
			try {
				req = new XMLHttpRequest();
			} catch (e) {
				if (dest) dest.innerHTML = 'ajax ... error';
			}
		} else if (window.ActiveXObject) {
			try {
				req = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				try {
					req = new ActiveXObject('Microsoft.XMLHTTP');
				} catch (e) {
					if (dest) dest.innerHTML = 'ajax ... error';
				}
			}
		}
		if (req) {
			document.body.style.cursor = "wait";
			if (dest) dest.innerHTML = 'ajax get ...';
			req.onreadystatechange = aliteLoadXMLDocStateChange;
			req.open(sendMethod, url, true);
			req.send(null);
			return true;
		} else {
			if (dest) dest.innerHTML = 'ajax ... error';
			return false;
		}
	} else {
		return false;
	}
	
	function aliteLoadXMLDocStateChange() {
		if (req.readyState == 4) {
			document.body.style.cursor = "default";
			var s = '';
			if (req.status == 200) {
				if (req.responseText) {
					try {
						s = decodeURI(req.responseText);
					} catch (e) {
						s = req.responseText;
					}
				} else {
					s = '';
				}
			} else {
				s = 'ajax ... error status';
			}
			if (dest) {
				dest.innerHTML = aliteJsAddSlashes(s);
				//setTimeout('document.getElementById("' + destElm + '").innerHTML = "";', 15000);
			}
		}	
	}
}

function aliteLoadTableRow(url, destElm) {
	var dest = null;
	if (destElm) var dest = document.getElementById(destElm);
	if (dest) dest.rows[1].cells[0].children[0].innerHTML = '<img src="/_images/ajax-loader.gif" alt="ajax load..." style="display: block; margin-left: 15px;" \/>';
	if (url) {
		var req = null;
		if (window.XMLHttpRequest) {
			try {
				req = new XMLHttpRequest();
			} catch (e) {
				alert(e.message);
			}
		} else if (window.ActiveXObject) {
			try {
				req = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				try {
					req = new ActiveXObject('Microsoft.XMLHTTP');
				} catch (e) {
					alert(e.message);
				}
			}
		}
		if (req) {
			req.onreadystatechange = aliteLoadTableRowStateChange;
			req.open("GET", url, true);
			req.send(null);
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
	
	function aliteLoadTableRowStateChange() {
		if (req.readyState == 4) {
			if (dest) {
				if (req.status == 200) {
					var s = '';
					try {
						s = decodeURI(req.responseText);
					} catch (e) {
						s = req.responseText;
					}
					dest.rows[1].cells[0].children[0].innerHTML = aliteJsAddSlashes(s);
				} else {
					alert('Ajax error status');
				}
			}
		}	
	}
}

function aliteValidateEmail(emailStr) {
	var reg = new RegExp(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/i);
	if (!reg.test(emailStr)) {
		return false;
	} else {
		return true;
	}
}

//list of files already added
var externalFilesAdded = '';

function aliteLoadExternalJsCssFile(fileName, fileType, media, charset) {
	if (externalFilesAdded.indexOf('[' + fileName + ']') == -1) {
		if (fileType == 'js') {
			//if fileName is a external JavaScript file
			var fileRef = document.createElement('script');
			fileRef.setAttribute('type','text/javascript');
			fileRef.setAttribute('src', fileName);
			if (charset && typeof charset != 'undefined') {
				fileRef.setAttribute('charset', charset);
			}
		} else if (fileType == 'css') {
			//if fileName is an external CSS file
			var fileRef = document.createElement('link');
			fileRef.setAttribute('rel', 'stylesheet');
			fileRef.setAttribute('type', 'text/css');
			fileRef.setAttribute('href', fileName);
			if (media && typeof media != 'undefined') {
				fileRef.setAttribute('media', media);
			}
		}
		if (fileRef && typeof fileRef != 'undefined') {
			document.getElementsByTagName('head')[0].appendChild(fileRef);
			externalFilesAdded += '[' + fileName + ']';
		}
	}
}

//эта переменная установливается и здесь и в _admin/left.php
var group_item_id_active_prior = '';

function aliteMenuGroupClick(items_tagname, items_name, item_id, hide_no_active, title) {
	var groups = document.getElementsByTagName(items_tagname);
	if (groups && groups.length) {
		for (var i = 0; i < groups.length; i++) {
			if (groups[i].getAttribute('name') == items_name) {
				if (groups[i].id != item_id) {
					if (hide_no_active) groups[i].style.display = 'none';
				} else {
					var td_datas = document.getElementById('td_datas');
					if (groups[i].style.display == 'block') {
						if (group_item_id_active_prior == item_id || !td_datas) groups[i].style.display = 'none';
					} else {
						groups[i].style.display = 'block';
					}
					if (groups[i].style.display == 'block') {
						aliteCheckExistsMenuActiveItem(groups[i]);
						var y = aliteActiveItemTop(groups[i]);
						if (y) window.scrollTo(0, y);
						if (group_item_id_active_prior != item_id) {
							if (td_datas) {
								td_datas.innerHTML = '<p class="admin_page_title">' + title + '<\/p>';
								var _clone = groups[i].cloneNode(true);
								_clone.style.display = 'block';
								_clone.setAttribute('name', '');
								_clone.setAttribute('id', '');
								var divAdmTpc = document.createElement("DIV");
								divAdmTpc.setAttribute('class', 'admin_topic');
								divAdmTpc.appendChild(_clone);
								td_datas.appendChild(divAdmTpc);
							}
							group_item_id_active_prior = item_id;
						}
					}
					if (!hide_no_active) {
						var expDate = new Date;
						expDate.setTime(expDate.getTime() + 30 * 24 * 60 * 60 * 1000);
						setCookie(items_name + '_' + item_id, groups[i].style.display, expDate, '/', document.location.hostname, false);
						break;
					}
				}
			}
		}
	}
	
	function aliteActiveItemTop(_item) {
		var y_doc = 0;
		if (isMSIE) {
			y_doc = document.documentElement.scrollTop + document.body.scrollTop;
		} else {
			y_doc = window.scrollY;
		}
		if (y_doc) {
			var elmt = _item.parentNode;
			var y = 0;
			if (elmt != null) {
				while (elmt != null) {
					y += elmt.offsetTop;
					elmt = elmt.offsetParent;
				}
			}
			if (isNaN(y)) {
				y = 0;
			} else {
				y -= 2;
			}
			if (y - y_doc > 0) y = 0;
			return y;
		} else {
			return 0;
		}
	}
	
	function aliteCheckExistsMenuActiveItem(_this) {
		if (_this != null && _this.childNodes.length) {
			for (var i = 0; i < _this.childNodes.length; i++) {
				menuItem = _this.childNodes[i];
				if (menuItem != null && menuItem.childNodes.length) {
					for (var j = 0; j < menuItem.childNodes.length; j++) {
						if (menuItem.childNodes[j].tagName == 'SPAN') {
							document.location.reload();
						} else if (menuItem.childNodes[j].tagName == 'UL') {
							aliteCheckExistsMenuActiveItem(menuItem.childNodes[j])
						}
					}
				}
			}
		}
	}
}

function aliteShowFullTextInRowTable(ttl) {
	var window_alite = document.getElementById('window_alite');
	if (window_alite && typeof window_alite != 'undefined') {
		window_alite.rows[0].cells[0].innerHTML = ttl;
		window_alite.rows[1].cells[0].children[0].style.maxHeight = Math.round(parseInt(aliteGetWindowRealHeight()) * 0.7) + 'px';
		window_alite.style.display = 'block';
	}
}

function aliteSetsLoginForm(fid, fcsd) {
	var f = document.getElementById(fid);
	if (f && typeof f != 'undefined') {
		f.setAttribute('autocomplete', 'off');
		if (fcsd) f.elements[0].focus();
	}
}

function aliteSetGroupActions(group_name, layer_action_bts_id, text_field_vals_id) {
	var ids = '';
	var group = document.getElementsByName(group_name);
	var layer_action_bts = document.getElementById(layer_action_bts_id);
	if (layer_action_bts && typeof layer_action_bts != 'undefined' && group && typeof group != 'undefined' && group.length) {
		var btns_active = false;
		for (var i = 0; i < group.length; i++) {
			if (group[i].checked) {
				btns_active = true;
				if (ids) ids = ids + ',';
				ids = ids + group[i].value;
				group[i].parentElement.parentElement.className += ' select';
			} else {
				group[i].parentElement.parentElement.className = group[i].parentElement.parentElement.className.replace(/ select/g, '');
			}
		}
		for (var i = 0; i < layer_action_bts.children.length; i++) {
			if (btns_active) {
				layer_action_bts.children[i].src = layer_action_bts.children[i].src.replace(/_gray\.gif/g, '.gif');
				layer_action_bts.children[i].style.cursor = 'pointer';
			} else {
				layer_action_bts.children[i].src = layer_action_bts.children[i].src.replace(/\.gif/g, '_gray.gif');
				layer_action_bts.children[i].style.cursor = 'default';
			}
		}
	}
	var field_vals_id = document.getElementById(text_field_vals_id);
	if (field_vals_id && typeof field_vals_id != 'undefined') {
		field_vals_id.value = ids;
	}
}

function aliteShowFileMangerActions(title, row_idx) {
	var win = document.getElementById('window_alite_file_manager_actions');
	if (win && typeof win != 'undefined') {
		win.rows[0].cells[0].children[0].innerHTML = title;
		for (var i = 1; i < win.rows.length; i++) win.rows[i].style.display = 'none';
		if (row_idx) {
			win.rows[row_idx].style.display = 'block';
			win.style.display = 'block';
		} else {
			win.style.display = 'none';
		}
	}
}

function aliteFixCookieDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0) date.setTime(date.getTime() - skew);
}

function aliteSetCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '/') + ((domain) ? '; domain=' + domain : document.location.hostname) + ((secure) ? '; secure' : '');
}

function aliteDelCookie(name, path, domain) {
	if (aliteGetCookie(name)) {
		document.cookie = name + '=' + ((path) ? '; path=' + path : '/') + ((domain) ? '; domain=' + domain : document.location.hostname) + 'expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

function aliteGetCookie(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 aliteGetCookieVal(j);
		//i = document.cookie.indexOf(' ', 1 ) + 1;
		i++;
		if (i == 0) break;
	}
	return false;
	
	function aliteGetCookieVal(offset) {
		var endstr = document.cookie.indexOf(';', offset);
		if (endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
}

function aliteTrim(str){
	str = str.replace(/&nbsp;|&#160;/g, ' ');
	return str.replace(/(^\s+)|(\s+$)/g, '');
}

// Find position of first occurrence of a case-insensitive string
function aliteStrIPos(f_haystack, f_needle, f_offset) {
	var haystack = f_haystack.toLowerCase();
	var needle = f_needle.toLowerCase();
	var index = 0;
	if (!f_offset || f_offset == undefined) f_offset = 0;
	if ((index = haystack.indexOf(needle, f_offset)) > -1) {
		return index;
	}
	return false;
}
