// JavaScript Document

var cc_maincontents = new Array();
cc_maincontents[0] = "featured";
cc_maincontents[1] = "viewall";
cc_maincontents[2] = "findme";

var g3n3hashed = "";

function hideElement(id) {
	if (document.getElementById) { 
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { 
			document.id.display = 'none';
		}
		else { 
			document.all.id.style.display = 'none';
		}
	}
}

function showElement(id) {
 	if (document.getElementById) { 
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { 
			document.id.display = 'block';
		}
		else { 
			document.all.id.style.display = 'block';
		}
	}
}

function switchfeature(current_id, target_id)
{	
	var last_id = 2;
	if (target_id == 0) {target_id = last_id;}
	if (target_id > last_id ){target_id = 1;}
	closediv = 'feature_'+current_id
	showdiv = 'feature_'+target_id
	hideElement(closediv);
	showElement(showdiv);
}

function reset_btn()
{
	for (i=0;i<cc_maincontents.length;i++)
	{
		imgsrc = '/sg/personal/cards/images/cchome_'+cc_maincontents[i]+'.gif';
		document.getElementById('btn_'+cc_maincontents[i]).setAttribute("src",imgsrc);
	}
}

function close_contents()
{
	for (i=0;i<cc_maincontents.length;i++)
	{
		hideElement('content'+cc_maincontents[i]);
		hideElement('contentg3n3cards');
	}
	
}

function show_btn(id)
{
	imgsrc = '/sg/personal/cards/images/cchome_'+id+'_o.gif';
	document.getElementById('btn_'+id).setAttribute("src",imgsrc);
}

function show_content(id)
{
	showElement('content'+id);
}

function main_switch_content(id,id2)
{

	var address = top.document.location.protocol + "//" +
		  top.document.location.host +
		  top.document.location.pathname +
		  '#' + id ;			  
	location.replace(address); 
	
	reset_btn();
	show_btn(id);
	close_contents();
	show_content(id);	
	if (id2 != undefined){show_content(id2);}	
}	

//ArrROW stores the Cards
//Each card must have a corresponding Sol and Solimg ID, starting from 0, the cards must correspond with the COLUMN in the EXCELL
//e.g <a href="/sg/personal/cards/dbs_altitude_amex" id="Sol0" style="color: '#000000';">
//<img id="Solimg0" src="/sg/personal/cards/allcards/images/altitude-amex.jpg" border="0">
//the first card in the excell is DBS Altitude American Express Card therefore its Sol and Solimg number is 0
	
//ArrCol stores the ON/OFF for cards features
//The form element has to return corresponding values as per the ROW in the EXCELL
//e.g. <input type="radio" id="1" name="1" value="1" onClick="processAR1();">Credit</input>
//credit is the first item in the EXCELL, therefore its value must be 1

//MasterArr stores the generated algorithm BITS that will control the ON/OFF switch. 1 is ON 0 is OFF
//To add cards to the FRONT, just add the 

var ArrRow = 22; //number of cards
var ArrCol = 15; //number of solutions
var fieldtype;
var MasterArr=new Array(
'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','1',
'1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',
'0','1','1','1','1','1','0','0','0','1','1','1','1','1','0','1','0','0','1','0','1','0',
'1','0','0','1','1','1','0','0','0','1','0','0','0','1','1','1','0','0','0','0','0','0',
'0','0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',
'0','0','0','0','1','1','0','0','1','0','0','0','0','0','1','1','0','0','0','0','0','0',
'0','0','0','0','1','1','0','0','0','1','0','0','0','0','0','1','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0','0','0','0','1','0','1','0','0','0','1','0','1','1',
'1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',
'1','1','1','1','1','1','1','1','1','1','1','1','0','1','0','1','1','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','1',
'0','0','1','1','0','0','1','1','1','0','1','1','1','1','0','1','1','1','1','1','1','1',
'0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1',
'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');

