CurrentUrl = null;
function setCurrentUrl(Url) {
	CurrentUrl = Url;
}

function getElementsByClass(searchClass, tag, node) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getParameterFromUrlString( name , urlString )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( urlString );
  if( results == null )
    return "";
  else
    return results[1];
}

function urlInsertParam(url, key, value)
{
    key = escape(key); value = escape(value);

    var urlPagePart = url.split('#');
    var urlParamPart = urlPagePart[0].split('?');

    if (urlParamPart[1]) {
    	var kvp = urlParamPart[1].split('&');
    } else {
    	var kvp = new Array();
    }

    var i=kvp.length; var x; while(i--)
    {
        x = kvp[i].split('=');

        if (x[0]==key)
        {
                x[1] = value;
                kvp[i] = x.join('=');
                break;
        }
    }

    if(i<0) {kvp[kvp.length] = [key,value].join('=');}

    returnUrl = urlParamPart[0] + '?' + kvp.join('&');
    if (urlPagePart[1]) {
    	returnUrl = returnUrl + '#' + urlPagePart[1];
    }

   	return returnUrl;
}

function hideAdministrationBar(){
	document.getElementById('AdministrationBarButton').style.display = 'block';
	document.getElementById('ActionBarPresentationAdministrator').style.display = 'none';
}


function showAdministrationBar(){
	document.getElementById('AdministrationBarButton').style.display = 'none';
	document.getElementById('ActionBarPresentationAdministrator').style.display = '';
}

// Wrtten by Jason Karl Davis
// http://www.webdeveloper.com/forum/archive/index.php/t-102595.html

if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
HTMLElement.prototype.click=function(){
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}

// END

// show hide elements
function setElementByIdDisplay(ElementId, Display) {
	Element = document.getElementById(ElementId);
	if (Element) {
		Element.style.display = Display;
	}
}

function removeContentItemImage(ContentItem_Id) {
	var url = 'ajax.php?ScriptName=Ajax_RemoveContentItemImage&ContentItem_IdForImage='+ContentItem_Id;
	if (!send_xmlhttprequest(hideContentItemImage, 'GET', url)) {
		return false;
	}
}

function hideContentItemImage(xmlhttp) {
	ImageDiv = document.getElementById('ContentItemImage');
	ImageDiv.style.display = 'none';
	return true;
}

// START ContextMenu block
// @author: peter.hrusovsky@abeo.cz

var ContextMenuWindow = null;
var LastCallingElement = null;
var ActionBarElementActualShown = null;
var AdminBarIdActualShown = null;


function activateContextMenu(DivElement, AdminBarId) {
	showContextMenuButton(DivElement, AdminBarId);
}

function deactivateContextMenu(DivElement, AdminBarId) {
	if (DivElement) {
		hideContextMenuButton(DivElement, AdminBarId);
	} else if (ActionBarElementActualShown) {
		// hide last shown context menu and button
		destroyContextMenuContent();
		hideContextMenuButton(ActionBarElementActualShown, AdminBarIdActualShown);
	}
}

function closeLastContextMenu(e) {
	var event = e || window.event;
	destroyContextMenuContent();
	if (event.stopPropagation) {
		event.stopPropagation();
	} else {
		event.cancelBubble = true;
	}
	return true;
}

function showContextMenuButton(DivElement, AdminBarId) {
	if (DivElement!=ActionBarElementActualShown) {
		destroyContextMenuContent();
		hideContextMenuButton(ActionBarElementActualShown, AdminBarIdActualShown);
		document.getElementById('ActionBarContentBlock-' + AdminBarId).style.display = 'block';
		document.getElementById('ActionBarLayoutBlock-' + AdminBarId).style.display = 'block';
		highlightElement(getElementChildNode(DivElement, 1), 'LB');
		ActionBarElementActualShown = DivElement;
		AdminBarIdActualShown = AdminBarId;
		LastCallingElement = null;
	}
	return true;
}

