function boxToggle(name) {
	Element.toggle(name + '_editor');
	Element.toggle(name + '_content');
}

function ajaxLoader(element) {
	src = '/images/cms/ajax-loader.gif';
	$(element).innerHTML = '<img src="' + src + '">';
}

function showElement(element) {
	$(element).show();
}

function areyousurereturn(msg) {
	if(confirm(msg)) {
		return true;
	}
	
	return false;
}

function actionMessage(msg, success) {

	document.write('<div id="dimmer" class="dimmer" onClick="hideActionMessage()">');
	dimensions = $('dimmer').getDimensions();
	var left = (dimensions.width) / 2 - 150 + 'px';

	document.write('<div id="actionMessage" class="actionMessage" align="center" style="left: ' + left + ';" onClick="hideActionMessage()">' + (success ? "" : "<span style=\"color: red;\">") + msg + (success ? "" : "</span>") + '<br><br><input type="button" id="okBtn" style="width: auto; border: 1px solid #c1d1d6;" value=" OK "></div>');
	document.write('</div>');
	
	$('okBtn').focus();
}

function hideActionMessage() {
	$('dimmer').hide();
	$('actionMessage').hide();
}

/**
 * cms class
 */
cms = {
	
	siteurl: "",
	sitelang: "",
	
	initialize: function() {
		if(typeof(Prototype) != "undefined") {
			Event.observe(document, 'mousemove', this.mousemove.bindAsEventListener(this));
		}
	},

	mousemove: function (e) {
		this.pos_x = Event.pointerX(e);
		this.pos_y = Event.pointerY(e);
		this.movePopup();
	},
	
	showPopup: function(msg) {
		$('cmsPopup').innerHTML = msg;
		$('cmsPopup').style.display = "block";
	},
	
	hidePopup: function() {
		$('cmsPopup').hide();
	},
	
	movePopup: function() {
		
		// get dimensions of the popup
		var dimensions = $('cmsPopup').getDimensions();
		
		var popupLeft = this.pos_x - (dimensions.width / 2) + 'px';

		// move popup right if it's too far in the left
		if(this.pos_x < 165) {
			var popupLeft = this.pos_x - (dimensions.width / 2) + 140 + 'px';
		}

		// move popup right if it's too far in the left
		if(this.pos_x + 300 > screen.width) {
			var popupLeft = this.pos_x - (dimensions.width / 2) - 300 + 'px';
		}

		var popupTop = this.pos_y - dimensions.height - 20 + 'px';

		// move popup underneath if it's too close to the top
		if(this.pos_y < 150) {
			var popupTop = this.pos_y + 25 + 'px';
		}
		$('cmsPopup').setStyle( {'left': popupLeft, 'top': popupTop } );
		
	}
}

cms.initialize();

/** COOKIES **/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/** MOUSE POSITION **/
function mouseX(evt) {
	if(evt.pageX) {
		return evt.pageX;
	}
	else if(evt.clientX) {
	   return evt.clientX + (document.documentElement.scrollLeft ?
							   document.documentElement.scrollLeft :
							   document.body.scrollLeft);
	}
	else {
		return null;
	}
}

function mouseY(evt) {
	if(evt.pageY) {
		return evt.pageY;
	}
	else if(evt.clientY) {
		return evt.clientY + (document.documentElement.scrollTop ?
	  							document.documentElement.scrollTop :
	   							document.body.scrollTop);
	}
	else {
		return null;
	}
}

function refresh() {
	var sURL = unescape(window.location);
	window.location.href = sURL;
}

function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function setEditableAreas() {

	var pid = "{PID}";

	elements = $('adminMainMenu').getElementsBySelector('[rel="lightEditable"]');

	// add event observer for each ligthwindow editable element
	elements.each(
		function(elem) {

			$(elem).style.cursor = "pointer";
			$(elem).observe('click', function(event){
					myLightWindow.activateWindow({
						href: '?s=editmodule&module=' + Event.element(event).id + '&pid=' + pid,
						height: 650,
						width: 940,
						title: '&nbsp;'
					});
				}
			);
		}
	);
}

function matchStrings(str1, str2) {
	
	if(str1 == str2) {
		return true;
	}
	else {
		return false;
	}

}
