/* urf codes for alerts:
\u00 +
ä: e4, ö: f6, ü: fc
Ä: c4, Ö: d6, Ü: dc
ß: df
zB \u00e4
*/

var actContent = 'product';
var whoisWindow = null;

function SAjax() {
	this.url = "/shop/server/feasy.php";
	this.target = null;
	this.method="POST";	
	this.demand = null;
	
	this.setDemand = function(d) {
		this.demand = d;
	}
	
	this.setTarget = function(tgt) {
		this.target = tgt;
	}
	
	this.setParams = function(p) {
		this.params = p;
		if(this.demand != null) {
			this.params = "demand=" + this.demand + "&" + this.params;
		}
	}

	/* what to do on a successful reply */		
	this.onSuccess = function(txt, xml) {
//	  window.defaultStatus = (this.demand + " ==== " + this.target);
		switch (this.demand) {
			case 'productform': {
				document.getElementById(this.target).innerHTML = txt;
				document.getElementById(this.target).style.display = 'block';
				
				break;
			}
			case "paketinfo" : {
//				showContent("product");
				document.getElementById('product').style.display = 'block';
				setPaketInfoTxt(txt);
				window.setTimeout("showPaketInfo()", 300);
				break;
			}
			case "domainconfig" : {
				var ss = "";
				var dd = xml.getElementsByTagName("root")[0].childNodes;
				for(var i = 0; i < dd.length; i++) {
					ss += this.serializeNode(dd[i]);
				}
				ss = "<div>" + ss + "</div>";
				document.getElementById("domain_box").innerHTML = txt;
				
				window.setTimeout("dc.addDomainFromInfo()", 1000);
				window.setTimeout('doAfterSiteDomainLoaded()', 500);
				
				break;
			}
			case "prodconfig" : {
				document.getElementById(this.target).innerHTML = txt;
				window.setTimeout("getDomains(1, 0)", 300);
				break;
			}
			case "cartform": {
				document.getElementById(this.target).innerHTML = txt;
				break;
			}
			case "sendorder" : {
				//document.getElementById("cart_customer_div").innerHTML = txt;
				
		
				//call google tracker
				pageTracker._trackPageview('webshop/ordered');
		
				document.location.href = '/index.php?id=272';
				break;
			}
			case "cartinfo" : {
				var id = xml.getElementsByTagName("id")[0].firstChild.data;
				document.getElementById(this.target).value = id;
				break;
			}
			case "whois" : {
				document.getElementById(this.target).innerHTML = txt;
				document.getElementById(this.target).style.display = "block";
				break;
			}
			case "save_snapshot" : {
				document.getElementById("snapshot_number").value = txt;
				document.getElementById("div_snapshot_content").style.display = "block";
				break;
			}
			default: {
				try {
					if(this.target) {
						document.getElementById(this.target).innerHTML = txt;
					} else { 
						alert("target not found!!!! responseText=" + txt);
					}
				} catch(ex) {
					alert("SAjax.onSuccess threw exception: " + ex + " --- Demand=" + this.demand + " Target=" + this.target);
				}
			}
		}
	}
}


SAjax.inherits(Ajax);

function showContent(what) {
	if(actContent != what) {
		if((actContent == 'cart') && (what == 'config')) {
			if(document.getElementById("has_optional_features")) {
				var has_optional_features = document.getElementById('has_optional_features').value;
				if(has_optional_features == 0) {
					what = 'domain_box';
				}
			}
		}
		if((actContent == 'domain_box') && (what == 'config')) {
			if(document.getElementById("has_optional_features")) {
				var has_optional_features = document.getElementById('has_optional_features').value;
				if(has_optional_features == 0) {
					what = 'cart';
				}
			}
		}
		if(what == 'config' || what == 'cart') {
			if(document.getElementById('SEL_PAKET_ID').value == 0 || flag_dsearch) {
				alert("Bitte w\u00e4hlen Sie ein Paket!");
				if(flag_dsearch) {
					flag_dsearch = false;
					document.getElementById('paketinfo').style.display = 'none';
				}
				showContent('product');
				return;
			}
		}

		try {
			document.getElementById(actContent).style.display = 'none';
		} catch (e) {
			alert("Fehler - actContent = " + actContent);
		}
		actContent = what;
		document.getElementById(what).style.display = 'block';
	
		document.getElementById('navi_product').className = 'naviitem';
		document.getElementById('navi_domain').className = 'naviitem';
		document.getElementById('navi_config').className = 'naviitem';
		document.getElementById('navi_cart').className = 'naviitem';
	
		switch(what) {
			case 'product': document.getElementById('navi_product').className = 'naviitem_selected'; break;		
			case 'domain_box': document.getElementById('navi_domain').className = 'naviitem_selected'; break;		
			case 'config': document.getElementById('navi_config').className = 'naviitem_selected'; break;		
			case 'cart': document.getElementById('navi_cart').className = 'naviitem_selected'; updateCart(); break;		
		}
		
		if(what == 'domain_box'){
			//alert(document.forms.f_selected_domains +'#'+ dc.getMainDomain());
			if(dc.getMainDomain())
				updateDomainList();
			
			if(dc.getDomainArray().length == 0 && !sessdom_started) {
				sessdom_started = true;
				if(document.forms.f_selected_domains) getSessDomains();
				else window.setTimeout('getSessDomains()',500);
			}
			if(dsearch_domain)
				startLinkedDomainSearch();
			else
				setFocusOnDomainInput();
		}
		
		window.scrollTo(window.pageXOffset,302);
		
		//call google tracker
		pageTracker._trackPageview('webshop/'+what);
	}
}

