/*************************************************
 * $Workfile:: Tools.js                          $
 *  $Modtime:: 24-09-08 16:38                    $
 *     $Date:: 25-09-08 16:21                    $
 * $Revision:: 16                                $
 *   $Author:: Mveldt                            $
 *  $History: Tools.js $
 * 
 * *****************  Version 16  *****************
 * User: Mveldt       Date: 25-09-08   Time: 16:21
 * Updated in $/Information Managment/DocumentRouter/Scripts
 * Added search in profiles
 * Added Default.aspx?Tab parameter (Report and Search) and session var
 * for upload page reentry
 * Version 2.5.0.52
 * 
 * *****************  Version 15  *****************
 * User: Mveldt       Date: 18-07-08   Time: 11:59
 * Updated in $/Information Managment/DocumentRouter/Scripts
 * Added resize location iframe for upload
 * Fixed refresh selection list when page count was decremented
 * Added Authorisation for application functions
 * Added Authorisation info in Info.aspx
 * 
 * *****************  Version 14  *****************
 * User: Mveldt       Date: 10-07-08   Time: 11:12
 * Updated in $/Information Managment/DocumentRouter/Scripts
 * Added RadComboBox handling
 * 
 * *****************  Version 13  *****************
 * User: Mveldt       Date: 10-01-08   Time: 18:31
 * Updated in $/Information Managment/DocumentRouter/Scripts
 * Disabled default value replace when object is not found (for multiple #
 * - # values)
 * Changed #now(-31) date format
 * Version 2.2.0.46
 * 
 ************************************************/

var FilterArray = new Array();

function SetVisibility(id, show)
{	
	try
	{
		if (show)
		{	document.getElementById(id).style.display = "block"; }				
		else
		{	document.getElementById(id).style.display = "none";  } 
	}
	catch(err)
	{}
}

