var ajax = new Array();

function getSubCategoryList(sel)
{
	var category = sel.options[sel.selectedIndex].value;
	document.getElementById('subcat').options.length = 0;	// Empty city select box
	if(category.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'js/kategori_sel.php?category='+category;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createSubCategories(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createSubCategories(index)
{
	var obj = document.getElementById('subcat');
	document.getElementById('alt_cat').style.visibility='visible';
	document.getElementById('alt_cat').style.height='100%';
	
	eval(ajax[index].response);
		// Executing the response from Ajax as Javascript code	
}
function getSubCategoryGetir(sel)
{
	var category = sel;
	document.getElementById('subcat2').options.length = 0;	// Empty city select box
	if(category.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'js/kategori_sel.php?category='+category;	// Specifying which file to get
		ajax[index].onCompletion = function(){ getirSubCategories(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function getirSubCategories(index)
{
	var obj = document.getElementById('subcat2');
	document.getElementById('alt_cat2').style.visibility='visible';
	document.getElementById('alt_cat2').style.height='100%';
	eval(ajax[index].response);
	document.getElementById('alt_cat2').style.visibility='visible';
		// Executing the response from Ajax as Javascript code	
}	


function removeFormField(num) {
	$("p #pk"+num).remove();
	$("#katar"+num).remove();
	$('#katlist').highlightFade({
		 speed:1000
	 });
}
function addFormField(num){
	
	$("input #katar").remove();
	$("#katlist").prepend(" <input type='hidden' value='"+num+"' name='katar[]' id='katar"+num+"' >");
	 $('#katlist').highlightFade({
		 speed:1000
	 });
}

//Step 2: Define a "callback" function to process the data returned by the Ajax request:
function processGetPost(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
var kid=ajaxpack.kid;
	/**/
	if(myajax.responseText == 9){		
		getSubCategoryGetir(kid);
	}else{
		if (myajax.readyState == 4){ //if request of file completed
			if (myajax.status == 200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
				$("<p id='pk"+kid+"'>"+myajax.responseText+"  &nbsp;&nbsp; (<a style='cursor:pointer;' class='remove' onclick='removeFormField("+kid+")'>Sil</a>)</p>").appendTo("#katlist");
				addFormField(kid);
				
			}
		}
		
		document.getElementById('alt_cat2').style.visibility='hidden';
		
	}
}


