function statCounter(target, lang){
	var sTy = 1, sId = 'ID', sTm = 6, sDt = 0, sLn = 'pl', sWh = 10, sHt = 10, sSc = 'no', sBd = '0';
	sCode = new String('<'+'if'+'rame src="http://counters.stat24.com/statcnt.html?type={sTy}&id={sId}&time={sTm}&data={sDt}&lang={sLn}" width="{sWh}" height="{sHt}" scrolling="{sSc}" frameborder="{sBd}"><'+'/ifr'+'ame>');
	sLn = (lang == undefined ? sLn : lang);
	this.statCBuild=function(){
		sCodeX = sCode.replace('{sTy}', sTy);
		sCodeX = sCodeX.replace('{sId}', sId);
		sCodeX = sCodeX.replace('{sTm}', sTm);
		sCodeX = sCodeX.replace('{sDt}', sDt);
		sCodeX = sCodeX.replace('{sLn}', sLn);
		sCodeX = sCodeX.replace('{sWh}', sWh);
		sCodeX = sCodeX.replace('{sHt}', sHt);
		sCodeX = sCodeX.replace('{sSc}', sSc);
		sCodeX = sCodeX.replace('{sBd}', sBd);
		document.getElementById(target).value = sCodeX;
	}
	this.statCSize = function(w,h) {sWh = w; sHt = h; this.statCBuild();}
	this.statCType = function(t) {sTy = t; this.statCBuild();}
	this.statCId = 	 function(id) {sId = id; this.statCBuild();}
	this.statCTime = function(t) {sTm = t; this.statCBuild();}
	this.statCData = function(d) {sDt = d; this.statCBuild();}	
	this.statCLang = function(l) {sLn = l; this.statCBuild();}	
	this.statCBuild();
}

//---------------------------------------------------------------
function send() {
	var login = $('#login').val();
	var pass = $('#password').val();
	$('#tbody').hide();
	$('#info').show();
	$('#loading').show();
	$.ajax({
		type: "GET",
		url: "/engine/dane/counters_server.php?&login="+login+"&f_md5pass="+hex_md5(pass),
		success: function(r) {
			$('#loading').hide();
			$('#id options').each(function() {
				$(this).remove();
			});
			$('#komunikat').hide();
			$('#komunikat_tresc').html('');
			var arr_str = false;
				if (r.slice(0,6)=='ERROR@') {
					$('#komunikat').show();
					$('#komunikat_tresc').html(r.slice(6));
				} else if (r.slice(0,3)=='OK$') {
					arr_str=r.slice(3);
				} else {
					$('#komunikat').show();
					$('#komunikat_tresc').html(r);
				}

			if(arr_str!=false) {
				arr=Array();
				delete arr.inArray;
				var tmp=arr_str.split("$");
				for (var v in tmp){ 
					if(typeof(tmp[v])=='string'){
						elm=tmp[v].split('@');
						arr[elm[1]]=elm[0];
					}
				}
				_initValue(document.getElementById('form').id,arr);
				$('#tbody').show('medium')
				$('#info').hide()
				CCode.statCId($('#id').val());
			}
		}
	})
}

//---------------------------------------------------------------
function _initValue(inputscope,data) {
	var i = 0;
	for (var v in data){
		if(typeof(data[v])=='string'){
		inputscope.options[i] = new Option(data[v],v);
		++i;
		}
	}
}
//---------------------------------------------------------------
//sluzy do ustawienia klikniecia na licznik - pokazuje w i h + numer danego licznika
function ustawLiczniki() {
	$('#liczniki input:radio').each(function(k) {
		$(this).bind('click', function() {
			$(this).parent().parent().parent().parent().parent().find('div').css('background','');
			var obr = $(this).parent().parent().find('img')[0];
			$(this).parent().parent().parent().css('background','#FFCC66');
			CCode.statCSize(obr.width,obr.height); 
			CCode.statCType(k+1)
		})
	})
}

//---------------------------------------------------------------
$(document).ready(function() {
	CCode = new statCounter('countercode');
	CCode.statCSize(88,31);
	ustawLiczniki();
	$('#image_w').bind('click', function() {send(); return false;})
	$('#id').bind('change', function() {CCode.statCId(this.value);});
	$('#time').bind('change', function() {CCode.statCTime(this.value);});
	$('#data').bind('change', function() {CCode.statCData(this.value);});
})
//---------------------------------------------------------------