function addToCart(productId, quantity, module){
	var postBody = 'action=addToCart&productId=' + productId + '&quantity=' + quantity + '&module=' + module;
	
	new Ajax.Request('processForms.php', {method:'post', postBody: postBody, onSuccess: succFunc, onFailure: errFunc});
}

function removeFromCart(form){
	for(var i = 0; i < form.elements.length; i++){
		var curId = form.elements[i].id.split('_');
		if(curId[0] == 'chbx' && form.elements[i].checked == true){
			var postBody = 'action=removeFromCart&productId=' + curId[1] + '&module=' + curId[2];	
			new Ajax.Request('processForms.php', {method:'post', postBody: postBody});
		}
	}
	new Ajax.Request('processForms.php', {method:'post', onSuccess: succFunc, onFailure:errFunc});	
}

function updateCart(productId, newVal, module){
	var postBody = 'action=updateCart&productId=' + productId + '&newVal=' + newVal + '&module=' + module;
	
	new Ajax.Request('processForms.php', {method:'post', postBody: postBody, onSuccess: succFunc, onFailure:errFunc});
}

var succFunc = function(t){
	document.location.href = 'index.php?action=showCartStep1';	
}

var errFunc = function(t){
	showBox('Błąd: akcja zakończona niepowodzeniem.<br />' + 'http://' + location.hostname + '/processForms.php' + ' ' + t.status);	
}

function showBox(message){

	var width = 350;
	var height = 200;
	var coords = getTopLeft(width, height);	

	document.getElementById('messageBoxContent').style.top = coords['top'] + 'px';
	document.getElementById('messageBoxContent').style.left = coords['left'] + 'px';
	document.getElementById('messageBoxBody').innerHTML = message;
	document.getElementById('messageBoxWrapper').style.display = 'block';
}

function hideBox(){
	document.getElementById('messageBoxBody').innerHTML = '';
	document.getElementById('messageBoxWrapper').style.display = 'none';
}

function getTopLeft(width, height){
	var windowWidth = 1024;
	var windowHeight = 768;

 	if(navigator.appName.indexOf('Microsoft') != -1){		
  		windowWidth = (-2) * document.body.offsetWidth;
  		windowHeight = document.body.offsetHeight;
 	}else{	
  		windowWidth = window.innerWidth;
  		windowHeight = window.innerHeight;			
	}
	
	var result = new Array(2);
	result['top'] = 0;
	result['left'] = 0;
	
	if(((windowWidth / 2) - (width / 2)) > 0){
		result['left'] = ((windowWidth / 2) - (width / 2));	
	}
	if(((windowHeight / 2) - (height / 2)) > 0){
		result['top'] = ((windowHeight / 2) - (height / 2));	
	}

	return result;
}

function getModels(marque){
		document.getElementById('model').options.length = 1;
		var postBody = 'marque=' + marque;
		new Ajax.Request('getModels.php?marque=' + marque, {method:'post', onSuccess:function(t){ var box = document.getElementById('model'); eval(t.responseText); }});
}

