//enable and disable fields based on objectType
function toogleOnCategoryChange(){
    var price = $("ObjectsForm_objectPrice");
    var discussable = $("ObjectsForm_objectDiscussable");
    var rent = $("ObjectsForm_objectRent");
    var charges = $("ObjectsForm_objectCharges");
    var guarantee = $("ObjectsForm_objectGuarantee");
    var fee = $("ObjectsForm_objectFee");

    var category = $("ObjectsForm_objectCategoryID");

    if(category.value == 1){
        price.disabled = false;
        //discussable.disabled = false;
        setNodeAttribute(rent, "disabled", "disabled"); 
        setNodeAttribute(charges, "disabled", "disabled");
        setNodeAttribute(guarantee, "disabled", "disabled");
        setNodeAttribute(fee, "disabled", "disabled");
    } else if(category.value == 2){
        setNodeAttribute(price, "disabled", "false");
        //setNodeAttribute(discussable, "disabled", "disabled");
        rent.disabled = false;
        charges.disabled = false;
        guarantee.disabled = false;
        fee.disabled = false;
    } else if(category.value == 3){
        setNodeAttribute(price, "disabled", "false");
        //setNodeAttribute(discussable, "disabled", "disabled");
        setNodeAttribute(rent, "disabled", "disabled");
        setNodeAttribute(charges, "disabled", "disabled");
        setNodeAttribute(fee, "disabled", "disabled");
    }          

}

function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
	}
}

function processFeatures(xmlHttp){
    var featureListAvailable = $('ObjectsForm_featureSelector_available');
    var featureListSelected = $('ObjectsForm_featureSelector_selected');

	if (!hasOptions(featureListAvailable)) { return; }
	for (var i=(featureListAvailable.options.length-1); i>=0; i--) { 
		featureListAvailable.options[i] = null; 
		} 
	featureListAvailable.selectedIndex = -1; 

	if (!hasOptions(featureListSelected)) { return; }
	for (var i=(featureListSelected.options.length-1); i>=0; i--) { 
		featureListSelected.options[i] = null; 
		} 
	featureListSelected.selectedIndex = -1; 
    
    for(var feature in xmlHttp){
        if (feature != 'tg_flash') {
            addOption(featureListAvailable,xmlHttp[feature],feature,false);
        }          
    }        
}

function processErrors(xmlHttp){
    alert(xmlHttp);
}

function updateFeatureList(){

    activeSubObject = $('ObjectsForm_objectSubTypeID');
    activeSubObjectValue = activeSubObject.value;
    featureHttp = loadJSONDoc("/modify/objects/getObjectFeatures", {"subObject" : activeSubObjectValue});
    featureHttp.addCallbacks(processFeatures, processErrors);
}
