// JavaScript Document
// Author : Dimitris Kossikidis


var firstBto = 0;
var afterBto = 8;
var imgfolder = "layout/bto/";
var btoForm;





/* --------------------------------------------------------- */
function PrintOffer ( prtype ){
	var frmaction = 'printoffer.php?p='+prtype;
	var frmdefaction = document.forms['btoForm'].action;	
	var winfeat = 'status=yes,scrollbars=yes,resizable=yes,width=670,height=520, menubar=yes';
	var mywin = window.open('printoffer.php','printwnd', winfeat );
	mywin.focus();
	
	document.forms['btoForm'].target = 'printwnd';
	document.forms['btoForm'].action = frmaction;
	document.forms['btoForm'].submit();
	document.forms['btoForm'].target = '_new';
	document.forms['btoForm'].action = frmdefaction;	
}

/* --------------------------------------------------------- */

/* --------------------------------------------------------- */
function ExportOffer ( prtype ){
	var frmaction = 'exportoffer.php?p='+prtype;
	var frmdefaction = document.forms['btoForm'].action;	
	var winfeat = 'status=yes,scrollbars=yes,resizable=yes,width=460,height=400, menubar=yes';
	var mywin = window.open(frmaction,'exportwnd', winfeat );
	mywin.focus();
	
	document.forms['btoForm'].target = 'exportwnd';
	document.forms['btoForm'].action = frmaction;
	document.forms['btoForm'].submit();
	document.forms['btoForm'].target = '_new';
	document.forms['btoForm'].action = frmdefaction;	
}

/* --------------------------------------------------------- */

/* --------------------------------------------------------- */

function OpenDetails( cmb ){
	if ( cmb.selectedIndex > 0 ){
		var code =  encodeURIComponent(cmb.options[cmb.selectedIndex].value) ;
		var mywin = window.open( 'popupproduct.php?code=' + code,'1product', 'status=yes,scrollbars=yes,resizable=yes,width=680,height=530' );
		mywin.focus();
	}
}

/* ---------------------------------------------------------- */
function CheckCmp( theObj ){
	
	if ( hasConstrains( theObj.name ) )
		CheckCompatibility( theObj );

	if ( theObj.name == 'hdd' || theObj.name == 'mb' ) ChkNumHdd();		
	if ( theObj.name == 'hdd2' || theObj.name == 'mb' ) ChkNumHdd2();
	if ( theObj.name == 'ram' || theObj.name == 'mb' ) ChkMbToRamQuan();
	if ( theObj.name == 'vga' || theObj.name == 'mb' ) ChkNumVGA();

	if ( theObj.name == 'cpu' )
		if ( theObj.selectedIndex > 0 )
			document.forms['btoForm'].pccode.value = dbcpu[theObj.selectedIndex-1].pccode;			
		else
			document.forms['btoForm'].pccode.value = 'none';

	UpdatePrice(theObj);
	CalculateTotals();

}


function hasConstrains( theName ){
	for ( i = 0; i < vitems.length; i++ )
		if ( vitems[i][0] == theName )
			return true;	
	return false;
}
/* ---------------------------------------------------------- */
function PopulateCombo( cmbObj, arPop, ch ){	
	var cur = "euro";
	if ( arPop.length ) {
		cmbObj.options[0] = new Option("Επιλέξτε...", 0, true, false );	
		for ( var i = 0; i < arPop.length; i++ ){
			if ( ch !='' )
				value = "" + arPop[i].company + " ["+ arPop[i][ch] +"]  "+ arPop[i].name + " ... [" + arPop[i].fprice + " \u20AC]";
			else
				value = ""+ arPop[i].company +" - "+ arPop[i].name + "... [" + arPop[i].fprice + " \u20AC]";
			cmbObj.options[i+1] = new Option(value, arPop[i].code, false, false );
		}
	}else{
		cmbObj.options[0] = new Option("Μη διαθέσιμα", 0, true, false );			
	}
}

