// JavaScript functions
// ifan technology.


// Update a combobox with filter value
// object_value_array format
// object_value_array[n] = option value
// object_value_array[n+1] = option text 1
// object_value_array[n+2] = option text 2
// object_value_array[n+3] = option filter value
function js_updatecombo(obj, object_value_array, filter_value) {	
	var value = (obj.selectedIndex > -1) ? obj.options[obj.selectedIndex].value : null;
	for (var i = obj.length-1; i > 0; i--) {
		obj.options[i] = null;
	}	
	for (var j=0; j<object_value_array.length; j=j+4) {
		if (object_value_array[j+3].toUpperCase() == filter_value.toUpperCase()) {
			js_newopt(obj, object_value_array[j], object_value_array[j+1], object_value_array[j+2]);			
		}	
	}
	js_selectopt(obj, value);
}

// Create combobox option 
function js_newopt(obj, value, text1, text2) {
	var text = text1;
	if (text2 != "")
		text += js_fieldSep + text2;
	var optionName = new Option(text, value, false, false)
	var length = obj.length;
	obj.options[length] = optionName;
}

// Select combobox option
function js_selectopt(obj, value) {
	if (value != null) {
		for (var i = obj.length-1; i>=0; i--) {
			if (obj.options[i].value.toUpperCase() == value.toUpperCase()) {
				obj.selectedIndex = i;
				break;
			}
		}
	}
}

// Get image width/height
function js_getimagesize(file_object, width_object, height_object) {
	if (navigator.appVersion.indexOf("MSIE") != -1)	{
		myimage = new Image();
		myimage.onload = function () {
			width_object.value = myimage.width; height_object.value = myimage.height;
		}		
		myimage.src = file_object.value;
	}
}