//-Funktionen für Weiterleitungen
function updateDomainList() {
	if(!document.forms.f_selected_domains) { //Timeout wegen Ladeverzögerung
		window.setTimeout('updateDomainList()',500);
	} else dc.checkDomains();
}
function startLinkedDomainSearch() {
	if(!document.getElementById('req_domain')) { //Timeout wegen Ladeverzögerung
		window.setTimeout('startLinkedDomainSearch()',500);
	} else {
		document.getElementById('req_domain').value = dsearch_domain;
		startDomainCheck();
		dsearch_domain = '';
	}
}
function setFocusOnDomainInput() {
	if(!document.getElementById('req_domain')) { //Timeout wegen Ladeverzögerung
		window.setTimeout('setFocusOnDomainInput()',500);
	} else {
		document.getElementById('req_domain').select();
	}
}
function doAfterSiteDomainLoaded() {
	if(dc.getDomainArray().length == 0 && !sessdom_started) {
		sessdom_started = true;
		getSessDomains();
	}
}
//--


function doRequest(demand, params, target) {
	sendRequest(demand, params, target, true);
}


function sendRequest(demand, params, target, async) {
	var ar = new SAjax();
	ar.setAsync(async);
	ar.setDemand(demand);
	ar.setParams(params);
	ar.addParameter("ust", with_ust() ? "true" : "false");
	if(target) {
		ar.setTarget(target);
	}
	ar.doRequest();
}


function init(id) {
	var params = "id=" + id;
	sendRequest("productform", params, "product", false);
	setPaketInfo(id);
//	window.setTimeout("setPaketInfo(" + id + ")", 300);
//setPaketInfo(id);
}


function setPaketInfo(id,order) {
	var idstr = "id=" + id;
		
	sendRequest('paketinfo', idstr, "paketinfo", false);
	sendRequest('domainconfig', idstr, "domain_box", false);
	sendRequest('prodconfig', idstr, 'config', false);
	
//	dc = new DomainController();

	if(document.getElementById("bestell_id"))
		document.getElementById("bestell_id").value = 0;
	
	if(document.getElementById('SEL_PAKET_ID'))
		document.getElementById('SEL_PAKET_ID').value=id;

//	doRequest('cartform', '', 'cart');

	//save to session
	jQuery.get('/shop/updateSessionVar.php',{ variable:'paket', val:id });

	if(order) showContent('domain_box');
}

function changedFeature(id,on) {
	//save to session
	jQuery.get('/shop/updateSessionVar.php',{ array:'features', variable:id, val:(on?1:0) });
}





var pktInfo = "";
function setPaketInfoTxt(info) {
	pktInfo = info;
}

function showPaketInfo() { //alert('showpi '+ pktInfo);
//	dc = new DomainController();
	deleteDomainRows();
	document.getElementById("paketinfo").innerHTML = pktInfo;
	document.getElementById("paketinfo").style.display = 'block';
	document.getElementById("first_content_nav").style.visibility='visible';
}


function sendForm(f, demand, target) {
	var ajax = new SAjax();
	var xml = ajax.createXMLParam(f);
	ajax.setDemand(demand);
	ajax.setParams("xml=" + xml);
	ajax.addParameter("with_ust", with_ust() ? "true" : "false");
	if(target)
		ajax.setTarget(target);
	ajax.doRequest();
}


function getDomains(flag, myCaller) {
	if(document.getElementById("req_domain")) {
		var dn = document.getElementById("req_domain").value;
	}
	var ajax = new SAjax();
	ajax.setUrl("/shop/emwho/whois.php");
	ajax.setParams("demand=domains");
	ajax.addParams("included=" + flag);
	ajax.addParameter("ust", with_ust());

	whodiv = "whois_domains";
	if(myCaller == 2) {
		whodiv = "domaincheck_div";
		ajax.addParams("search_only=1");
	}
	if(dn) {
		ajax.addParams("domain=" + dn);
	}
	ajax.setDemand("domain");
	ajax.setTarget(whodiv);
	ajax.doRequest();
}


function setDomain(name, act) {
	var id = act + "_domain";
	document.getElementById(id).innerHTML = name;
}


function addIncludedDomain(tld) {
	var sld = this.getElementById("req_domain").value;
	var d = sld + "." + tld;
	addDomain(d, "included");
}


function fnWhoisCallback(flag, f) {
	if(flag == 1) {
		addDomains(f);
	}
	if(flag == 2) {
		getDomains(f, 2);
	}
	if(flag == 3) {
		toggleDomain(f);
	}
}