/* ---------------------------------------------------------- */
function PopulateItems(){
	var thePos, theItem, theData, theChar, i;
	
	for (i=0; i < dbitems.length; i++){
		theItem = document.getElementById( dbitems[i][0] );		
		theData = dbitems[i][1];
		theChar = dbitems[i][3];
		PopulateCombo ( theItem, theData, theChar);
	}
}

/* ---------------------------------------------------------- */
function CheckCompatibility( selCombo ){	
	var selIdx, selData, selFilter, depCombo, i;
	
	if ( selCombo.length ){		
		selIdx = getPos(selCombo.name);
		if ( selIdx>-1 ){		
			selData= vitems[selIdx][1];		
			selDep = vitems[selIdx][2]; 
			selFilter = vitems[selIdx][3];
			for (i=0; i<selDep.length; i++){ // walking deps
				depCombo = document.getElementById( selDep[i] );
//				if ( selCombo.selectedIndex > 0 ){					
					RemoveFilters(selCombo, selData, selDep[i], selFilter[i]);						
					//ApplyFilters( selCombo, selData, selDep[i], selFilter[i] );
					depIdx = getPos(selDep[i]);
					if ( depIdx>-1 ){
						depData = vitems[depIdx][1];
						depDep = vitems[depIdx][2];
						depFilters = vitems[depIdx][3];
						for (j=0; j < depDep.length; j++ ){
							depDepCombo = document.getElementById(depDep[j]);
							if ( depDepCombo.selectedIndex > 0 )
								CheckCompatibility2(depDepCombo);
						}
					}										
			}
		}
	}
}
/* ---------------------------------------------------------- */
function CheckCompatibility2( selCombo ){	
	var selIdx, selData, selFilter, depCombo, i;
	
	if ( selCombo.length ){		
		selIdx = getPos(selCombo.name);
		if ( selIdx>-1 ){		
			selData= vitems[selIdx][1];		
			selDep = vitems[selIdx][2]; 
			selFilter = vitems[selIdx][3];
			for (i=0; i<selDep.length; i++){ // walking deps
				depCombo = document.getElementById( selDep[i] );
				if ( selCombo.selectedIndex > 0 )
					ApplyFilters( selCombo, selData, selDep[i], selFilter[i] );	
				else
					RemoveFilters(selCombo, selData, selDep[i], selFilter[i]);					
			}
		}
	}
}

/* ---------------------------------------------------------- */
function ApplyFilters( selCombo, selData, selDep, selFilter ){
	var toIdx, toCombo, toData, selProperty, toProperty, found, i;
	
	toIdx = getPos(selDep);
	if ( toIdx>-1 ){
		toCombo = document.getElementById(vitems[toIdx][0]);
		//alert ("Apply filters from " + selCombo.name +" to "+ toCombo.name);
		toData =  vitems[toIdx][1];
		
		selProperty = GetProperty( selCombo.selectedIndex-1, selData, selFilter );
		for (i=1; i<toCombo.length; i++ ){
			toProperty = GetProperty( i-1, toData, selFilter );
			found = FoundInStr( selProperty, toProperty );
			if ( !found )
				DisableOption( toCombo.options[i] );

		}

	}

}
/* ---------------------------------------------------------- */
function RemoveFilters( selCombo, selData, selDep, selFilter ){
	var toIdx, toCombo, toData, i;
	
	toIdx = getPos(selDep);
	if ( toIdx>-1 ){
		toCombo = document.getElementById(vitems[toIdx][0]);		
		//alert("removing filters from "+ selCombo.name +" to "+ toCombo.name);
		for (i=1; i<toCombo.length; i++){
			EnableOption( toCombo.options[i] );	
		}
	}
}
/* ---------------------------------------------------------- */
function ResetCombo( theCombo ){
	for(i=0; i<theCombo.length; i++)
		EnableOption( theCombo.options[i] );
}
/* ---------------------------------------------------------- */
function DisableOption( SelectedOption ){
	SelectedOption.disabled = true;
	SelectedOption.className = "NotCompatible";							
	if ( SelectedOption.selected ) SelectedOption = false;	
}
/* ---------------------------------------------------------- */
function EnableOption( SelectedOption ){
	SelectedOption.disabled = false;
	SelectedOption.className = "";		
}
/* ---------------------------------------------------------- */
function getPos( ObjectName ){
	for (i=0; i<vitems.length; i++)
		if ( vitems[i][0] == ObjectName )	
			return i;
	return -1;
}