function AddItem (list, input, listTo, hiddenmail)
{
	try
	{
		var mylist  = document.getElementById(list);
		var mylistTo  = document.getElementById(listTo);
		var myinput = document.getElementById(input);
		if(mylist == 0)
		{
			return;
		}
		
		var idx = mylist.selectedIndex;

		if(myinput && mylistTo)
		{
			if (myinput.value == '')
			{
				if (idx < 0)
				{
					return;
				}
				// Add from list
				mylistTo.options[mylistTo.options.length] = new Option(mylist.options[mylist.selectedIndex].text + ' (' + mylist.options[mylist.selectedIndex].value +')', mylist.options[mylist.selectedIndex].value);
			}
			else
			{
				// Check email input
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (filter.test(myinput.value) == false)
				{
					alert('E-mail incorrect');
					myinput.focus();
					return;
				}
				
				// Add from input
				mylistTo.options[mylistTo.options.length] = new Option(myinput.value, myinput.value);
				myinput.value = '';
			}
			mylistTo.style.width = 'auto';
			RebuildList(hiddenmail, listTo);
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}

function DeleteListItem(list, hiddenmail)
{
	try
	{
		var mylist  = document.getElementById(list);
		if(mylist == 0)
		{
			return;
		}
		
		var idx = mylist.selectedIndex;
		if (idx < 0)
		{
			return;
		}
		// Add from list
		mylist.options[idx] = null;// = new Option(mylist.options[mylist.selectedIndex].text + ' (' + mylist.options[mylist.selectedIndex].value +')', mylist.options[mylist.selectedIndex].value);
		if(mylist.options.length == 0)
		{
			mylist.style.width = '100%';
			mylist.style.height = '100%';
		}
		try
		{
			mylist.selectedIndex = idx;
		}
		catch(e){}
		RebuildList(hiddenmail, list);
	}
	catch(err)
	{
		alert(err.description);
	}
}

function RebuildList(input, listTo)
{
	try
	{
		var mylistTo  = document.getElementById(listTo);
		var myinput = document.getElementById(input);
		if(mylistTo == null)
		{
			return;
		}
		if(myinput == null)
		{
			return;
		}
		myinput.value = '';
		for(i=0; i<mylistTo.options.length; i++)
		{
			if(myinput.value == '')
			{
				myinput.value = mylistTo.options[i].value;
			}
			else
			{
				myinput.value += ';';
				myinput.value += mylistTo.options[i].value;
			}
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}
 
function CheckRange(itemName, id, minVal, maxVal)
{	
	try
	{
		if (document.getElementById(id).value<minVal)
		{	
			alert('Aantal ' + itemName+' moet groter of gelijk aan '+minVal+' zijn'); 
			document.getElementById(id).value = minVal;
			return minVal;
		}				
		if (document.getElementById(id).value>maxVal)
		{	
			alert('Aantal ' + itemName+' moet kleiner of gelijk aan '+maxVal+' zijn'); 
			document.getElementById(id).value = maxVal;
			return maxVal;
		}				
	}
	catch(err)
	{
		alert('Aantal '+itemName+' geen geldig aantal!!');
		return document.getElementById(id).value;
	}
	return document.getElementById(id).value;
}

function ShowCompareMessageLabel(e1,e2, labelID, type)
{
	edit1 = document.getElementById(e1).value;
	edit2 = document.getElementById(e2).value;
	showLabel=false;
	if (type.indexOf('!=')>=0)
	{
		if (edit1!=edit2)
		{
			showLabel=true;
		}
	}
	else
	{
		if (type.indexOf('=')>=0)
		{
			if (edit1==edit2)
			{
				showLabel=true;
			}
		}
	}
	if (type.indexOf('>')>=0)
	{
		if (edit1>edit2)
		{
			showLabel=true;
		}
	}
	if (type.indexOf('<')>=0)
	{
		if (edit1>edit2)
		{
			showLabel=true;
		}
	}
	if (type.indexOf('E')>=0)
	{
		if ((edit1=='')||(edit2==''))
		{
			showLabel=true;
		}
	}
	if (type.indexOf('N')>=0)
	{
		if ((edit1=='')||(edit2==''))
		{
			showLabel=false;
		}
	}
	if (showLabel)
	{
		document.getElementById(labelID).style.visiblity = "visible";
	}
	else
	{
		document.getElementById(labelID).style.visiblity = "hidden";
	}
}

function OnDivScroll(listname)
{
	var lstNames = document.getElementById(listname);

	//The following archives two things while scrolling
	//a) On horizontal scrolling: To avoid vertical scroll bar in select box when the size of 
	//	 the selectbox is 8 and the count of items in selectbox is greater than 8.
	//b) On vertical scrolling:	To view all the items in selectbox
	
	//Check if items in selectbox is greater than 8, if so then making the size of the selectbox to count of
	//items in selectbox,so that vertival scrollbar won't appear in selectbox
	if (lstNames.options.length > 8)
	{
		lstNames.size = lstNames.options.length;
	}
	else
	{
		lstNames.size=8;
	}
}
			
//On focus of Selectbox
function OnSelectFocus(divname, listname)
{
	//On focus of Selectbox, making scroll position of DIV to very left i.e 0 if it is not. The reason behind
	//is, in this scenario we are fixing the size of Selectbox to 8 and if the size of items in Selecbox is greater than 8 
	//and to implement downarrow key and uparrow key functionality, the vertical scrollbar in selectbox will
	//be visible if the horizontal scrollbar of DIV is exremely right.
	if (document.getElementById(divname).scrollLeft != 0)
	{
		document.getElementById(divname).scrollLeft = 0;
	}
	
	var lstNames = document.getElementById(listname);
	//Checks if count of items in Selectbox is greater than 8, if yes then making the size of the selectbox to 8.
	//So that on pressing of downarrow key or uparrowkey, the selected item should also scroll up or down as expected.
	if( lstNames.options.length > 8)
	{
	 	lstNames.focus();
	 	lstNames.size=8;
	}
}			

function ResizeTables()
{
	try
	{
		var ContentFrame = document.getElementById('tblDoc');
		if(ContentFrame != null)
		{
		    if(ContentFrame.style.height != document.body.clientHeight - ContentFrame.parentElement.offsetTop)
		    {
		    	ContentFrame.style.height = document.body.clientHeight - ContentFrame.parentElement.offsetTop;
		    }
		}
	}
	catch(e)
	{
	}
	try
	{
		var ContentFrame = document.getElementById('divContent');
		if(ContentFrame != null)
		{
		    if(ContentFrame.style.height != document.body.clientHeight - 260)
		    {
			    ContentFrame.style.height = document.body.clientHeight - 260;
			}
		}
	}
	catch(e)
	{
	}
	try
	{
		var ContentFrame = document.getElementById('divContentSearch');
		if(ContentFrame != null)
		{
		    if(ContentFrame.style.height != document.body.clientHeight - 354)
		    {
    			ContentFrame.style.height = document.body.clientHeight - 354;
    		}
		}
	}
	catch(e)
	{
	}
	try
	{
		var ContentFrame = document.getElementById('divContentReport');
		if (ContentFrame != null)
		{
			if (ContentFrame.style.height != document.body.clientHeight - 117)
			{
				ContentFrame.style.height = document.body.clientHeight - 117;
			}
		}
	}
	catch (e)
	{
	}
}

function GetValueFromObject(obj)
{
	try
	{
		if (obj == null)
		{
			return "";
		}
		if (obj.get_value)
		{
			return obj.get_value();
		}
		if (obj.get_selectedDate)
		{
			var d = obj.get_selectedDate();
			if (d == null)
			{
				return "";
			}
			return d.format("dd-MM-yyyy");
		}
		if (obj.tagName == "INPUT")
		{
			if (obj.type == "checkbox")
			{
				var v = "";
				if (obj.checked)
				{
					v = obj.getAttribute("CheckValueTrue");
				}
				else
				{
					v = obj.getAttribute("CheckValueFalse");
				}
				return v;
			}
			return obj.value;
		}
		if (obj.tagName == "SELECT")
		{
			return obj.options[obj.selectedIndex].text;
		}
		return obj.text;
	}
	catch (e)
	{
		return "";
	}
}

function GetIsCheckedFromObject(obj)
{
	try
	{
		if (obj == null)
		{
			return false;
		}
		if ((obj.tagName == "INPUT") && (obj.type == "checkbox"))
		{
			return obj.checked;
		}
		return false;
	}
	catch (e)
	{
		return false;
	}
}

function GetObjectValue(obj, sFunction)
{
    try
    {
        var sValue = GetValueFromObject(obj);
        if (sValue == "")
        {
            return "";
        }
        if (sFunction == "")
        {
            return sValue;
        }
        sValue = eval("sValue" + sFunction);
        return sValue;
    }
    catch (e)
    {
        return "";
    }
}

function getIdFromObjectName(name)
{
	var theID = "";
	var sep = "";
	if (name.indexOf("ProfilePane1$") == 0)
	{
		sep = "$";
	}
	if (name.indexOf("ProfilePane1:") == 0)
	{
		sep = ":";
	}
	if (sep === "")
	{
		return "";
	}
	// ProfilePane1$ProfileTest_&_Test$ProfileTest_&_Test_txt
	theID = name.replace("ProfilePane1" + sep + "Profile", "");
	theID = theID.substring(0, theID.indexOf(sep));
	return theID;
}

function GetProfileObject(FieldName)
{
	// Profile value
	var fName = FieldName.replace(/ /g, "_");
	var profile = document.getElementById("ProfilePane1_Profile" + fName + "_Profile" + fName + "_txt");
	if (profile == null)
	{
		// Profile RadCombo?
		try
		{
			// loop controls
			var combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
			for (var i = 0; i < combos.length; i++)
			{
				if (combos[i].get_id() == "ProfilePane1_Profile" + fName)
				{
					return combos[i];
				}
			}
		}
		catch (e)
		{
		}
		// try get text from textbox...
		profile = document.getElementById("ProfilePane1_Profile" + fName + "_Input");
	}
	if (profile == null)
	{
		// Date Picker
		profile = $find("ProfilePane1_Profile" + fName + "_Profile" + fName + "_date");
	}
	if (profile == null)
	{
		// Profile Combo?
		profile = document.getElementById("ProfilePane1_Profile" + fName);
	}
	return profile;
}

function GetProfileValue(FieldName)
{
	var profile = GetProfileObject(FieldName);
	return GetValueFromObject(profile);
}
function SetProfileValue(FieldName, value)
{
	var profile = GetProfileObject(FieldName);
	return SetValueToObject(profile, value);
}
function GetIsProfileChecked(FieldName)
{
	var profile = GetProfileObject(FieldName);
	return GetIsCheckedFromObject(profile);
}

function SetDefaultValue(id, defaultvalue)
{
	// Parse and Fill value of object
	try
	{
		var ctrl = document.getElementById(id);
		ctrl.value = ParseDefaultValue(defaultvalue);

		// Check if control has trigger
		var fName = "";
		var change = null;
		try
		{
			// radcontrol
			fName = ctrl.get_attributes().getAttribute("FieldName");
			if (fName != "")
			{
				FieldUpdated(fName, ctrl.get_id(), cltr.get_value());
			}
			return;
		}
		catch (e)
		{
			// 'normal' control
			change = ctrl.getAttribute("onchange");
			if (change != null)
			{
				// construct FieldName from id
				fName = getIdFromObjectName(ctrl.name);
			}
		}
		if (change != null)
		{
			FieldUpdated(fName, ctrl.id, ctrl.value);
    	}
    }
    catch(e)
    {
    }
}

function Trim(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

//
// Parse string for #...# values and replace with object values
//
function ParseDefaultValue(defaultvalue)
{
    try
    {
        var newvalue = defaultvalue;
        if(newvalue.indexOf("#") != -1)
        {
            // Replace special values with object values
            var x = newvalue.split("#");
            for(y in x)
            {
                if(Trim(x[y]) == "")
                {
                    continue;
                }
                var sField = x[y];
                var str = "#" + sField + "#";
                var sFunction = "";
                
                // Check if valid name
                if(str != "##")
                {
                    // Must start and end with # in original definition
                    if(newvalue.indexOf(str) != -1) {

                        // Check if there is a function defined
                        if (sField.indexOf(".") != -1)
                        {
                            //
                            sFunction = sField.substr(sField.indexOf("."));
                            sField = sField.replace(sFunction, "");
                        }
                        
                        // Field can not have spaces
                        sField = sField.replace(/ /g, "_");
                        
                        if(sField.indexOf("Location") != -1)
                        {
                            // get selected location folder
            	            var location = document.getElementById("LocationPane1_dp" + sField);
    	                    if (location != null)
    	                    {
    	                        newvalue = newvalue.replace(str, GetObjectValue(location, sFunction));
    	                    }
    	                    else
    	                    {
    	                        // remove from default string
    	                        newvalue = newvalue.replace(str, "");
    	                    }
                        }
                        else
                        {
                            // Profile value
                        	var profile = GetProfileObject(sField);
    	                    if (profile != null)
    	                    {
    	                        newvalue = newvalue.replace(str, GetObjectValue(profile, sFunction));
    	                    }
    	                    else
    	                    {
    	                        // remove from default string
    	                        //newvalue = newvalue.replace(str, "");
    	                    }
    	                }
                    }
                }
            }
        }
        return newvalue;
     }
     catch(e)
     {
        return defaultvalue;
     }   
}

//
// Change alt to title with updated values
//
function SetDefaultTooltip(id)
{
    // Parse and Fill tooltip of image button
    try
    {
        var obj = document.getElementById(id);
        if(obj != null)
        {
            obj.title = ParseDefaultValue(obj.alt);
        }
    }
    catch(e)
    {
    }
}

//
// Location functions
//

function updateFolder(comboname, docid)
{
    ShowWait();
	if(docid == '-1')
	{
		// empty selected, just disable next ones
		ClearAndHide(comboname);
        HideWait();
	}
	else
	{
		ClearAndHide(comboname);
		
		// Get child folders of docid asynchronous
        xmlHttp = GetXmlHttpObject(stateChangeAjaxHandler);

        // Get db
        var ctrl = document.getElementById("LocationPane1_dpLocation0");
        if(ctrl == null)
        {
            alert("Selecteer een database AUB.");
            HideWait();
            return;
        }
        url = "Default.aspx?RequestFolders=" + comboname + "&DocID=" + docid + "&DBPath=" + ctrl.value + "&sid=" + Math.random();
        //Send the XMLHttp get to the specified url
        XMLHttp_Get(xmlHttp, url);
	}
}

function ClearAndHide(comboname)
{
	var ctrl = document.getElementById("LocationPane1_dpLocation"+comboname);
	var row = document.getElementById("LocationPane1_Location"+comboname);
	while(ctrl != null)
	{
		//Clear the dropdown list
		for (var count = ctrl.options.length-1; count >-1; count--)
		{
			ctrl.options[count] = null;
		}
		ctrl.style.display = 'none';
		ctrl.disabled = true;
		if(row != null)
		{
    		row.style.display = 'none';
		}
		comboname = comboname+1;
		ctrl = document.getElementById("LocationPane1_dpLocation"+comboname);
	    row = document.getElementById("LocationPane1_Location"+comboname);
	}
	
	try
	{
		parent.ResizeFrame(window);
	}
	catch(e)
	{
	}
}

function RefreshCombos()
{
    // Find first empty combo
    var counter = 0;
    var ctrl = document.getElementById("LocationPane1_dpLocation" + counter);
	while(ctrl != null)
	{
		//Check if empty
		if (ctrl.options.length == 0)
		{
			ClearAndHide(counter);
			try
			{
				parent.ResizeFrame(window);
			}
			catch (e)
			{
			}
			return;
		}
		counter = counter+1;
		ctrl = document.getElementById("LocationPane1_dpLocation"+counter);
	}
	try
	{
		parent.ResizeFrame(window);
	}
	catch(e)
	{
	}
}

function stateChangeAjaxHandler()
{
    //readyState of 4 or 'complete' represents that data has been returned
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
    {
        //Gather the results from the callback
        var str = xmlHttp.responseText;

        // populate Combo
        if (xmlHttp.responseXML.documentElement != null)
        {
            ClearAndSetCombo(xmlHttp.responseXML.documentElement);
        }
        else
        {
            alert("Fout met verkrijgen folders");
            HideWait();
        }
    }
}

function ClearAndSetCombo(xmlNodes)
{
    var comboname = xmlNodes.getElementsByTagName('ComboName');
    var folderNameNodes = xmlNodes.getElementsByTagName('name');
    var folderIDNodes = xmlNodes.getElementsByTagName('docid');
    var textValueName;
    var idValueName;
    var optionItemName;

    var ctrl = document.getElementById("LocationPane1_dpLocation"+GetInnerText(comboname[0]));
	var row = document.getElementById("LocationPane1_Location"+GetInnerText(comboname[0]));
    if(ctrl == null)
    {
		try
		{
			parent.ResizeFrame(window);
		}
		catch(e)
		{
		}
        HideWait();
        return;
    }

    //Clears the ctrl dropdown list
    for (var count = ctrl.options.length-1; count >-1; count--)
    {
        ctrl.options[count] = null;
    }
    if(folderNameNodes.length == 0)
    {
		try
		{
			parent.ResizeFrame(window);
		}
		catch(e)
		{
		}
		HideWait();

		TriggerFolder(GetInnerText(comboname[0]));
        return;
    }
    // Add new folders to list
    optionItemName = new Option( "", "-1",  false, false);
    ctrl.options[ctrl.length] = optionItemName;
    
    for (var count = 0; count < folderNameNodes.length; count++)
    {
        textValueName = GetInnerText(folderNameNodes[count]);
        idValueName = GetInnerText(folderIDNodes[count]);
        optionItemName = new Option( textValueName, idValueName,  false, false);
        ctrl.options[ctrl.length] = optionItemName;
    }
    ctrl.disabled = false;
    ctrl.style.display = 'inline';
    if(row != null)
    {
        row.style.display = '';
    }
	try
	{
		parent.ResizeFrame(window);
	}
	catch(e)
	{
	}
	HideWait();

	TriggerFolder(GetInnerText(comboname[0]));
}

//Returns the node text value
function GetInnerText (node)
{
    return (node.textContent || node.innerText || node.text) ;
}

function GetXmlHttpObject(handler)
{ 
	var objXmlHttp = null; //Holds the local xmlHTTP object instance 
	try
	{
		objXmlHttp = new XMLHttpRequest(); // Opera, MSIE 7, Mozilla 
	}
	catch (e)
	{
		try
		{
			objXmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // IE 5.5+
		}
		catch (e)
		{
			objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE 5.x
		}
	}

	if(objXmlHttp != null)
	{
		objXmlHttp.onreadystatechange = handler;
	}

	return objXmlHttp;
} 

function XMLHttp_Get(xmlhttp, url)
{
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}

// RadComboBox item changed
function OnClientSelectedIndexChanged(combo, eventArgs)
{
	var item = eventArgs.get_item();
	var fName = "";
	try
	{
		fName = combo.get_attributes().getAttribute("FieldName");
	}
	catch (e) { }
	FieldUpdated(fName, combo.get_id(), item.get_value());
}

// RadComboBox dropdown opening
function OnClientDropDownOpening(combo, eventArgs)
{
	// Check if filter is applied to this combobox
	var fName = combo.get_attributes().getAttribute("FieldName");
	for (filter in FilterArray)
	{
		if (filter === fName)
		{
			// Filter found
			var f = FilterArray[filter].toString().split("#");
			if (f.length === 2)
			{
				if (f[0] === "s")
				{
					FilterComboStartWith(fName, f[1]);
				}
				else
				{
					FilterComboContains(fName, f[1]);
				}
			}
		}
	}
}

function FieldUpdated(name, id, value)
{
	try
	{
		// Get selected DB
		var db = "";
		var ctrl = document.getElementById("LocationPane1_dpLocation0");
		if (ctrl != null)
		{
			db = ctrl.options[ctrl.selectedIndex].text;
		}
		if (db === "")
		{
			return;
		}
		TriggerFieldUpdated(db, name.replace(/ /g, "_"), id, value);
		//alert('db: [' + db + '] name: [' + name + '] id: [' + id + '] Value: [' + value + ']');
	}
	catch (e)
	{
		alert('Fout in FieldUpdated: ' + e.message);
	}
}

function SetValueToObject(obj, value)
{
	try
	{
		if (obj == null)
		{
			return false;
		}
		if (obj.findItemByValue)
		{
			var cbItem = obj.findItemByValue(value);
			if (cbItem != null)
			{
				cbItem.select();
			}
			else
			{
				obj.set_text(value);
				obj.showDropDown();
				obj.clearSelection(); // no selection, because change event must happen when client clicks item
			}
		}
		else if(obj.set_selectedDate)
		{
			if (value === "")
			{
				obj.set_selectedDate(value);
			}
			else
			{
				var d = new Date();
				d.setFullYear(parseInt(value.toString().substr(6, 4)), parseInt(value.toString().substr(3,2))-1, parseInt(value.toString().substr(0,2)));
				obj.set_selectedDate(d);
			}
		}
		else
		if (obj.tagName == "INPUT")
		{
			if (obj.type == "checkbox")
			{
				var sTrue = "";
				var sFalse = "";
				sTrue = obj.getAttribute("CheckValueTrue");
				sFalse = obj.getAttribute("CheckValueFalse");
				if ((sTrue == value) || (value == "1") || (value == "true"))
				{
					obj.checked = true;
					return true;
				}
				if ((sFalse == value) || (value == "0") || (value == "false"))
				{
					obj.checked = false;
					return true;
				}
			}
			else
			{
				obj.value = value;
			}
		} else
			if (obj.tagName == "SELECT")
		{
			obj.value = value;
		} else
		{
			obj.value = value;
		}
		return true;
	}
	catch (e)
	{
		return false;
	}
}

function TriggerFolder(comboNumber)
{
	var db = "";
	var ctrl = document.getElementById("LocationPane1_dpLocation0");
	if (ctrl != null)
	{
		db = ctrl.options[ctrl.selectedIndex].text;
	}
	if (db === "")
	{
		return;
	}

	var parCombo = document.getElementById("LocationPane1_dpLocation" + (comboNumber - 1));

	TriggerFolderUpdated(db, comboNumber - 1, GetObjectValue(parCombo, ""));
	//alert('Db: [' + db + '] folderNr: [' + comboNumber - 1 + '] Value: [' GetObjectValue(parCombo, "") + ']');
}

function FilterComboStartWith(FieldName, value)
{
	var obj = GetProfileObject(FieldName);
	if (obj != null)
	{
		if (obj.setAllItemsVisible)
		{
			// Fist show all
			obj.setAllItemsVisible(true);
			
			// hide items that do not begin with value
			obj.get_items().forEach(function(d)
			{
				if (d.get_text().toLowerCase().indexOf(value.toLowerCase()) != 0)
				{
					d.set_visible(false);
				}
			});
		}
		// Save filter
		FilterArray[FieldName] = "s#" + value;
	}
}

function FilterComboContains(FieldName, value)
{
	var obj = GetProfileObject(FieldName);
	if (obj != null)
	{
		if (obj.setAllItemsVisible)
		{
			// Fist show all
			obj.setAllItemsVisible(true);

			// hide items that do not contains value
			obj.get_items().forEach(function(d)
			{
				if (d.get_text().toLowerCase().indexOf(value.toLowerCase()) < 0)
				{
					d.set_visible(false);
				}
			});
		}
		// Save filter
		FilterArray[FieldName] = "c#" + value;
	}
}

function FilterComboReset(FieldName)
{
	var obj = GetProfileObject(FieldName);
	if (obj != null)
	{
		if (obj.setAllItemsVisible)
		{
			// Show all
			obj.setAllItemsVisible(true);
		}
		// Save filter
		FilterArray[FieldName] = "";
	}
}