function addDomains(f) {
	for(var i = 0; i < f.length; i++) {
		var e = f.elements[i];
    	if((e.type == 'checkbox') && (e.checked)) {
			var preis = document.getElementById("PREIS_"+e.name).firstChild.data;
			var preis_nto = document.getElementById("PREIS_NTO_"+e.name).firstChild.data;
			var einmal_preis = f.elements["EINMAL_PREIS_"+e.name].value;
			var einmal_preis_nto = f.elements["EINMAL_PREIS_NTO_"+e.name].value;
			var mlz = f.elements["MLZ_" + e.name].value;
			var included = f.elements["INCL_" + e.name].value;
			var info = document.getElementById("WHOISINFO_" + e.name).value.split(":");
	// info = domain : available : valid : configured
			dc.addDomain(info[0], info[1], info[2], info[3], included, preis, preis_nto, einmal_preis, einmal_preis_nto, mlz, e.name);
    	}
	}
	dc.checkDomains();
}


function toggleDomain(name) {
	var f = document.forms.domaincheck;
	for(var i = 0; i < f.length; i++) {
		var e = f.elements[i];
		if(e.type == "button" && e.name == name) {
	    	//if((e.checked)) {
	    		if(document.getElementById("WHOISINFO_" + e.name).value.substr(0, 10) != "WHOISINFO_") {
					var preis = document.getElementById("PREIS_"+e.name).firstChild.data;
					var preis_nto = document.getElementById("PREIS_NTO_"+e.name).firstChild.data;
					var einmal_preis = f.elements["EINMAL_PREIS_"+e.name].value;
					var einmal_preis_nto = f.elements["EINMAL_PREIS_NTO_"+e.name].value;
					var mlz = f.elements["MLZ_" + e.name].value;
					var included = f.elements["INCL_" + e.name].value;
					var info = document.getElementById("WHOISINFO_" + e.name).value.split(":");
	// info = domain : available : valid : configured
					dc.addDomain(info[0], info[1], info[2], info[3], included, preis, preis_nto, einmal_preis, einmal_preis_nto, mlz, e.name);
					dc.checkDomains();	
				}
    		/*} else {
				var info = 	document.getElementById("WHOISINFO_" + e.name).value.split(":");
    			removeDomain(info[0]);
			}*/
		}
	}

}


function removeDomain(domain) {
	dc.removeDomain(domain);
	alert(unescape("Die Domain " + domain + " wurde gel%F6scht"));
	dc.checkDomains();
}


function setMaindomain(domain) {
	dc.setMainDomain(domain);
}


function deleteDomainRows() {
	var d = document.getElementById("selected_domains");
	if(d) {
		while(d.rows.length > 1) {
			d.deleteRow(1);
		}
	}
}


var dc = new DomainController();

/***************************************************************************
 * class DomainController
 ***************************************************************************/
