var domain = location.protocol + "//" + location.host;

// reset the form
function resetForm(cnt){
	for (var i=1; i < (eval(cnt)+1); i++){
		$('in'+i).value="0";
		$('in'+i).hide();
	}
	return false;
}

//disable the clicks
function disableClick(cnt){
	for (var i=1; i < (eval(cnt)+1); i++){
		$('img'+i).onclick="";
	}
	return false;
}

// save the form data
function saveFormData(cnt, txt){
  try{

	//disable form
	$('counterForm').disable();
	// save the parameters 
	var params = 'in=';
	for (var i=1; i < eval(cnt); i++){
		params = params + $('in'+i).value + ",";
	}
	params = params + $('in'+eval(cnt)).value;
	
	// save the data
	new Ajax.Request(
        domain + '/counter.php',
        {asynchronous:true,
        evalScripts:true,
        onComplete:function(transport){
			resetForm(cnt);
			disableClick(cnt);
			// update the main counters
			arr = transport.responseText.split(',');
			var totallyLost = 0;
			for (var i=1; i < eval(cnt)+1; i++){
				//$('tot'+i).innerHTML=arr[i-1];
				totallyLost += eval(arr[i-1]);
			}
			$('totallyLost').innerHTML = totallyLost;
			$('counterForm').fade({duration:1, from:1.0, to:0.0});
			$('confirmMessage').appear({duration:2, from:-1.0, to:1.0});
			return false;
		},
        onLoading:function(request){
        },
        parameters:params
        });

  } catch(e)
  {
      //alert(e.message);
  }

	return false;
}

// update the click
function saveClick(i){
	$('in'+i).value=eval($('in'+i).value)+1;
	$('in'+i).show();
	return false;
}