var test;

function updatemenu(catID, selectbox, id, obj)
{
	obj.disabled='true';
	
	document.getElementById("loadingCatsmenu").style.display = "block";

	clearboxesmenu(id); // clear any dropdowns from the page which have an id greater than the current dropdown
	
	getsubcatsmenu(catID, obj, id); // call the getsubcats function to retrieve the new dropdown data for the selected <option> in the currnet dropdown
	
	document.getElementById("toCat").value = catID;
	
	document.getElementById("curdivmenu").value = obj.id;

    var apickList = document.getElementById(obj.id);
    var apickIndex = apickList.selectedIndex;
    var curtext = apickList[apickIndex].text; 
	var curval = apickList[apickIndex].value; 
	
	if(curval != 0)
	document.getElementById("under").innerHTML = curtext;
	else
	document.getElementById("under").innerHTML = "None";
}



function getsubcatsmenu(scatID, obj, id)
{
    var http = false;

    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
       http = new XMLHttpRequest();
    }


      http.open("GET", "getmenu.php?id=" + scatID + "&boxid=" + parseInt(id + 1), true);
	  
	  //return data will be a dropdown <select> with <option> elements.
	  
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
		
		  obj.disabled='';
		  
		  document.getElementById("loadingCatsmenu").style.display = "none";
		  
		  var a = http.responseText;
		  
		  if(a.length > 10) // make sure there is some returned data from the ajax call
		  {	  
		  createSubDropmenu(http.responseText, parseInt(document.getElementById("boxmenu").value) + 1,  parseInt(document.getElementById("boxmenu").value), obj); // call the subdropdown function creator
		  
		  document.getElementById("boxmenu").value = parseInt(document.getElementById("boxmenu").value) + 1;

		  }
        }
      }
      http.send(null);
	  
	  
}

function createSubDropmenu(idata, divid, curdivid, obj)
{
	var newdiv = document.createElement('div'); // create a new div to hold the submenu
	
	var cdiv = document.getElementById('div_' + curdivid);	

	newdiv.innerHTML = idata; // fill the new div with the contents of the ajax call
	
	newdiv.setAttribute('id','div_' + divid); // set the id of the div elements
	
	target = document.getElementById('div_lastboxmenu');
	
    target.parentNode.insertBefore(newdiv,target); // insert the new div after the last div element
}


function clearboxesmenu(nid)
{
    var searchin = document.getElementById('tosearchmenu');
	
	var x = searchin.getElementsByTagName('div'); 
	
	//alert(x.length);

    for(var i = nid +1; i<x.length-2;)
    {
	   
            //alert(x.length + " / " +  (nid+2));
            
            if(parseInt(x[i].id.substr(4)) > nid)
            {
                  document.getElementById("boxmenu").value = parseInt(document.getElementById("boxmenu").value) - 1;
                  
                  x[i].parentNode.removeChild(x[i]);
                  
                // x.length++;
            }
    }
}



function addbanner()
{
	var myid;
	
	myid = document.getElementById("toCat").value;
	
	window.open("addproduct.php?id="  + myid, "_parent");
	
}


function modifycat()
{
	var myid;
	
	myid = document.getElementById("toCat").value;
	
	popUp('editcategory.php?id=' + myid);
}

function confirmSubmit() 
{
	var agree=confirm("Do you really want to delete this category off the system?");
	
	if (agree)
	{
		var myid;
				
		catid = document.getElementById("toCat").value;
				
		window.open("process_catagory.php?deletecat=1&catID="  + catid, "_parent");
	}
	else
		return false;
}

