// EVENTS FUNCTIONS
function AttachEvent(obj,evt,fnc,useCapture){
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 

function MyAttachEvent(obj,evt,fnc){
	if (!obj.myEvents) obj.myEvents={};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}

function MyFireEvent(obj,evt){
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}
// END EVENTS FUNCTIONS


// POPUP BANNER FUNCTIONS
function showPopupBanner() {
	var $banner = document.getElementById('banner-popup');
	var $width = $banner.style.width;
	$banner.style.left = Math.round((getBrowserWidth()/2 )-(parseInt($width)/2)) + 'px';
	if (isIE()) {
		$banner.style.position = "absolute";
		AttachEvent(window, "scroll", fixPopupBanner);
		AttachEvent(window, "onresize", fixPopupBanner);
	}
	$banner.style.display = '';
}

function fixPopupBanner(){
	document.getElementById('banner-popup').style.top = parseInt(document.documentElement.scrollTop + 200) + "px";
}

function closePopupBanner($id) {
	setCookie('popupBanner', $id + '|', null, '/');
	document.getElementById('banner-popup').style.display = 'none';
}
// POPUP BANNER FUNCTIONS

// OTHER FUNCTIONS
function getBrowserWidth() {
	if(window.innerWidth) {
		return window.innerWidth;
	}
	return document.body.clientWidth;
}

function isIE() {
	if (window.innerWidth) {
		return false;
	}
	return true;
}
// END OTHER FUNCTIONS

// RS FUNCTIONS
function onMeistClick(id)
{
    if (document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display='inline';
    } else {
        document.getElementById(id).style.display='none';
    }
    return false;
}

function textCounter(field, cntfield, maxlimit)
{
    if (field.value.length > maxlimit) {
        // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    } else {
        // otherwise, update 'characters left' counter
        cntfield.value = maxlimit - field.value.length;
    }
}
// END RS FUNCTIONS