function hideContextMenuButton(DivElement, AdminBarId) {
	if (DivElement && !ContextMenuWindow) {
		AdminBarElement = document.getElementById('ActionBarContentBlock-' + AdminBarId);
		if (AdminBarElement) {
			AdminBarElement.style.display = 'none';
		}
		AdminBarElement = document.getElementById('ActionBarLayoutBlock-' + AdminBarId);
		if (AdminBarElement) {
			AdminBarElement.style.display = 'none';
		}
		unhighlightElement(getElementChildNode(DivElement, 1));
		ActionBarElementActualShown = null;
		AdminBarIdActualShown = null;
	}
	return true;
}

function showContextMenuContent(CallingElement, ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, MenuType, ContentPackageLayoutBlockIndex, Page_Id, CurrentNid) {
	if (CallingElement==LastCallingElement) {
		destroyContextMenuContent();
		return true;
	} else {
		createContextMenuContent('<div id="ContextMenuWindowContent" onclick="eventStopPropagation(event);"></div>');
		if (ContextMenuWindow) {
			// get the body width
			bodyArray = document.getElementsByTagName('body');
			bodyTag = bodyArray[0];

			// set the correct position
			CallingElementPosition = findPos(CallingElement);
			if (!MenuType || MenuType=='ContentBlock' || MenuType=='ContentPackage') {
				ContextMenuWindow.style.right = (bodyTag.offsetWidth - CallingElementPosition[0] - CallingElement.offsetWidth - 5) + 'px';
				ContextMenuWindow.style.top = CallingElementPosition[1] -2 + 'px';
			}  else if (MenuType=='LayoutBlock') {
				ContextMenuWindow.style.left = CallingElementPosition[0] - 4 + 'px';
				ContextMenuWindow.style.top = CallingElementPosition[1] - 3 + 'px';
			} else if (MenuType=='AdminBarFavorite'
						 || MenuType=='AdminBarOtherAction'
						 || MenuType=='AdminBarAddPage'
						 || MenuType=='AdminBarEditPage'
					  	) {
				ContextMenuWindow.style.position = 'fixed';
				ContextMenuWindow.style.right = (bodyTag.offsetWidth - CallingElementPosition[0] - CallingElement.offsetWidth - 3) + 'px';
				ContextMenuWindow.style.top = CallingElementPosition[1] + 23 + 'px';
			}
			LastCallingElement=CallingElement;
			if (!MenuType || MenuType=='ContentBlock') {
				_renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, 'GetContextMenuWindowContent', null, null, null, Page_Id);
			} else if (MenuType=='ContentPackage') {
				_renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, 'GetContextMenuCPWindowContent');
			} else if (MenuType=='LayoutBlock') {
				_renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, 'GetContextMenuLBWindowContent', null, null, ContentPackageLayoutBlockIndex, Page_Id);
			} else if (MenuType=='AdminBarFavorite') {
				_renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, 'GetContextMenuAdminBarFavoriteWindowContent', null, null, null, Page_Id);
			} else if (MenuType=='AdminBarAddPage') {
				_renderContextMenuWindowContent(null, null, null, null, 'GetContextMenuAdminBarAddPageWindowContent', null, null, null, null, CurrentNid);
			} else if (MenuType=='AdminBarEditPage') {
				_renderContextMenuWindowContent(null, null, null, null, 'GetContextMenuAdminBarEditPageWindowContent', null, null, null, null, CurrentNid);
			} else if (MenuType=='AdminBarOtherAction') {
				_renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, 'GetContextMenuAdminBarOtherActionWindowContent');
			}
		}
		return true;
	}
}