function DomainController() {
	var myDomains = new Array();
	var gesamtPreis = 0;
	var gesamtPreisNto = 0;
	var gesamtEinmalPreis = 0;
	var gesamtEinmalPreisNto = 0;
	var includedDomains = 0;
	var mainDomain = null;
	
	this.findDomain = function(domain) {
		var n = 1;
		for(var i = 0; i < myDomains.length; i++) {
			if(myDomains[i].domain == domain) {
				return myDomains[i];
			}
		}
		return 0;
	}
	
	this.getDomainArray = function() {
		return myDomains;
	}
	
	
	this.addDomainFromInfo = function() {
		if(document.getElementById('domaininfo')) {
			var v = document.getElementById('domaininfo').value;
			if(v != "") {
				info = v.split(":");
				this.addDomain(info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7], info[8]);
				if(document.forms.f_selected_domains) {
					this.checkDomains();
				} else {
					for(var i = 0; i < 10; i++) {
						if(document.forms.f_selected_domains) {
							window.setTimeout("checkDomains", 1000);
						}
					}
				}		
				var dmn = info[0];
				var pos = dmn.indexOf(".");
				if(pos > 0) {
					dmn = dmn.substring(0, pos);
				}
				if(document.getElementById('req_domain')) {
					document.getElementById('req_domain').value = dmn;
				}
			}
		}
	}


	this.addDomain = function(domain, available, valid, configured, included, preis, preis_nto, einmal_preis, einmal_preis_nto, mlz, tld, sess_call) {
		//alert('add '+ domain +' '+ available +' '+ document.getElementById('number_included_domains'));
		
		if(this.findDomain(domain) != 0 && !sess_call)
			return;
			
		var len = myDomains.length;
		if(document.getElementById('number_included_domains')) { //alert(domain +':'+document.getElementById('number_included_domains').value);
			var number_included_domains = document.getElementById('number_included_domains').value;

			var data = new Object();
				data.domain = domain;
				data.available = available;
				
				myDomains[len] = data;
				
				data.preis = preis;
				data.preis_nto = preis_nto;
				data.einmal_preis = einmal_preis;
				data.einmal_preis_nto = einmal_preis_nto;
				data.included = included;
				data.mlz = mlz;
				data.main_domain = false;
				data.ndx = len;
				data.row = null;
		
			if(included && (DomainController.includedDomains < number_included_domains)) {
				data.isIncluded = 1;
				includedDomains++;
			} else {
				data.isIncluded = 0;
			}
		}
//		this.displayDomainData(data, len);

		//save to session
		jQuery.get('/shop/updateSessionVar.php',{ array:'domains', variable:domain, val:domain+':'+available+':'+valid+':'+configured+':'+included+':'+preis+':'+preis_nto+':'+einmal_preis+':'+einmal_preis_nto+':'+mlz+':'+tld });
	}


	this.removeDomain = function(domain) {
		var d = document.getElementById("selected_domains");
		var data = this.findDomain(domain);
		if(data) {
			d.deleteRow(data.ndx + 1);
			if(data.isIncluded) {
				includedDomains--;
			}
			var arr = myDomains;
			myDomains = new Array();
			for(var i = 0; i < arr.length; i++) {
				if(arr[i].domain != domain) {
					myDomains.push(arr[i]);
				}
			}
			if(data.domain == this.mainDomain) {
				this.mainDomain = null;
				if(myDomains.length > 1) {
					this.setMainDomain(myDomains[0].domain, 1);
				}
			}
		delete data;
		delete arr;
		}

		//save to session
		jQuery.get('/shop/updateSessionVar.php',{ array:'domains', variable:domain, val:0 });
	}
	

	this.setMainDomain = function(domain, setCheck) {
		this.mainDomain = null;
		for(var i = 0; i < myDomains.length; i++) {
			if(myDomains[i].domain == domain) {
				this.mainDomain = domain;
				if(setCheck) {
					var inp = document.forms["f_selected_domains"].elements[i*2];       // this is a workaround for the shit-m$-ie !!!!!!
					inp.checked="checked";
				}
				myDomains[i].main_domain = true;
			} else {
				if(setCheck) {
					var inp = document.forms["f_selected_domains"].elements[i*2];       // this is a workaround for the shit-m$-ie !!!!!!
					inp.checked=false;
				}
				myDomains[i].main_domain = false;
			}
		}
	}

	this.getMainDomain = function() {
		return this.mainDomain;
	}

	this.displayDomainData = function(data, ndx) {
		var d = document.getElementById("selected_domains");
		if(!d)
		  return;
		if(data.row != null) {
		    try {
		      d.deleteRow(ndx+1);
		    } catch (e) {
		    }
		}
		var tr = d.insertRow(ndx+1);
		var td = tr.insertCell(-1);
		td.setAttribute("class", "selected_domain_name");
		
		td.appendChild(document.createTextNode(data.domain +(data.available==0?' (Transfer)':'') ));
		td = tr.insertCell(-1);
		
		if(data.isIncluded) {
			td.setAttribute("class", "selected_domain_included_isincluded");
			td.appendChild(document.createTextNode("im Paketpreis inkludiert"));
		} else {
			td.setAttribute("class", "selected_domain_included");
			var span = document.createElement("span");
			span.appendChild(document.createTextNode(data.preis));
			span.className = "preis";
			td.appendChild(span);
			span = document.createElement("span");
			span.className = "preis_nto";
			span.appendChild(document.createTextNode(data.preis_nto));
			td.appendChild(span);
			var euro = document.createElement("span");
			euro.innerHTML = "&euro;";
			td.appendChild(euro);
			euro.setAttribute("style", "float:right");

		}

		td = tr.insertCell(-1);
		var inp = document.createElement("input");
			inp.setAttribute("type", "radio");
			td.appendChild(inp);
			td.setAttribute("class", "selected_domain_radio");
			inp.setAttribute("title", "Hauptdomain");
			inp.setAttribute("name", "main_domain");
			inp.onclick = function() {dc.setMainDomain(data.domain, 1)};
		if(this.mainDomain == null) {
			this.mainDomain = data.domain;
			inp.checked = "checked";
		}
//		if(data.domain == this.mainDomain) {
//			inp.setAttribute("checked", "checked");
//		}
		td = tr.insertCell(-1);
		var bn = document.createElement("button");
		td.appendChild(bn);
		
		td.setAttribute("class", "selected_domain_remove");
		bn.onclick=function(){removeDomain(data.domain)};
		bn.className = "selected_domain_remove_btn";
		bn.setAttribute("title", "l\u00f6schen");
		data.row = tr;
		data.ndx = ndx;
	}


	this.checkDomains = function() {
		includedDomains = 0;
		gesamtPreis = 0;
		gesamtPreisNto = 0;
		var number_included_domains = 0;
		var d = document.getElementById("selected_domains");
		var n = document.getElementById("number_included_domains");
		if(n)
		  number_included_domains = document.getElementById("number_included_domains").value;
		if(document.getElementById("tr_no_rows_selected")) {
			d.deleteRow(1);
		}

		for(var i = 0; i < myDomains.length; i++) {
			data = myDomains[i];
			if(data.included && (includedDomains < number_included_domains)) {
				includedDomains++;
				data.isIncluded = 1;
			} else {
				data.isIncluded = 0;
				gesamtPreis = gesamtPreis + Number(data.preis);
				gesamtPreisNto = gesamtPreisNto + Number(data.preis_nto);
			}
			this.displayDomainData(data, i);
		}
		if(this.mainDomain == null) {
			if(myDomains[0]) {
				this.setMainDomain(myDomains[0].domain, 1);
			}
		} else {
			this.setMainDomain(this.mainDomain, 1);
		}

		if(myDomains.length == 0) {
		    if(d) {
			var tr = d.insertRow(1);
			tr.setAttribute("id", "tr_no_rows_selected");
			var td = tr.insertCell(-1);
			td.setAttribute("colspan", "4");
			td.appendChild(document.createTextNode(unescape("Noch keine Domain ausgew%E4hlt")));
		    }
		}
		
		var nu = new Number(gesamtPreis);
		if(document.getElementById("domain_gesamt_preis"))
		  document.getElementById("domain_gesamt_preis").innerHTML = nu.toFixed(2);
		this.setStyles();
	}

	this.setStyles = function() {
		for(var i = 0; i < myDomains.length; i++) {
			data = myDomains[i];
			data.row.className = (i % 2) ? "odd" : "even";
		}
	}

	this.getDomains = function(included) {
		var arr = new Array();
		for(var i = 0; i < myDomains.length; i++) {
			var data = myDomains[i];
			if(data.isIncluded == included) {
				arr.push(data.domain +(data.available==0?' (Transfer)':'') );
			}
		}
		return arr;
	}

	this.getPreisForDomain = function(domain) {
		var data = this.findDomain(domain);
		if(data)
			return data.preis;
		return "";
	}


	this.getPreisNtoForDomain = function(domain) {
		var data = this.findDomain(domain);
		if(data)
			return data.preis_nto;
		return "";
	}


	this.getPreis = function() {
		return gesamtPreis;
	}


	this.getPreisNto = function() {
		return gesamtPreisNto;
	}


	this.getPreisFirstYear = function() {
		var p = 0;
		for(var i = 0; i < myDomains.length; i++) {
			if(myDomains[i].isIncluded == 0) {
				p += Number(myDomains[i].preis * myDomains[i].mlz);
			}
		}
		return p;
	}
}