//must have equal number of '1' to ArrRow (number of cards), this array resets the features for calculation
var SolsArr=new Array('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');
//Value stored for future expansion usage on cards finder
var ProdArr=new Array('DBS Altitude American Express Card','DBS Black American Express Card','Live Fresh by DBS','DBS Womans Card','DBS Visa Platinum Card','DBS MasterCard Platinum Card','DBS Visa Classic Card','DBS MasterCard Classic Card','DBS Esso Platinum Card','Takashimaya American Express Platinum Card','Takashimaya Visa Gold Card','Takashimaya Visa Card','CapitalCard Visa Platinum Card','BHG Visa Platinum Card','DBS SAAB Visa Platinum Card','DBS NUSS Visa Platinum Card','DBS NUS Alumni Gold MasterCard Card','MoneySmart MasterCard Debit Card','DBS CapitalCard MasterCard Platinum Debit','DBS NUS Debit Card','Takashimaya Visa Debit Card');

function RecolorElement(id,newcolor) {
		  
	if (document.getElementById) { 
		document.getElementById(id).style.color = newcolor;
	}
	else {
		if (document.layers) { 
			document.id.color = newcolor;
		}
		else { 
			document.all.id.style.color = newcolor;
		}
	}
}

function AlphaElement(id,newalpha) {
	if (document.getElementById) { 
		document.getElementById(id).style.opacity = newalpha/10;
		document.getElementById(id).style.filter  = 'alpha(opacity=' + newalpha*10 + ')';
	}
	else {
		if (document.layers) { 
			document.id.style.opacity = newalpha/10;
			document.id.style.filter  = 'alpha(opacity=' + newalpha*10 + ')';
		}
		else { 
			document.all.id.style.opacity = newalpha/10;
			document.all.id.style.filter  = 'alpha(opacity=' + newalpha*10 + ')';
		}
	}
}

function resetall(){
	for (var i = 1; i <= ArrCol; i++){
			document.getElementById(i).checked = false;
			document.getElementById(i).disabled = false;
			}
	for (var i = 0; i <= ArrRow; i++)
	{
		var divID = 'Sol' + i
		var divIDimg = 'Solimg' + i
		AlphaElement(divIDimg,"10");
		RecolorElement(divID,"#000000");
	}
}


function processAR1(){

var SolsArr=new Array('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');

var option1='';
var outstr='';
var outstr1='';
var divID='';


if (document.getElementById(1).checked == true){
	for (var i = 1; i <= ArrCol; i++){
			document.getElementById(i).disabled = false;
	}
}
if (document.getElementById(2).checked == true){
	for (var i = 3; i <= ArrCol; i++){
			document.getElementById(i).disabled = true;
	}
}
for (var j = 1; j < ArrCol; j++)
 {
  var option1='';
  var outstr='';
  var outstr1='';
  if (document.getElementById(j).checked == true){
  option1 = j;
   for (var i = 0; i < ArrRow; i++)
   {
	if (option1 > 0){
	SolsArr[i] = SolsArr[i] * MasterArr[((option1-1)*ArrRow)+i];
	outstr1=outstr1+MasterArr[((option1-1)*ArrRow)+i]+' ';
	}
   }
  }

	
   for (var i = 0; i < ArrRow; i++)
   {
	if (SolsArr[i] == '1'){
	var divID = 'Sol' + i
	var divIDimg = 'Solimg' + i
	AlphaElement(divIDimg,"10");
	RecolorElement(divID,"#000000");
	}
	if (SolsArr[i] == '0'){
	var divID = 'Sol' + i
	var divIDimg = 'Solimg' + i
	AlphaElement(divIDimg,"2");
	RecolorElement(divID,"#cccccc")
	}

	outstr=outstr+SolsArr[i]+' ';

	if (outstr =='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'){
	}
   }
 }
}

function cards_deeplink(){
if (location.href.indexOf("#") != -1) {
 if (g3n3hashed == ""){
        if (location.href.indexOf("findme") != -1){
		  main_switch_content('findme','g3n3cards');
		}
		if (location.href.indexOf("viewall") != -1){
		  main_switch_content('viewall','g3n3cards');
		}
		if (location.href.indexOf("featured") != -1){
		  main_switch_content('featured');
		}
		g3n3hased = "YES";
 }
}
}