function createContextMenuContent(contextMenuHtml) {
	bodyArray = document.getElementsByTagName('body');
	bodyTag = bodyArray[0];
	if (ContextMenuWindow) {
		bodyTag.removeChild(ContextMenuWindow);
	}
	ContextMenuWindow = document.createElement('div');
	ContextMenuWindow.setAttribute('class', "ContextMenuContent");
	ContextMenuWindow.setAttribute('className', "ContextMenuContent");
	ContextMenuWindow.innerHTML = contextMenuHtml;
	bodyTag.appendChild(ContextMenuWindow);
	return true;
}

function destroyContextMenuContent() {
	if (ContextMenuWindow) {
		bodyArray = document.getElementsByTagName('body');
		bodyTag = bodyArray[0];
		bodyTag.removeChild(ContextMenuWindow);
		LastCallingElement = null;
		ContextMenuWindow = null;
		return true;
	}
}

//
// Function for calling ajax script.
//
function _renderContextMenuWindowContent(ContentBlockContainer_Id, ContentBlock_Id, ContentPackage_Id, LayoutBlockCode, ScriptName, Entity, Action, ContentPackageLayoutBlockIndex, Page_Id, CurrentNid){
	var url = 'ajax.php?';
	if(ScriptName != null){
		url = url + '&ScriptName=' + ScriptName;
	}
	if(Entity != null){
		url = url + '&Entity=' + Entity;
	}
	if(Action != null){
		url = url + '&Action=' + Action;
	}
	if(ContentPackage_Id != null){
		url = url + '&ContentPackage_Id=' + ContentPackage_Id;
	}
	if(ContentPackageLayoutBlockIndex != null){
		url = url + '&ContentPackageLayoutBlockIndex=' + ContentPackageLayoutBlockIndex;
	}
	if(Page_Id != null){
		url = url + '&Page_Id=' + Page_Id;
	}
	if(CurrentNid != null){
		url = url + '&CurrentNid=' + CurrentNid;
	}

	url = url + '&ContentBlockContainer_Id=' + ContentBlockContainer_Id;
	url = url + '&ContentBlock_Id=' + ContentBlock_Id;
	url = url + '&LayoutBlockCode=' + LayoutBlockCode;
	// odeslání požadavku na aktualizaci dat
	if (!send_xmlhttprequest(_showContextMenuWindowContent, 'GET', url)) {
		return false;
	}
	return true;
}

//
// Function for getting result about saving constant to db.
//
function _showContextMenuWindowContent(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		document.getElementById('ContextMenuWindowContent').innerHTML = xmlhttp.responseText;
	}
}

// END ContextMenu block

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function generateGuid() {
	var result, i, j;
	result = '';
	for(j=0; j<32; j++)	{
		if( j == 8 || j == 12|| j == 16|| j == 20)
		result = result + '-';
		i = Math.floor(Math.random()*16).toString(16).toLowerCase();
		result = result + i;
	}
	return result
}

//
// FF takes empty spaces between elements as text nodes, IE does not.
// getElementChildNode() function returns elementNodeIndex-th element
// of the parentElement. (i.e. for elementNodeIndex=3 returns third element node
// of the parentElement.)
//
function getElementChildNode(parentElement, elementNodeIndex) {
	if (parentElement) {
		countOfChildNodes = parentElement.childNodes.length;
		countOfElementNodes = 0;
		for (i=0; i<countOfChildNodes; i++) {
			if (parentElement.childNodes[i].nodeType == 1) {
				if (countOfElementNodes==elementNodeIndex) {
					return parentElement.childNodes[i];
				}
				countOfElementNodes++;
			}
		}
	    return false;
	} else {
		return false;
	}
}

function getElementNextSibling(elementNode) {
	if (elementNode.parentNode) {
		elementIndex = getChildNodeElementIndex(elementNode.parentNode, elementNode);
		if (elementIndex!==false) {
			return getElementChildNode(elementNode.parentNode, elementIndex+1);
		}
	}
	return null;
}

function getElementPreviousSibling(elementNode) {
	if (elementNode.parentNode) {
		elementIndex = getChildNodeElementIndex(elementNode.parentNode, elementNode);
		if (elementIndex!==false) {
			return getElementChildNode(elementNode.parentNode, elementIndex-1);
		}
	}
	return null;
}

