function addWk(id) {
	addWkGeneric(id,"small");
}

function addWkGeneric(id,type,page) {
	anz=$('ANZ_'+id).value;

	postvars='action=add&id='+id+"&anzahl="+anz+"&type="+type+"&P="+page;

	ajax=new IREDS_URL('/dynamic/addwk.php',{method:'POST',vars:postvars});

	ajax.call();
}

function removeWk(id) {
	removeWKGeneric(id,"mini");
}

function removeWKGeneric(id,type,page) {
	anz=0;

	postvars='action=add&id='+id+"&anzahl="+anz+"&type="+type+"&P="+page;

	ajax=new IREDS_URL('/dynamic/addwk.php',{method:'POST',vars:postvars});

	ajax.call();
}

function setWkCount(count) {
	document.getElementById('basketItemCount').innerHTML=count;
}

function pageMiniWk(idx) {
	new IREDS_URL('/dynamic/addwk.php',{method:'GET',vars:'type=page&wk_idx='+idx}).call();
}

function showRegion(id,type) {
	new IREDS_URL('/dynamic/regiontree.php',{method:'GET',vars:type+'='+id}).call();
}

function showSorte(id,type) {
	new IREDS_URL('/dynamic/sortentree.php',{method:'GET',vars:type+'='+id}).call();
}

function openWKSmall() {
	ShowContent('miniBasketBox');
}

function openWKAfterAdd() {
	openFromAdd=true;
	openWKSmall();
}

var openFromAdd=false;

function hideWKSmall() {
	if(!openFromAdd) {
		 HideContent('miniBasketBox');
	}
}

function hideWKAfterAdd() {
	openFromAdd=false;
	hideWKSmall();
}

function pwVergessen() {
	email=document.getElementById('pwVergessenMail').value;

	new IREDS_URL('/dynamic/pwdVergessen.php',{method:'POST',vars:'MAIL='+email}).call();
}

Containments=new Hash();
Hovered="";

function addToHash(container,contains) {
	if((idx=Containments.keys().indexOf(container))==-1) {
		eval("Containments.merge(new Hash({"+container+":['"+contains+"']}));");
	}
	else {
		Containments[container].push(contains);
	}
}

function hideVContent_Evt(evt) {
	child=Event.element(evt);
	if(child.id!=Hovered) {
		Event.stop(evt);
	}
	else {
		HideVContent(Hovered);
	}
}

function HideVContent(d) {
	if(d && d.length < 1) { 
		return; 
	}
	else {
		document.getElementById(d).style.visibility = "hidden";
		if(Containments[d]) {
			Containments[d].each(hideContainments);
		}
		Hovered="";
	}
}

function hideContainments(value,index) {
	document.getElementById(value).className='optionsDivInvisible';	
}

function ShowVContent(d) {
	if(d && d.length < 1) { return; }
	Hovered=d;
	document.getElementById(d).style.visibility = "visible";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.visibility == "hidden") { document.getElementById(d).style.visibility = "visible"; }
	else { document.getElementById(d).style.visibility = "hidden"; }
}

/* AJAX detailsuche */

function showLabel(id) {
	id="label_"+id;
	if(document.getElementById(id)) {
		document.getElementById(id).style.display="inline";
	}
}

function hideLabel(id) {
	id="label_"+id;
	if(document.getElementById(id)) {
		document.getElementById(id).style.display="none";
	}
}


function load_sorten() {
	art=document.getElementById('DETSEARCHTYP').value;
	new IREDS_URL('/dynamic/detailsuche.php',{method:'GET',vars:"TYPE=SORTE&ART="+art}).call();
}

function load_regionen() {
	art=document.getElementById('DETSEARCHLAND').value;
	new IREDS_URL('/dynamic/detailsuche.php',{method:'GET',vars:"TYPE=REGION&ART="+art}).call();
}

function load_gebiete() {
	art=document.getElementById('DETSEARCHREGION').value;
	new IREDS_URL('/dynamic/detailsuche.php',{method:'GET',vars:"TYPE=GEBIET&ART="+art}).call();
}


var myQ=0;

function replaceSelect(id) {
		q=myQ++;
		var myReplace=document.getElementById(id);
		//create and build div structure
		var selectArea = document.createElement('div');
		var left = document.createElement('div');
		var right = document.createElement('div');
		var center = document.createElement('div');
		var button = document.createElement('a');
		var text = document.createTextNode(selectText);
		center.id = "mySelectText"+q;
		var selectWidth = parseInt(myReplace.className.replace(/width_/g, ""));
		center.style.width = selectWidth - 10 + 'px';
		selectArea.style.width = selectWidth + selectRightSideWidth + selectLeftSideWidth + 'px';
		button.style.width = selectWidth + selectRightSideWidth + selectLeftSideWidth + 'px';
		button.style.marginLeft = - selectWidth - selectLeftSideWidth + 'px';
		button.href = "javascript:showOptions("+q+")";
		button.onkeydown = selectEvent;
		button.className = "selectButton"; //class used to check for mouseover
		selectArea.className = "selectArea";
		selectArea.id = "sarea"+q;
		left.className = "left";
		right.className = "right";
		center.className = "center";
		right.appendChild(button);
		center.appendChild(text);
		selectArea.appendChild(left);
		selectArea.appendChild(right);
		selectArea.appendChild(center);
		//hide the select field
        myReplace.style.display='none'; 
		//insert select div
		myReplace.parentNode.insertBefore(selectArea, myReplace);
		//build & place options div
		
		var optionsDiv = document.createElement('div');
		optionsDiv.style.width = selectWidth + 1 + 'px';
		optionsDiv.className = "optionsDivInvisible";
		optionsDiv.id = "optionsDiv"+q;
		container=myReplace.getAttribute("container");
		if(container) {
			optionsDiv.onmouseover=new Function ("show"+container,"ShowVContent('"+container+"'); return true;");
			addToHash(container,optionsDiv.id);
		}
		if(myReplace.getAttribute("onchange")) {
			onchange_fct=myReplace.getAttribute("onchange");
		} else {
			onchange_fct=myReplace.getAttribute("on_nice_change");
		}

		optionsDiv.style.left = findPosX(selectArea) + 'px';
		optionsDiv.style.top = findPosY(selectArea) + selectAreaHeight - selectAreaOptionsOverlap + 'px';
		//get select's options and add to options div
		for(var w = 0; w < myReplace.options.length; w++) {
			var optionHolder = document.createElement('p');
			var optionLink = document.createElement('a');
			var optionTxt = document.createTextNode(myReplace.options[w].text);
			optionLink.href = "javascript:showOptions("+q+");selectMe('"+myReplace.id+"',"+w+","+q+");";
			if(onchange_fct) {
				optionLink.href+=onchange_fct;
			}
			optionLink.appendChild(optionTxt);
			optionHolder.appendChild(optionLink);
			optionsDiv.appendChild(optionHolder);
			//check for pre-selected items
			if(myReplace.options[w].selected) {selectMe(myReplace.id,w,q);}
		}
		//insert options div
		document.getElementsByTagName("body")[0].appendChild(optionsDiv);
}

function setZahlung(value) {
	if(value=='CC') {
		new IREDS_URL('/dynamic/setZahlung.php',{method:'GET',vars:"ZA=CC"}).call();
	}
	else {
		new IREDS_URL('/dynamic/setZahlung.php',{method:'GET',vars:"ZA=BANK"}).call();
	}
}
