/*
 * formValidator - The form validator
 * Copyright (C) 2010 Ipportunities
 *
 * This is the integration file for JavaScript.
 *
 * It defines the formValidator class that can be used to create formValidator
 * instances in a HTML form.
 *
 * requires jquery
 * see http://www.jquery.com
 *
 */

var userAgent = navigator.userAgent.toLowerCase();
var browser = {version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1], safari:/webkit/.test(userAgent), opera:/opera/.test(userAgent), msie:/msie/.test(userAgent)&&!/opera/.test(userAgent), mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};
//alert(browser.version);



// formValidator Class
var formValidator = function(form_object, send_location, options_object)
{
	// Properties
	this.ie = browser.msie;
	
	this.FormObject = form_object;
	this.Elements = form_object.elements;
	this.Proceed = true;
	this.Message = "";
	
	this.Prefix = "";
	this.SuffixCheck = "_must";
	this.SuffixEmpty = "_empty";
	this.SuffixValid = "_valid";
	this.Callback = "";
	this.CloseOnSubmit = "false";
	
	this.ErrorAlert = false;
	this.ErrorMessage = true;

	this.SendAlert = false;
	this.SendMessage = true;
	
	this.ParamsAsObject = false;

	this.RadioChecked = new Array();
	this.CheckboxGroupChecked = new Array();

	for(var variable in options_object)
	{
		this.setVar(variable, options_object[variable]);
	}
	
	this.SendLocation = send_location;
	
	if(document.getElementById("div_" + this.Prefix + "warning"))
	{
		$("#div_" + this.Prefix + "warning").hide("fast");
	}
}


/**
* trims a string
*/
formValidator.prototype.trim = function(text)
{
	return new String(text).replace(/^\s*/, "").replace(/\s*$/, "");
}


/**
* sets the vars values
*/
formValidator.prototype.setVar = function(variable, value)
{
	//var check_string = 'if(this.' + variable + ') { this.' + variable + ' = "' + value + '"; }';
	var check_string = 'this.' + variable + ' = "' + value + '";';

	eval(check_string);
}

/**
* sets the options
*/
formValidator.prototype.setOption = function(option, value)
{
	this.Option[option] = value;
}


/**
* gets the results
*/
formValidator.prototype.getResults = function()
{
	return this.Results;
}


/**
* adds element to error message
*/
formValidator.prototype.addToMessage = function(element_id)
{
	if(document.getElementById(element_id).getAttribute("title") && ("" != document.getElementById(element_id).getAttribute("title")))
	{
		this.Message += "U dient " + document.getElementById(element_id).getAttribute("title") + " in te vullen.\n";
	} else
	{
		this.Message += "U dient \"" + element_id.substr(0, new String(element_id).length - this.SuffixCheck.length) + "\" in te vullen.\n";
	}
}
/**
* sets up warning message if required element is not set
*/
formValidator.prototype.addError = function(element_id)
{
	this.Proceed = false;
	
	var suffix_check_length = new String(this.SuffixCheck).length;
	var warning_id = new String(element_id);
	warning_id = new String(warning_id).substring(0, (new String(element_id).length - suffix_check_length));
	warning_id += this.SuffixEmpty;
	
	if(true == Boolean(this.ErrorMessage) || document.getElementById(warning_id))
	{
		$("#" + warning_id).show("fast");
	}
	if(true == Boolean(this.ErrorAlert))
	{
		this.addToMessage(element_id);
	}
}

/**
* adds element to error message
*/
formValidator.prototype.addToMessageValid = function(element_id)
{
	if(document.getElementById(element_id).getAttribute("title") && ("" != document.getElementById(element_id).getAttribute("title")))
	{
		this.Message += "U heeft " + document.getElementById(element_id).getAttribute("title") + " niet juist ingevuld.\n";
	} else
	{
		this.Message += "U heeft \"" + element_id.substr(0, new String(element_id).length - this.SuffixCheck.length) + "\" niet juist ingevuld.\n";
	}
}
/**
* sets up warning message if required element is not set
*/
formValidator.prototype.addErrorValid = function(element_id)
{
	this.Proceed = false;
	
	var suffix_check_length = new String(this.SuffixCheck).length;
	var warning_id = new String(element_id);
	if(this.SuffixCheck == element_id.substr(new String(element_id).length - suffix_check_length, suffix_check_length))
	{
		warning_id = new String(warning_id).substring(0, (new String(element_id).length - suffix_check_length));
	}
	warning_id += this.SuffixValid;
	
	if(true == Boolean(this.ErrorMessage) || document.getElementById(warning_id))
	{
		$("#" + warning_id).show("fast");
	}
	if(true == Boolean(this.ErrorAlert))
	{
		this.addToMessageValid(element_id);
	}
}


/**
* submits the form
*/
formValidator.prototype.submit = function(only_parameters)
{
	var prefix = this.Prefix;
	if("true" == this.ParamsAsObject)
	{
		var post_query = new Object();
	} else
	{
		var post_query = "";	
	}
	
	var call_back = this.Callback;
	var close_on_submit = this.CloseOnSubmit;
	
	for(var ie = 0; ie < this.Elements.length; ie ++)
	{
		var element_data = this.getDataElement(this.Elements[ie]);
		if("" != element_data[0])
		{
			if("true" == this.ParamsAsObject)
			{
				// as object
				if(("select-multiple" == this.Elements[ie].type) || ("checkbox" == this.Elements[ie].type))
				{
					if("" != trim(element_data[1]))
					{
						eval("post_query." + element_data[0] + " = " + element_data[1]);
					}
				} else
				{
					eval("post_query." + element_data[0] + " = '" + element_data[1] + "'");
				}
			} else
			{			
				// as string
				if("select-multiple" == this.Elements[ie].type)
				{
					var values_array = element_data[1];
					for(var iva = 0; iva < values_array.length; iva ++)
					{
						post_query += "&" + element_data[0] + "[]=" + values_array[iva];
					}
				} else if("checkbox" == this.Elements[ie].type)
				{
					var values_array = element_data[1];
					if(values_array.length <= 1)
					{
						post_query += "&" + element_data[0] + "=" + element_data[1];
					} else
					{
						for(var iva = 0; iva < values_array.length; iva ++)
						{
							post_query += "&" + element_data[0] + "[]=" + values_array[iva];
						}
					}
				} else
				{
					post_query += "&" + element_data[0] + "=" + element_data[1];
				}
			}
		}
	}
	if("true" != this.ParamsAsObject)
	{
		post_query = new String(post_query).substr(1);
	}
	
	/*if("true" == this.ParamsAsObject)
	{
		var dat = "";
		for(var iobj in post_query)
		{
			dat += iobj + "=" + post_query[iobj] + "\n";
		}
		alert(dat);
	} else
	{
		alert(post_query);
	}*/
	//return;
	
	$("#div_" + prefix + "error").hide("fast");
	$("#div_" + prefix + "success").hide("fast");
	$("#div_" + prefix + "options").hide("fast");
	
	if(only_parameters)
	{
		return post_query;
	}
	
	$.post(this.SendLocation, post_query,
		function(reply)
		{
			if("ok" == new String(reply).substring(0, 2))
			{
				var results = new String(reply).split("|");
				if("" != call_back)
				{
					var eval_string = call_back + "('" + results[0] + "', '" + results[1] + "', '" + results[2] + "', '" + prefix + "');";
					//alert(eval_string);
					eval(eval_string);
				}
				if(document.getElementById("div_" + prefix + "success"))
				{
					$("#div_" + prefix + "success").slideToggle("slow");
				}
				if(document.getElementById("div_" + prefix + "warning"))
				{
					$("#div_" + prefix + "warning").hide("fast");
				}
				if("true" == close_on_submit)
				{
					if(document.getElementById("div_" + prefix + "form"))
					{
						$("#div_" + prefix + "form").hide("slow");
					}
				}
				if(document.getElementById("div_" + prefix + "options"))
				{
					var html = $("#div_" + prefix + "options").html();
					html = new String(html).replace(/%id%/g, results[1]);
					$("#div_" + prefix + "options").html(html);
					$("#div_" + prefix + "options").slideToggle("slow");
				}
				if(document.getElementById("div_" + prefix + "error"))
				{
					$("#div_" + prefix + "error").hide("slow");
				}
			} else
			{
				if(document.getElementById("div_" + prefix + "error"))
				{
					if(document.getElementById("div_" + prefix + "error_inside"))
					{
						$("#div_" + prefix + "error_inside").html(reply);
					} else
					{
						$("#div_" + prefix + "error").html(reply);
					}
					//$("#div_" + prefix + "error").show("slow");
					$("#div_" + prefix + "error").slideToggle("slow");
				} else
				{
					alert(reply);
				}
			}
			/*if(document.getElementById("div_panel_left_content"))
			{
				document.getElementById("div_panel_left_content").scrollTop = 0;
			}*/
		}
	);
}


/**
* gets post_query data from one element
*/
formValidator.prototype.getDataElement = function(element)
{
	if("button" == element.type || "submit" == element.type)
	{
		return ["", ""];
	}
	
	var suffix_check_length = this.SuffixCheck.length;
	var prefix_length = this.Prefix.length;

	if(this.SuffixCheck == element.name.substr(new String(element.name).length - suffix_check_length, suffix_check_length))
	{
		var element_name = new String(element.name).substr(0, new String(element.name).length - suffix_check_length);
	} else
	{
		var element_name = element.name;
	}
	element_name = new String(element_name).substr(prefix_length);

	if("text" == element.type || "password" == element.type || "textarea" == element.type || "select-one" == element.type || "hidden" == element.type)
	{
		var element_value = escape(convertUTF8(element.value));
	}

	/*if("checkbox" == element.type)
	{
		if(element.checked)
		{
			var element_value = element.value;
		} else
		{
			var element_value = 0;
		}
	}*/
	if("checkbox" == element.type)
	{
		var hoofd_element_id = element.name;
		//var hoofd_element_id = element_id.substr(0, new String(element.name).length - suffix_check_length);
		//alert(hoofd_element_id);
		
		var checkboxes = this.FormObject.elements[hoofd_element_id];
		//alert(checkboxes.length);
		if(this.CheckboxGroupChecked[hoofd_element_id])
		{
			return ["",""];
		} else
		{
			this.CheckboxGroupChecked[hoofd_element_id] = 1;
			var element_value = new Array();
			if(checkboxes.length)
			{
				var count_values = 0;
				for(var ic = 0; ic < checkboxes.length; ic ++)
				{
					if(checkboxes[ic].checked)
					{
						element_value[count_values ++] = escape(convertUTF8(checkboxes[ic].value));
					}
				}
			} else
			{
				if(checkboxes.checked)
				{
					element_value[0] = escape(convertUTF8(element.value));
				} else
				{
					element_value[0] = 0;
				}
			}
		}
	}

	if("radio" == element.type)
	{
		var hoofd_element_id = element.name;
		//var hoofd_element_id = element_id.substr(0, new String(element.name).length - suffix_check_length);
		//alert(hoofd_element_id);
		
		var is_checked = false;
		if(!this.RadioChecked[hoofd_element_id])
		{
			var radios = this.FormObject.elements[hoofd_element_id];
			if(radios.length)
			{
				for(var ii = 0; ii < radios.length; ii ++)
				{
					if(radios[ii].checked)
					{
						var element_value = escape(convertUTF8(radios[ii].value));
						break;
					}
				}
			} else
			{
				var element_value = escape(convertUTF8(element.value));
			}
		}
	}
	
	if("select-multiple" == element.type)
	{
		var element_value = new Array();
		var count_values = 0;
		
		for(var ism = 0; ism < element.length; ism ++)
		{
			if(element.options[ism].selected) 
			{
				element_value[count_values ++] = escape(convertUTF8(element[ism].value));
			}
		}
		/*
		for(var select_value in element)
		{
			if(element.select_value.selected)
			{
				element_value[count_values ++] = element.select_value.value;
			}
		}*/
	}
	
	return [element_name, element_value];
}

/**
* validates the form and submits it
*/
formValidator.prototype.send = function()
{
	for(var ie = 0; ie < this.Elements.length; ie ++)
	{
		this.validateElement(this.Elements[ie]);
	}
	
	if(this.Proceed)
	{
		this.submit();
		return true;
	} else
	{
		if(true == Boolean(this.ErrorAlert))
		{
			alert(this.Message);
		}
		if(document.getElementById("div_" + this.Prefix + "warning"))
		{
			$("#div_" + this.Prefix + "warning").slideToggle("fast");
		}
		return false;
	}
}


/**
* gets the parameters of the form without submitting it
*/
formValidator.prototype.getParams = function(show_warning)
{
	for(var ie = 0; ie < this.Elements.length; ie ++)
	{
		this.validateElement(this.Elements[ie]);
	}
	
	if(this.Proceed)
	{
		if(show_warning && document.getElementById("div_" + this.Prefix + "warning"))
		{
			$("#div_" + this.Prefix + "warning").slideToggle("fast");
		}
		return this.submit(true);
	} else
	{
		if(true == Boolean(this.ErrorAlert))
		{
			alert(this.Message);
		}
		if(document.getElementById("div_" + this.Prefix + "warning"))
		{
			$("#div_" + this.Prefix + "warning").slideToggle("fast");
		}
		return false;
	}
}


/**
* validates an element
*/
formValidator.prototype.validateElement = function(element)
{
	var element_id = element.id;
	var suffix_check_length = this.SuffixCheck.length;

	if("" == element_id)
	{
		return;
	}
	if(document.getElementById(element_id).getAttribute("alt"))
	{
		if(!this.validContent(element, document.getElementById(element_id).getAttribute("alt")))
		{
			this.addErrorValid(element_id);
		}
	}

	if(this.SuffixCheck != element_id.substr(new String(element_id).length - suffix_check_length, suffix_check_length))
	{
		return;
	}

	if("text" == element.type || "textarea" == element.type || "hidden" == element.type || "password" == element.type || "select-one" == element.type)
	{
		if( ("" == this.trim(element.value)) || (document.getElementById(element_id).getAttribute("title") == this.trim(element.value)) )
		{
			this.addError(element_id);
		}
	}
	
	// radio
	if(("radio" == element.type) || ("checkbox" == element.type))
	{
		var hoofd_element_id = element.name;
		//var hoofd_element_id = element_id.substr(0, new String(element.name).length - suffix_check_length);
		//alert(hoofd_element_id);
		
		var is_checked = false;
		if(!this.RadioChecked[hoofd_element_id])
		{
			var radios = this.FormObject.elements[hoofd_element_id];
			if(radios.length)
			{
				for(var ii = 0; ii < radios.length; ii ++)
				{
					if(radios[ii].checked)
					{
						is_checked = true;
						break;
					}
				}
			} else
			{
				is_checked = element.checked;
			}
			
			if(!is_checked)
			{
				this.addError(hoofd_element_id);
				this.RadioChecked[hoofd_element_id] = 1;
			}
		}
	}
	
	// select-multiple
	if("select-multiple" == element.type)
	{
		var smi = 0;
		for(var ism = 0; ism < element.length; ism ++)
		{
			if(element.options[ism].selected) 
			{
				smi = smi + 1;
			}
		}
		if(0 == smi)
		{
			this.addError(element_id);
		}
	}
}

/**
* validates the content of an element based on given standard type
*/
formValidator.prototype.validContent = function(element, type)
{
	return formValidator._validContent(element, type);

	/*if("" == this.trim(element.value))
	{
		return true;
	}

	switch(type)
	{
		case "email":
			if("" == new String(element.value).replace(/[a-z\d_\-\.]+@[a-z\d_\-\.]+\.[a-z\.]{2,5}/, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;
			
		case "website":
			if("" == new String(element.value).replace(/(https?:((\/\/)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)/, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;

		case "phone":
			if("" == new String(element.value).replace(/[0\+]\d{1,5}[\- ]?\d{7,10}/i, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;

		default:
			return true;
	}*/
}

/**
* validates the content of an element based on given standard type
*/
formValidator._validContent = function(element, type)
{
	if("" == trim(element.value))
	{
		return true;
	}

	switch(type)
	{
		case "email":
			if("" == new String(element.value).replace(/[a-z\d_\-\.]+@[a-z\d_\-\.]+\.[a-z\.]{2,5}/, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;
			
		case "website":
			if("" == new String(element.value).replace(/(https?:((\/\/)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)/, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;

		case "phone":
			if("" == new String(element.value).replace(/[0\+]\d{1,5}[\- ]?\d{7,10}/i, ""))
			{
				return true;
			} else
			{
				return false;
			}
			break;

		default:
			return true;
	}
}

/*
* extra functions for form
*/
function resetForm(form_object, hide_spans, hide_elements)
{
	form_object.reset();

	if(hide_spans)
	{
		for(var f = 0; f < hide_spans.length; f ++)
		{
			//$("span[id^='" + hide_spans[f] + "']").css("display", "none");
			$("span[id^='" + hide_spans[f] + "']").hide("fast");
		}
	}
	
	if(hide_elements)
	{
		for(var f = 0; f < hide_elements.length; f ++)
		{
			$("#" + hide_elements[f]).hide("fast");
		}
	}
}


function emailValid(email)
{
	if("" == new String(email).replace(/[a-z\d_\-\.]+@[a-z\d_\-\.]+\.[a-z\.]{2,5}/, ""))
	{
		return true;
	} else
	{
		return false;
	}
}


function passwordStrength(password)
{
	return true;	
}

// converts Chinese characters to Unicode numbers
function convertUTF8(text_string)
{
	var utf_string = "";
	
	for(var it = 0; it < text_string.length; it ++)
	{
		if(text_string.charCodeAt(it) > 127)
		{
			utf_string += "&#" + text_string.charCodeAt(it) + ";";
		} else
		{
			utf_string += text_string.charAt(it);
		}
	}
	
	return utf_string;
}

function sendFormStandard(form_object, prefix)
{
	//var form_validator = new formValidator(form_object, "../includes/helpers/get_form_standard_edit_results.php", {'Prefix':prefix, 'ErrorAlert':true, CloseOnSubmit:"true"});
	var form_validator = new formValidator(form_object, "../includes/helpers/get_form_standard_edit_results.php", {'Prefix':prefix, CloseOnSubmit:"true"});
	form_validator.send();
}











/*
 * inputAssistant - The search assistant for text input fields
 * Copyright (C) 2010 Ipportunities
 *
 * This is the integration file for JavaScript.
 *
 * It defines the inputAssistant class that can be used to create inputAssistant
 * instances in a HTML page in the client side.
 *
 * requires jquery
 * see http://www.jquery.com
 *
 */


// array to keep track of the input assistants
var assistants = new Array();

var userAgent = navigator.userAgent.toLowerCase();
var browser = {version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1], safari:/webkit/.test(userAgent), opera:/opera/.test(userAgent), msie:/msie/.test(userAgent)&&!/opera/.test(userAgent), mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};
//alert(browser.version);


/*
* creates an input assistant and binds it to the parent input element
*/
function bindAssistant(inputId, containerId, path)
{
	var assistant = new inputAssistant(inputId, containerId, path);

	if(! (document.getElementById(inputId) && document.getElementById(containerId)) )
	{
		return false;
	}
	
	var el = document.getElementById(inputId);
	var type = "keyup";
	//var handle = assistant.update;
	var handle = _updateInputAssistant;
	
	if(el.addEventListener)
	{
		el.addEventListener(type, handle, false);
	} else if(el.attachEvent)
	{
		el.attachEvent("on" + type, handle);
	}
	if(document.getElementById(inputId))
	{
		assistants[inputId] = assistant;
	}
}

/*
* keyup handler of the parent element
*/
function _updateInputAssistant(event)
{
	//alert(event);
	var el = event.target ? event.target : event.srcElement;
	
	var value = new String(el.value).replace(/^\s*/g, "");
	//alert('-'+value+'-');
	
	if(assistants[el.getAttribute("id")])
	{
		var assistant = assistants[el.getAttribute("id")];
		
		if(27 == event.keyCode)
		{
			assistant.close();
			return;
		}

		if(0 == new String(value).length)
		{
			assistant.close();
		} else
		{
			if(!assistant.isOpen())
			{
				var firstChar = new String(value).charAt(0);
				if(assistant.isLoaded(firstChar))
				{
					assistant.FirstChar = firstChar;
				} else
				{
					assistant.getInfo(firstChar);
				}
				assistant.open();
			}
			assistant.suggest(value);			

			if(assistant.isOpen())
			{
				assistant.proceedEvent(event);
			}
		}
	}
}


/*
* close all assistants if escape key is pressed
*/
var el = document;
var type = "keyup";
var handle = _escapeHandler;

if(el.addEventListener)
{
	el.addEventListener(type, handle, false);
} else if(el.attachEvent)
{
	el.attachEvent("on" + type, handle);
}

/*
* handles escape key to close the open assistants
*/
function _escapeHandler(event)
{
	if(27 == event.keyCode)
	{
		closeAssistants();
	}
}

/*
* closes all assistants
*/
function closeAssistants()
{
	for(var ia in assistants)
	{
		assistants[ia].close();
	}
}


/*
* selects value from the list
*/
function _ia_selectValue(id, value)
{
	document.getElementById(id).value = value;
	document.getElementById(id).focus();
	if(assistants)
	{
		if(assistants[id])
		{
			assistants[id].close();
		}
	}
}


/*
* gets actual offsets of the element
*/
function _getOffsets(el_id)
{
	var el = document.getElementById(el_id);
	
	var offsetLeft = 0;
	var offsetTop = 3;
	
	//if(el.offsetParent)
	//{
		do
		{
			offsetLeft += el.offsetLeft;
			offsetTop += el.offsetTop;
		}
		while(el = el.offsetParent);
		return [offsetLeft, offsetTop];
	//}
}



// inputAssistant Class
var inputAssistant = function(parentId, containerId, infoFile)
{
	// Properties
	this.ie = browser.msie;
	
	this.InfoFile = infoFile;
	
	this.ContainerId = containerId;
	this.ParentId = parentId;
	
	this.FirstChar = "";
	this.AllOptions = new Array();
	this.Options = new Array();
	
	this.LoadedChars = new Array();
	
	this.idPrefix = "_ia_" + parentId + "_";
	
	this.ClassTD = "input_assistant";
	this.ClassTDhover = "input_assistant_hover";
	
	this.MaxOptions = 8;
	
	this.RowHeight = 25;
	
	this.Width = 300;
	this.Height = 25;
		
	this.Top = 0;
	this.Left = 0;
	
	this.BorderWidth = 1;

	if(document.getElementById(this.ParentId))
	{
		var parent = document.getElementById(this.ParentId);
		//alert(parent.offsetHeight);

		this.Width = parent.offsetWidth - 2 - (this.ie ? 0 : (2 * this.BorderWidth));
		
		this.setPosition();
	}

	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		
		container.className = "input_assistant_container";
		
		container.style.width = this.Width;
		container.style.height = this.Height;
		
		container.style.borderWidth = this.BorderWidth;
	}

	this.SelectedIndex = null;

	this.isShown = false;

	this.Header = "<table border='0' cellspacing='0' cellpadding='0' style='width:" + this.Width + "px;'>";
	this.Footer = "</table>";
	this.Line = "<tr><td id='" + this.idPrefix + "%index%' class='" + this.ClassTD + "' onmouseover='this.className=\"" + this.ClassTDhover + "\"' onmouseout='this.className=\"" + this.ClassTD + "\"' onclick='_ia_selectValue(\"" + this.ParentId + "\", \"%option%\");' style='height:" + this.RowHeight + "px;'>%option%</td></tr>";	
}



/**
* sets the classes
*/
inputAssistant.prototype.setClasses = function(classTD, classTDhover)
{
	this.ClassTD = classTD || "input_assistant";
	this.ClassTDhover = classTDhover || "input_assistant_hover";
}

/**
* sets the maximal number of options
*/
inputAssistant.prototype.setMaxOptions = function(maxOptions)
{
	this.MaxOptions = maxOptions;
}


/**
* sets the position of the assistant
*/
inputAssistant.prototype.setPosition = function()
{
	var offsets = _getOffsets(this.ParentId);

	var parent = document.getElementById(this.ParentId);

	this.Top = parseInt(offsets[1]) + parent.offsetHeight;
	this.Left = parseInt(offsets[0]);
	
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		
		container.style.top = this.Top + "px";
		container.style.left = this.Left + "px";
	}
}


/**
* opens the assistant
*/
inputAssistant.prototype.open = function()
{
	if(document.getElementById(this.ContainerId))
	{
		this.setPosition();
		this.isShown = true;
		document.getElementById(this.ContainerId).style.display = "block";
	}
}
/**
* closes the assistant
*/
inputAssistant.prototype.close = function()
{
	this.isShown = false;
	
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		container.scrollTop = 0;
		container.style.display = "none";
		
		this.SelectedIndex = null;
	}
}

/**
* checks if the assistant is open
*/
inputAssistant.prototype.isOpen = function()
{
	return this.isShown;
}

/**
* checks if the list of suggestions for the given first letter is already loaded
*/
inputAssistant.prototype.isLoaded = function(firstChar)
{
	return this.LoadedChars[firstChar];
}


/**
* reads the info file
*/
inputAssistant.prototype.readInfoFile = function()
{
	var data;
	var query = "";

	$.ajax({
		type: "GET",
		url: this.InfoFile + this.FirstChar + ".cache?nd=" + new Date().getTime(),
		data: query,
		async: false,
		timeout: 5000,
		success: function(reply)
			{
				//alert(reply);
				data = reply;
			},
		error: function(e)
			{
				data = "";
				//alert(e);
			}
	});
	return data;
}

/**
* gets list of suggestions for the first letter
*/
inputAssistant.prototype.getInfo = function(firstChar)
{
	this.FirstChar = firstChar;
	var reply = this.readInfoFile();
	if("" == reply)
	{
		var options = new Array();
	} else
	{
		var options = new String(reply).split(",");
	}

	this.LoadedChars[this.FirstChar] = true;

	this.AllOptions[this.FirstChar] = options;
	this.setOptions(options);
}


/**
* sets options array to work with
*/
inputAssistant.prototype.setOptions = function(options)
{
	this.Options = options;

	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		
		var content = this.Header;
		for(var io = 0; ( (io < this.Options.length) && (io < this.MaxOptions) ); io ++)
		{
			var line = new String(this.Line).replace(/%option%/g, this.Options[io]).replace(/%index%/g, io);
			content += line;
		}
		content += this.Footer;
		
		container.innerHTML = content;
	}
}



/**
* processes a key event
*/
inputAssistant.prototype.proceedEvent = function(event)
{
	if(40 == event.keyCode)
	{
		this.next();
	}
	if(38 == event.keyCode)
	{
		this.prev();
	}
	if(13 == event.keyCode)
	{
		this.setValue();
	}
}


/**
* switches to the next option
*/
inputAssistant.prototype.next = function()
{
	if(0 == this.Options.length)
	{
		return false;
	}
	
	if(this.MaxOptions > this.Options.length)
	{
		var lastIndex = this.Options.length - 1;
	} else
	{
		var lastIndex = this.MaxOptions - 1;
	}

	if(null == this.SelectedIndex)
	{
		this.SelectedIndex = 0;
	} else
	{
		this.SelectedIndex ++;
		
		if(this.SelectedIndex > lastIndex)
		{
			this.SelectedIndex = 0;
		}
	}
	
	this.selectOption(this.SelectedIndex);
}

/**
* switches to the previous option
*/
inputAssistant.prototype.prev = function()
{
	if(0 == this.Options.length)
	{
		return false;
	}
	
	if(this.MaxOptions > this.Options.length)
	{
		var lastIndex = this.Options.length - 1;
	} else
	{
		var lastIndex = this.MaxOptions - 1;
	}
	//alert(lastIndex);
	if(null == this.SelectedIndex)
	{
		this.SelectedIndex = lastIndex;
	} else
	{
		this.SelectedIndex --;
		
		if(this.SelectedIndex < 0)
		{
			this.SelectedIndex = lastIndex;
		}
	}
	
	this.selectOption(this.SelectedIndex);
}

/**
* selects the given option based on index
*/
inputAssistant.prototype.selectOption = function(index)
{
	document.getElementById(this.idPrefix + index).className = this.ClassTDhover;
	document.getElementById(this.idPrefix + index).focus();
	
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		container.scrollTop = (this.SelectedIndex - 1) * this.RowHeight;
	}
	var parent = document.getElementById(this.ParentId);
	parent.focus();
}

/**
* trims the selection based on input
*/
inputAssistant.prototype.suggest = function(input)
{
	var options = new Array();
	var count = 0;
	
	for(var io = 0; io < this.AllOptions[this.FirstChar].length; io ++)
	{
		if(input == new String(this.AllOptions[this.FirstChar][io]).substring(0, new String(input).length))
		{
			options[count++] = this.AllOptions[this.FirstChar][io];
		}
	}

	this.setOptions(options);
	
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		//alert(parseInt(container.style.borderWidth));
		
		if(this.Options.length > this.MaxOptions)
		{
			var height = (this.RowHeight + (this.ie ? 4 : 0)) * this.MaxOptions;
		} else
		{
			var height = (this.RowHeight + (this.ie ? 4 : 0)) * this.Options.length;
		}
		//var newHeight = height + (this.ie ? (2 * parseInt(container.style.borderWidth)) : 0)
		//container.style.height = newHeight + "px";
		container.style.height = height + "px";
	}
	
	if(0 == this.Options.length)
	{
		this.close();
	}

}

/**
* sets value of the parent input field
*/
inputAssistant.prototype.setValue = function()
{
	if(document.getElementById(this.ParentId))
	{
		var parent = document.getElementById(this.ParentId);
		if(null != this.SelectedIndex)
		{
			parent.value = this.Options[this.SelectedIndex];
		}
		
		this.close();
		parent.focus();
	}
}





/*
 * selector - The selector for grids
 * Copyright (C) 2010 Ipportunities
 *
 * This is the integration file for JavaScript.
 *
 * It defines the selector class that can be used to create selector
 * instances in a HTML page in the client side.
 *
 * requires jquery
 * see http://www.jquery.com
 *
 */

// array to keep track of the selectors
var selectors = new Array();


var userAgent = navigator.userAgent.toLowerCase();
var browser = {version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1], safari:/webkit/.test(userAgent), opera:/opera/.test(userAgent), msie:/msie/.test(userAgent)&&!/opera/.test(userAgent), mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};



/*
* creates an input assistant and binds it to the parent input element
*/
function bindSelector(inputId, parentId, hiddenId, containerId, infoFile, fileParameters, callBack, defaultId, options_object)
{
	var create_new_selector = true;
	if(selectors[inputId])
	{
		//alert(selectors[inputId].getVar("ParentId"));
		if( (selectors[inputId].getVar("ParentId") == parentId) && (selectors[inputId].getVar("HiddenId") == hiddenId) && (selectors[inputId].getVar("ContainerId") == containerId) && (selectors[inputId].getVar("InfoFile") == infoFile) && (selectors[inputId].getVar("FileParameters") == fileParameters) && (selectors[inputId].getVar("CallBack") == callBack) )
		{
			
			create_new_selector = false;
		}
	}
	
	if(create_new_selector)
	{
		var selector = new inputSelector(inputId, parentId, hiddenId, containerId, infoFile, fileParameters, callBack, defaultId, options_object);

		if(! (document.getElementById(inputId) && document.getElementById(parentId) && document.getElementById(hiddenId) && document.getElementById(containerId)) )
		{
			return false;
		}
		
		var el = document.getElementById(inputId);
		var type = "keyup";
		var handle = _updateSelector;
		
		if(el.addEventListener)
		{
			el.addEventListener(type, handle, false);
		} else if(el.attachEvent)
		{
			el.attachEvent("on" + type, handle);
		}
		
		selectors[inputId] = selector;
	} else
	{
		selectors[inputId].setVar("DefaultId", defaultId);
		for(var variable in options_object)
		{
			selectors[inputId].setVar(variable, options_object[variable]);
		}

		selectors[inputId].resetOptions();
		selectors[inputId].open();
	}
}

/*
* keyup handler of the parent element
*/
function _updateSelector(event)
{
	//alert(event);
	var el = event.target ? event.target : event.srcElement;
	
	var value = new String(el.value).replace(/^\s*/g, "");
	//alert('-'+value+'-');
	
	if(selectors[el.getAttribute("id")])
	{
		var selector = selectors[el.getAttribute("id")];
		
		// escape
		if(27 == event.keyCode)
		{
			selector.close();
			return false;
		}

		if(!selector.isOpen())
		{
			selector.open();
		}

		if(selector.isOpen())
		{
			selector.proceedEvent(event, value);
		}
	}
}


/*
* close all assistants if escape key is pressed
*/
var el = document;
var type = "keyup";
var handle = _escapeHandlerSelector;

if(el.addEventListener)
{
	el.addEventListener(type, handle, false);
} else if(el.attachEvent)
{
	el.attachEvent("on" + type, handle);
}

/*
* handles escape key to close the open selectors
*/
function _escapeHandlerSelector(event)
{
	if(27 == event.keyCode)
	{
		closeSelectors();
	}
}

/*
* closes all selectors
*/
function closeSelectors()
{
	for(var ia in selectors)
	{
		selectors[ia].close();
	}
}

/*
* reloads all selectors
*/
function reloadSelectors()
{
	for(var ia in selectors)
	{
		selectors[ia].getInfo();
	}
}


/*
* kill all selectors
*/
function killSelectors()
{
	for(var ia in selectors)
	{
		selectors[ia] = null;
	}
	selectors = new Array();
}


/*
* selects value from the list
*/
function _s_selectValue(input_id, parent_id, hidden_id, id, value)
{
	document.getElementById(hidden_id).value = id;
	//alert(value + " " + new String(value).replace(/&quot;/g, '"'));
	document.getElementById(parent_id).value = new String(value).replace(/&quot;/g, '"').replace(/#34;/g, '"').replace(/#39;/g, "'");
	document.getElementById(parent_id).focus();

	if(selectors)
	{
		if(selectors[input_id])
		{
			selectors[input_id].close();
		}
	}
}

/*
* sets the start page
*/
function _s_setPageStart(input_id, parent_id, start)
{
	if(selectors)
	{
		if(selectors[input_id])
		{
			selectors[input_id].setPageStart(start);
		}
	}
	selectors[input_id].open();
}


// selector Class
var inputSelector = function(inputId, parentId, hiddenId, containerId, infoFile, fileParameters, callBack, defaultId, options_object)
{
	// Properties
	this.ie = browser.msie;
	
	this.InputId = inputId;
	this.ParentId = parentId;
	this.HiddenId = hiddenId;
	this.ContainerId = containerId;

	this.InfoFile = infoFile;
	this.FileParameters = fileParameters;
	this.CallBack = callBack || "";
		
	this.AllOptions = new Array();
	this.CurrentOptions = new Array();
	this.Options = new Array();
	this.DefaultId = defaultId || "";
	this.PageStart = 0;
	this.MaxOptions = 25;
	this.MaxNumberOfHeaders = 7;
	
	this.idPrefix = "_is_" + parentId + "_";
	
	this.ClassTDheader = "selector_header";
	this.ClassTD = "selector";
	this.ClassTDhover = "selector_hover";
	this.ClassTDdefault = "selector_default";
	this.ClassTDmatch = "selector_match";
	
	this.Separator = "=";
	
	this.RowHeight = 1;
	
	this.Top = 0;
	this.Left = 0;
	
	this.BorderWidth = 1;

	this.SelectedIndex = null;
	
	this.isShown = false;

	this.Width = 150;
	for(var variable in options_object)
	{
		this.setVar(variable, options_object[variable]);
	}
	
	this.Height = (this.RowHeight + (this.ie ? 5 : 0)) * (this.MaxOptions + 1);

	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		
		container.className = "selector_container";
		
		container.style.width = this.Width;
		//container.style.height = this.Height;
		
		container.style.borderWidth = this.BorderWidth;
	}

	
	this.Header = "<table border='0' cellspacing='0' cellpadding='0' style='width:" + this.Width + "px;'><tr><td id='" + this.idPrefix + "header' class='" + this.ClassTDheader + "' style='height:" + this.RowHeight + "px;' align='center'><br/></td></tr>";
	
	this.Footer = "</table>";
	this.Line = "<tr><td id='" + this.idPrefix + "%index%' class='%class_name%' onmouseover='this.className=\"" + this.ClassTDhover + "\"' onmouseout='this.className=\"%class_name%\"' onclick='_s_selectValue(\"" + this.InputId + "\", \"" + this.ParentId + "\", \"" + this.HiddenId + "\", \"%id%\", \"%option%\");' style='height:" + this.RowHeight + "px;'>%option_show%</td></tr>";

	this.getInfo();
	this.open();
	
	/*
	* attach event listener to all the html input elements on the page
	* close selectors on click on these elements
	*/
	var body_inputs = $(":input");
	for(var ii = 0; ii < body_inputs.length; ii ++)
	{
		//alert(body_inputs[ii].id);		

		if(body_inputs[ii].id == this.InputId)
		{
			continue;
		}
		if(body_inputs[ii].id == this.ParentId)
		{
			continue;
		}
		/*if(body_inputs[ii].id == (this.ParentId + "_start"))
		{
			continue;
		}*/
		var input_el = body_inputs[ii];
		var type = "click";
		var handle = closeSelectors;
	
		if(input_el.addEventListener)
		{
			input_el.addEventListener(type, handle, false);
		} else if(input_el.attachEvent)
		{
			input_el.attachEvent("on" + type, handle);
		}
	}
}


