function toggleAssetAttribute(id) {
	var aaCheckbox = document.getElementById("ar-"+id);
	var aaBoxes = document.getElementsByName("aa["+id+"][]");
	var aaForm = document.getElementById("assetattributes");
	for(i=0;i<aaBoxes.length;i++) {
		document.getElementById("aa-"+id+"-"+i).checked = aaCheckbox.checked;
	}

	doSearchWithAttributes();
}

function toggleAssetAttributeChild(id) {
	var aaCheckbox = document.getElementById("ar-"+id);
	var aaBoxes = document.getElementsByName("aa["+id+"][]");
	var aaForm = document.getElementById("assetattributes");
	var notAll = false;
	for(i=0;i<aaBoxes.length;i++) {
		if(document.getElementById("aa-"+id+"-"+i).checked==false) {
			notAll = true;	
		}
	}
	if(notAll==false) {
		aaCheckbox.checked = true;	
	} else {
		aaCheckbox.checked = false;	
	}
	
	doSearchWithAttributes();
}

function toggleMaincat(what) {
	var Boxes = document.getElementsByName("cat[]");
	if(what=="all") {
		for(i=0;i<Boxes.length;i++) {
			Boxes[i].checked = true;
		}
	} else {
		for(i=0;i<Boxes.length;i++) {
			Boxes[i].checked = Boxes[i].checked==true ? false : true;
		}
	}
}

function addEvent(obj, evType, fn, useCapture){
  if(obj) {
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

var DEF_VAL   = "Suchbegriff"; // Default Value
var isSafari  = ((parseInt(navigator.productSub)>=20020000)&&     // detecting WebCore
               (navigator.vendor.indexOf("Apple Computer")!=-1));

function replaceSearchField() {
  // Replaces normal input text field with safari's neat search field
  if (!document.getElementById)
    return;
  var searchField = document.getElementById('query');
  if (isSafari) {
    // changing type to "search"
    if(searchField) {
    	searchField.setAttribute('type', 'search');
    	searchField.setAttribute('autosave', 'dmd.radeberger.search');
    	searchField.setAttribute('results', '5');
    	searchField.setAttribute('placeholder', DEF_VAL);
    }
  } else {
    // doing the "Search this Site..."-Displaying- & -Hiding-Stuff
    addEvent(searchField, 'focus', focusSearch, false);
    addEvent(searchField, 'blur',  blurSearch, false);
    if(searchField) {
	    //if (searchField.value=='') searchField.value = DEF_VAL;
    }
  }

  startList()
  
}

function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("topnav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function focusSearch() {
  // removes the initial value from the search field
  if (this.value==DEF_VAL) {
    this.value = '';
    this.setAttribute('class', 'focus');
  }
}

function blurSearch() {
  // assigns default value, if no value has been entered
  if (this.value=='') {
    this.value = DEF_VAL;
    this.removeAttribute('class', 'focus');
  }
}

function showDownloadBox(obj) {
	var previewImg = obj;	
	var downloadBox = document.getElementById("downloadBox");	
	previewImg.className = 'overlay';
	downloadBox.style.display = 'block';
	
}

function hideDownloadBox() {
	var previewImg = document.getElementById("preview");	
	var downloadBox = document.getElementById("downloadBox");
	previewImg.className = '';
	downloadBox.style.display = 'none';
}

function toggleFormat(id) {
	if(Element.visible('wrapper-'+id)) {
		Effect.toggle('wrapper-'+id, 'blind')
		Element.show('open-'+id);
		Element.hide('close-'+id);
	} else {
		Effect.toggle('wrapper-'+id, 'blind')
		Element.hide('open-'+id);
		Element.show('close-'+id);
	}
}

function resize(obj, action) {
	if(action=="plus") {
		width = $(obj).style.width;
		height = $(obj).style.height;
		height = height.replace(/px/, "");
		width = width.replace(/px/, "");
		width = (width*1)+50;
		height = (height*1)+50;
		$(obj).style.width = width+"px";
		$(obj).style.height = height+"px";
		$(obj).style.display = "block";
		$(obj).style.clear = "both";
	} else {
		width = $(obj).style.width;
		height = $(obj).style.height;
		height = height.replace(/px/, "");
		width = width.replace(/px/, "");
		width = (width*1)-50;
		height = (height*1)-50;
		if(width==200) {
			$(obj).style.width = "200px";
			$(obj).style.height = "50px";
			$(obj).style.display = "inline";
			//$(obj).style.float = "left";
			return;
		}
		if(width<200) {
			return;
		}
		if(height<50) {
			$(obj).style.display = "inline";
			//$(obj).style.float = "left";
			return;
		}
		$(obj).style.width = width+"px";
		$(obj).style.height = height+"px";
		$(obj).style.display = "block";
		$(obj).style.clear = "both";
	}
	return;
}

function updateSubNav(obj) {
	if(obj.options[obj.selectedIndex].value == '') {
		obj.options[obj.selectedIndex].value = '00000001';
	}
	var url = "/ajax/updateSubNav.php";
	var para = 'id='+obj.options[obj.selectedIndex].value;
	//document.getElementById('subsubnav-select').innerHTML('');
	
	$('subsubnav-select').update('');
	new Ajax.Updater(
		'subnav-select', 
		url, 
		{
			method: 'get',
			parameters: para
		}
	);
}

function updateSubsubNav(obj) {
	if(obj.options[obj.selectedIndex].value == '') {
		obj.options[obj.selectedIndex].value = '00000001';
	}
	var url = "/ajax/updateSubsubNav.php";
	var para = 'id='+obj.options[obj.selectedIndex].value;
	
	new Ajax.Updater(
		'subsubnav-select', 
		url, 
		{
			method: 'get',
			parameters: para
		}
	);
}

function updateSubsubNavSession(obj) {
	if(obj.options[obj.selectedIndex].value == '') {
		obj.options[obj.selectedIndex].value = '00000001';
	}
	var url = "/ajax/updateSubsubNavSession.php";
	var para = 'id='+obj.options[obj.selectedIndex].value;
	
	new Ajax.Request(
		url, 
		{
			method: 'get',
			parameters: para
		}
	);
}

function invert(field) {
	l = document.forms['user'].elements[field+"[]"].length;
	for(i=0;i<l;i++) {
		document.forms['user'].elements[field+"[]"][i].checked = document.forms['user'].elements[field+"[]"][i].checked==true ? false : true;
	}
}

function checkAll(field) {
	l = document.forms['user'].elements[field+"[]"].length;
	for(i=0;i<l;i++) {
		document.forms['user'].elements[field+"[]"][i].checked = true;
	}
}

function checkNone(field) {
	l = document.forms['user'].elements[field+"[]"].length;
	for(i=0;i<l;i++) {
		document.forms['user'].elements[field+"[]"][i].checked = false;
	}
}
addEvent(window, 'load', replaceSearchField, false);