/* ---------------------------------------------------------- */
function FoundInStr( str1, str2 ){
	var found = false;
	if ( str1 == '' || str2 == '' ) 
		found = true;
	
	var expr = ",";
	var re = new RegExp( expr, "g" );
	var res = str1.match(re);
	if ( res ){
		regs = str1.split(expr);
	}else{
		expr = "/";
		re = new RegExp( expr, "g" );
		res = str1.match(re);
		if ( res )
			regs = str1.split(expr);
		else
			regs = new Array(str1);
	}

	for (i=0; i < regs.length; i++){
		if ( str2.indexOf(regs[i])!=-1 || regs[i].indexOf(str2)!=-1 ){			
			found = true;
			break;
		}
		///alert("\"" + regs[i] + "\"");
	}	
	return found;
}

/* ---------------------------------------------------------- */
function GetProperty( idx, db, property ){
	prop = '';
	if ( idx<0 ) return prop;	
	switch( property ){
		case "socket" : prop = db[idx].socket; break;
		case "dimm"   : prop =  db[idx].dimm; break;		
		case "num_dimm"   : prop =  db[idx].num_dimm; break;
		case "hdd"   : prop =  db[idx].hdd; break;		
		case "vga"   : prop =  db[idx].vga; break;
		case "num_vga"   : prop =  db[idx].num_vga; break;
		case "color"  : prop =  db[idx].color; break;
		case "ctype"  : prop =  db[idx].ctype; break;		
		default : prop =  "";
	}
	return prop;
}



/* ---------------------------------------------------------- */
function CalculateTotals(){
	var itemquantity, itemunitprice, subtotal, totals;
	var totals=0;
	
	//reset products prices;
	for ( i=firstBto; i<document.forms['btoForm'].elements.length-afterBto; i=i+5 ) {
			if ( !document.forms['btoForm'].elements[i].selectedIndex){
				document.forms['btoForm'].elements[i+2].value="0.00";
				document.forms['btoForm'].elements[i+3].value="0.00";
			}
	}

	for ( i=firstBto; i<document.forms['btoForm'].elements.length-afterBto; i=i+5 ) {
		itemquantity  = eval(document.forms['btoForm'].elements[i+1].value);
		itemunitprice = eval(document.forms['btoForm'].elements[i+2].value);
		subtotal = eval( itemquantity * itemunitprice ); 					
		subtotal = (Math.round(subtotal*100))/100;		
		totals += subtotal;
		document.forms['btoForm'].elements[i+3].value = subtotal.toFixed(2);
		setStatus( document.forms['btoForm'].elements[i] );
	}
	
	
	var	multi = document.forms['btoForm'].elements['multi'].selectedIndex + 1;	
	totals = ( (Math.round(totals*100))/100 ) * multi; 
	var strTotals = totals;
	
	var fpaObj = document.forms["btoForm"].fpa;
	var intfpa = fpaObj.options[fpaObj.selectedIndex].value;

	document.forms['btoForm'].elements["total"].value = strTotals.toFixed(2);	
	var totalfpa = ( (totals * intfpa ) /100 )+ totals;	
	totalfpa = (Math.round(totalfpa*100))/100;	
	var strTotalFpa = totalfpa;
	document.forms['btoForm'].elements["totalfpa"].value = strTotalFpa.toFixed(2);	
	
}
/* ---------------------------------------------------------- */

