
function load(width,height,url) {
    var load = window.open(url,'','scrollbars=no,menubar=no,height='+ height +',width='+ width +',resizable=yes,toolbar=no,location=no,status=no');
}

// JScript File
function isNumeric(strString){
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   
   for (i = 0; i < strString.length && blnResult == true; i++){
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1){
         blnResult = false;
      }
   }
   return blnResult;
}

function Ccur(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	    i = Math.abs(i);
	    
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	
	if(s.indexOf('.') < 0) { s += '.00'; }
	    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	        s = minus + s;
	return s;
}



function broschyr_parmberakning(){
	var bokbredden = document.forms[0].bokbredd.value;
	var bokhojden = document.forms[0].bokhojd.value;
	var bokpapper_varde = 0;
	var resultat = 0;

		bokpapper_varde = document.forms[0].Bokpapper.options[document.forms[0].Bokpapper.selectedIndex].value;
		resultat = ( (document.forms[0].OMFANG.value / 2) * (bokpapper_varde * 0.001) );
		resultat = Math.ceil( resultat );
		resultat += 1;

		if ( resultat > 6 ){
		    document.forms[0].Information.value = resultat;
		    document.forms[0].Information2.value = bokbredden;
		    document.forms[0].Information3.value = bokhojden;
		    document.forms[0].Information4.value = bokhojden;
		    document.forms[0].Information5.value = (bokbredden * 2) + resultat;
		}
		else {
		    document.forms[0].Information.value = 0;
		    document.forms[0].Information2.value = 0;
		    document.forms[0].Information3.value = 0;
		    document.forms[0].Information4.value = 0;
		    document.forms[0].Information5.value = 0;
		}
}

function forlags_parmberakning(){
    //*******************
	// INITIERA VARIABLER
	//*******************

	var bokbredden = parseInt(document.forms[0].Bokbredd.value);

	var bokhojden = parseInt(document.forms[0].Bokhojd.value);

	var bokpapper_varde = 0;

	var resultat = 0;

		bokpapper_varde = document.forms[0].Bokpapper.options[document.forms[0].Bokpapper.selectedIndex].value;

		if ( (isNaN(document.forms[0].Bokbredd.value) == false) && (isNaN(document.forms[0].Bokhojd.value) == false) && (isNaN(document.forms[0].OMFANG.value) == false) ) {

			//**************
			// BOKTJOCKLEKEN
			//**************

			resultat = ( (document.forms[0].OMFANG.value / 2) * (bokpapper_varde * 0.001) );

			resultat = Math.ceil(resultat);	

			if (resultat >= 6 ) {

				if (document.forms[0].Boksort[1].checked) {

					if (resultat > 40) 

						document.forms[0].Information.value = resultat + 5;
		
					else {

						if (resultat > 30)

							document.forms[0].Information.value = resultat + 4 ;

						else
							
							document.forms[0].Information.value = resultat + 3;
		
					}

				}

				else {

					if (resultat > 40) 

						document.forms[0].Information.value = resultat + 6;
		
					else {

						if (resultat > 30)

							document.forms[0].Information.value = resultat + 5 ;

						else {
						
					 		if (resultat > 20)
	
								document.forms[0].Information.value = resultat + 4;

							else

								document.forms[0].Information.value = resultat + 3;
		
						}

					}

				}

				//*************
				// VISA VÄRDENA
				//*************

				document.forms[0].Information2.value = bokbredden - 3 + 7;

				document.forms[0].Information3.value = bokhojden + 5;

				document.forms[0].Information4.value = parseInt(document.forms[0].Information3.value);
	
				document.forms[0].Information5.value = ( (parseInt(document.forms[0].Information2.value) + parseInt(document.forms[0].Flikar.value) ) * 2 ) + parseInt(document.forms[0].Information.value);

			}

			else {

				document.forms[0].Information.value = 0;

				document.forms[0].Information2.value = 0;

				document.forms[0].Information3.value = 0;

				document.forms[0].Information4.value = 0;
	
				document.forms[0].Information5.value = 0;
	
			}

		}

		else {

			document.forms[0].Information.value = 0;

			document.forms[0].Information2.value = 0;

			document.forms[0].Information3.value = 0;

			document.forms[0].Information4.value = 0;
	
			document.forms[0].Information5.value = 0;

		}
}

