var ajax = new Array();

function getQuerystring(key, default_){
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function getSubCategoryList(sel, current_category_id, current_form, model){
	var prod_id = sel.options[sel.selectedIndex].value;
	
	document.getElementById('hc-model_id'+current_form).options.length = 0;	// Empty sub category select box
	if(prod_id.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		if (model > 0)
			ajax[index].requestFile = 'hardcopy.php?hc-prod_id='+prod_id+'&hc-cid='+current_category_id+'&hc-query=qm&hc-model_id='+model;
		else
			ajax[index].requestFile = 'hardcopy.php?hc-prod_id='+prod_id+'&hc-cid='+current_category_id+'&hc-query=qm&hc-model_id='+getQuerystring('hc-model_id');	// Specifying which file to get
		ajax[index].onCompletion = function(){ createSubCategories(index, current_form) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createSubCategories(index, current_form){
	document.getElementById('hc-model_id'+current_form).className='selected'; // change CSS class
	var obj = document.getElementById('hc-model_id'+current_form);
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}