/* ---------------------------------------------------------- */
/* ---------------------------------------------------------- */
function UpdateFields( theCombo, theData){
	var theForm, subtotal, itemprice, i, stock;
	theForm = theCombo.form;
	for ( i = firstBto; i<theForm.elements.length - afterBto; i++ ){
		if ( theForm.elements[i].name == theCombo.name ){
			if ( theForm.elements[i-1].selectedIndex == 0 ){
				theForm.elements[i+1].value = '0.00';
				theForm.elements[i+2].value = '0.00';
				theForm.elements[i+3].value = '';
			}else{
				stock = theData[theForm.elements[i-1].selectedIndex - 1].stock;
				itemprice = theData[theForm.elements[i-1].selectedIndex - 1].price;
				subtotal  = theCombo.selectedIndex * itemprice;
				theForm.elements[i+1].value = itemprice.toFixed(2);
				theForm.elements[i+2].value = subtotal.toFixed(2);
				theForm.elements[i+3].value = theData[theForm.elements[i-1].selectedIndex - 1].availability;
			}
			break;
		}
	}
	CalculateTotals();
}

/* ---------------------------------------------------------- */
function UpdateProduct( theCombo, theData){
	var theForm, subtotal, itemprice, i, stock;
	theForm = theCombo.form;
	for ( i = firstBto; i<theForm.elements.length - afterBto; i++ ){
		if ( theForm.elements[i].name == theCombo.name ){
			if ( theForm.elements[i].selectedIndex == 0 ){
				theForm.elements[i+2].value = '0.00';
				theForm.elements[i+3].value = '0.00';
				theForm.elements[i+4].value = '';
			}else{
				stock = theData[theForm.elements[i].selectedIndex - 1].stock;
				itemprice = theData[theForm.elements[i].selectedIndex - 1].price;
				subtotal  = theForm.elements[i+1].selectedIndex * itemprice;
				theForm.elements[i+2].value = itemprice.toFixed(2);
				theForm.elements[i+3].value = subtotal.toFixed(2);
				theForm.elements[i+4].value = theData[theForm.elements[i].selectedIndex - 1].availability; //getStock( stock );
			}
			break;
		}
	}
}

/* ---------------------------------------------------------- */
function UpdatePrice( theCombo ){
	var theData, found, i;
	found = false;
	for ( i = 0; i < dbitems.length; i++ )
		if ( theCombo.name == dbitems[i][0] ){
			theData = dbitems[i][1];
			found = true;
		}
		
	if ( found )
		UpdateProduct( theCombo, theData );
}
/* ---------------------------------------------------------- */
/* ---------------------------------------------------------- */
function getElemPos (theElem){
	var theForm, i;
	theForm = theElem.form;	
	for ( i = firstBto; i < theForm.elements.length - afterBto; i++ )
		if ( theForm.elements[i].name = theElem.name )
			return i;			
	return -1;
}

/* ---------------------------------------------------------- */
function MatchExpr( expr, mystr ){
	var result;
	var re = new RegExp( expr , "g" );
	result = mystr.match(re);
	if ( result ) return true; else return false;
}


/* ---------------------------------------------------------- */
function ChkNumHdd(){
	var vgaObj = document.forms['btoForm'].hdd;
	var vgaitemsObj = document.forms['btoForm'].hdd_items;
	var mbObj = document.forms['btoForm'].mb;
	var expr = "/"; // string splitter
	
	if ( mbObj.selectedIndex < 1 || vgaObj.selectedIndex < 1) return true;
	// assign vga char
	var vgaSlot = dbhdd[vgaObj.selectedIndex-1].hdd;	
	// assign mb vga char
	var mbVga = dbmb[mbObj.selectedIndex-1].hdd;
	// assign mb num_vga
	var numVga = dbmb[mbObj.selectedIndex-1].num_hdd;

	var imax = 0;
	var imin = 0;
	var imaxidx = 0;
	var iminidx = 0;
	var regnumVga = new RegExp( expr, "g");
	var resnumVga = numVga.match( regnumVga );	
	// found which position is the maximum allowed
	if ( resnumVga ){
		regsnumVga = numVga.split( expr );
		for ( i=0; i < regsnumVga.length; i++){
			if ( regsnumVga[i] > imax ) {
				imax = regsnumVga[i];
				imaxidx = i;
			}
			if ( regsnumVga[i] < imin || imin == 0 ){
				imin = regsnumVga[i];
				iminidx = i;
			}
		}
	}else{
		imax = numVga;
		imin = 1;
	}

	// explode mb vga
	var regmbVga = new RegExp(expr, "g");
	var resmbVga = mbVga.match( expr, "g");
	if ( resmbVga ){
		regsmbVga = mbVga.split( expr )	;
		if ( !MatchExpr ( regsmbVga[imaxidx], vgaSlot )  ){
			sel = imin;
		}else{
			sel = imax;
		}
	}else{
		if ( !MatchExpr( mbVga, vgaSlot )  )
			sel = imin;
		else
			sel = imax;
	}
	
	allow = sel - document.forms['btoForm'].hdd2_items.selectedIndex+1;
	if ( vgaitemsObj.selectedIndex  > allow ){
		if ( allow > 0 ){
			alert ("Μπορείτε να επιλέξετε μέχρι "+ allow +" HDD");
		}else{
			alert ("Δεν μπορείτε να επιλέξετε περισσότερους από "+ sel + " HDD");
		}
		
		vgaitemsObj.selectedIndex = allow;
		return false;
	}
	
}