/***************************************************************************
 * ende class DomainController
 ***************************************************************************/


function saveSnapshot() {
//	alert("Lieber Adino, ich arbeite daran! Liebe Gruesse, Pedro");
	var d = encodeURIComponent(document.getElementById("main").innerHTML);
	doRequest("save_snapshot", "main=" + d, "");
}

function getProduktId() {
	var produkt_id = document.getElementById('produkt_id').value;
	return produkt_id;	
}


function getProduktName() {

	if(document.getElementById("produkt_name"))
		return document.getElementById("produkt_name").firstChild.firstChild.data;
	return "";
}


function getProduktBeschreibung() {
	if(document.getElementById('produkt_beschreibung'))
		return document.getElementById('produkt_beschreibung').firstChild.data;
	return "";
}


function getIncludedDomains() {
	var domains = dc.getDomains(1);
	return domains;
}


function getExtraDomains() {
	var domains = dc.getDomains(0);
	return domains;
}	


var opt_feature_preis = 0;
var opt_feature_preis_nto = 0;

function getOptionalFeatures(want_ids) {
	var names;
	var features = new Array();
	var of = document.getElementById("optional_features").getElementsByTagName("input");
	opt_feature_preis = 0;
	opt_feature_preis_nto = 0;

	if(!want_ids) {
		names = document.getElementById("optional_features").getElementsByTagName("tr");
	}
	for(i = 0; i < of.length; i++) {
		var inp = of[i];
		if(inp.type == "checkbox") {
			if(inp.checked) {
				var o = new Object;
				if(want_ids) {
//					features.push(inp.value);
					o.name = inp.value;
				} else {
//					features.push(names[i].firstChild.firstChild.data);
					if(names[i]) {
						o.name = names[i].getElementsByTagName("td")[0].innerHTML + " ";
						o.name += names[i].getElementsByTagName("td")[1].innerHTML;
					}
				}
				spans = names[i].getElementsByTagName("span");
				
				o.preis = Number(spans[1].innerHTML);
				o.preis_nto = Number(spans[2].innerHTML);
//				o.preis_nto = Number(inp.parentNode.previousSibling.lastChild.innerHTML);
				features.push(o);
				opt_feature_preis += o.preis;
				opt_feature_preis_nto += o.preis_nto;
			}
		}
	}
	return features;
}


