var AjaxObject = {
   handleSuccess:function(o){
     this.processResult(o);
   },

   handleFailure:function(o){
     //document.getElementById('loader').style.visibility = 'hidden';
     if (o.responseText !== undefined){
       alert('ERROR:' + o.responseText);
     }
   },

   processResult:function(o){  
     // This member is called by handleSuccess
	var root = o.responseXML.documentElement;
     var categories = root.getElementsByTagName('category');
     var catList = document.getElementById('subcategory');
   
     try{
                while (catList.length > 0) catList.remove(0);
                
                if(categories.length > 0) {
                        var i = 0;
                                     
                        while (i < categories.length)
                        {
                                var opt = new Option();
                                opt.value = categories[i].attributes.getNamedItem("id").nodeValue;
                                opt.text = categories[i].attributes.getNamedItem("name").nodeValue;
                                catList.options.add(opt, ++i);
                        }
    			}
    			else
    			{
			             var opt = new Option();
			             opt.value = "-1";
			             opt.text = "----";                               
			             catList.options.add(opt,0);
			    }    			

        } catch(e) {alert(e.message);}
   },

   startRequest: function(form) {
     YAHOO.util.Connect.setForm(form);
     this.cObj = YAHOO.util.Connect.asyncRequest('POST', 
'ajax/Resources/GetSubcat/', callback);
   }

};

/*
  * Define the callback object for success and failure
  * handlers as well as object scope.
  */
var callback =
{
   success: AjaxObject.handleSuccess,
   failure: AjaxObject.handleFailure,
   scope: AjaxObject
};

if (!Array.prototype.indexOf) {
   Array.prototype.indexOf = function(val, fromIndex) {
     if (typeof(fromIndex) != 'number') fromIndex = 0;
     for (var i = fromIndex,len = this.length; i < len; i++)
       if (this[i] == val) return i;
     return -1;
   }
}

function ChooseCategory(value)
{
        if (value == '-1') 
        {
		     var catList = document.getElementById('subcategory');
			 while (catList.length > 0) catList.remove(0);		     
             var opt = new Option();
             opt.value = "-1";
             opt.text = "----";                               
             catList.options.add(opt,0);
             return;
		}        	
        var form = document.forms['catadd'];
        form.elements['params'].value = value;
        AjaxObject.startRequest(form);
}