// Setup ------------------------------------------------------------------------------------------------------------------------------

// Liste der Softwarelösungen
var Products = new Array('Office Line Basic',
						 'Office Line Business',
						 'Classic Line Standard',
						 'Classic Line Professional',
						 'Personalwirtschaft',
						 'ACT',
						 'Sage CRM',
						 'SalesLogix');
// Produktgruppen
var ProductGrps = 		new Array(3);
	ProductGrps[0] =	new Array(0,1,2,3);
	ProductGrps[1] =	new Array();
	ProductGrps[1][0] = 4;
	ProductGrps[2] =	new Array(5,6,7);
// Varible ID der HTML Seite							
var pfBestStr = new Array(
						  'pfOLBest',
						  'pfOLBest',
						  'pfOLBest',
						  'pfOLBest',
						  'pfOLBestPW',
						  'pfCRMBest',
						  'pfCRMBest',
						  'pfCRMBest'
						  );
var pfVarBestStr = new Array(8);
	pfVarBestStr[0] = new Array('pfOLProductName','pfOLBr','');
	pfVarBestStr[1] = new Array('pfOLProductName','pfOLBr','');
	pfVarBestStr[2] = new Array('pfOLProductName','pfOLBr','');
	pfVarBestStr[3] = new Array('pfOLProductName','pfOLBr','');
	pfVarBestStr[4] = new Array('','','');
	pfVarBestStr[5] = new Array('pfCRMProductName','pfCRMBr','');
	pfVarBestStr[6] = new Array('pfCRMProductName','pfCRMBr','');
	pfVarBestStr[7] = new Array('pfCRMProductName','pfCRMBr','');
							 
// Produkt Links
// 
var ProdLinks= new Array('/smb/prodloes/ol/evolution/evolution.asp',
						 '/smb/prodloes/ol/evolution/evolution.asp',
						 '/smb/prodloes/cl/',
						 '/smb/prodloes/cl/',
						 '/smb/prodloes/pw/',
						 '/smb/prodloes/act/',
						 '/smb/prodloes/sage%5Fcrm/',
						 '/smb/prodloes/sales%5Flogix/');

//Packshots
var Packshots= new Array('http://www.sage.de/images/smb/packshots/office_line_pb.png',
						 'http://www.sage.de/images/smb/packshots/office_line_pb.png',
						 'http://www.sage.de/images/smb/packshots/classic_line_pb.png',
						 'http://www.sage.de/images/smb/packshots/classic_line_pb.png',
						 'http://www.sage.de/images/smb/packshots/personalwirtschaft_pb.png',
						 'http://www.sage.de/images/smb/packshots/act_pb.png',
						 'http://www.sage.de/images/smb/packshots/sage_crm_pb.png',
						 'http://www.sage.de/images/smb/packshots/slx_pb.png');



// Anwendungsbereiche welche die Software erfüllen soll
var AppProp  = new Array('Finanzbuchhaltung',
						 'Anlagenbuchhaltung',
						 'Controlling',
						 'Business Intelligence',
						 'Kostenrechnung',
						 'Mahnwesen',

						 'Lager & Beschaffung',
						 'Angebote & Faktura',
						 'Produktionsplanung',
						 'Produktkonfiguration',
						 'Projektverwaltung',

						 'Lohn & Gehalt',
						 'Reisekosten',
						 'Zeitwirtschaft',
		
						 'Kundenservice / Support',
						 'Marketing',
						 'Kundenmanagement / CRM',
						 'eBusiness',
						 'Mobiler Datenzugriff');
// 	weitere Angaben
var AppSett  = new Array('1-3 Arbeitsplätze',
						 '4-10 Arbeitsplätze',
						 '11-49 Arbeitsplätze',
						 '>50 Arbeitsplätze',

						 'Dienstleister',
						 'Hersteller',
						 'Handel',
						 'Öffentliche Einrichtung',
						 'Non-Profit Organisationen',

						 'Windows',
						 'Linux/Unix',
						 'egal',
		
						 'günstige Standardlösung',
						 'egal',
						 'individuelle, integrierbare Lösung');