/**
* resets all the values
*/
inputSelector.prototype.resetOptions = function()
{
	this.CurrentOptions = new Array();
	
	for(var index in this.AllOptions)
	{
		this.CurrentOptions[index] = trim(this.AllOptions[index]);
		var id = this.getID(this.AllOptions[index]);
		
		if(("" != this.DefaultId) && (this.DefaultId == id) )
		{
			if(this.CurrentOptions.length > this.MaxOptions)
			{
				this.PageStart = Math.floor(index / this.MaxOptions) * this.MaxOptions;
			}
		}
	}
	this.getOptionsPage();
}


/**
* sets the start index
*/
inputSelector.prototype.setPageStart = function(page_start)
{
	this.PageStart = page_start;
	this.getOptionsPage();
	document.getElementById(this.InputId).focus();
	this.open();
}


/**
* sets the vars values
*/
inputSelector.prototype.setVar = function(variable, value)
{
	if(("MaxOptions" == variable) || ("MaxNumberOfHeaders" == variable) || ("PageStart" == variable))
	{
		var check_string = 'this.' + variable + ' = ' + value + ';';
	} else
	{
		var check_string = 'this.' + variable + ' = "' + value + '";';
	}
	eval(check_string);
}

/**
* gets the var value
*/
inputSelector.prototype.getVar = function(variable)
{
	var check_string = 'var value = this.' + variable + ';';
	eval(check_string);
	
	return value;
}


/**
* opens the assistant
*/
inputSelector.prototype.open = function()
{
	document.getElementById(this.InputId).value = "";

	if(document.getElementById(this.ContainerId))
	{
		this.isShown = true;
		document.getElementById(this.ContainerId).style.display = "block";
	}
}
/**
* closes the assistant
*/
inputSelector.prototype.close = function()
{
	this.isShown = false;
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		container.innerHTML = "";
		container.style.display = "none";
		
		this.SelectedIndex = null;
	}
	
	if(this.CallBack)
	{
		eval(this.CallBack + "()");
	}
}

/**
* checks if the assistant is open
*/
inputSelector.prototype.isOpen = function()
{
	return this.isShown;
}


/**
* reads the info file
*/
inputSelector.prototype.readInfoFile = function()
{
	var data;
	var query = "";

	$.ajax({
		type: "GET",
		url: this.InfoFile + "?nd=" + new Date().getTime() + this.FileParameters,
		data: query,
		async: false,
		timeout: 5000,
		success: function(reply)
			{
				//alert(reply);
				data = reply;
			},
		error: function(e)
			{
				data = "";
				//alert(e);
			}
	});
	return data;
}

/**
* gets list of all available options
*/
inputSelector.prototype.getInfo = function()
{
	var reply = this.readInfoFile();
	if("" == reply)
	{
		var options = new Array();
	} else
	{
		var options = new String(trim(reply)).split("\n");
	}

	this.AllOptions = options;
	this.resetOptions();
}


/**
* sets options array to work with
*/
inputSelector.prototype.getOptionsPage = function()
{
	this.Options = new Array();
	for(var io = this.PageStart; ((io < (this.PageStart + this.MaxOptions)) && (io < this.CurrentOptions.length)) ; io ++)
	{
		if(trim(this.CurrentOptions[io]))
		{
			this.Options[io] = trim(this.CurrentOptions[io]);
		}
	}
	this.setOptions();
}

/**
* sets options array to work with
*/
inputSelector.prototype.setOptions = function()
{
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		
		var input = trim(document.getElementById(this.InputId).value);
		
		var content = this.Header;
		for(var index in this.Options)
		{
			var id = this.getID(this.Options[index]);
			var option = this.getOption(this.Options[index]);
			
			if("" == input)
			{
				var option_show = option;
			} else
			{
				if(1 == new String(input).length)
				{
					if(input.toLowerCase() == String(option).substring(0, 1).toLowerCase())
					{
						var option_show = "<span class='" + this.ClassTDmatch + "'>" + input + "</span>" + new String(option).substring(1);
					} else
					{
						var option_show = option;
					}
				} else
				{
					var re = new RegExp(input, "gi");
					var option_show = new String(option).replace(re, "<span class='" + this.ClassTDmatch + "'>" + input + "</span>");
				}
			}
			
			if(id == this.DefaultId)
			{
				var class_name = this.ClassTDdefault;
			} else
			{
				var class_name = this.ClassTD;
			}

			option = new String(option).replace(/&quot;/g, "#34;").replace(/"/g, "#34;").replace(/'/g, "#39;");
			var line = new String(this.Line).replace(/%option%/g, option).replace(/%option_show%/g, option_show).replace(/%index%/g, index).replace(/%id%/g, id).replace(/%class_name%/g, class_name);
			//var x = new String("'\"");
			//alert(line);
			content += line;
		}
		content += this.Footer;
		
		container.innerHTML = content;
		
		this.setHeader();
	}
}


/**
* sets header navigation to scroll pages
*/
inputSelector.prototype.setHeader = function()
{
	var header_id = this.idPrefix + "header";
	if(this.CurrentOptions.length <= this.MaxOptions)
	{
		if(0 == this.CurrentOptions.length)
		{
			var header_content = "niets gevonden";
		} else
		{
			var header_content = "1-" + this.CurrentOptions.length;
		}
	} else
	{
		var header_content = "";
		var number_of_headers = Math.ceil(this.CurrentOptions.length / this.MaxOptions);
		var last_header = (number_of_headers - 1) * this.MaxOptions;
		var points_position_distance = Math.floor(this.MaxNumberOfHeaders / 2) - 1;
		
		for(var np = 0; np < this.CurrentOptions.length; np += this.MaxOptions)
		{
			var end = Math.min((np + this.MaxOptions), (this.CurrentOptions.length - 0));
			if(np == this.PageStart)
			{
				header_content += " " + (np + 1) + "-" + end;
			} else
			{
				var current_distance = Math.abs(np - this.PageStart) / this.MaxOptions;
				if( (number_of_headers < this.MaxNumberOfHeaders) || (0 == np) || (last_header == np) || (current_distance < points_position_distance) )
				{
					header_content += " <a href=\"javascript:void(0)\" onclick=\"_s_setPageStart('" + this.InputId + "', '" + this.ParentId + "', " + np + ");\">" + (np + 1) + "-" + end + "</a>";
				} else if( ((np - (points_position_distance * this.MaxOptions)) == this.PageStart) || ((np + (points_position_distance * this.MaxOptions)) == this.PageStart) )
				{
					header_content += " ...";
				}
			}
		}
	}
	document.getElementById(header_id).innerHTML = header_content;
}