function getChildNodeElementIndex(parentNode, childNode) {
	countOfElementChildNodes = 0;
	if (parentNode && childNode) {
		for (i=0; i<parentNode.childNodes.length; i++) {
			if (parentNode.childNodes[i]==childNode) {
				return countOfElementChildNodes;
			}
			if (parentNode.childNodes[i].nodeType == 1) {
				countOfElementChildNodes++;
			}
		}
	}
	return false;
}

function getCountOfElementChilds(parentElement) {
	if (parentElement) {
		countOfChildNodes = parentElement.childNodes.length;
		countOfElementNodes = 0;
		for (i=0; i<countOfChildNodes; i++) {
			if (parentElement.childNodes[i].nodeType == 1) {
				countOfElementNodes++;
			}
		}
	    return countOfElementNodes;
	} else {
		return -1;
	}
}


function getViewportSize() {
	var viewportwidth;
	var viewportheight;

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth,
	  viewportheight = window.innerHeight
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
	}

	// older versions of IE

	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [viewportwidth, viewportheight];
}

function getParentOfElementType(object, elementType) {
	if (object && object.parentNode) {
		do {
			if (object.nodeName==elementType.toUpperCase()) {
				return object;
			}
		} while (object = object.parentNode);
	}
	return false;
}

/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

//Sample usages
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

function swapElementsWithSameParent(elementToSwap, elementToSwapFor) {
	if (elementToSwap && elementToSwapFor && elementToSwap.parentNode==elementToSwapFor.parentNode) {
		parentElement = elementToSwap.parentNode;

		sourceNodeIndex = getChildNodeElementIndex(parentElement, elementToSwap);
		destinationNodeIndex = getChildNodeElementIndex(parentElement, elementToSwapFor);

		if (sourceNodeIndex>destinationNodeIndex) {
			parentElement.insertBefore(elementToSwap, elementToSwapFor);
		} else if (destinationNodeIndex+1==getCountOfElementChilds(parentElement)) {
			parentElement.appendChild(elementToSwap);
		} else if (sourceNodeIndex<destinationNodeIndex) {
			parentElement.insertBefore(elementToSwap, getElementNextSibling(elementToSwapFor));
		}

		return true;
	} else {
		return false;
	}
}

function preventDragImages(e) {
	e = e || window.event;
	if (e.preventDefault) {
		e.preventDefault();
	}
}

function dynamicLoadJavaScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

function doAjaxFormProcess(htmlForm) {
	// get the form fields
	if (!(formFieldValueArray = getHtmlFormValuesArray(htmlForm))) {
		return false;
	}
	// build parameter serialized string to send
	serializedParamString = '';
	for (x in formFieldValueArray) {
		if (x!='FormActionME') {
			serializedParamString = serializedParamString + '&' + x + '=' + formFieldValueArray[x];
		}
	}
	// get the target script
	if (formFieldValueArray['FormActionME']) {
		formActionME = formFieldValueArray['FormActionME'];
	} else {
		return false;
	}



	return false;
}

function getHtmlFormValuesArray(htmlForm) {
	var returnArray = {};
	if (htmlForm) {
		// parse INPUT
		elementArray = htmlForm.getElementsByTagName('input');
		for (i=0; i<elementArray.length; i++) {
			// parse text
			if (elementArray[i]=='text') {
				if (elementArray[i].name && elementArray[i].value!=null) {
					returnArray[elementArray[i].name] = elementArray[i].value;
				}
			}
			// parse checkbox
			if (elementArray[i]=='checkbox') {
				if (elementArray[i].name && elementArray[i].value!=null && elementArray[i].checked!=null) {
					returnArray[elementArray[i].name] = elementArray[i].value;
				}
			}
			// parse radio
			if (elementArray[i]=='radio') {
				if (elementArray[i].name && elementArray[i].value!=null && elementArray[i].checked!=null) {
					returnArray[elementArray[i].name] = elementArray[i].value;
				}
			}
		}
		// parse SELECT
		elementArray = htmlForm.getElementsByTagName('select');
		for (i=0; i<elementArray.length; i++) {
			if (elementArray[i].name && elementArray[i].value!=null) {
				returnArray[elementArray[i].name] = elementArray[i].value;
			}
		}
		// parse TEXTAREA
		elementArray = htmlForm.getElementsByTagName('textarea');
		for (i=0; i<elementArray.length; i++) {
			if (elementArray[i].name && elementArray[i].value!=null) {
				returnArray[elementArray[i].name] = elementArray[i].value;
			}
		}

		return returnArray;
	}
	return false;
}