// 	Matrix nach welcher das Produkt bestimmt wird!!!
//	Die Zeilen entsprechen den Einträgen des AppProp Arrays - Spalten  entsprechen den Softwarelösungen ( Products Array )
//	
//	Die einzelnen Zeilen werden durch die Checkboxen auf der Html Seite ausgewählt.
//	Ausgwählte Zeilen werden spaltenweise aufsummiert - Die größte Summe gewinnt
var AppPropArray       = new Array(AppProp.length);
	AppPropArray[  0 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  1 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  2 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  3 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  4 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  5 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  6 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  7 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[  8 ] = new Array( 10, 10,   5,   5,  0,  0,  0,  0 );
	AppPropArray[  9 ] = new Array(  0, 1000, 0,   0,  0,  0,  0,  0 );
	AppPropArray[ 10 ] = new Array( -10,10,   0,   0,  0,  0,  0,  0 );
	AppPropArray[ 11 ] = new Array(  0,  0,  10,  10, 10,  0,  0,  0 );
	AppPropArray[ 12 ] = new Array( -2, -1,  10,  10, 10,  0,  0,  0 );
	AppPropArray[ 13 ] = new Array( -2, -1,  10,  10, 10,  0,  0,  0 );
	AppPropArray[ 14 ] = new Array(  0,  0,-100,-100,  0, -1, 10, 10 );
	AppPropArray[ 15 ] = new Array(  0,  0,-100,-100,  0, -1, 10, 10 );
	AppPropArray[ 16 ] = new Array(  0,  0,   0,   0,  0, 10,  5,  5 );
	AppPropArray[ 17 ] = new Array( 10, 10,  10,  10,  0,  0,  0,  0 );
	AppPropArray[ 18 ] = new Array( 10, 10,  10,  10,  0,  0,  0, 10 );

// 	weitere Angaben (Rechengrundlage)
var AppSettArray      = new Array(AppSett.length);
	//workstations
	AppSettArray[ 0 ] = new Array( 10,  3, 10,  3, 10, 10,  5,  3 );
	AppSettArray[ 1 ] = new Array(  0, 10,  0, 10, 10,  5, 10,  5 );
	AppSettArray[ 2 ] = new Array(  0, 10,  0,  7, 10,  0, 10, 10 );
	AppSettArray[ 3 ] = new Array(  0, 10,  0,  7, 10,  0,  4, 10 );

	//industry
	AppSettArray[ 4 ] = new Array( 10, 10,  0,  0, 10, 10, 10, 10 );
	AppSettArray[ 5 ] = new Array( 10, 10, 10, 10, 10, 10, 10, 10 );
	AppSettArray[ 6 ] = new Array( 10, 10, 10, 10, 10, 10, 10, 10 );
	AppSettArray[ 7 ] = new Array( 10, 10,  5,  5, 10, 10, 10, 10 );
	AppSettArray[ 8 ] = new Array( 10, 10,  5,  5, 10, 10, 10, 10 );

	//operating system
	AppSettArray[ 9 ]  = new Array(   0,   0,   0,   0,   0,   0,   0,   0 );
	AppSettArray[ 10 ] = new Array(-100,-100,1000,1000,-100,-100, 100, 100 );
	AppSettArray[ 11 ] = new Array(   0,   0,   0,   0,   0,   0,   0,   0 );

	//customisability
	AppSettArray[ 12 ] = new Array(  5, -5, 10,  5,-10, 10,  0,-10 );
	AppSettArray[ 13 ] = new Array(  1,  1,  0,  0,  0,  0,  5,  0 );
	AppSettArray[ 14 ] = new Array(  7, 10,  0,  0, 10,  0,  5, 10 );

var settingsCount = AppPropArray.length+AppSettArray.length;
var productsCount = Products.length;
var choice = new Array( settingsCount );

var step = 1;
var steps = 4;

function pfInit() // Setz wohl beim starten alles auf Anfang
{
	pfResetChoice();
	for ( var i = 1; i <= steps; i++ )
	{
		var o = pfByID( 'pfStep' + i );
		o.style.display = 'none';
	}
	ResetProd();
	pfReset();		// Setzt die Comboboxen auf none
	pfSwapStep();	// Erste Seite wird erstellt
};
// Setup end -----------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------------------

function pfReset(){	// Reset der Comboboxen
	var arr = new Array('pfDefault','pfOLBest','pfOLBestPW','pfOLBestCRM','pfCRMBest','pfCRMBestOL');
	var o;
	for(var i in arr){
		o = pfByID(arr[i]);
		o.style.display = 'none';
	}	
};
function pfSubmit()
{
	return false;
};
function pfByID( id )	// Elemente des Dokuments werden ausgelesen
{
	return document.getElementById( id );
};
function pfSwapStep()
{
	var o = pfByID( 'pfStep' + step );

	if ( o.style.display == 'none' )
		o.style.display = 'block';
	else
		o.style.display = 'none';
};
function pfNextStep( id )	// schaltet die Seiten weiter (ist exakt das gleiche wie die nächste Funktion!?)
{
	pfSwapStep();
	step = id;//++;
	pfSwapStep();
};
function pfPrevStep( id )
{
	pfSwapStep();
	step = id;//--;
	pfSwapStep();
};
function pfResetChoice()	//Löscht die Auswahl (Sowohl aus dem Anwendungbereich wie auch aus den Anderen)
{
	for ( var i = 0; i < settingsCount; i++ )
		choice[ i ] = false;
};
function ResetProd(){
	for ( var i = -1; i <= productsCount; i++ )
	{
		var o = pfByID( 'pfProduct' + i );
		o.style.display = 'none';
	}	
};
function pfGetRadioChoice( id, num, index )	// Liest die Radiobuttons aus und schreibt die Auswahl in den choice Array
{
	for ( var i = 0; i < num; i++ )
	{
		var o = pfByID( id + i );
		choice[ index + i ] = o.checked;
		if(choice[ index + i ])
		 	var ret = index + i;
	}
	return(ret);
};
function SumProduct(){	// Macht das gleiche wie die Exel Datei (Diese Funktion sollte meiner Meinung nach die richtige Software auswählen)
	
	var SumAppProp = new Array( productsCount );
	var SumAppSett = new Array( productsCount );
		
	for (var ProdIndex = 0; ProdIndex < productsCount; ProdIndex++){							// For-Schleife über alle Produkte
		SumAppProp[ ProdIndex ] = 0;
		SumAppSett[ ProdIndex ] = 0;									
			
		for ( var i in AppPropArray)
			SumAppProp[ ProdIndex ] += (choice[i]) ? AppPropArray[i][ProdIndex] : 0;			// wenn Anwendungseigenschaft ausgewählt dann Summe(Auswahl & Wert)
																								// (über Anwendunsbereich, AnBu, Controlling etc.)
		if (SumAppProp[ ProdIndex ]>0){
			for ( var j = 0; j < AppSettArray.length; j++){
				SumAppSett[ ProdIndex ] += (choice[j+21]) ? AppSettArray[j][ProdIndex] : 0;		// wenn Summe > 0 dann wird weiter summiert
			}																					// (über die Einträge Arbeitsplätze, Brache ...)
			results[ ProdIndex ] = SumAppProp[ ProdIndex ]+SumAppSett[ ProdIndex ];
		}else{
			results[ ProdIndex ] = 0;
		}
	}
	//alert(SumAppProp);
};
function getMaxResultValue(Indexes){ //gibt den Maximalwert aus den angegebenen Indices von results an
	var maxRes = 0;
	var maxInd = -1
	for(var i in Indexes){
		if(results[Indexes[i]]>maxRes){
			maxRes = results[Indexes[i]];
			maxInd = Indexes[i];
		}
	}
	return(maxInd);
}
function setDElement(IDs , Val){
	for(var ID in IDs){
		if(IDs[ID] != ''){
			document.getElementById(IDs[ID]).firstChild.data = Val;	
		}
	}
}
function pfCalculate()
{
	pfResetChoice();
	ResetProd();
	pfReset();
	
	var solutionString = '';
	var osString = '?';
	var workspaceString = '?';
	var userString = '?';
	
	var customString = '?';
	for ( var i = 0; i < AppProp.length; i++ )
	{
		var o = pfByID( 'pfID' + i );
		choice[ i ] = o.checked;
		if ( o.checked ) {
			solutionString += AppProp[ i ] + ', ';
		}		
	}
	
	solutionString = solutionString.substr( 0, solutionString.length - 2 );
	
	// Auswahl String wird erstellt
	workspaceString = AppSett[pfGetRadioChoice( 'pfWS', 4, 21 )-AppProp.length];
	userString      = AppSett[pfGetRadioChoice( 'pfBr', 5, 25 )-AppProp.length];
	osString		= AppSett[pfGetRadioChoice( 'pfOS', 3, 30 )-AppProp.length];
	customString	= AppSett[pfGetRadioChoice( 'pfCA', 3, 33 )-AppProp.length];
	
	setDElement(new Array('pfOLBr','pfUserString','pfCRMBr') , userString);
	setDElement(new Array('pfCRMId','pfOLId') , solutionString);
	
	//-- Pesonalmanagement als Einziges ausgewählt ?

		
// Produktauswahlroutine -----------------------------------------------------------------------------------------------------------------------------
	results    = new Array( productsCount );
	SumProduct();	
	//alert(results); // Unkommentieren um mit Exeltabelle zu vergleichen ( Achtung Reihenfolge ist etwas anders) 
	Res = getMaxResultValue(new Array(0,1,2,3,4,5,6,7));
	o = pfByID( 'pfProduct' + Res );	// Produktauswahl
	o.style.display = 'block';
	var CRMHeadline = 'Sage CRM';
	var DPackShot = -1;
	
	for(var Index in ProductGrps){	// Produktbeschreibung
		var ID = getMaxResultValue(ProductGrps[Index]);
		if(ID > -1){
			if(Index == 0){
				// Result in Hauptgruppe
				CRMHeadline = Products[ID];
				DPackShot = ID;
			}
			o = pfByID('pfDefault');
			o.style.display = 'block';
			
			o = pfByID(pfBestStr[ID]);
			o.style.display = 'block';
			setDElement(new Array(pfVarBestStr[ID][0]) , Products[ ID ]);
			selID = ID;
		}
	}

	// Headline Sage CRM
	setDElement(new Array('pfCRMHead') , CRMHeadline);
	
	
// Ende Produktauswahl ----------------------------------------------------------------------------------------------------------------------------
	var btn = pfByID( 'pfContactButton' );
	var ifb = pfByID( 'pfInfoButton' );
	var img = pfByID( 'pfProductShot' );
	
	if(Res > -1){
		// Angebotbutton Auswahl wird gesetzt
		btn.href = '/smb/kontakt/kontaktformular.asp?thema=prodkonf&bestProduct=' + Products[ selID ] + ' für ' + solutionString + ' für ' + userString + ' mit ' + workspaceString + ' auf dem Betriebssystem ' + osString + '. Anpassbarkeit: ' + customString;

		// Infobutton Auswahl wird gesetzt
		ifb.href = ProdLinks[ selID ];
		btn.style.display = 'block';
		ifb.style.display = 'block';
		img.style.display = 'block';
		
	} else {
		btn.style.display = 'none';
		ifb.style.display = 'none';
		img.style.display = 'none';
	}
	
	document.getElementById('pfProductShot').src = Packshots[ selID ] ;
	
    var newLink = ProdLinks[ selID ].replace('/smb/prodloes/','') ;
    
}