/**
* processes a key event
*/
inputSelector.prototype.proceedEvent = function(event, value)
{
	// PageDown
	if(34 == event.keyCode)
	{
		this.left();
		return true;
	}
	// PageUp
	if(33 == event.keyCode)
	{
		this.right();
		return true;
	}
	
	// arrow down
	if(40 == event.keyCode)
	{
		this.next();
		return true;
	}
	// arrow up
	if(38 == event.keyCode)
	{
		this.prev();
		return true;
	}
	
	// enter
	if(13 == event.keyCode)
	{
		this.setValue();
		return true;
	}
	
	this.suggest(value);
}


/**
* switches to the previous page selection
*/
inputSelector.prototype.left = function()
{
	var new_start = parseInt(this.PageStart - this.MaxOptions);
	if(this.PageStart > 0)
	{
		this.setPageStart(new_start);
	}
}

/**
* switches to the next page selection
*/
inputSelector.prototype.right = function()
{
	var new_start = parseInt(this.PageStart + this.MaxOptions);
	if(this.PageStart <= (this.CurrentOptions.length - this.MaxOptions))
	{
		this.setPageStart(new_start);
	}
}


/**
* switches to the next option
*/
inputSelector.prototype.next = function()
{
	if(0 == this.Options.length)
	{
		return false;
	}
	
	if(this.MaxOptions < this.CurrentOptions.length)
	{
		if(0 == this.Options.length % this.MaxOptions)
		{
			var lastIndex = this.PageStart + this.MaxOptions - 1;
		} else
		{
			var lastIndex = this.PageStart + (this.Options.length % this.MaxOptions) - 1;
		}
	} else
	{
		var lastIndex = this.CurrentOptions.length - 1;
	}

	if((null == this.SelectedIndex) || (this.SelectedIndex < this.PageStart) || (this.SelectedIndex > lastIndex))
	{
		this.SelectedIndex = this.PageStart;
	} else
	{
		var id = this.getID(this.Options[this.SelectedIndex]);
		if(this.DefaultId == id)
		{
			document.getElementById(this.idPrefix + this.SelectedIndex).className = this.ClassTDdefault;
		} else
		{
			document.getElementById(this.idPrefix + this.SelectedIndex).className = this.ClassTD;
		}
		
		this.SelectedIndex ++;
		
		if(this.SelectedIndex > lastIndex)
		{
			this.SelectedIndex = this.PageStart;
		}
	}
	
	this.selectOption(this.SelectedIndex);
}

/**
* switches to the previous option
*/
inputSelector.prototype.prev = function()
{
	if(0 == this.Options.length)
	{
		return false;
	}
	
	if(this.MaxOptions < this.CurrentOptions.length)
	{
		if(0 == this.Options.length % this.MaxOptions)
		{
			var lastIndex = this.PageStart + this.MaxOptions - 1;
		} else
		{
			var lastIndex = this.PageStart + (this.Options.length % this.MaxOptions) - 1;
		}
	} else
	{
		var lastIndex = this.CurrentOptions.length - 1;
	}

	if((null == this.SelectedIndex) || (this.SelectedIndex < this.PageStart) || (this.SelectedIndex > lastIndex))
	{
		this.SelectedIndex = lastIndex;
	} else
	{
		var id = this.getID(this.Options[this.SelectedIndex]);
		if(this.DefaultId == id)
		{
			document.getElementById(this.idPrefix + this.SelectedIndex).className = this.ClassTDdefault;
		} else
		{
			document.getElementById(this.idPrefix + this.SelectedIndex).className = this.ClassTD;
		}
		
		this.SelectedIndex --;
		
		if(this.SelectedIndex < this.PageStart)
		{
			this.SelectedIndex = lastIndex;
		}
	}
	
	this.selectOption(this.SelectedIndex);
}

/**
* selects the given option based on index
*/
inputSelector.prototype.selectOption = function(index)
{
	if(!document.getElementById(this.idPrefix + index))
	{
		return false;
	}
	
	document.getElementById(this.idPrefix + index).className = this.ClassTDhover;
	document.getElementById(this.idPrefix + index).focus();
	
	if(document.getElementById(this.ContainerId))
	{
		var container = document.getElementById(this.ContainerId);
		container.scrollTop = (this.SelectedIndex - 1) * this.RowHeight;
	}
	document.getElementById(this.InputId).focus();
}



/**
* trims the selection based on input
*/
inputSelector.prototype.suggest = function(input)
{
	this.PageStart = 0;
	this.CurrentOptions = new Array();
	var count = 0;

	input = trim(input);
	
	for(var io = 0; io < this.AllOptions.length; io ++)
	{
		var option = this.getOption(this.AllOptions[io]);

		if("" == input) 
		{
			this.CurrentOptions[count++] = this.AllOptions[io];
		} else
		{
		
			if(1 == new String(input).length)
			{
				if(input.toLowerCase() == new String(option).substring(0, new String(input).length).toLowerCase())
				{
					this.CurrentOptions[count++] = this.AllOptions[io];
				}
			} else
			{
				if(-1 != new String(option).toLowerCase().indexOf(input.toLowerCase()))
				{
					this.CurrentOptions[count++] = this.AllOptions[io];
				}
			}
		}
	}

	this.getOptionsPage();
}


/**
* sets value of the parent input field
*/
inputSelector.prototype.setValue = function()
{
	if(document.getElementById(this.HiddenId) && document.getElementById(this.ParentId))
	{
		var parent = document.getElementById(this.ParentId);
		var hidden = document.getElementById(this.HiddenId);
		if(null != this.SelectedIndex)
		{
			parent.value = new String(this.getOption(this.Options[this.SelectedIndex])).replace(/&quot;/g, '"');
			hidden.value = this.getID(this.Options[this.SelectedIndex]);
		}
		
		this.close();
		parent.focus();
	}
}


/**
* gets id based on option data
*/
inputSelector.prototype.getID = function(option_data)
{
	var index_separator = new String(option_data).indexOf(this.Separator);
	if(-1 == index_separator)
	{
		return "";
	} else
	{
		return trim(new String(option_data).substring(0, index_separator));
	}
}

/**
* gets option name based on option data
*/
inputSelector.prototype.getOption = function(option_data)
{
	var index_separator = new String(option_data).indexOf(this.Separator);
	if(-1 == index_separator)
	{
		return this.Options[this.SelectedIndex];
	} else
	{
		return trim(new String(option_data).substring(index_separator + 1));
	}
}
