function toggleSearchForm(obj)
{
	if (obj.value.length <= 0){
		document.getElementById('search_select_1').disabled=false;
		document.getElementById('search_select_2').disabled=false;
		document.getElementById('search_select_3').disabled=false;
		document.getElementById('search_select_4').disabled=false;
		document.getElementById('search_select_5').disabled=false;
	}else{
		document.getElementById('search_select_1').disabled=true;
		document.getElementById('search_select_2').disabled=true;
		document.getElementById('search_select_3').disabled=true;
		document.getElementById('search_select_4').disabled=true;
		document.getElementById('search_select_5').disabled=true;
	}
}

function set_avatar(imgurl) {
	document.getElementById('curravatar').src = imgurl;
	document.getElementById('local_avatar').value = imgurl;

//	var return_text = post_xml(xmlurl + '&act=avatar&avatar=' + imgurl, 'objects');

	document.getElementById('avatarmessage').innerHTML = return_text;
}

function checkform(AlertMessage)
{
	if (document.topsearch.term.value.length < 3)
	{
		alert(AlertMessage);
		document.topsearch.term.focus();
		return (false);
	}
}

function checkform_top(AlertMessage)
{
	if (document.topsearch.term.value.length < 3)
	{
		alert(AlertMessage);
		document.topsearch.term.focus();
	}else{
		document.topsearch.submit();
	}
}

function checkform_left(AlertMessage)
{
	if (document.leftsearch.term.value.length < 3)
	{
		alert(AlertMessage);
		document.leftsearch.term.focus();
	}else{
		document.leftsearch.submit();
	}
}


function checkform_notes(AlertMessage)
{
	if (document.note_search.term.value.length < 3)
	{
		alert(AlertMessage);
		document.note_search.term.focus();
	}else{
		document.note_search.submit();
	}
}

function campagne_renew(id) {
	expMenu('renew_' + id);
	expMenu('renew_campagne_' + id);

	if (document.getElementById('renew_campagne_' + id).style.display == "none")
	{
		document.getElementById('renew_campagne_' + id).checked = false;
	}else{
		document.getElementById('renew_campagne_' + id).checked = true;
	}
}

function expMenu(id) {
	var itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all) {
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	if (!itm) {
		// do nothing
	} else if (itm.style) {
		if (itm.style.display == "none") { itm.style.display = ""; }
		else { itm.style.display = "none"; }
	} else { itm.visibility = "show"; }
}

function post_vars(what, fields) {
	if (!what) {
			return;
	}
	var res = '';
	var myType = '';
	var myName = '';
	if (what.elements) {
		for (var i=0, j=what.elements.length; i<j; i++) {
			myType = what.elements[i].type;
			myName = what.elements[i].name;
			if (myName == fields || fields == 'all') {
				if (myType == 'radio') {
					if (what.elements[i].checked) {
						res += '&' + myName + '=' + what.elements[i].value;
					}
				}
				if (myType == 'checkbox') {
					if (what.elements[i].checked) {
						res += '&' + myName + '=' + what.elements[i].value;
					}
				}
				if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea') {
					if (what.elements[i].value != '') {
						res += '&' + myName + '=' + what.elements[i].value;
					}
				}
				if (myType == 'select-one' || myType == 'select-multiple') {
					if (what.elements[i].options[what.elements[i].selectedIndex].value != '') {
						res += '&' + myName + '=' + what.elements[i].options[what.elements[i].selectedIndex].value;
					}
				}
			}
		}
	}
	return res;
}

function post_xml(url, result) {
	var xmlDoc = Sarissa.getDomDocument()
	xmlDoc.async = false;
	xmlDoc.load(url);
	xmlDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
	xmlDoc.setProperty("SelectionLanguage", "XPath");
	return xmlDoc.selectSingleNode("//return").text;
}

var last_url = '';
function get_xml(url, result_div) {
	last_url = url;
	last_url = last_url.replace('&sort=name', '');
	last_url = last_url.replace('&sort=price', '');

	var xmlDoc = Sarissa.getDomDocument()
	xmlDoc.async = false;
//	document.getElementById('posted').innerHTML = '' + url;
//	document.getElementById(result_div).innerHTML = 'Loading...';
	xmlDoc.load(url);

	var xslDoc = Sarissa.getDomDocument();
	xslDoc.async = false;
	xslDoc.load('skin/kunstpakhuis/widgets.xsl');

	var processor = new XSLTProcessor();
	processor.importStylesheet(xslDoc);
	
	var newDocument = processor.transformToDocument(xmlDoc);
//	alert(Sarissa.getParseErrorText(newDocument));

	Sarissa.updateContentFromNode(xmlDoc, document.getElementById(result_div), processor);
	
	processor = null;
	newDocument = null;
	
	change_artcount();
}

