function onFocusZoek(obj){
	if(obj.value == "Zoekterm")
	obj.value ="";

}
     var zcats;
     var adm = false;
function onBlurZoek(obj){
	if(obj.value =="")
	obj.value="Zoekterm"
}

function onFocusMail(obj){
	if(obj.value == "Uw emailadres")
	obj.value ="";

}

function onBlurMail(obj){
	if(obj.value =="")
	obj.value="Uw emailadres"
}

var http_request = false;
function makeRequest(url,functionName) {
	http_request = false;
	if (window.ActiveXObject) { // IE
	try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	}
	} else if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	}

	if (!http_request) {
		//alert('');
		return false;
	}
	http_request.onreadystatechange = function() {

		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				eval(functionName+"(http_request.responseXML);");
			} else {
				//  alert('There was a problem with the request.');
			}
		}


	}
	http_request.open('GET', url, true);
	http_request.send(null);

}




function fillSearchBox(xmlObj){
         zcats = xmlObj;
        if(place_ads == "true" && sCat == '')  {
         fillAdForm(zcats); }
         
        if(adm == "true"){
        	fillAdFormAdm(zcats);
		}
		
		if(place_ads == "true" && sCat != ''){
			fillPlaceAdForm(zcats)
			
		}
        //else
       // alert(place_ads);
	elem2 = document.createElement("option");
	elem2.value = "all";
	elem2.innerHTML = "Alle rubrieken...";
	elem3 = document.createElement("option");
	elem3.value = "all";
	elem3.innerHTML = "-----------------------------";
    try{
	if(!subcat && !cat){
		var cats = xmlObj.getElementsByTagName("cat");
		document.getElementById("categorie").appendChild(elem2);
		document.getElementById("categorie").appendChild(elem3);
		for(var i=0; i <cats.length;i++){
			elem = document.createElement("option");
			elem.value = "hr_"+cats.item(i).getAttribute("catid");
			elem.innerHTML = cats.item(i).getAttribute("name");
			document.getElementById("categorie").appendChild(elem);

		}

	}
	else{
		var cats = xmlObj.getElementsByTagName("cat");
		var subcats;

		for(var i=0; i <cats.length;i++){
			if(cats.item(i).getAttribute("catid") == cat){
				subcats = cats.item(i).getElementsByTagName("subcat");
				elem = document.createElement("option");

				elem.value = "hr_"+cats.item(i).getAttribute("catid");
				elem.innerHTML = cats.item(i).getAttribute("name");
               if(zoekterm != "Zoekterm"){
				document.getElementById("categorie").appendChild(elem);
				document.getElementById("categorie").appendChild(elem2);
				document.getElementById("categorie").appendChild(elem3);
                }else{

				document.getElementById("categorie").appendChild(elem2);
                document.getElementById("categorie").appendChild(elem);
				document.getElementById("categorie").appendChild(elem3);

                }

			}

		}
		for(var i=0; i <subcats.length;i++){


			elem = document.createElement("option");
			elem.value = "sr_"+subcats.item(i).getAttribute("catid")+"_"+cat;
			elem.innerHTML = subcats.item(i).getAttribute("name");
			if(subcats.item(i).getAttribute("catid") == subcat && zoekterm !="Zoekterm")
			{
				elem.selected = true;
			}
			document.getElementById("categorie").appendChild(elem);
		}
	}
    }catch(e){}
}
function zoekbox (postcode, postcodeland){
	var term;
	term = "Zoekterm";
	
	document.write('<form onSubmit="if(document.getElementById(\'term\').value == \'Zoekterm\' || document.getElementById(\'term\').value ==\'\') { alert(\'Voer een zoekopdracht in bij het veld waar nu Zoekterm term staat.\'); return false;}" action="http://zoek.tweedehands.net/search.php" method="get" id="zoeken">'+
	'<input value="'+term+'" id="term" onclick="onFocusZoek(this)" onblur="onBlurZoek(this)" type="text" name="q" />'+
	'<select name="categorie" id="categorie">'+
	'</select>');
	if(postcode != ""){
		document.write('<input name="postcode2" class="postcode" type="text" onclick="if(this.value==\'Postcode\') this.value=\'\'"  onblur="if(this.value==\'\') {this.value=\'Postcode\';} " value="'+postcode+'" maxlength="8">');
	}
	else{
		document.write('<input name="postcode2" class="postcode" type="text" onclick="if(this.value==\'Postcode\') this.value=\'\'"  onblur="if(this.value==\'\') {this.value=\'Postcode\';}" value="Postcode" maxlength="8">');
	}
	if(postcodeland == "België"){
		postcodeland = " selected";
	}
	document.write('<select name="postcodeland" id="postcodeland">'+
		'<option value="NL">NL</option>'+
		'<option value="BE"' + postcodeland + '>BE</option>'+
	'</select>'+
	'<select name="maxafstand" id="maxafstand">'+
		'<option value="">Alle afstanden...</option>'+
		'<option value="5">< 5 km</option>'+
		'<option value="10">< 10 km</option>'+
		'<option value="15">< 15 km</option>'+
		'<option value="25">< 25 km</option>'+
		'<option value="50">< 50 km</option>'+
		'<option value="75">< 75 km</option>'+
		'<option value="100">< 100 km</option>'+
		'<option value="150">< 150 km</option>'+
	'</select>'+
	
	'<input type="submit" name="submit" id="zoekknop_algemeen" value="Zoek"></form>');
}
function formSubmit(idForm,idField,value){

	document.getElementById(idField).value = value;
	document.getElementById(idForm).submit();
}

