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

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 add2basket(i, c) {
	var o = $('basket_content'), tmr, areq = 0, tact = false;
	if(typeof(c) == 'undefined') c = 0;
	new ajx('ajax.php?p=add2basket', {
		m: 'p',
		p: {i: i, c: c},
		i: function() {
			tact = true;
			areq++;
			o.innerHTML = '';
			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(areq == 0) o.innerHTML = r;
		},
		f: function() {
			if(areq == 0) o.innerHTML = 'error';
		}
	});
}

function rate(table, id, rate) {
	new ajx('ajax.php?p=rating', {
		m: 'p',
		p: {table: table, id: id, rate: rate},
		i: function() {
			$('ratingdiv').innerHTML = 'astepata'
		},
		s: function(r) {
			$('ratingdiv').innerHTML = r
		},
		f: function() {
			$('ratingdiv').innerHTML = 'eroare'
		}
	});
}