/* ---------------------------------------------------------- */
function ChkNumHdd2(){
	var vgaObj = document.forms['btoForm'].hdd2;
	var vgaitemsObj = document.forms['btoForm'].hdd2_items;
	var mbObj = document.forms['btoForm'].mb;
	var expr = "/"; // string splitter
	
	if ( mbObj.selectedIndex < 1 || vgaObj.selectedIndex < 1) return true;

	// assign vga char
	var vgaSlot = dbhdd[vgaObj.selectedIndex-1].hdd;	

	// assign mb vga char
	var mbVga = dbmb[mbObj.selectedIndex-1].hdd;
	// assign mb num_vga
	var numVga = dbmb[mbObj.selectedIndex-1].num_hdd;
	var imax = 0;
	var imin = 0;
	var imaxidx = 0;
	var iminidx = 0;
	var regnumVga = new RegExp( expr, "g");
	var resnumVga = numVga.match( regnumVga );
	// found which position is the maximum allowed
	if ( resnumVga ){
		regsnumVga = numVga.split( expr );
		for ( i=0; i < regsnumVga.length; i++){
			if ( regsnumVga[i] > imax ) {
				imax = regsnumVga[i];
				imaxidx = i;
			}
			if ( regsnumVga[i] < imin || imin == 0 ){
				imin = regsnumVga[i];
				iminidx = i;
			}
		}
	}else{
		imax = numVga;
		imin = 1;
	}
	// explode mb vga
	var regmbVga = new RegExp(expr, "g");
	var resmbVga = mbVga.match( expr, "g");
	if ( resmbVga ){
		regsmbVga = mbVga.split( expr )	;
		if ( !MatchExpr ( regsmbVga[imaxidx], vgaSlot )  )
			sel = imin;
		else
			sel = imax;		
	}else{
		if ( !MatchExpr( mbVga, vgaSlot )  )
			sel = imin;
		else
			sel = imax;
	}
	
	allow = sel - document.forms['btoForm'].hdd_items.selectedIndex;
	if ( vgaitemsObj.selectedIndex  > allow ){
		if ( allow > 0 ){
			alert ("Μπορείτε να επιλέξετε μέχρι "+ allow +" HDD2");
		}else{
			alert ("Δεν μπορείτε να επιλέξετε περισσότερους από "+ sel + " HDD");
		}		
		vgaitemsObj.selectedIndex = allow;
		return false;
	}	
}

/* ---------------------------------------------------------- */
function ChkMbToRamQuan(){
	var ramObj = document.forms['btoForm'].ram;
	var ramitemsObj = document.forms['btoForm'].ram_items;
	var mbObj = document.forms['btoForm'].mb;

	if ( mbObj.selectedIndex < 1 || ramObj.selectedIndex < 1) return true;
		
	var mbNumDimm = dbmb[mbObj.selectedIndex-1].num_dimm;
	
	var expr = "-";
	var re = new RegExp( expr, "g");
	var result = mbNumDimm.match(re);
	
	if ( result ){
		var regs = mbNumDimm.split("-");
		imin = regs[0];
		imax = regs[1];
		if ( ramitemsObj.selectedIndex > imax ){
			//alert("Τα τεμάχια της μνήμης πρέπει να είναι μέχρι " + imax +".");
			ramitemsObj.selectedIndex  = imax;
		}
	}else{
		if ( ramitemsObj.selectedIndex > mbNumDimm ){
			//alert("Τα τεμάχια της μνήμης πρέπει να είναι μέχρι " + mbNumDimm + "." );
			ramitemsObj.selectedIndex  = mbNumDimm;
		}
	}
}//end function 