function fillAdForm(xmlObj){if(adm && adm == "true") return;
	if(document.getElementById("hr")){
		
	var cats = xmlObj.getElementsByTagName("cat");
	for(var i=0; i <cats.length;i++){
		elem = document.createElement("option");
		elem.value = ""+cats.item(i).getAttribute("catid");
		elem.innerHTML = cats.item(i).getAttribute("name");
		document.getElementById("hr").appendChild(elem);

	}
	zcats = xmlObj;
	}
}



function fillAdFormSubCat(id){
	if(id == "none"){
		document.getElementById("sr").innerHTML = '';
		 return;
	}
	document.getElementById("sr").innerHTML = "";
	var subcats;
	var cats = zcats.getElementsByTagName("cat");
	for(var i=0; i <cats.length;i++){
		if(cats.item(i).getAttribute("catid") == id){
			subcats = cats.item(i).getElementsByTagName("subcat");
			
		}
	}

	
	for(var i=0; i <subcats.length;i++){
		elem = document.createElement("option");
		elem.value = ""+subcats.item(i).getAttribute("catid");
		elem.innerHTML = subcats.item(i).getAttribute("name");
		if(subcats.item(i).getAttribute("catid") == subcat)
		{
			elem.selected = true;
		}
		document.getElementById("sr").appendChild(elem);
	}

}



var firstTime = "true";
function fillPlaceAdForm(xmlObj){
	var cats = xmlObj.getElementsByTagName("cat");
	
	for(var i=0; i <cats.length;i++){
		elem = document.createElement("option");
		if(cats.item(i).getAttribute("catid") == sCat){
			elem.selected = true;
			
		}
		elem.value = ""+cats.item(i).getAttribute("catid");
		elem.innerHTML = cats.item(i).getAttribute("name");
		document.getElementById("hr").appendChild(elem);

	}
	if(firstTime == "true"){
	fillPlaceAdFormSubCat(sCat);
	firstTime = "false";
	}
}