function updateCart() {
	//Produkt
	var f = document.order_form;
	var str = "";	
	var produktname;
	var paketpreis = document.getElementById('input_produkt_preis').value;
	var paketpreis_nto = document.getElementById('input_produkt_preis_nto').value;
	var need_domain = document.getElementById('need_domain').value;
	
	f.paket.value = getProduktId();
	produktname = getProduktName();
	document.getElementById('cart_produkt_bezeichnung').innerHTML = produktname;
	document.getElementById('cart_produkt_name').value = produktname;
	document.getElementById('cart_produkt_preis').innerHTML = "&euro; " + paketpreis 
		+ "<input type='hidden' name='paket_preis' value='" + paketpreis + "'>";

	document.getElementById('cart_produkt_preis_nto').innerHTML = "&euro; " + paketpreis_nto; 
		+ "<input type='hidden' name='paket_preis_nto' value='" + paketpreis_nto + "'>";

	//Domain
	var mainDomain = dc.getMainDomain();
	var arr = getIncludedDomains();
	var earr = getExtraDomains();
	var number_of_selected_domains = arr.length + earr.length;
	
	str += "<input type='hidden' name='main_domain' value='" + mainDomain + "' />\n";


	if(number_of_selected_domains > 0) {
		document.getElementById("cart_customer").style.display = 'block';
		//str += "<h3 class='headline'>Ihre gew&auml;hlten Domains</h3>\n";
		document.getElementById("cart_err").innerHTML = '';
		
		var out_str = "<h3 class='headline'>Weitere Domains hinzuf&uuml;gen:</h3>";
			out_str += 'Gehen sie zur <a href="javascript:showContent(\'domain_box\')">Domainauswahl</a> zur&uuml;ck, wenn Sie weitere Domains hinzuf&uuml;gen m&ouml;chten.';
		
		var el = document.getElementById("cart_more_domains");
			el.innerHTML = out_str;
			el.style.display = 'block';
	} else {
		if(need_domain == 1) {
			var err_str = "<br><h3 class='headline'>Es wurde keine Domain ausgew&auml;hlt</h3>";
				err_str += "Bitte gehen Sie zur&uuml;ck zur <a style='text-decoration:underline;cursor:pointer' onclick='showContent(\"domain_box\")'>Domainauswahl</a>";
			
			document.getElementById("cart_err").innerHTML = err_str;
			
			document.getElementById("cart_customer").style.display = 'none';
			document.getElementById("cart_more_domains").style.display = 'none';
		} else {
			//str += "<h3 class='headline'>Es wurde keine Domain ausgew&auml;hlt</h3>";
			document.getElementById("cart_err").innerHTML = '';
		}
	}

	var trclass = 'even';
	str += "<table id='cart_table_domains'>";

	if(arr.length > 0) {
		for(var i = 0; i < arr.length; i++) {
			trclass = (trclass == 'even') ? 'odd' : 'even';
			str += "<tr class='" + trclass + "'><td>" + arr[i] + ((arr[i] == mainDomain) ? " (Hauptdomain)" : "") 
				+ "</td><td><span class='preis'>Im Paketpreis inkludiert</span>"
				+ "<span class='preis_nto'>Im Paketpreis inkludiert</span></td></tr>\n";
			str += "<input type='hidden' name='cart_domain_" + i + "' value='" + arr[i] + "'/>";
		}
	}
//	document.getElementById('cart_included_domains').innerHTML = str;

//	str = "";
	if(earr.length > 0) {
//		str += "<h3>Extra Domains</h3>\n";
		for(var i = 0; i < earr.length;i++) {
			trclass = (trclass == 'even') ? 'odd' : 'even';
			str += "<tr class='" + trclass + "'><td>" + earr[i] +  ((earr[i] == mainDomain) ? " (Hauptdomain)" : "")  
				+ "<td><span class='preis'>&euro; " + Number(dc.getPreisForDomain(earr[i])).toFixed(2) + "</span>"
				+ "<span class='preis_nto'>&euro; " + Number(dc.getPreisNtoForDomain(earr[i])).toFixed(2) + "</span></td>"
				+ "</tr>\n";
			str += "<input type='hidden' name='cart_extra_domain_" + i + "' value='" + earr[i] + "'/>";
		}
		if(dc.getPreis()) {
			//trclass = (trclass == 'even') ? 'odd' : 'even';
			//str += "<tr class='" + trclass + "'><td colspan='2'>";
			str += "<input type='hidden' name='cart_domain_preis' value='" + Number(dc.getPreis()).toFixed(2) + "'/>";
			//str += "<div id='cart_domain_preis' class='preis'>Preis Domains: &euro; " + Number(dc.getPreis()).toFixed(2) + "</div>";
			str += "<input type='hidden' name='cart_domain_preis_nto' value='" + Number(dc.getPreisNto()).toFixed(2) + "'/>";
			//str += "<div id='cart_domain_preis_nto' class='preis_nto'>Preis Domains: &euro; " + Number(dc.getPreisNto()).toFixed(2) + "</div>";
			//str += "</td></tr>";
		}
		str += "</table>";

	}
	document.getElementById('cart_extra_domains').innerHTML = str;

	//Features
	trclass = 'even';
	str = "";
	var pf = 0;
	arr = getOptionalFeatures();
	if(arr.length > 0) {
		//str += "<h3 class='headline'>Ihre gew&auml;hlten optionalen Features</h3>\n";
		str += "<table id='cart_table_optional'>";
		for(i = 0; i < arr.length; i++) {
			trclass = (trclass == 'even') ? 'odd' : 'even';
			str += "<tr class='" + trclass + "'>";
			str += "<td>" + arr[i].name;
			str += "<input type='hidden' name='cart_option_" + i + "' value='" + arr[i].name + "'></td>\n";;
			str += "<td><span class='preis'>&euro; " + Number(arr[i].preis).toFixed(2) + "</span>";
			str += "<span class='preis_nto'>&euro; " + Number(arr[i].preis_nto).toFixed(2) + "</span></td>\n";
			str += "</tr>\n";
		}
		trclass = (trclass == 'even') ? 'odd' : 'even';
		/*if(opt_feature_preis != 0) {
			str += "<tr class='" + trclass + "'><td colspan='2'>"
				+ "<span id='cart_opt_feature_preis' class='preis'>Preis opt. Features: &euro; " 
				+ Number(opt_feature_preis).toFixed(2) 
				+ "</span>"
				+ "<span id='cart_opt_feature_preis_nto' class='preis_nto'>Preis opt. Features: &euro; " 
				+ Number(opt_feature_preis_nto).toFixed(2) 
				+ "</span>"
				+ "</td></tr>";
		}*/
		str += "</table>\n\n";
		str += "<input type='hidden' name='preis_optionale_features' value='" + Number(opt_feature_preis).toFixed(2) + "'>";
		str += "<input type='hidden' name='preis_optionale_features_nto' value='" + Number(opt_feature_preis_nto).toFixed(2) + "'>";

		//str += "<br>"

		document.getElementById('cart_optional_features').innerHTML = str;
	} else { //clear opt features
		document.getElementById('cart_optional_features').innerHTML = '';
	}
	
	pf = Number(paketpreis) + Number(dc.getPreis()) + Number(opt_feature_preis);
	document.getElementById('cart_preis_gesamt').innerHTML = "Gesamtpreis monatlich: &euro; " + Number(pf).toFixed(2)
			+ "<input type='hidden' name='input_gesamtpreis' value='" + Number(pf).toFixed(2) + "'>";
	pf = Number(paketpreis_nto) + Number(dc.getPreisNto()) + Number(opt_feature_preis_nto);
	document.getElementById('cart_preis_gesamt_nto').innerHTML = "Gesamtpreis monatlich: &euro; " + Number(pf).toFixed(2)
			+ "<input type='hidden' name='input_gesamtpreis_nto' value='" + Number(pf).toFixed(2) + "'>";

	sendCartInfo(f);
}