function alertArray(inputArray) {
	Message = '';
	for (x in inputArray) {
		Message = Message + x + ': ' + inputArray[x] + "\n";
	}
	alert(Message);
}

function explode (delimiter, string, limit) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.
    //
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/explode    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
     var emptyArray = { 0: '' };

    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||        typeof arguments[1] == 'undefined' ) {
        return null;
    }

    if ( delimiter === '' ||        delimiter === false ||
        delimiter === null ) {
        return false;
    }
     if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;    }

    if ( delimiter === true ) {
        delimiter = '1';
    }
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;    }
}

// http://www.quirksmode.org/dom/getstyles.html
function getStyle(el,styleProp)
{
	if (el) {
		x = el;
		if (x.currentStyle)
			var y = x.currentStyle[styleProp];
		else if (window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
		return y;
	}
}

var Underlayer = null;
var UnderlayerShown = 0;

function showUnderlayer() {
	if (!Underlayer) {
		bodyArray = document.getElementsByTagName('body');
		bodyTag = bodyArray[0];
		Underlayer = document.createElement('div');
		Underlayer.setAttribute('class', "Underlayer");
		Underlayer.setAttribute('className', "Underlayer");
		Underlayer.style.width = bodyTag.offsetWidth + 'px';
		Underlayer.style.height = bodyTag.offsetHeight + 'px';
		bodyTag.appendChild(Underlayer);
		bodyTag.style.overflow = 'hidden';
	}
	UnderlayerShown++;
	return true;
}

function hideUnderlayer() {
	UnderlayerShown--;
	if (UnderlayerShown<=0 && Underlayer) {
		bodyArray = document.getElementsByTagName('body');
		bodyTag = bodyArray[0];
		bodyTag.removeChild(Underlayer);
		Underlayer = null;
		UnderlayerShown = 0;
		bodyTag.style.overflow = 'scroll';
	}
	return true;
}

function eventStopPropagation(e) {
	var event = e || window.event;
	if (event.stopPropagation) {
		event.stopPropagation();
	} else {
		event.cancelBubble = true;
	}
}

function reloadPageWithMessage(messageArray) {
	newUrl = window.location.toString();
	if (messageArray) {
		for (x in messageArray) {
			newUrl = urlInsertParam(newUrl, x, messageArray[x]);
		}
	}
	window.location = newUrl;
}

function redirectPageWithMessage(redirectUrl, messageArray) {
	if (messageArray) {
		for (x in messageArray) {
			redirectUrl = urlInsertParam(redirectUrl, x, messageArray[x]);
		}
	}
	window.location = redirectUrl;
}

function changeAdminBarApperance() {
	adminBar = document.getElementById('ActionBarPresentationAdministrator');
	if (adminBar) {
		bodyTag = document.getElementsByTagName('body')[0];
		adminBar.style.position = 'fixed';
		adminBar.style.top = '0px';
		adminBar.style.left = '0px';
		adminBar.style.width = '100%';
		curBodyMarginTop = getStyle(bodyTag, 'margin-top');
		if (!curBodyMarginTop) curBodyMarginTop = getStyle(bodyTag, 'marginTop');
		newBodyMarginTop = parseInt(curBodyMarginTop) + 60;
		bodyTag.style.marginTop = newBodyMarginTop + 'px';
		return true;
	}
}

function addEventToElementByAttribute(element, eventType, jsCode) {
	if (element) {
		curEventCode = element.getAttribute(eventType);
		curEventCode = curEventCode + ';' + jsCode;
		element.setAttribute(eventType, curEventCode);
	}
}

function popupOkMessage() {
	messageOkArray = getElementsByClass('Message_Ok');
	if (messageOkArray[0]) {
		messagePopup(messageOkArray[0]);
	}
}

function hideOkMessages() {
	messageOkArray = getElementsByClass('Message_Ok');
	if (messageOkArray[0]) {
		for (x in messageOkArray) {
			messageOkArray[x].style.display = 'none';
		}
	}
}

function messagePopup(messageElement) {
	if (messageElement) {
		bodyTag = document.getElementsByTagName('body')[0];
		messageElement.style.position = 'fixed';
		messageElement.style.display = 'block';
		if (messageElement.offsetWidth < 400) {
			messageElement.style.width = '400px';
		}
		centerElementOnScreen(messageElement);
		bodyTag.appendChild(messageElement);
		setTimeout(function() {messageClose(messageElement)}, 1500);
	}
}

function centerElementOnScreen(element) {
	if (element) {
		bodyTag = document.getElementsByTagName('body')[0];

		// solve position
		screenScrollTop = document.body.scrollTop + document.documentElement.scrollTop + document.body.scrollTop + document.documentElement.scrollTop;
		screenScrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft + document.body.scrollLeft + document.documentElement.scrollLeft;

		leftPosition = ((getViewportSize())[0] - element.offsetWidth) / 2;
		topPosition = ((getViewportSize())[1] - element.offsetHeight) / 2;

		element.style.left = leftPosition + screenScrollLeft + 'px';
		element.style.top = topPosition + screenScrollTop + 'px';
	}
	return true;
}

function messageClose(element, runCount) {
	if (runCount==null) {
		runCount = 100;
	}
	if (element) {
		element.style.opacity = runCount/100;
		element.style.filter = 'alpha(opacity=' + runCount + ')';
		if (runCount>0) {
			setTimeout(function() {messageClose(element, runCount-1)}, 10);
		} else {
			bodyTag = document.getElementsByTagName('body')[0];
			bodyTag.removeChild(element);
		}
	}
}

function removeCssClass(cssClassName, element) {
	if (element) {
		cssClasses = element.getAttribute('class');
		if (!cssClasses) {
			cssClasses = element.getAttribute('className');
		}
		cssClassArray = explode(' ', cssClasses);
		cssClasses = null;
		for (x in cssClassArray) {
			if (cssClassArray[x]!=cssClassName) {
				if (cssClasses!=null) {
					cssClasses = cssClasses + ' ';
				} else {
					cssClasses = '';
				}
				cssClasses = cssClasses + cssClassArray[x];
			}
		}
		element.setAttribute('class', cssClasses);
		element.setAttribute('className', cssClasses);
		return true;
	} else {
		return false;
	}
}

function addCssClass(cssClassName, element) {
	if (element) {
		removeCssClass(cssClassName, element);
		cssClasses = element.getAttribute('class');
		if (!cssClasses) {
			cssClasses = element.getAttribute('className');
		}
		cssClasses = cssClasses + ' ' + cssClassName;
		element.setAttribute('class', cssClasses);
		element.setAttribute('className', cssClasses);
		return true;
	} else {
		return false;
	}
}

function IsIE8Browser() {
    var rv = -1;
    var ua = navigator.userAgent;
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null) {
        rv = parseFloat(RegExp.$1);
    }
    return (rv == 4);

}

function IsIE7PlusBrowser() {
	var ie7=document.all && window.XMLHttpRequest && !window.opera;
	return ie7;
}

