var resizeInterval = setInterval(FitWindow,2000);
//document.writeln("<div nowrap id='loadDiv'>Loading...</div>");
var ua = navigator.userAgent.toLowerCase();
var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 

function FitWindow() {
//	if (document.readyState == 'complete') {
//		clearInterval(resizeInterval);
		//document.getElementById("loadDiv").style.display = 'none';
//	} else return;

	try { var tl = top.location.href; }
	catch(er) {}
//alert(tl + " " + location.href);
	if (tl != location.href) {
		window.resizeTo(document.body.scrollWidth,document.body.scrollHeight);
	}
}

function FrmSubmit(title,popup) {
	AddToFaves("http://www.a1credit.co.uk/currency.php?ref=Favorites", title);

	//if (popup)
		//OpenPopupWindow();
}

function AddToFaves(url, title) {
	if (GetCookie('AskFavs') != null)
		return;
	
	AddBookmark(url, title);
	
	// Set Cookie
	SetCookie("AskFavs","done");
}

function AddBookmark(url, title) {
	if (url=='' || title=='')
		return;

	if (window.external) {
		window.external.AddFavorite(url,title);
	} else if (window.sidebar) {
//       document.body.innerHTML += '<'+'a href="'+bmurl+'" title="'+bmtitle+'" rel="sidebar" target="_blank" style="display: none;" id="addbookmark">click<'+'/a>';
//       document.getElementById('addbookmark').click();
       //document.getElementById('addbookmark').outerHTML = '';		
		window.sidebar.addPanel(title, url, '');
	}
}
	
function OpenPopupWindow() {
	// Set Cookie
	var newVal = GetCookie('CardPopup');
	if (newVal == null)
		newVal = 1;
	else
		newVal = parseInt(newVal) + 1;
		
	SetCookie("CardPopup", newVal);
	
	if (newVal != 1)
		return;
		
	
	r = Math.floor(Math.random() * 20);
	switch (r)
	{
		case 0:
			url = 'http://whitelabel.moneysupermarket.com/loans/PreApply2.asp?LoansId=1646&BestBuy=1&d=1&Source=CDS';
			break;
		case 1:
			url = 'http://whitelabel.moneysupermarket.com/loans/PreApply2.asp?LoansId=1640&BestBuy=1&d=1&Source=CDS';
			break;
		case 2:
			url = 'http://whitelabel.moneysupermarket.com/loans/PreApply2.asp?LoansId=1351&BestBuy=1&d=1&Source=CDS';
			break;
		case 3:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=338&ProviderID=308&Source=CDS&BestBuy=1&Url=http://secure-uk.imrworldwide.com/cgi-bin/a/ci_800050/et_2/cg_800393/pi_1001490/ai_804300';
			break;
		case 4:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=173&ProviderID=400&Source=CDS&BestBuy=1&Url=http://clk.atdmt.com/MDG/go/mnysphsb0080000796mdg/direct/01/';
			break;
		case 5:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=671&ProviderID=553&Source=CDS&BestBuy=1&Url=http://uk.virginmoney.com/ccard/active/BannerRecorder?source=MSP-SE-31149-32129';
			break;
		case 6:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=814&ProviderID=569&Source=CDS&BestBuy=1&Url=https://www.co-operativebank.co.uk/cgi-bin/app_form/accapp_all.cgi?cardid=814';
			break;
		case 7:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=536&ProviderID=558&Source=CDS&BestBuy=1&Url=http://www.sainsburysbank.co.uk/redirect/newccards/moneysuper-stm1.html';
			break;
		case 8:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=173&ProviderID=400&Source=CDS&BestBuy=1&Url=http://clk.atdmt.com/MDG/go/mnysphsb0080000796mdg/direct/01/';
			break;
		case 9:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=785&ProviderID=439&Source=CDS&BestBuy=1&Url=http://www.morethancard.com/servlet/morethansiteselector?mkt=05KKB2KZ2I~amp~url=http://www.morethancard.com';
			break;
		case 0:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=381&ProviderID=467&Source=CDS&BestBuy=1&Url=https://acctcentre.msdwcard.com/servlet/ProcessAdvertisement?id=4766988';
			break;
		case 11:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=381&ProviderID=467&Source=CDS&BestBuy=1&Url=https://acctcentre.msdwcard.com/servlet/ProcessAdvertisement?id=4766988';
			break;
		case 12:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=381&ProviderID=467&Source=CDS&BestBuy=1&Url=https://acctcentre.msdwcard.com/servlet/ProcessAdvertisement?id=4766988';
			break;
		case 13:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=381&ProviderID=467&Source=CDS&BestBuy=1&Url=https://acctcentre.msdwcard.com/servlet/ProcessAdvertisement?id=4766988';
			break;
		case 14:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=536&ProviderID=558&Source=CDS&BestBuy=1&Url=http://www.sainsburysbank.co.uk/redirect/newccards/moneysuper-stm1.html';
			break;
		case 15:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=536&ProviderID=558&Source=CDS&BestBuy=1&Url=http://www.sainsburysbank.co.uk/redirect/newccards/moneysuper-stm1.html';
			break;
		case 16:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=536&ProviderID=558&Source=CDS&BestBuy=1&Url=http://www.sainsburysbank.co.uk/redirect/newccards/moneysuper-stm1.html';
			break;
		case 17:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=671&ProviderID=553&Source=CDS&BestBuy=1&Url=http://uk.virginmoney.com/ccard/active/BannerRecorder?source=MSP-SE-31149-32129';
			break;
		case 18:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=671&ProviderID=553&Source=CDS&BestBuy=1&Url=http://uk.virginmoney.com/ccard/active/BannerRecorder?source=MSP-SE-31149-32129';
			break;
		case 19:
			url = 'http://whitelabel.moneysupermarket.com/Cards/DoIQualifyExternal.asp?CardID=671&ProviderID=553&Source=CDS&BestBuy=1&Url=http://uk.virginmoney.com/ccard/active/BannerRecorder?source=MSP-SE-31149-32129';
			break;
	}
	//(new Image()).src='http://www.a1credit.co.uk/imglog.php?url=' + escape('CurrencyPopup: '+url);
//	url = 'http://www.a1credit.co.uk/redir.php?label=CurrencyPopup&url=' + escape(url);
	//(new Image()).src = url;
//	ele.value = url;
	//window.top.open(url,"PopUp");
	//window.focus();
}


    function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      return null;
    }
	
	function getCookieVal(offset) {
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}

	
	function SetCookie (name, value) {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }