// JavaScript Document
rootDir='/';
//*********************************
function hookSelectBody()
{
	if (document.getElementById('carId') != null){urls="&carId="+$("#carId").val();}else{urls='';}
	$.ajax({
			url:rootDir + "GetKomercBody.php?komercType=" + $("#komercType").val()+urls,
			success: function(data){
			$("div#body_area").show().html(data);
			}
		});
}

function hookSelectModels()
{
	if (document.getElementById('carId') != null){urls="&carId="+$("#carId").val();}else{urls='';}
	$.ajax({
		url:rootDir + "GetKomercModels.php?markId=" + $("#mark").val()+urls,
		success: function(data){
		$("div#models_area").show().html(data);
		}
	});
}

function hookSelectMark()
{
	if (document.getElementById('carId') != null){urls="&carId="+$("#carId").val();}else{urls='';}
	$.ajax({
			url:rootDir + "GetKomercMark.php?komercType=" + $("#komercType").val() +urls,
			success: function(data){
			$("div#mark_area").show().html(data);
			hookSelectChange();
			}
		});
	
}

function hookSelectChange()
{
	hookSelectModels();
	if (document.getElementById('parentId') != null){urls="&parentId="+$("#parentId").val();}else{urls='';}
  	$("#mark").change(function(){
		hookSelectModels();
  	});
}


$(document).ready(function(){
	//****************************************
	hookSelectBody();
	hookSelectMark();
	$("#skaits").change(function(){
   		window.location.href = rootDir + 'processSearch.php?action=searchKomercPerPage&CarPerPage=' + $("#skaits").val();
	});
	$("#searchAllKomerc").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=searchKomerc';
	});
	$("#searchAllSpec").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=searchSpec';
	});
	
	$("#sortModel").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=sortKomerc&sortId=1';
	});
	$("#sortCena").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=sortKomerc&sortId=2';
	});
	$("#sortGads").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=sortKomerc&sortId=3';
	});
	$("#sortNobraukums").click(function(){
   		window.location.href = rootDir + 'processSearch.php?action=sortKomerc&sortId=4';
	});
});

