var ajax = new sack();
ajax.onLoading = wczytywanie;
ajax.onLoaded = eofWczytywanie;


// sortownia wszytkich produktow
function getCarModels(sel){

	var countryCode = sel.options[sel.selectedIndex].value;
	ajax.setVar("idCat", countryCode);
	document.getElementById('modele').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		ajax.requestFile = 'ajax/getCarModels.php?kategoria='+countryCode;	// Specifying which file to get
		ajax.onCompletion = createModele;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}


function wczytywanie(){
	document.getElementById('searchLoader').style.display = "block";		
}


function eofWczytywanie(){
	document.getElementById('searchLoader').style.display = "none";
}
	
function createModele()
{		
	var obj = document.getElementById('modele');	
	obj.removeAttribute("disabled", "disabled" );
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}	

// eof sortowni

// modele samochodow

function getCarModels22(sel)
{

	var countryCode = sel.options[sel.selectedIndex].value;
	ajax.setVar("idCat", countryCode);
	ajax.setVar("action", 'getFirst');
	
	var ttt = document.getElementById('myNewSel')
//	ttt.removeChild(ttt.lastChild);
	ttt.innerHTML = '';

//	document.getElementById('kategorieSamochodow').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		ajax.requestFile = '/admin/ajax/getCarModels.php';	// Specifying which file to get
		ajax.onCompletion = createModels;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function createModels(){		
	var obj = document.createElement('select');
	obj.name = 'demecoSecCategory';
//	obj.setAttribute("onChange", "getNextChild(this)" );
//	obj.setAttribute("id", "drugi" );

	document.getElementById('myNewSel').appendChild(obj);
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
	
}	


function getNextChild(sel)
{
	var ttt = document.getElementById('myNewSel')
	var countryCode = sel.options[sel.selectedIndex].value;
	ajax.setVar("action", 'getSecond');
	ajax.setVar("idCat", countryCode);
	
//	ttt.innerHTML = '';

//	document.getElementById('kategorieSamochodow').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		ajax.requestFile = '/admin/ajax/getCarModels.php';	// Specifying which file to get
		ajax.onCompletion = createModels;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
//	ttt.removeChild(ttt.lastChild);
}

// funkcje sprawdzajace

function doFormCheck(form){
//	alert(selectedSite);
/*	var form = document.getElementById('formSend');
	ajax.setVar("name", form.name.value); 
	
*/	

	if(form.marki.value == 'pusty' && form.podKategorie.value == 'pusty'){
		var error = 2;
	}

	
	if(error == 2){
		alert('Wybierz markę samochodu lub kategorie !');	
		return false;
	}else{		
		return true;
	}
/*
	if(error == 1){
		alert('Wybierz kategorie produktu ! \n Ostatnie pole w wyszukiwarce.');
		return false;
	}else if(error == 2){
		alert('Wybierz markę samochodu !');	
		return false;
	}else if(error == 3){
		alert('Jeśli wybrałeś markę - musisz wybrać model samochodu !');	
		return false;
	}else{		
	//	form.action = '/'+form.kategoria.value+'/lista.html';
	//	alert(form.action+' asdf');
		return true;
	}
	*/

}



