// Only show the warning once until the options change
var warning_shown = 0;
	
function process_product_options(name) {
	
	var questions = new Array();
	questions[2] = 0;
	questions[3] = 0;
	questions[4] = 0;
	questions[5] = 0;
	questions[6] = 0;
	questions[7] = 0;
	
	var recommendations = new Array();
	recommendations[0]  = 0; // Basic EFTPOS
	recommendations[1]  = 0; // EFTPOS + (CPC and Hospitality)
	recommendations[2]  = 0; // EFTPOS + (CPC)
	recommendations[3]  = 0; // EFTPOS + (Hospitality)
	recommendations[4]  = 0; // EFTPOS + (Top-up)
	recommendations[5]  = 0; // EFTPOS + (Hospitality and Top-up)
	recommendations[6]  = 0; // POSLink
	recommendations[7]  = 0; // Fixed Wireless EFTPOS
	recommendations[8]  = 0; // PC EFTPOS
	recommendations[9]  = 0; // Mobile EFTPOS
	recommendations[10] = 0; // ANZ eGate – Server Hosted
	recommendations[11] = 0; // ANZ eGate? – Merchant Hosted + Authentication
	recommendations[12] = 0; // Mail, Fax or Telephone Order

	var register_checked = check_register();
	
	var list = new Array();
	list[0] = 0; // POSLink - cash registers
	list[1] = 0; // Point of sale list
	// This is the actual thinking part. Run through the selected options for each
	// question and build the array of what needs to be displayed
	
	// Multi select on Q1, Q2, Q6
	
	// Question 1 - answer A - Face to Face (over the counter)
	if ( document.productSelector.qnum1a.checked ) {
		questions[2] = 1;
		if ( document.productSelector.qnum2[1].checked ) {
			// If Q2 = A or B => Q3
			questions[3] = 1;
			if ( document.productSelector.qnum3[0].checked ) {
				// If Q3 = A => Q4
				// list of cash registers
				list[0] = 1;
				questions[4] = 1;
			} else if ( document.productSelector.qnum3[1].checked ) {
				// IF Q3 = B => Q4
				// list point of sale pc cert
				list[1] = 1;
				questions[4] = 1;
			} else if ( document.productSelector.qnum3[2].checked ) {
				// IF Q3 = C => Q5
				questions[5] = 1;
				if ( document.productSelector.qnum5[0].checked ) {
					recommendations[7]  = 1;// recomendation - fixed wireless
					recommendations[0]  = 1;// Recomendation - basic eftpos
					
				}
			}
			if ( questions[4] == 1 ) {
				// We're in Q4
				if ( document.productSelector.qnum4[0].checked && document.productSelector.qnum3[0].checked && register_checked ) {
					// If Q4 = A and 3 = An Electronic Cash Register
					recommendations[6]  = 1;// recomendation - poslink		
					//recommendations[0]  = 1;// Recomendation - basic eftpos
				} else if ( document.productSelector.qnum4[0].checked && document.productSelector.qnum3[1].checked && register_checked ) {
					// If Q4 = A and 3 = A Point of Sale System
					recommendations[8]  = 1;// recomendation - pc eftpos	
					recommendations[6]  = 1;// recomendation - poslink				
				} else if( document.productSelector.qnum4[1].checked ) {
					// If Q4 = C => Q5
					questions[5] = 1;
					//recommendations[8]  = 1;// recomendation - pc eftpos	
					//recommendations[6]  = 1;// recomendation - poslink
					//recommendations[0]  = 1;// Recomendation - basic eftpos
				}
				
			}
			
		} else if ( document.productSelector.qnum2[0].checked ) {
			// If Q2 = A
			//recommendations[0]  = 1;// Recomendation - basic eftpos
			//questions[5] = 1;
			questions[8] = 1;
			if ( document.productSelector.qnum8[1].checked ) {
			// if Q8 (Q3) = B
				questions[5] = 1;
				
			} else if ( document.productSelector.qnum8[0].checked ) {
			// If Q8 = A
				
					// If Q3 = A => Q4
					// list of cash registers
					list[0] = 1;
					questions[4] = 1;
				
			}
			if ( questions[4] == 1 ) {
				// We're in Q4
				if ( document.productSelector.qnum4[0].checked && document.productSelector.qnum8[0].checked && register_checked ) {
					// If Q4 = A 
					recommendations[6]  = 1;// recomendation - poslink
					recommendations[0]  = 1;// Recomendation - basic eftpos
							
				} else if( document.productSelector.qnum4[1].checked ) {
					// If Q4 = C => Q5
					questions[5] = 1;
				}
			}
			if ( document.productSelector.qnum5[0].checked ) {
				// if Q5 = A
				recommendations[0]  = 1;// Recomendation - basic eftpos
				recommendations[7]  = 1;// Recomendation - fixed wireless
			} else if ( document.productSelector.qnum5[1].checked ) {
				// if Q5 = B
				recommendations[0]  = 1;// Recomendation - basic eftpos
			}
		}
		if ( document.productSelector.qnum2[1].checked && questions[5] == 1 ) {
			// We're in Q5
			if ( document.productSelector.qnum5[0].checked ) {
				// If Q5 = A 
				recommendations[7]  = 1;// recomendation - fixed wireless
				recommendations[0]  = 1;// Recomendation - basic eftpos
			} else if ( document.productSelector.qnum5[1].checked ) {
				// If Q5 = B => Q6
				questions[6] = 1;
				// Q6 is multi choice
				
				if ( document.productSelector.qnum6a.checked && document.productSelector.qnum6b.checked ) {
					// If A + B =>
					recommendations[1]  = 1;// Recomendation - eftpos + hospo + CPC
				}
				else if ( document.productSelector.qnum6a.checked && document.productSelector.qnum6c.checked ) {
					// If A + C =>
					recommendations[5]  = 1;// Recomendation - eftpos + hospo + top up
				}
				else if ( document.productSelector.qnum6a.checked ) {
					// If Q6 = A 
					recommendations[3]  = 1;// Recomendation - eftpos + hospo
				}
				else if ( document.productSelector.qnum6b.checked ) {
					// If Q6 = B 
					recommendations[2]  = 1;// Recomendation - eftpos + CPC
				}
				else if ( document.productSelector.qnum6c.checked ) {
					// If Q6 = C 
					recommendations[4]  = 1;// Recomendation - eftpos + Top up
				}
				else if ( document.productSelector.qnum6d.checked ) {
					// If Q6 = D 
					recommendations[0]  = 1;// Recomendation - basic eftpos
				}
				
				if ( document.productSelector.qnum6b.checked && document.productSelector.qnum6c.checked ) {
					// If Q6 = A + B + C  OR B + C => Error		
					// Reset recomendations
					recommendations[1]  = 0;// Recomendation - eftpos + hospo + CPC	
					recommendations[3]  = 0;// Recomendation - eftpos + hospo + top up
					recommendations[4]  = 0;// Recomendation - eftpos + hospo 
					// Make new ones
					if ( document.productSelector.qnum6a.checked && document.productSelector.qnum6b.checked && document.productSelector.qnum6c.checked ) {
						recommendations[1]  = 1;// Recomendation - eftpos + hospo + CPC
						recommendations[4]  = 1;// Recomendation - eftpos + Top up
					} else {
						recommendations[2]  = 1;// Recomendation - eftpos + CPC
						recommendations[4]  = 1;// Recomendation - eftpos + Top up
					}
					if ( warning_shown == 0 ) {
						// Only want to show this once, unless they deselect something
					 	warning_shown = 1
						window.alert("Please note, the value-added options you have selected are not available on one EFTPOS terminal. If you require all these services you may require more than one solution.")	
					} 
				} else {
					// We can reset the warning message now
					warning_shown = 0
				}
			}
		}
	}
	
	// Question 1 - answer B - Face to Face (mobile)
	if ( document.productSelector.qnum1b.checked ) {
		questions[2] = 1;
		if ( document.productSelector.qnum2[0].checked || document.productSelector.qnum2[1].checked ) {
			// If Q2 = A or B 
			recommendations[9]  = 1;// Recomendation - mobile eftpos
		}
	} 
	
	// Question 1 - answer C - Online / internet
	if ( document.productSelector.qnum1c.checked ) {
		questions[7] = 1;
		if ( document.productSelector.qnum7[0].checked ) {
			// If Q7 = A
			recommendations[10]  = 1;// Recomendation ANZ eGate server hosted
		} else if ( document.productSelector.qnum7[1].checked ) {
			// If Q7 = B
			recommendations[11]  = 1;// Recomendation ANZ eGate Merchant hosted
		}
	} 
		
	// Question 1 - answer D - Phone Fax Mail order
	if ( document.productSelector.qnum1d.checked ) {
		recommendations[12]  = 1;// Recomendation - mail, fax, pone
	}
	
	// There are 7 questions, the first one is always visible, this will turn on/off the other ones
	// There is a special case for 8, which is sort 3 alt
	
	for ( i=2; i<=8; i++ ) {
		if ( questions[i]==1 ) {
			if ((document.getElementById("lyr_"+'ps_q_'+i).style.display==="") || (document.getElementById("lyr_"+'ps_q_'+i).style.display==="none")){
				logOCPV('isconv=0|pover=Payment Solutions - Product Selector'+i)
				//alert('setting :'+i)	
			}
			reveal('ps_q_'+i)			
			
		} else {
			disguise('ps_q_'+i)
		}
	}
	
	// There are 13 recomendations numbered 0 - 12
	disguise('ps_recomendations')
	for ( b=0; b<=12; b++ ) {
		rec = 'recomendation_'+b
		if ( recommendations[b]==1)	{
			//window.alert(b);
			reveal('ps_recomendations');
			
			// Show the recommendations
			document.getElementById(rec).value=1
		} else {
			document.getElementById(rec).value=0
		}
	}
	//logOCPV('isconv=0|pover=Payment Solutions - Product Selector2');
	var show_list = 0
	// There are two lists of things to display
	for ( x=0; x<=1; x++ ) {
		if ( list[x]==1 ) {
			show_list = 1
			reveal('list_'+x)
			reveal('list_word_'+x)
			
		} else {
			disguise('list_'+x)
			disguise('list_word_'+x)
		}
	}
	if ( show_list == 1 ) reveal('list');
}


function check_register() {
	 for (var y=0; y<document.productSelector.register.length; y++)  {
		if (document.productSelector.register[y].checked)  {
			return 1;
		}
	}
	return 0;
}

function selector_reset() {
	for ( i=2; i<=7; i++ ) {
			disguise('ps_q_'+i)
	}
	
	// There are 13 recomendations numbered 0 - 12
	disguise('ps_recomendations')
	for ( b=0; b<=12; b++ ) {
		rec = 'recomendation_'+b
		document.getElementById(rec).value=0
	}
	
	for ( x=0; x<=1; x++ ) {
			disguise('list_word_'+x)
	}
}