/* ---------------------------------------------------------- */
function ChkNumVGA(){
	var vgaObj = document.forms['btoForm'].vga;
	var vgaitemsObj = document.forms['btoForm'].vga_items;
	var mbObj = document.forms['btoForm'].mb;
	var expr = "/"; // string splitter
	
	if ( mbObj.selectedIndex < 1 || vgaObj.selectedIndex < 1) return true;

	// assign vga char
	var vgaSlot = dbvga[vgaObj.selectedIndex-1].vga;	

	// assign mb vga char
	var mbVga = dbmb[mbObj.selectedIndex-1].vga;
	
	// assign mb num_vga
	var numVga = dbmb[mbObj.selectedIndex-1].num_vga;
	//	alert ("num_vga = " + numVga );
	var imax = 0;
	var imaxidx = 0;
	var regnumVga = new RegExp( expr, "g");
	var resnumVga = numVga.match( regnumVga );
	
	// found which position is the maximum allowed
	if ( resnumVga ){
		regsnumVga = numVga.split( expr );
		for ( i=0; i < regsnumVga.length; i++){
			if ( regsnumVga[i] > imax ) {
				imax = regsnumVga[i];
				imaxidx = i;
			}
		}
	}else{
		imax = numVga;
	}
		
//	alert ( "Max number is " + imax + " \n Max position is " + imaxidx);
	
	// explode mb vga
	var regmbVga = new RegExp(expr, "g");
	var resmbVga = mbVga.match( expr, "g");
	if ( resmbVga ){
//		alert ("There is a slash");
		regsmbVga = mbVga.split( expr )	;
//		alert ("Check for " + regsmbVga[imaxidx] + " in " + vgaSlot );	
		if ( !MatchExpr ( regsmbVga[imaxidx], vgaSlot )  ){
//			alert ("Not found so maximum is 1");
			maximum = 1;
		}else{
//			alert ("Found so maximum is " + imax );
			maximum = imax;
		}
	}else{
//		alert ("There is NOT a slash");		
//		alert ("Check for " + mbVga + " in " + vgaSlot );	
		if ( !MatchExpr( mbVga, vgaSlot ) ){
//			alert ("Not found so maximum is 1");
			maximum = 1;	
		}else{
//			alert ("Found so maximum is " + imax );
			maximum = imax;
		}
	}
	
	if ( vgaitemsObj.selectedIndex > maximum ){
		alert ("Μπορείτε να επιλέξετε μέχρι "+ maximum +" VGA");
		vgaitemsObj.selectedIndex = maximum;
		return;
	}
	
}// end function 

function setStatus( theCombo ){
	var theName = theCombo.name;
	var theIcon = document.getElementById(theName+"_status");

	var theQuan= document.getElementById(theName+"_items");
	for ( var i=0; i < dbitems.length; i++ ){
		if ( dbitems[i][0] == theName )
			var status = dbitems[i][2];
	}
	
	if ( theCombo.name == 'mb' )
		if ( theCombo.selectedIndex > 0 )
			if ( dbmb[theCombo.selectedIndex-1].vgaonboard == "YES" )	
				dbitems[6][2] = 0;
			else
				dbitems[6][2] = 1;
		else
			dbitems[6][2] = 0;

	if ( theCombo.name == 'cs')
		if ( theCombo.selectedIndex > 0 )
			if ( dbcs[theCombo.selectedIndex-1].power == "NO PSU" )	
				dbitems[11][2] = 1;
			else
				dbitems[11][2] = 0;
		else
			dbitems[11][2] = 0;
	

	if ( theCombo.selectedIndex > 0 && !theCombo.options[theCombo.selectedIndex].disabled )
		theIcon.src = imgfolder + "ok.gif";
	else if ( theCombo.selectedIndex > 0 && theCombo.options[theCombo.selectedIndex].disabled )
		theIcon.src = imgfolder + "err.gif";
	else if ( theCombo.selectedIndex == 0 )
		switch ( status ){
			case 0 : if ( theIcon!='undefined' ) theIcon.src = imgfolder + "opt.gif"; break;
			case 1 : if ( theIcon!='undefined') theIcon.src = imgfolder + "req.gif"; break;
			case 2 : if ( theIcon!='undefined') theIcon.src = imgfolder + "opt.gif"; break;
		}
}

