
function openPopup(item) {
	var theUrl = 'popup.php?_file=' + item + '&_type=detail';
	newWindow = window.open(theUrl, 'popup', 'width=622, height=467, location=no, resizable=no, status=no, toolbar=no');
	newWindow.focus();
}

/**
 * confirmation delete item
 */
function confirmDeleteItem(uri, catalog, id) {
	check = confirm("Soll diese Kategorien und alle Produkte in dieser Kategorie gelöscht werden?");
	if(check==false) {
		return false;
	} else {
		window.location.href = uri + "?catalog=" + catalog + "&id=" + id;
	}
}

/**
 * confirmation delete product
 */
function confirmDeleteProduct(uri, catalog, id, product) {
	check = confirm("Sollen das ausgewählte Produkte gelöscht werden?");
	if(check==false) {
		return false;
	} else {
		window.location.href = uri + "?catalog=" + catalog + "&id=" + id + "&productId=" + product;
	}
}

function confirmDeleteNews(uri, id) {
	check = confirm("Soll der Eintrag gelöscht werden?");
	if(check==false) {
		return false;
	} else {
		window.location.href = uri + "?id=" + id;
	}
}

function confirmDeleteFile(uri, id, filename) {
	check = confirm("Soll die Datei gelöscht werden?");
	if(check==false) {
		return false;
	} else {
		window.location.href = uri + "?id=" + id + "&file=" + filename;
	}
}

/**
 * Ajax call for updating the
 * shopping basket display
 */
function putItemInBasket(material, session, id) {
	
	var quantity = document.getElementById(material).value;
	var price = document.getElementById(material).name;
	var thisMaterial = material.split(',');
	var partno = thisMaterial[0];

	
	// check if quantity is a number
	if (!isNaN(quantity)) {
		if(quantity > 0) {
			
			// the return function
			function ausgeben() {
				if (http.readyState == 4) {
					// debugging
					//alert(http.responseText);
					var data = http.responseXML;
					var result = data.getElementsByTagName('basket');
					
					for (var i = 0; i < result.length; i++) {
	   	    			var items, value;
	   	    			var thisResult = result[i];
	   	    	
	   	    			for (var j = 0; j < thisResult.childNodes.length; j++) {
            				with (thisResult.childNodes[j]) {
               					if (nodeName == 'items') {
                  					items = firstChild.nodeValue;
               					} else if (nodeName == 'value') {
                  					value = firstChild.nodeValue;
               					} 
            				}     
         				}
         			}
					
					
					// replace number of items
					var rd_Start = 0;
  					var rd_Laenge = document.getElementById('basketitems').firstChild.nodeValue.length;
  					document.getElementById('basketitems').firstChild.replaceData(rd_Start, rd_Laenge, items);
					
					// replace value of basket
					var rd_Start = 0;
  					var rd_Laenge = document.getElementById('basketvalue').firstChild.nodeValue.length;
  					document.getElementById('basketvalue').firstChild.replaceData(rd_Start, rd_Laenge, value);
  					
  					// clean entered value
  					document.getElementById(material).value = '';
  					
  					// user notification
  					alert('Der gewünschte Artikel wurde Ihrem Warenkorb hinzugefügt.');
				}
			}
			
			// debug
			// alert('put in basket\n' + 'quantity: ' + quantity + '\nmaterial: ' + material + '\nprice: ' + price);
			
			// call the server
			var http = null;
			if (window.XMLHttpRequest) {
		    	http = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
		   		http = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (http != null) {
		   		http.open('GET', 'facade/addToBasket.php?action=add&material=' + material + '&quantity=' + quantity + '&session=' + session, true);
		   		http.onreadystatechange = ausgeben;
		   		http.send(null);
			}
		} else {
			alert('Bitte geben Sie die gewünschte Stückzahl ein.');
		}		
	} else {
		alert('Bitte geben Sie nur nummerische Werte für die gewünschte Anzahl ein.');
	}
}
