var activerub = "";
var pic = new Array();
var resto;
resto = document.location.href.indexOf("resto.bliz.be") != -1 ? 1 : 0;

function showrubs(o) {
	noprov();
	var a = getpos($(o));
	$('rubdiv').style.left = (a[0]) + "px";
	$('rubdiv').style.top = (a[1] + 35) + "px";
	$('rubdiv').style.display = "block";
	$('rubclose1').style.left = (a[0] + 537 - 90) + "px";
	$('rubclose1').style.top = (a[1]) + "px";
	$('rubclose1').style.display = "block";
}
function showrub(l) {
	if (activerub != "") {
		$('rubs_'+activerub).style.display = "none";
		$('rublet'+activerub).className = "rublet_off";
	}
	$('rubs_'+l).style.display = "block";
	$('rublet'+l).className = "rublet_on";
	activerub = l;
}
function norub() {
	$('rubdiv').style.display = "none";
	$('rubclose1').style.display = "none";
}
function selectrub(o) {
	$("q").value = "";
	$("q").style.fontStyle = "";
	$("q").value = "rubriek:\"" + str_replace("&amp;", "&", o.innerHTML) + "\"";
	norub();
}
function removeemptyvalues(url) {
	if (url.indexOf("?") == -1) return url;
	var z = url.split("?");
	var p = z[1].split("&");
	var params = new Array();
	for (var i=0; i<p.length; i++) {
		var t = p[i].split("=");
		if (t[1] != "") params.push(p[i]);
	}
	return z[0] + "?" + params.join("&");
}
function dosearch() {
	var q = $('q').value;
	var w = $('w').value;
	if (resto == 1) {
		var budget = $('budget').value;
		if (isNaN(budget)) budget = "";
		var typekeuken = $('typekeuken').value;
		if (typekeuken.substring(0,1) == "(") typekeuken = "";
	}
	if (q.substring(0,1) == "(") q = "";
	if (w.substring(0,1) == "(") w = "";
	if (resto == 0) {
		if (w != "" || q != "") {
			document.location.href = "/zoek.php?q=" + escape(unescape(q)) + "&w=" + escape(unescape(w));
		} else {
			alert('Gelieve minstens een zoekterm of locatie in te geven.');
		}
	} else {
		if (typekeuken != "" || budget != "" || w != "" || q != "") {
			document.location.href = "/zoek.php?q=" + escape(unescape(q)) + "&w=" + escape(unescape(w)) + "&budget=" + escape(unescape(budget)) + "&typekeuken=" + escape(unescape(typekeuken));
		} else {
			alert('Gelieve minstens een zoekterm of locatie in te geven.');
		}
	}
}
function dosearchadvanced() {
	var q2 = $('q2').value;	// keywords
	var w4 = $('w4').value;	// gemeente
	var w3 = "";
	if (resto == 1) {
		w3 = $('w3').value;	// rub
		var budget = $('budget2').value;
		if (isNaN(budget)) budget = "";
		var typekeuken = $('typekeuken2').value;
		var specialiteit = $('specialiteit').value;
	}
	if (q2.substring(0,1) == "(") q2 = "";
	if (w3.substring(0,1) == "(") w3 = "";
	if (w4.substring(0,1) == "(") w4 = "";
	if (w3 != "") w3 = "rubriek:\"" + w3 + "\"";
	
	if (resto == 0) {
		if (w3 != "" || w4 != "" || q2 != "" || $('straat').value != "" || $('tel').value != "") {
			var url = "/zoek.php?q=" + escape(unescape(trim(q2 + (w3!=""?" "+w3:"")))) + "&w=" + escape(unescape(w4)) + "&opensun=" + ($('opensun').checked?"1":"") + "&radius=" + $('straal').value + "&phone=" + escape($('tel').value).replace("+", "%2B") + "&street=" + escape($('straat').value);
			url = removeemptyvalues(url);
			document.location.href = url;
		} else {
			alert('Gelieve minstens een zoekterm of locatie in te geven.');
		}
	} else {
		if (specialiteit != "" || typekeuken != "" || budget != "" || w3 != "" || w4 != "" || q2 != "" || $('straat').value != "" || $('tel').value != "") {
			var url = "/zoek.php?q=" + escape(unescape(trim(q2 + (w3!=""?" "+w3:"")))) + "&w=" + escape(unescape(w4)) + "&budget=" + escape(unescape(budget)) + "&typekeuken=" + escape(unescape(typekeuken)) + "&specialiteit=" + escape(unescape(specialiteit)) + "&has_tuin=" + ($('has_tuin').checked?"1":"") + "&has_terras=" + ($('has_terras').checked?"1":"") + "&opensun=" + ($('opensun').checked?"1":"") + "&radius=" + $('straal').value + "&phone=" + escape($('tel').value).replace("+", "%2B") + "&street=" + escape($('straat').value);
			url = removeemptyvalues(url);
			document.location.href = url;
		} else {
			alert('Gelieve minstens een zoekterm of locatie in te geven.');
		}
	}
}
function showprovs(o) {
	norub();
	var a = getpos($(o));
	$('provdiv').style.left = (a[0] + 52) + "px";
	$('provdiv').style.top = (a[1] + 35) + "px";
	$('provdiv').style.display = "block";
	$('provclose1').style.left = (a[0] + 524 - 90 + 52) + "px";
	$('provclose1').style.top = (a[1]) + "px";
	$('provclose1').style.display = "block";
}
function noprov() {
	try {
	$('provdiv').style.display = "none";
	$('provclose1').style.display = "none";
	} catch(e) { }
}
function selectprov(t) {
	$("w").value = "";
	$("w").style.fontStyle = "";
	$("w").value = "provincie:\"" + t + "\"";
	noprov();
}