function pallberakning() {

		var STOTANTAL = 4
		var BOKANTAL = 4
		var PALLANGD = 770
		var PALLBREDD = 1170
		var Antal_bocker = 0
		var Antal_bocker_max = 0
		var Antal_bocker_rader_bredd = 0
		var Antal_bocker_rader_langd = 0
		var Antal_rader_langd = 0
		var Antal_stotar_max = 0
		var bokpappertjocklek = 0
		var Bok_bredd = 0
		var Bok_langd = 0
		var Bok_tjocklek = 0
		var hojdrader = 0
		var Ny_bok_summa = 0
		var omfangsidor = 0
		var Optimal_bok_summa = 0
		var Optimal_rader_hojd = 0
		var Optimal_rader_langd = 0
		var pall_hojd = 0
		var raknare = 0
		var Rest = 0
		var siffra = 0
		var Slutlig_hojd = 0
		var tmp_Antal_bocker_max = 0
		var Totalt_antal_bocker = 0

			if ( (parseInt(document.forms[0].Bokbredd.value)==0) || (parseInt(document.forms[0].Bokhojd.value)==0) || (parseInt(document.forms[0].Omfang.value)==0) || (document.forms[0].Bokbredd.value == "") || (document.forms[0].Bokhojd.value == "") || (document.forms[0].Omfang.value == "")) {
				document.forms[0].Information.value = "0 stycken";
				document.forms[0].Information2.value = "0 stycken";
				document.forms[0].Information3.value = "0 stycken";
			} else {

				//******************
				//INITIERA VARIABLER
				//******************

				if ((document.forms[0].Boksort[0].checked)==true) {
					siffra = 4;
					Bok_bredd = parseInt(document.forms[0].Bokbredd.value) + 6;
					Bok_langd = parseInt(document.forms[0].Bokhojd.value) + 6;
				} else {
					siffra = 1;
					Bok_bredd = document.forms[0].Bokbredd.value;
					Bok_langd = document.forms[0].Bokhojd.value;
				}
	
				omfangsidor = document.forms[0].Omfang.value;
				pall_hojd = document.forms[0].PALLANGD.value;
				bokpappertjocklek = document.forms[0].Bokpapper.options[document.forms[0].Bokpapper.selectedIndex].value;
				Bok_tjocklek = ((omfangsidor / 2) * (bokpappertjocklek * 0.001) + siffra);
	
				//***********************
				// ANTAL BÖCKER PÅ HÖJDEN
				//***********************
	
				for (raknare=0; raknare<2; raknare++) {

					if (Slutlig_hojd < ( Antal_stotar_hojd((STOTANTAL + raknare), Bok_tjocklek, pall_hojd) * (BOKANTAL + raknare) * Bok_tjocklek ) ) {
						Slutlig_hojd = (Antal_stotar_hojd(STOTANTAL + raknare, Bok_tjocklek, pall_hojd) * (BOKANTAL + raknare) * Bok_tjocklek);
						Antal_bocker = (BOKANTAL + raknare) * Antal_stotar_hojd(STOTANTAL + raknare, Bok_tjocklek, pall_hojd);
						Antal_bocker_max = BOKANTAL + raknare;
						Antal_stotar_max = Antal_stotar_hojd(STOTANTAL + raknare, Bok_tjocklek, pall_hojd);
					}

				}

				if (Antal_bocker_max < Antal_stotar_max) {
					tmp_Antal_bocker_max = Antal_bocker_max;
					Antal_bocker_max = Antal_stotar_max;
					Antal_stotar_max = tmp_Antal_bocker_max;
				}

				//***********************************
				//ANTAL BÖCKER PÅ BREDDEN OCH LÄNGDEN
				//***********************************

				Antal_rader_langd = (Math.floor(PALLANGD / Bok_langd))

				for (hojdrader=1;hojdrader<Antal_rader_langd;hojdrader++) {
					Rest = (PALLANGD - (hojdrader * Bok_langd));
					Antal_rader_bredd = (Math.floor(Rest / Bok_bredd));

					if (Antal_rader_bredd > 0) {

						Ny_bok_summa = ((Math.floor(PALLBREDD / Bok_bredd) * hojdrader) + (Math.floor(PALLBREDD / Bok_langd) * Antal_rader_bredd))

						if (Ny_bok_summa > Optimal_bok_summa) {
							Optimal_bok_summa = ((Math.floor (PALLBREDD / Bok_bredd) * hojdrader) + (Math.floor(PALLBREDD / Bok_langd) * Antal_rader_bredd));
							Antal_bocker_rader_langd = Math.floor(PALLBREDD/Bok_bredd) * hojdrader;
							Antal_bocker_rader_bredd = Math.floor(PALLBREDD/Bok_langd) * Antal_rader_bredd;
							Optimal_rader_langd = hojdrader;
							Optimal_rader_hojd = Antal_rader_bredd;
						}
					}
				}

				Totalt_antal_bocker = Antal_bocker * (Antal_bocker_rader_langd + Antal_bocker_rader_bredd);

				//*******************
				// VISA UTRÄKNINGARNA
				//*******************

				document.forms[0].Information.value = Antal_bocker + " stycken (" + Antal_stotar_max + " stötar med " + Antal_bocker_max + " böcker)";
				document.forms[0].Information2.value = (Antal_bocker_rader_langd + Antal_bocker_rader_bredd) + " stycken (" + Optimal_rader_langd + " * " + Optimal_rader_hojd + " rader)";
				document.forms[0].Information3.value = Totalt_antal_bocker + " stycken";

			}
	}
	