function fillPlaceAdFormSubCat(id){
	if(id == "none"){
		document.getElementById("sr").innerHTML = '<option>Kies eerst een rubriek</option>';
		 return;
	}

		document.getElementById("sr").innerHTML = '';

		
	document.getElementById("sr").innerHTML = "";
	var subcats;
	var cats = zcats.getElementsByTagName("cat");
	for(var i=0; i <cats.length;i++){
		if(cats.item(i).getAttribute("catid") == id){
			subcats = cats.item(i).getElementsByTagName("subcat");
			
		}
	}

	
	for(var i=0; i <subcats.length;i++){
		elem = document.createElement("option");
		elem.value = ""+subcats.item(i).getAttribute("catid");
		elem.innerHTML = subcats.item(i).getAttribute("name");
		try{
		if(subcats.item(i).getAttribute("catid") == sSubCat)
		{
			elem.selected = true;
		}}catch(e){}
		document.getElementById("sr").appendChild(elem);
	}

}
var place_ads="false";
function popUp(location, w, h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
win = window.open(location, '', 'width='+w+', height='+h+', top='+wint+', left='+winl+', scrollbars=no')
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
var easyads="<div style=\"margin-top:5px;color:#666666\">[geplaatst via AdvertentiePlanet.nl]</div>";

function setUrl(obj, url, stat){
	obj.onmouseover = function(){
		obj.className += " hover";
		if(url) window.status = url;
	}
	
	obj.onmouseout = function(){
		obj.className = obj.className.replace("hover", " ");
		window.status = "";
	}
	
	obj.onclick = function(){
		window.location = url;
	}
}
function setAdsenseUrl(obj, url, stat){
	obj.onmouseover = function(){
		obj.className += " hover";
		// if(stat) window.status = stat;
	}
	
	obj.onmouseout = function(){
		obj.className = obj.className.replace("hover", " ");
		// window.status = "";
	}
/*	
	obj.onclick = function(){
		window.open(url);
		pageTracker._trackPageview('http://www.tweedehands.net/Adsense-Premium/');
	}
*/
}
function changeBox(cbox) {
	box = eval(cbox);
	box.checked = !box.checked;
}
function popup (fotoid,aid) { window.open("http://www.tweedehands.net/popup.php?photoid="+escape(fotoid)+"&aid="+escape(aid), "", "resizable=0,height=100,width=100"); }

function changepic(source, source2) {
//bouw de informatie op
	var url = '<a href="'+source2+'" class="highslide" onclick="return hs.expand(this, {captionId: \'caption1\'})">';
	var image = '<img src="'+source+'" alt="Klik om te vergroten" />';
	var vergroot = '<img src="/img/vergroot.gif" id="vergroot" alt=""/></a>';
	//zet de informatie in de DIV
	document.getElementById('ad_img_links').innerHTML = url +' '+image+' '+vergroot;
}
function showthumbs(fotos, map, aid){
	if(fotos > 1){
	document.write("<div id=\"ad_img_rechts\">");
	for (var i= 1; i <= fotos; i++) {
		document.write("<a href=\""+map+i+"c.jpg\" class=\"highslide\" onclick=\"return hs.expand(this, {captionId: 'caption1'})\" onmouseover=\"changepic('"+map+i+"b.jpg', '"+map+i+"c.jpg');\">");
		document.write("<img src=" + map + i + "a.jpg />");
		document.write("</a>");
	}
	document.write("</div>");
	}
}
function isEmail(str) {

   if((str.indexOf(".") > 0) && (str.indexOf("@") > 0)){
	return true;
	}else
{	alert("Vul een correct e-mail adres in");
	return false;
}

}
function smartResize(oImg) {
	if ( ( (oImg.width>oImg.height) && (oImg.width>180) ) || (oImg.width>180 && oImg.height <= 200 ))
		oImg.width = 180;
	else if( (oImg.height > oImg.width) && (oImg.height > 200))
		oImg.height = 200;
	if (typeof oImg.style != 'undefined')
	setTimeout('document["'+oImg.name+'"].style.visibility = "visible"',1000);
}

function erotiek(){
	return confirm('De pagina die u wilt bezoeken kan aanstootgevend erotisch materiaal bevatten en is niet geschikt voor minderjarigen. Weet u zeker dat u door wilt gaan?');
}

sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
sfFocus2 = function() {
	var sfEls = document.getElementsByTagName("TEXTAREA");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
noskyscraper = false;
//if (window.attachEvent) window.attachEvent("onload", sfFocus2);
//if (window.attachEvent) window.attachEvent("onload", sfFocus);