function change_artcount(Noworksfound, Foundworks) {
	var artcount = document.getElementById('testcount');
	if (artcount) {
		var artcount_td = document.getElementById('artcount');
		if (artcount.value == '') {
			artcount_td.innerHTML = Noworksfound;
		} else if (artcount_td) {
			if (artcount.value == 750) {
				if (Foundworks.indexOf('found') > 0) {
					artcount_td.innerHTML = artcount.value + Foundworks.replace('found', 'found (= maximum)');
				} else {
					artcount_td.innerHTML = artcount.value + Foundworks.replace('d.', 'd. (= maximum)');
				}
			} else {
				artcount_td.innerHTML = artcount.value + Foundworks;
			}
		}
	}
}

function removeElement(parent_el, child_el)
{
	var d = document.getElementById(parent_el);
	d.innerHTML = '';
//var olddiv = document.getElementById(child_el);
//	if (d && olddiv) {
//		d.removeChild(olddiv);
//	}
}

function uitklappen(id) {
	var itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all) {
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	if (!itm) {
		// do nothing
	} else if (itm.style) {
		if (itm.style.display == "none") { 
			itm.style.display = ""; 
		} else {
			//itm.style.display = "none"; 
		}
	} else { itm.visibility = "show"; }
}
function inklappen(id) {
	var itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all) {
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	if (!itm) {
		// do nothing
	} else if (itm.style) {
		if (itm.style.display == "none") { 
			//itm.style.display = ""; 
		} else {
			itm.style.display = "none"; 
		}
	} else { 
		//itm.visibility = "show"; 
	}
}

function MouseOver() {
	if (document.getElementById) {
		var x = document.getElementsByTagName('IMG');
		var y = document.getElementsByTagName('INPUT');
	} else if (document.all) {
		var x = document.all.tags('IMG');
		var y = document.all.tags('INPUT');
	}	else {
		return;
	}
	var preloads = new Object();
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('hsrc')) {
			if (!preloads['n'+x[i].id]) {
				preloads['n'+x[i].id] = new Image;
				preloads['n'+x[i].id].src = x[i].src;
			}
			if (!preloads['o'+x[i].id]) {
				preloads['o'+x[i].id] = new Image;
				preloads['o'+x[i].id].src = x[i].getAttribute('hsrc');
			}
			x[i].onmouseover = function () {this.src=preloads['o'+this.id].src;}
			x[i].onmouseout = function () {this.src=preloads['n'+this.id].src;}
		}
	}
	for (var i=0;i<y.length;i++) {
		if (y[i].getAttribute('hsrc')) {
			if (!preloads['n'+y[i].id]) {
				preloads['n'+y[i].id] = new Image;
				preloads['n'+y[i].id].src = y[i].src;
			}
			if (!preloads['o'+y[i].id]) {
				preloads['o'+y[i].id] = new Image;
				preloads['o'+y[i].id].src = y[i].getAttribute('hsrc');
			}
			y[i].onmouseover = function () {this.src=preloads['o'+this.id].src;}
			y[i].onmouseout = function () {this.src=preloads['n'+this.id].src;}
		}
	}
}

function check_sell_type(select_object) {
	if (select_object.options[select_object.selectedIndex].value == 'expose') {
		inklappen('auction_price');
		inklappen('sell_price');
		inklappen('auction_date_end');
	} else if (select_object.options[select_object.selectedIndex].value == 'buy') {
		inklappen('auction_price');
		inklappen('auction_date_end');
		uitklappen('sell_price');
	} else if (select_object.options[select_object.selectedIndex].value == 'price_request') {
		inklappen('auction_price');
		inklappen('auction_date_end');
		inklappen('sell_price');
	} else {
		uitklappen('auction_price');
		uitklappen('auction_date_end');
		inklappen('sell_price');
	}
}

function pausecomp(millis) 
{
	date = new Date();
	var curDate = null;
	
	do { var curDate = new Date(); } 
	while(curDate-date < millis);
	date = null
}

function PopWindow(mypage,myname,w,h,scroll){
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';

	window.open(mypage,myname,settings);
}
