//	event handling

function addEvent(element, eventType, lamdaFunction, useCapture) {
	if (element.addEventListener) {
		element.addEventListener(eventType, lamdaFunction, useCapture);
		return true;
	}
	if (element.attachEvent) return element.attachEvent('on' + eventType, lamdaFunction);
	return false;
}

function knackerEvent(e) {
	if (e && e.stopPropagation) e.stopPropagation();
    if (window.event && window.event.cancelBubble ) window.event.cancelBubble = true;
    if (e && e.preventDefault) e.preventDefault();
    if (window.event) window.event.returnValue = false;
}

//	rollover

function rolloverImage(e) {
	var target = window.event ? window.event.srcElement : e ? e.target : null;
	if (!target) return;
	target.src = target.src.replace('.gif', '_.gif');
}

function rolloutImage(e) {
	var target = window.event ? window.event.srcElement : e ? e.target : null;
	if (!target) return;
	target.src = target.src.replace('_.gif', '.gif');
}

function preloadImages() {
	var imgElements = document.images;
	if (!document.MM_preload) document.MM_preload = new Array();
	for (var i = 0, j = 0; i < imgElements.length; i++)
		if (imgElements[i].className.match(/\brollover\b/)) {
			document.MM_preload[j] = new Image;
			document.MM_preload[j++].src = imgElements[i].src.replace('.gif','_.gif');
			addEvent(imgElements[i], 'mouseover', rolloverImage, false);
			addEvent(imgElements[i], 'mouseout', rolloutImage, false);
		}
}

addEvent(window, 'load', preloadImages, false);

function ajx(u,o){var a=[],e,k,m=o.m=='p',p=o.p,x;try{x=new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP')}catch(e){x=new XMLHttpRequest()}}if(x==undefined)return false;for(e in p){if(typeof p[e]!='object')s(e,p[e]);else for(k=0;k<p[e].length;k++)s(e,p[e][k])}p=a.join("&");if(!m&&p)u+=(u.indexOf('?')>-1?'&':'?')+p;if(typeof o.i=='function')o.i();x.open(m?'POST':'GET',u,true);x.onreadystatechange=function(){if(x.readyState==4){if(typeof o.c=='function')o.c();if(x.status>=200&&x.status<300){if(typeof o.s=='function')o.s(x.responseText)}else if(typeof o.f=='function')o.f()}};x.setRequestHeader('X-Requested-With','XMLHttpRequest');if(m)x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');x.send(m?p:null);return true;function s(n,v){a.push(encodeURIComponent(n)+'='+encodeURIComponent(v))}}function frm(o){var a={},e,i,j,n,t;for(i=0;i<o.length;i++){e=o[i];n=e.name;if(!n||e.disabled)continue;t=e.type;if(/^(hidden|password|text(area)?)$/.test(t)||/^(checkbox|radio)$/.test(t)&&e.checked||/^select-one$/.test(t)&&e.selectedIndex>-1)s(n,e.value);else if(/^select-multiple$/.test(t)&&e.selectedIndex>-1){e=e.options;for(j=0;j<e.length;j++)if(e[j].selected)s(n,e[j].value)}}return a;function s(n,v){if(a[n]==undefined)a[n]=v;else{if(typeof a[n]!='object')a[n]=[a[n]];a[n].push(v)}}}

function $(s) {
	return document.getElementById(s);
}

function newsletter() {
	var o = $('newsletter_input'), tmr, areq = 0, tact = false, s;
	s = o.value;
	new ajx('ajax.php?p=newsletter', {
		m: 'p',
		p: {mail: s},
		i: function() {
			tact = true;
			areq++;
//			o.value = 'asteapta...';
			o.className = 'ajx';
			if(typeof(tmr) != 'undefined') clearTimeout(tmr);
			tmr = setTimeout(function(){if(!areq) o.className = '';tact = false;}, 1000);			
		},
		c: function() {
			areq--;
			if(!areq && !tact) o.className = '';
		},
		s: function(r) {
			if(r) if(areq == 0) o.value = 'te-ai abonat';
//			o.disabled = 'disabled';
		},
		f: function() {
//			if(areq == 0) o.value = 'error';
		}
	});
}

function cov(o, v) {
	document.getElementById(o).style.display = v ? 'block' : 'none';
}