function setNeuKunde(flag) {
	var partner='';
	if(document.getElementById("partner")) {
		partner = document.getElementById("partner").value;
	}
	doRequest('kunde', 'neu='+flag+"&partner="+partner, 'kunde');
}

function setRechnungPer(val) {
	if(document.getElementById("Rechnung_per")) {
		document.getElementById("Rechnung_per").value = val;
	}
}


function choose_zahlweise(v) {
	doRequest('zahlweise', 'typ=' + v, 'zahlweise');
}

function sendCartInfo(f) {
	sendForm(f, "cartinfo", "bestell_id");
}

function sendOrder(f) {
	if(checkOrderForm(f)) {
		//clear session
		jQuery.get('/shop/updateSessionVar.php',{ variable:'paket', val:0 });
		jQuery.get('/shop/updateSessionVar.php',{ variable:'domains', val:0 });
		jQuery.get('/shop/updateSessionVar.php',{ variable:'features', val:0 });
		
		document.getElementById('bestellung_submit_btn').disabled = true;
		sendForm(f, "sendorder", "customer");
	}
}

function isNeukunde() {
	if(document.order_form.elements.neukunde[0].checked == false)
		return 1;
	return 0;
}

function checkOrderForm(f) {
	var err = "";
	if(isNeukunde()) {
		if(f.kunde_name.value == "") {
			err += "Zuname ";
		}
		if(f.kunde_anrede.value == "Herr" || f.kunde_anrede.value == "Frau") {
			if(f.kunde_vorname.value == "") {
				err += "Vorname ";
			}		
		} else { //Firma ua
			if(f.kunde_firma.value == '')
				err += f.kunde_anrede.value+' ';
		}
		
		if(f.kunde_strasse.value == "") {
			err += "Stra\u00dfe/Nr. ";
		}
		if(f.kunde_plz.value == "") {
			err += "Postleitzahl ";
		}	
		if(f.kunde_ort.value == "") {
			err += "Ort ";
		}		
		if(f.kunde_land.value == "") {
			err += "Land ";
		}		
		if(f.kunde_fon.value == "") {
			err += "Telefon ";
		}		
		if(f.kunde_email.value == "") {
			err += "EMail ";
		}
		if(err != "") {
			err = "Bitte erg\u00e4nzen Sie folgende Angaben (Pflichtfelder): " + err;
		} else {
			var flag = 0;
			
		if(f.kunde_anrede.value == "Herr" || f.kunde_anrede.value == "Frau") {
			var date = new Date();
			var yy = date.getFullYear();
			
			if(yy - f.kunde_gebjahr.value < 18) {
				flag = 1;
			} else if (yy - f.kunde_gebjahr.value == 18) {
				var mm = date.getMonth() + 1;
				if(mm < f.kunde_gebmonat.value) {
					flag = 1;
				} else if(mm == f.kunde_gebmonat.value) {
					var dd = date.getDate();
					if (dd < f.kunde_gebtag.value) {
						flag = 1;
					}
				}
			}
			if(flag > 0) {
				err = "Mindestalter nicht erreicht - kein Vertragsabschluss m\u00f6glich!";
			}
		}
	}
	} else {
		if(f.kunden_email.value == "") {
			if(f.kunden_nummer.value == "") {
				err += "Bitte geben Sie uns entweder Ihre Kundennummer oder die bei uns registrierte Email-Adresse an ";
			}
		}
	}
	
	if(err != "") {
		alert(err);
		return false;
	}		
	
	if(!f.elements.agb.checked) {
		alert("Bitte best\u00e4tigen Sie, dass Sie mit den AGB einverstanden sind!");
		return false;
	}
	return true;		
}