function ValidateBTO( myFrm ){
	var btoFrm = myFrm;
	var message = "";

	var msg = "Η σύνθεση του υπολογιστή περιέχει λάθη ή ελείψεις.\n";
	msg += " Ελέγξτε ότι έχετε επιλέξει τα παρακάτω είδη καθώς και αριθμό τεμαχίων.\n\n";
	msg += " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n";
	msge = " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n";
	msge+= "Αν θέλετε να προχωρήσετε σε παραγγελία παρά τα σφάλματα πατήστε \"OK\"\n";
	msge+= "Αν δεν θέλετε να διορθώσετε την υπάρχουσα σύνθεση πατήστε \"CANCEL\"";
	if ( btoFrm.cpu.selectedIndex == 0 || document.forms['btoForm'].cpu_items.selectedIndex == 0 || btoForm.cpu.options[btoForm.cpu.selectedIndex].disabled )
		message += "--> CPU\n\n";
	
	if ( btoFrm.mb.selectedIndex == 0 || document.forms['btoForm'].mb_items.selectedIndex == 0 || btoForm.mb.options[btoForm.mb.selectedIndex].disabled)
		message += "--> Motheboard\n\n";
	else	
		if ( btoFrm.mb.selectedIndex > 0 )
			if ( dbmb[btoFrm.mb.selectedIndex-1].vgaonboard != "YES" || btoForm.vga.options[btoForm.vga.selectedIndex].disabled )
				if ( btoFrm.vga.selectedIndex == 0 || document.forms['btoForm'].vga_items.selectedIndex == 0 )
					message += "--> VGA \n\n";
	
	if ( btoFrm.ram.selectedIndex == 0 || document.forms['btoForm'].ram_items.selectedIndex == 0 || document.forms['btoForm'].ram.options[btoForm.ram.selectedIndex].disabled)
		message += "--> RAM \n\n";
	
	if ( btoFrm.hdd.selectedIndex == 0 || document.forms['btoForm'].hdd_items.selectedIndex == 0 || document.forms['btoForm'].hdd.options[btoForm.hdd.selectedIndex].disabled )
		message += "--> HDD \n\n";
	
	if ( btoFrm.cs.selectedIndex == 0 || document.forms['btoForm'].cs_items.selectedIndex == 0 || document.forms['btoForm'].cs.options[btoForm.cs.selectedIndex].disabled )
		message += "--> CASE \n\n";
	else
		if ( dbcs[btoFrm.cs.selectedIndex-1].power == "NO PSU" || document.forms['btoForm'].ps.options[btoForm.ps.selectedIndex].disabled)
			if ( document.forms['btoForm'].ps.selectedIndex == 0 || document.forms['btoForm'].ps_items.selectedIndex == 0 )
				message += "--> Power Supply\n\n";
	
	var conf = false;

	for (i=firstBto; i < document.forms['btoForm'].length - afterBto; i=i+5)
		if ( document.forms['btoForm'].elements[i].selectedIndex > 1 && document.forms['btoForm'].elements[i+1].selectedIndex > 0 ){
			conf = true;
			break;
		}

	if ( message != '' ){
		if ( conf ){
			if ( confirm( msg + message + msge) )
				return true;
			else	
				return false;
		}else{
			alert ( msg + message );
			return false;
		}
	}
	return true;

}
