//--------------------------------------------------------------------------------------------------------
// Neprom Search Engine Client Script
// Copyright (c) 2006 Solutior B.V.
//--------------------------------------------------------------------------------------------------------

var NepromSearch = new Object();

NepromSearch.onValidateNumber = function(e) {
	if (!e)
		e = window.event;

	if (e && e.type == "keypress") {
		var c = e.keyCode ? e.keyCode : e.which ? e.which : 0;

        if (c != 13) {
		    if (!(c >= 48 && c <= 57) && !(c >= 35 && c <= 39) && c != 8 && c != 9 && c != 46) {
			    e.cancelBubble = true;
			    e.returnValue = false;
    		
			    if (e.stopPropagation)
				    e.stopPropagation();

			    if (e.preventDefault)
				    e.preventDefault();
		    }
	    } else {
    	    e.cancelBubble = true;
		    e.returnValue = false;
    		
		    if (e.stopPropagation)
			    e.stopPropagation();

		    if (e.preventDefault)
			    e.preventDefault();
		    
		    document.searchform.submit();
	    }
	}
}

NepromSearch.onChangeNumber = function(e) {
	var val = this.value;
	var f_val = "";
	var f_null = 1;

	for(var i = 0;i < val.length;i ++)
		if (val.charCodeAt(i) >= 48 && val.charCodeAt(i) <= 57 && (!f_null || val.charCodeAt(i) != 48)) {
			f_val += val.charAt(i);
			f_null = 0;
		}

	val = "";

	if (f_val != "")
		f_val = String(parseInt(f_val));

	for(var i = f_val.length-1,j=0;i >= 0;i --) {
		val = f_val.charAt(i)+(j == 3 ? "." : "")+val;

		if (j == 3)
			j = 0;

		j ++;
	}

	if (val == "")
		val = "-";

	if (!this.orgLength)
		this.orgLength = this.maxLength;

	this.maxLength = 20;
	this.hasFocus = 0;

	if (this.value != val)
		this.value = val;
}

NepromSearch.onActivateNumber = function(e) {
	if (!this.hasFocus) {
		var val = this.value;
		var f_val = "";

		for(var i = 0;i < val.length;i ++)
			if (val.charCodeAt(i) >= 48 && val.charCodeAt(i) <= 57)
				f_val += val.charAt(i);

		this.value = f_val;
		this.maxLength = this.orgLength;
		this.select();
		this.hasFocus = 1;
	}
}

NepromSearch.onSelect = function(e) {
	if (!this.hasFocus) {
		this.select();
		this.hasFocus = 1;
	}
}

NepromSearch.onDeselect = function(e) {
	this.hasFocus = 0;
}

NepromSearch.onSortingChange = function(e) {
	if (document.searchform.sortorder) {
		document.searchform.sortorder.disabled = this.selectedIndex ? false : true;
	
		if (!this.selectedIndex)
			document.searchform.sortorder.selectedIndex = 0;
	}
}

NepromSearch.onLocationChange = function(e) {
	if (document.searchform.straal)
		document.searchform.straal.disabled = this.value != "" ? false : true;
}

NepromSearch.applyNumber = function(e) {
	e.onkeypress = NepromSearch.onValidateNumber;
	e.onfocus = NepromSearch.onActivateNumber;
	e.onblur = NepromSearch.onChangeNumber;
		
	if (e.captureEvents) {
		e.captureEvents(Event.KeyPress);
		e.captureEvents(Event.Focus);
		e.captureEvents(Event.Blur);
	}
	
	e.onblur();
}

NepromSearch.applySelection = function(e) {
	e.onfocus = NepromSearch.onSelect;
	e.onblur = NepromSearch.onDeselect;
		
	if (e.captureEvents) {
		e.captureEvents(Event.Focus);
		e.captureEvents(Event.Blur);
	}
}

NepromSearch.Initialize = function() {
	if (document.getElementById("results")){
		var n=document.body.clientHeight-125;
		document.getElementById("results").style.height = n+"px";
	}
	if (document.getElementById("details")){
		var n=document.body.clientHeight-70;
		document.getElementById("details").style.height = n+"px";
	}
	//try {
		if (document.searchform && document.searchform.plaats) {
			document.searchform.plaats.onchange = NepromSearch.onLocationChange;
			document.searchform.plaats.onpropertychange = NepromSearch.onLocationChange;

			document.searchform.plaats.onchange();

			if (document.searchform.plaats.captureEvents)
				document.searchform.plaats.captureEvents(Event.Change);

			if (document.searchform.metragevan)
				NepromSearch.applyNumber(document.searchform.metragevan);

			if (document.searchform.metragetot)
				NepromSearch.applyNumber(document.searchform.metragetot);

			if (document.searchform.sortby) {
				document.searchform.sortby.onchange = NepromSearch.onSortingChange;
				
				document.searchform.sortby.onchange();

				if (document.searchform.sortby.captureEvents)
					document.searchform.sortby.captureEvents(Event.Change);
			}
		}

		if (document.getElementById("NepromSearchTitle"))
			window.setTimeout("var p=document.getElementById('NepromSearchTitle');if(p){if(p.filters&&p.filters.length)p.filters[0].apply();p.style.visibility='visible';if(p.filters&&p.filters.length)p.filters[0].play();}",100);
		
		if (document.getElementById("zoek_presearch_result")){
			presearch(true);
			window.setTimeout("var p=document.getElementById('zoek_presearch_result');if(p){if(p.filters&&p.filters.length)p.filters[0].apply();p.style.visibility='visible';if(p.filters&&p.filters.length)p.filters[0].play();}",100);
		}
			
		if (typeof(NepromSearchMapInitialize) == "function")
			eval("NepromSearchMapInitialize();");
	//} catch(e) {}
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