function goodphone(t,l) {
	n=t.value; n2="";
	for (i=0;i<n.length;i++) {
		c=n.substring(i,i+1);
		if (parseInt(c)>=0 && parseInt(c)<=9) n2+=""+c;
	}
	while (n2.substring(0,1)=="00") n2=n2.substring(2);
	good=0;
	if (l=="be") {
		if (n2.length>=9) {
			if (n2.substring(0,2)=="32") n2=n2.substring(2);
			if (n2.length==9) {
				good=1;
				if (n2.substring(0,2) == "03" || n2.substring(0,2) == "02" || n2.substring(0,2) == "09") {
					area=n2.substring(0,2);
					num1=n2.substring(2,5);
				} else if (n2.substring(0,4) == "0800" || n2.substring(0,4) == "0900") {
					area=n2.substring(0,4);
					num1=n2.substring(4,5);
				} else {
					area=n2.substring(0,3);
					num1=n2.substring(3,5);
				}
				num2=n2.substring(5,7);
				num3=n2.substring(7,9);
			}
			if (n2.length==10) {
				good=1;
				area=n2.substring(0,4);
				num1=n2.substring(4,6);
				num2=n2.substring(6,8);
				num3=n2.substring(8,10);
			}
			if (good==1) {
				n2="+32 "+"(0)"+area.substring(1)+" "+num1+" "+num2+" "+num3;
				t.value=n2;
			}
		}
	}
	if (l=="nl") {
		zones=new Array("010","046","0111","0475","0113","0478","0114","0481","0115","0485","0117","0486","0118","0487","013","0488","015","0492","0161","0493","0162","0495","0164","0497","0165","0499","0166","050","0167","0511","0168","0512","0172","05130174","0514","0180","0515","0181","0516","0182","0517","0183","0518","0184","0519","0186","0521","0187","0522","020","0523","0222","0524","0223","0525","0224","0527","0226","0528","0227","0529","0228","053","0229","0541","023","0543","024","0544","0251","0545","0252","0546","0255","0547","026","0548","0294","055","0297","0561","0299","0562","030","0566","0313","0570","0314","0571","0315","0572","0316","0573","0317","0575","0318","0577","0320","0578","0321","058","033","0591","0341","0592","0342","0593","0343","0594","0344","0595","0345","0596","0346","0597","0347","0598","0348","0599","035","070","036","071","038","072","040","073","0411","074","0412","075","0413","076","0416","077","0418","078","043","079","045");
		if (n2.length>=10) {
			if (n2.substring(0,2)=="31") n2=n2.substring(2);
			if (n2.length==10) {
				good=1;
				if (n2.substring(0,2) == "06") {
					area=n2.substring(0,2);
					num1=n2.substring(2,4);
					num1+=" "+n2.substring(4,6);
				} else {
					found3=false;
					for (z=0;z<zones.length;z++) {
						if (zones[z]==n2.substring(0,3)) {
							area=n2.substring(0,3);
							num1=n2.substring(3,6);
							found3=true;
						}
					}
					if (!found3) {
						area=n2.substring(0,4);
						num1=n2.substring(4,6);
					}
				}
				num2=n2.substring(6,8);
				num3=n2.substring(8,10);
			}
			if (good==1) {
				n2="+31 "+"(0)"+area.substring(1)+" "+num1+" "+num2+" "+num3;
				t.value=n2;
			}
		}
	}
	if (l=="lu") {
		if (n2.length>=6) {
			if (n2.substring(0,3)=="352") n2=n2.substring(3);
			if (n2.length==6) {
				good=1;
				n2="+352 "+n2.substring(0,2)+" "+n2.substring(2,4)+" "+n2.substring(4,6);
			} else if (n2.length==8) {
				good=1;
				n2="+352 "+n2.substring(0,2)+" "+n2.substring(2,4)+" "+n2.substring(4,6)+" "+n2.substring(6,8);
			} else if (n2.length==9) {
				good=1;
				n2="+352 (0)"+n2.substring(1,3)+" "+n2.substring(3,5)+" "+n2.substring(5,7)+" "+n2.substring(7,9);
			}
			t.value=n2;
		}
	}
}

