// JavaScript Document

function roundNumber(decimalzahl, rundungswert) {
	
    decimalzahl = String(decimalzahl).replace(/,/g, ".");
    
    decimalzahl = parseFloat(decimalzahl);

	var exp = Math.pow(10,rundungswert);
	var wert = String(Math.round(decimalzahl * exp) / exp);    

	if(wert.substr(wert.indexOf(".")).length == 3) {
		wert = wert.substr(0, wert.indexOf(".")) + wert.substr(wert.indexOf(".") ) + "";
	}
	if(wert.substr(wert.indexOf(".")).length == 1) {
		wert = wert + ".00";
	}
	if(wert.substr(wert.indexOf(".")).length == 2) {
		wert = wert + "0";
	}
    if(wert.indexOf(".") !== -1) {
		wert = wert.substr(0, wert.indexOf(".")) + "," + wert.substr(wert.indexOf(".") + 1);    
    }

    	
	return wert.replace(/\./g, ",");
}

function cshow(thisid,subAnzahl)
{ 
var divid = "step"+thisid;
if (document.getElementById(divid).style.display=="inline")
{ 
//document.getElementById(divid).style.display="none";
} else { 
document.getElementById(divid).style.display="inline";
} 
for (i=1; i<=subAnzahl; ++i) 
{ 
if ("step"+i!=divid) 
eval ('document.getElementById("step' + i + '").style.display="none"'); 
} 
} 



function addrow(step) {
 
  blocktype="table-row";
if(window.pkcs11){y='Netscape';
 if(document.ids){y+='-4'; 
   if(window.navigator.securityPolicy)y+='.7 /4.8';}
   else if(window.atob)y='-7'; 
    else y+='-6';}

else if(document.defaultCharset){y='Int.Explorer';
			blocktype = "block";
           if(document.compatMode)y+='-6';
           else if(window.createPopup)y+='-5.5';
           else if(document.uniqueID)y+='-5';
          else y='-4';}

else if(!document.createRange){y='Opera';
              if (!window.opera) y+='-4';
            else if(!window.print) y+='-5'; 
           else if(!document.createComment) y+='-6';
          else y+='-7';}

else if(document.namespaceURI) y='Konq';

    document.getElementById("s" + step + "_l" + eval("s2" + step)).style.display = blocktype;
	eval("s2" + step + " = s2" + step + " + 1");
	if(eval("s2" + step) > 10) {
		document.getElementById("addrow2").style.display = "none";
	}
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function


// prepare the form when the DOM is ready 
$(document).ready(function() { 
    // bind form using ajaxForm 
	$("#Accordion1").accordion();
	
	/*
	$('.open0').click(function(){
	$('#Accordion1').activate(0);
	});
	$('.open1').click(function(){
	$('#Accordion1').activate(1);
	});
	$('.open2').click(function(){
	$('#Accordion1').activate(2);
	});
	$('.open3').click(function(){
	$('#Accordion1').activate(3);
	});
	$('.open4').click(function(){
	$('#Accordion1').activate(4);
	}); */

	$('#holzart').ajaxForm({
        dataType: 'html',
        beforeSubmit:  function() { if(document.getElementById('s1_holzart1').value.length < 1) { alert('Bitte eine Holzart aussuchen!'); return false; } else { return true; } },
        success:  processJson
    });
    $('#holzmenge').ajaxForm({
		dataType: 'html',
		beforeSubmit:  function() { /* if(document.getElementById('s2_total').value.length < 1) { alert('pls enter...'); return false; } else { */ return true; /* } */ },
		success:  processJson
    });
    $('#unterkonstruktion').ajaxForm({
		dataType: 'html',
		beforeSubmit:  function() { /* if(document.getElementById('s3_total').value.length < 1) { alert('pls enter...'); return false; } else { */ return true; /* } */ },
		success:  processJson
     });
    $('#transport').ajaxForm({
		dataType: 'html',
		beforeSubmit: checktransport,
		success:  processJson
     });

});

function agb() {
vertragstexte = window.open("vertragstexte.php#agb", "agb", "height=750,width=450,menubar=no,scrollbars=yes,status=no,toolbar=no,location=no");
}
function impressum() {
vertragstexte = window.open("vertragstexte.php#impressum", "agb", "height=750,width=450,menubar=no,scrollbars=yes,status=no,toolbar=no,location=no");
}
function versand() {
vertragstexte = window.open("vertragstexte.php#versand", "agb", "height=750,width=450,menubar=no,scrollbars=yes,status=no,toolbar=no,location=no");
}
function widerruf() {
vertragstexte = window.open("vertragstexte.php#widerruf", "agb", "height=750,width=450,menubar=no,scrollbars=yes,status=no,toolbar=no,location=no");
}


function checktransport() {
	if(document.getElementById("transport").adr1_nachname.value == '') { alert ("Bitte tragen Sie Ihren Nachnamen ein."); return false; }
	if(document.getElementById("transport").adr1_email.value == '') { alert ("Bitte tragen Sie Ihre E-Mailadresse ein."); return false; }
	if(document.getElementById("transport").adr1_strasse.value == '') { alert ("Bitte tragen Sie Ihren Strassennamen ein."); return false; }
	if(document.getElementById("transport").adr1_strnr.value == '') { alert ("Bitte tragen Sie Ihre Hausnummer ein."); return false; }
	if(document.getElementById("transport").adr1_plz.value == '') { alert ("Bitte tragen Sie Ihre Postleitzahl ein."); return false; }
	if(document.getElementById("transport").adr1_ort.value == '') { alert ("Bitte tragen Sie Ihren Ort ein."); return false; }
	if(document.getElementById("transport").adr1_telefon.value == '') { alert ("Bitte tragen Sie Ihre Telefonnummer ein."); return false; }
	return true;
}

function bestellcheck() {
	if(document.getElementById("s5_agb").checked == false) { alert("Bitte lesen und akzeptieren Sie unsere AGB!"); return false; }
	if(document.getElementById("s5_versand").checked == false) { alert("Bitte lesen und akzeptieren Sie unsere Versandbedingungen!"); return false; }
	if(document.getElementById("s5_widerruf").checked == false) { alert("Bitte lesen und akzeptieren Sie unsere Widerrufsbelehrung!"); return false; }
	return true;
}

function angebotprocessJson(data) {
    if(data == "email") {
	    $("#s5_emailbtn").replaceWith("<div id='s5_emailbtn'><p>Vielen Dank. Wir haben Ihnen das Angebot soeben per E-Mail zukommen lassen.<"+"/p><"+"/div>"); }
    if(data == "bestellung") {
	    $("#s5_angebotbtn").replaceWith("<div id='s5_angebotbtn'><p>Vielen Dank. Wir haben Ihre Bestellung erhalten.<"+"/p><"+"/div>"); }
    //processJson(data);
}


function emailprocessJson(data) {
    $("#s5_emailbtn").replaceWith("<div id='s5_emailbtn'><p>Vielen Dank. Wir haben Ihnen das Angebot soeben per E-Mail zukommen lassen.<"+"/p><"+"/div>");
    processJson(data);
}


function processJson(data) {
    $("<p>"+data+"<"+"/p>").appendTo('#test');
}

function loaddata(id, data) {
	$(id).load(id.substr(1, id.length) + ".php", data);
}
window.onbeforeunload = function(){
 return "Durch diese Aktion wird der Konfiguration beendet und Ihr Angebot nicht erstellt.\n\n";
}