function Antal_stotar_hojd(Antal_stotar, Bok_tjocklek, pallangden) {
    var PALLTRALL = 150;
    var LOCKMATT = 45;

    if ( (Math.floor(pallangden) > (PALLTRALL + LOCKMATT)) && (Bok_tjocklek > 0) && (Antal_stotar > 0))
        return (Math.floor( Math.floor( (pallangden - PALLTRALL - LOCKMATT) / Bok_tjocklek ) / Antal_stotar));
    else
        return 0
	
}


function kartonnage_parmberakning(){
    
    
	//*******************
	// INITIERA VARIABLER
	//*******************

	var bokbredden = parseInt(document.forms[0].Bokbredd.value);

	var bokhojden = parseInt(document.forms[0].Bokhojd.value);

	var bokpapper_varde = 0;

	var resultat = 0;

		//**********
		//BOKBREDDEN
		//**********

		bokpapper_varde = document.forms[0].Bokpapper.options[document.forms[0].Bokpapper.selectedIndex].value;

		if ( (isNaN(document.forms[0].Bokbredd.value) == false) && (isNaN(document.forms[0].Bokhojd.value) == false) && (isNaN(document.forms[0].OMFANG.value) == false) ) {

			resultat = ( (document.forms[0].OMFANG.value / 2) * (bokpapper_varde * 0.001) );

			resultat = Math.ceil(resultat);

			if (resultat >= 6) { 

				if (document.forms[0].Boksort[1].checked) {
				
					if (resultat > 40) 

						document.forms[0].Information.value = resultat + 5;
		
					else {

						if (resultat > 30)

							document.forms[0].Information.value = resultat + 4;

						else
							
							document.forms[0].Information.value = resultat + 3;
		
					}

				}

				else {

					if (resultat > 40) 

						document.forms[0].Information.value = resultat + 6;
		
					else {

						if (resultat > 30)

							document.forms[0].Information.value = resultat + 5; 

						else {
						
					 		if (resultat > 20)
	
								document.forms[0].Information.value = resultat + 4;

							else

								document.forms[0].Information.value = resultat + 3;
		
						}

					}

				}

				//*************
				// VISA VÄRDENA
				//*************

				document.forms[0].Information2.value = parseInt(document.forms[0].Information.value) + 14;

				document.forms[0].Information3.value = bokbredden - 3;

				document.forms[0].Information4.value = bokhojden + 5;
	
				document.forms[0].Information5.value = parseInt(document.forms[0].Information3.value) + 15;

				document.forms[0].Information6.value = parseInt(document.forms[0].Information4.value) + 30;

				document.forms[0].Information7.value = parseInt(document.forms[0].Information6.value);

				document.forms[0].Information8.value = ( parseInt(document.forms[0].Information5.value) * 2 ) + parseInt(document.forms[0].Information2.value);

			}

			else {

				document.forms[0].Information.value = 0;

				document.forms[0].Information2.value = 0;

				document.forms[0].Information3.value = 0;

				document.forms[0].Information4.value = 0;
	
				document.forms[0].Information5.value = 0;

				document.forms[0].Information6.value = 0;

				document.forms[0].Information7.value = 0;

				document.forms[0].Information8.value = 0;

			}

		}

		else {

			document.forms[0].Information.value = 0;

			document.forms[0].Information2.value = 0;

			document.forms[0].Information3.value = 0;

			document.forms[0].Information4.value = 0;
	
			document.forms[0].Information5.value = 0;

			document.forms[0].Information6.value = 0;

			document.forms[0].Information7.value = 0;

			document.forms[0].Information8.value = 0;

		}

    
    
   
}// JavaScript Document