function toggle_name(e) {
	//alert(e.value);
	f = e.form;
	if(e.value == "Herr" || e.value == "Frau") {
		document.getElementById('kunde_firma_txt').style.display = 'none';
		document.getElementById('kunde_firma_input').style.display = 'none';
		
		//document.getElementById('kunde_vorname_txt').style.display = 'inline';
		//document.getElementById('kunde_vorname_input').style.display = 'inline';
		document.getElementById('kunde_geburtsdatum_txt').style.display = 'inline';
		document.getElementById('kunde_geburtsdatum_input').style.display = 'inline';
		//document.getElementById('kunde_zuname_txt').innerHTML = "Zuname";
	} else {
		document.getElementById('kunde_firma_txt').innerHTML = e.value;
		document.getElementById('kunde_firma_txt').style.display = 'inline';
		document.getElementById('kunde_firma_input').style.display = 'inline';
		
		//document.getElementById('kunde_vorname_txt').style.display = 'none';
		//document.getElementById('kunde_vorname_input').style.display = 'none';
		document.getElementById('kunde_geburtsdatum_txt').style.display = 'none';
		document.getElementById('kunde_geburtsdatum_input').style.display = 'none';
		//document.getElementById('kunde_zuname_txt').innerHTML = "Name";

	}
}


function toggle_name_abweichend(e) {
	//alert(e.value);
	f = e.form;
	if(e.value == "Herr" || e.value == "Frau") {
		document.getElementById('abweichend_kunde_firma_txt').style.display = 'none';
		document.getElementById('abweichend_kunde_firma_input').style.display = 'none';
		/*document.getElementById('abweichend_kunde_vorname_txt').style.display = 'inline';
		document.getElementById('abweichend_kunde_vorname_input').style.display = 'inline';
		document.getElementById('abweichend_kunde_zuname_txt').innerHTML = "Zuname";*/
	} else {
		document.getElementById('abweichend_kunde_firma_txt').innerHTML = e.value;
		document.getElementById('abweichend_kunde_firma_txt').style.display = 'inline';
		document.getElementById('abweichend_kunde_firma_input').style.display = 'inline';
		/*document.getElementById('abweichend_kunde_vorname_txt').style.display = 'none';
		document.getElementById('abweichend_kunde_vorname_input').style.display = 'none';
		document.getElementById('abweichend_kunde_zuname_txt').innerHTML = "Name";*/

	}
}

function with_ust() {
	if(document.getElementById("inkl_mwst")) {
		return document.getElementById("inkl_mwst").checked ? true : false;
	}
	return true;
}


function findCssRule(name, sheet) {
	if(!sheet) {
		for(var i = 0; i < document.styleSheets.length; i++) {
			var ret = findCssRule(name, document.styleSheets[i]);
			if(ret)
				return ret;
		}
		return null;
	}

	var myRules = sheet.cssRules ? sheet.cssRules : sheet.rules;
	if(sheet.imports) {                                          // IE !!!
		for(var i = 0; i < sheet.imports.length; i++) {
			var r = findCssRule(name, sheet.imports[i]);
			if(r) {
				return r;
			}
		}
	}
	for(var j = 0; j < myRules.length; j++) {
		try {
			if(myRules[j].styleSheet) {
				var r = findCssRule(name, myRules[j].styleSheet);
				if(r) {
					return r;
				}			
			} else if(myRules[j].selectorText == name) {
				return myRules[j];
			}
		} catch (e) {
				alert(j + " findCssRule(" + name + ") - Exception: " + e);
		}
	}
	return null;
}

/*function toggleUst() {
	var myrule = null;
	if(with_ust()) {
		if((myrule = findCssRule(".preis")) != null) {
			myrule.style.display = "block";
		}
		if((myrule = findCssRule(".preis_nto")) != null) {
			myrule.style.display = "none";
		}
	} else {
		if((myrule = findCssRule(".preis")) != null) {
			myrule.style.display = "none";
		}
		if((myrule = findCssRule(".preis_nto")) != null) {
			myrule.style.display = "block";
		}
	}
}*/

function getCssSheet(name) {
	for(var i = 0; i < document.styleSheets.length; i++) {
		var ret = findCssRule(name, document.styleSheets[i]);
		if(ret)
			return document.styleSheets[i];
	}
	return null;
}

function toggleUst() {
	var css_preis = getCssSheet('.preis');
	var css_pnto  = getCssSheet('.preis_nto');
	
	var rule;
	
	//if(jQuery.browser.msie && jQuery.browser.version.slice(0,1) <= 8) {
	if(jQuery.browser.msie) {
		if(with_ust()) {
			rule = "display:block";
			css_preis.addRule('.preis',rule);
			rule = "display:none";
			css_preis.addRule('.preis_nto',rule);
		} else {
			rule = "display:none";
			css_preis.addRule('.preis',rule);
			rule = "display:block";
			css_preis.addRule('.preis_nto',rule);
		}
	} else {
		if(with_ust()) {
			rule = ".preis { display:block; }";
			css_preis.insertRule(rule, css_preis.cssRules.length);
			rule = ".preis_nto { display:none; }";
			css_preis.insertRule(rule, css_preis.cssRules.length);
		} else {
			rule = ".preis { display:none; }";
			css_preis.insertRule(rule, css_preis.cssRules.length);
			rule = ".preis_nto { display:block; }";
			css_preis.insertRule(rule, css_preis.cssRules.length);
		}
	}
}
