var loadingTitle;

function initLoadingTitle(title)
{
	loadingTitle = title;
}
//------------------------------------------------------------------------------
//   AJAX functions for manufacturers select
//------------------------------------------------------------------------------

function getPrinterTypeSelect()
{
    var parent_id=$F('brand');
    var url ='index.php';
    var pars ='page=modules/advancedcategories/ajaxresponse/advancedcategories_dropdown_selector&command=getPrinterTypes&categoryId='+parent_id+'&rid='+Math.random();

    var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: pars,
		onLoading: showWait4PrinterType,
		onComplete: showPrinterTypeResponse
	});
}
//------------------------------------------------------------------------------
function showWait4PrinterType()
{
    $('printer_type').options.length=0;
    $('printer_type_label').value = loadingTitle;
}
//------------------------------------------------------------------------------
function showPrinterTypeResponse(originalRequest)
{
    data = originalRequest.responseText.evalJSON();
    $('printer_type_label').value = type_title;
    $('printer_type').options[0] = new Option(type_title,0);
    $('models').options[0] = new Option(model_title,0);
    var count=1;
    $('printer_type').options.length=count;
    $('models').options.length=count;
    for (var i = 0; i < data.childs.length; i++) {
	    $('printer_type').options[count] = new Option(data.childs[i].name,data.childs[i].id);
	    count+=1;
	    $('printer_type').options.length=count;
    }

}

//------------------------------------------------------------------------------
//   AJAX functions for models select
//------------------------------------------------------------------------------
function getModelSelect()
{
    var parent_id=$F('printer_type');
    var url ='index.php';
    var pars ='page=modules/advancedcategories/ajaxresponse/advancedcategories_dropdown_selector&command=getPrinterModels&categoryId='+parent_id+'&rid='+Math.random();

    var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: pars,
		onLoading: showWait4Model,
		onComplete: showModelResponse
	});
}
//------------------------------------------------------------------------------
function showWait4Model()
{
    $('models').options.length=0;
    $('models_label').value = loadingTitle;
}
//------------------------------------------------------------------------------
function showModelResponse(originalRequest)
{
    data = originalRequest.responseText.evalJSON();
    $('models_label').value = model_title;
    $('models').options[0] = new Option(model_title,0);
    var count=1;
    $('models').options.length=count;
    for (var i = 0; i < data.childs.length; i++) {
	   $('models').options[count] = new Option(data.childs[i].name,data.childs[i].id);
	   count+=1;
	   $('models').options.length=count;
    }
}
//------------------------------------------------------------------------------
function getCartridges()
{
    var parent_id=$F('models');
    var url ='index.php';
    var pars ='page=modules/advancedcategories/ajaxresponse/get_child_categories_json&categoryId='+parent_id+'&rid='+Math.random();

    var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: pars,
		onComplete: showCartridges
	});
}
//------------------------------------------------------------------------------
function showCartridges(originalRequest)
{
    data = originalRequest.responseText.evalJSON();
    document.location.href = data.path;
}
//------------------------------------------------------------------------------
//   AJAX functions for manufacturers select
//------------------------------------------------------------------------------

function getPrinterTypeSelect2()
{
    var parent_id=$F('brand2');
    var url ='index.php';
    var pars ='page=modules/advancedcategories/ajaxresponse/get_child_categories_json&categoryId='+parent_id+'&rid='+Math.random();

    var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: pars,
		onLoading: showWait4PrinterType2,
		onComplete: showPrinterTypeResponse2
	});
}
//------------------------------------------------------------------------------
function showWait4PrinterType2()
{
    $('ink_laser').options.length=0;
    $('ink_laser').options[0] = new Option(loadingTitle,0);
}
//------------------------------------------------------------------------------
function showPrinterTypeResponse2(originalRequest)
{
    data = originalRequest.responseText.evalJSON();
    $('ink_laser').options[0] = new Option(data.type_title,0);
    $('categoryid').options[0] = new Option(data.model_title,0);
    var count=1;
    $('ink_laser').options.length=count;
    $('categoryid').options.length=count;
    for (var i = 0; i < data.childs.length; i++) {
	    $('ink_laser').options[count] = new Option(data.childs[i].name,data.childs[i].id);
	    count+=1;
	    $('ink_laser').options.length=count;
    }

}

//------------------------------------------------------------------------------
//   AJAX functions for models select
//------------------------------------------------------------------------------
function getModelSelect2()
{
    var parent_id=$F('ink_laser');
    var url ='index.php';
    var pars ='page=modules/advancedcategories/ajaxresponse/get_child_categories_json&categoryId='+parent_id+'&rid='+Math.random();

    var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: pars,
		onLoading: showWait4Model2,
		onComplete: showModelResponse2
	});
}
//------------------------------------------------------------------------------
function showWait4Model2()
{
    $('categoryid').options.length=0;
    $('categoryid').options[0] = new Option(loadingTitle,0);
}
//------------------------------------------------------------------------------
function showModelResponse2(originalRequest)
{
    data = originalRequest.responseText.evalJSON();

    $('categoryid').options[0] = new Option(data.model_title,0);
    var count=1;
    $('categoryid').options.length=count;
    for (var i = 0; i < data.childs.length; i++) {
	   $('categoryid').options[count] = new Option(data.childs[i].name,data.childs[i].id);
	   count+=1;
	   $('categoryid').options.length=count;
    }
}
//------------------------------------------------------------------------------