function changeMFA() {
	if($('MFA').value == 'Wybierz'){ $('TYPE').update(); $('MODEL').update(); return; }
	url = './ajax_czesci/modele/'+$('MFA').value+'?type='+$('form_type').value;
	new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { $('MODEL').update(transport.responseText); } });
	$('TYPE').update();
	$('MODEL').update();
}

function changeMODEL() {
	if($('MFA').value == 'Wybierz'){ return; }
	url = './ajax_czesci/types/'+$('MODEL').value+'?type='+$('form_type').value;
	new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { /*console.log($('TYPE'));*/ $('TYPE').update(transport.responseText); } });

}

function checkBeforeSend(event) {
	var element = event.element();
	if($('TYPE').value == '') {
		if($('MODEL').value == ''){ new Effect.Pulsate('MODEL_LABEL',{ pulses: 2, duration: 1 }); }
		new Effect.Pulsate('TYPE_LABEL',{ pulses: 2, duration: 1 });
		Event.stop(event);
	}
}

Event.observe(window, 'load', function(){
  Event.observe('MFA', 'change', changeMFA);
  Event.observe('MODEL', 'change', changeMODEL);
  Event.observe('start_form', 'submit', checkBeforeSend);
});

function AddToBasket(id,prcou) {
    var flashMovie;
    if (navigator.appName.indexOf("Microsoft")!=-1) {
        flashMovie = window["FlashHeader"];
    } else {
        flashMovie = document["FlashHeader"];
    }
	var ProdId = id;
	var ProdCou = prcou;
	$jq.get(
		'http://najczesci.pl/ajax_czesci/addtobasket/'+ProdId+'/'+ProdCou,{},
		function(jsontext) {
			eval("json = "+jsontext+";");
			if(json["summ"] && json["amount"]) {
				flashMovie.updateBasket(json["amount"],json["summ"]);
				//alert("Produkt dodany");
			}
		}
	);           
}
