//GLOBAL VARIABLES
var cards = new Array();
var apply_link = 'https://' + document.domain + '/cgi-bin/cards/cardapp/apply.cgi';
var apply_business_link = 'https://' + document.domain + '/cgi-bin/cards/busapp/apply.cgi';
var apply_creditline_link = 'https://' + document.domain + '/cgi-bin/cards/clsb/apply.cgi';
var compare_tool_link = 'http://' + document.domain + '/products/gic/tools/compare/index.html';
var select_tool_link = 'http://' + document.domain + '/products/gic/tools/select/index.html';
// Card object constructor
//Fields correspond to excel card data file
function Card(id, name, type, weight, goal1, goal2, goal3, goal4, amount1, amount2, access1, access2, term1, term2, term3, redeemable, min_inv, inv_terms, learn_more, desc, features, int_pay_opt, plan_eligib) {
	this.id=id;
	this.name=name;
	this.type=type;
	this.weight=weight;
	this.goal1=goal1;
	this.goal2=goal2;
	this.goal3=goal3;
	this.goal4=goal4;
	this.amount1=amount1;
	this.amount2=amount2;
	this.access1=access1;
	this.access2=access2;
	this.term1=term1;
	this.term2=term2;
	this.term3=term3;
	this.redeemable=redeemable;
	this.min_inv=min_inv;
	this.inv_terms=inv_terms;
	this.learn_more=learn_more;
	this.desc=desc;
	this.features=features;	
	this.int_pay_opt=int_pay_opt;	
	this.plan_eligib=plan_eligib;	
}
//Main function -- initialise cards, check query params, display cards
function initializeCards() {
	//Initialise cards
	cards.push(new Card("p00_non_redeemable", "Non-Redeemable GICs", "Guaranteed-return", "0", "2","10","10","8", "10","10", "-99","10", "10","10","10", "No", "<ul><li>$500 for RRSP, TFSA, RESP, RDSP</li><li>$1,000*,</li><li>$5,000 (for terms between 30 - 364 days) or</li><li>$100,000 (for less than 30 days)</li></ul><br />* $5,000 for clients who wish to receive interest monthly", "<ul><li>1 to 364 days</li><li>1 - 5, 7 or 10 years</li></ul>", "/products/gic/regulargic.html", "Offers a fixed interest rate for a specific term with both principal and interest payments guaranteed.", "<ul><li>Competitive interest rates</li><li>Choice of interest payment frequency</li><li>Flexible investment terms</li><li>Security and safety</li></ul>", "<ul><li>Terms less than one year, payable at maturity</li><li>Terms greater than or equal to one year, paid monthly, semi-annually, annually, or at maturity (interest compounded annually)</li></ul>","Non-Registered, RRSPs, TFSAs, RESPs, RRIFs, LIFs and RDSP<br /><br /><span class='subcopy'>Not all payment options are available for all plan types.</span>"));
	cards.push(new Card("p01_redeemable", "Redeemable GICs", "Guaranteed-return", "0", "7","10","10","5", "10","10", "7","-99", "10","10","10", "Yes, at a reduced rate", "<ul><li>$500 for RRSP, TFSA, RESP, RDSP</li><li>$1,000*,</li><li>$5,000 (for terms between 30 - 364 days) or</li><li>$100,000 (for less than 30 days)</li></ul><br />* $5,000 for clients who wish to receive interest monthly", "<ul><li>1 to 364 days</li><li>1 - 5, 7 or 10 years</li></ul>", "/products/gic/regulargic.html", "Offers a fixed interest rate for a specific term with both principal and interest payments guaranteed.", "<ul><li>Competitive interest rates</li><li>Choice of interest payment frequency</li><li>Flexible investment terms</li><li>Security and safety</li></ul>", "<ul><li>Terms less than one year, payable at maturity</li><li>Terms greater than or equal to one year, paid monthly, semi-annually, or annually</li></ul>","Non-Registered, RRSPs, and TFSAs<br /><br /><span class='subcopy'>Not all payment options are available for all plan types.</span>"));
	cards.push(new Card("p02_five_in_one", "Five-in-One GIC<sup>&reg;</sup>", "Guaranteed-return", "0", "-99","5","5","8", "-99","10", "-99","10", "-99","-99","10", "No. A portion of the funds becomes available at each anniversary", "$5,000", "Five years", "/products/gic/5in1.html", "Principal is automatically split into five equal parts with maturities of one to five years; as each part matures, you have the options to reinvest the funds for a five-year term and continue to follow a laddering strategy, invest differently or take the funds in cash.", "<ul><li>Higher earning than short-term GIC rates</li><li>Flexibility - access to 20% of principal annually</li><li>Diversification of investment terms - reduced potential risk associated with fluctuating interest rates</li><li>Ability to take advantage of changing interest rates over time</li></ul>", "<ul><li>Monthly</li><li>Semi-annually</li><li>Annually</li><li>At maturity (interest compounded annually)</li></ul>","Non-Registered only"));
	cards.push(new Card("p03_building_block", "Building Block GIC<sup>&reg;</sup>", "Guaranteed-return", "0", "7","1","5","-99", "10","5", "6","10", "-99","10","-99", "Yes, at a reduced rate", "$1,000<br />Pre-authorized purchase options:<br /><ul><li>$10 weekly</li><li>$25 biweekly</li><li>$50 monthly</li></ul>", "One year", "/products/gic/bblock.html", "Make regular pre-authorized payments to accumulate a target amount.", "<ul><li>Convenience - automatic contributions</li><li>Security of a guaranteed rate while accumulating principal</li><li>Satisfaction of setting and realizing a goal</li><ul>", "<ul><li>Interest paid at maturity</li></ul>","Non-Registered only"));
	cards.push(new Card("p04_canadian_marketlinked", "Canadian Market-Linked GICs<sup>&reg;</sup>", "RBC Market Access", "0", "-99","5","-99","10", "10","10", "-99","10", "-99","10","-99", "No", "$1,000", "Three years", "/products/gic/marketlinked.html", "Offers a variable return based on the increase in the S&P/TSX 60 Index over the investment term.", "<ul><li>Potential to earn higher rates of return</li><li>Security of guaranteed principal</li></ul>", "<ul><li>Return, if any, paid at maturity or at time of lock-in anniversary at the end of the second year</li></ul>","Non-Registered, RRSPs, TFSAs, RDSPs and RESPs"));
	cards.push(new Card("p05_global_marketlinked", "Global Market-Linked GICs&#153;", "RBC Market Access", "0", "-99","5","-99","10", "10","10", "-99","10", "-99","10","-99", "No", "$1,000", "Three years", "/products/gic/globallinked.html", "Offers a variable return based on the increase in a weighted composite of international market indexes over the investment term, and includes DAX (Germany), CAC (France), Nikkei (Japan), FT-SE (U.K.), S&P (U.S.).", "<ul><li>Potential to earn higher rates of return</li><li>Security of guaranteed principal</li></ul>", "<ul><li>Return, if any, paid at maturity or at time of lock-in anniversary at the end of the second year</li></ul>","Non-Registered, RRSPs, TFSAs, RDSPs and RESPs"));
	cards.push(new Card("p06_primelinked_cashable", "Prime-Linked Cashable GIC<sup>&reg;</sup>", "Interest Rate-linked", "0", "10","5","10","3", "-99","10", "10","-99", "10","10","-99", "Yes", "$5,000", "One year", "/products/gic/primelinked.html", "Offers an interest rate linked to changes in the RBC Royal Bank<sup>&reg;</sup> Canadian prime interest rate (rate is variable), and is redeemable at any time with interest paid if held 30 days or longer.", "<ul><li>Liquidity</li><li>Immediate benefit when there is an increase in the prime rate</li></ul>", "<ul><li>Monthly</li><li>Semi-annually</li><li>At maturity</li><li>At time of redemption if held 30 days or longer</li></ul>","Non-Registered only"));
	cards.push(new Card("p07_oneyear_cashable", "One-Year Cashable GIC&#153;", "Guaranteed-return", "0", "10","5","10","3", "10","10", "10","-99", "10","10","-99", "Yes", "<ul><li>$1,000*</li><li>*$5,000 for clients who wish to receive interest monthly</li></ul>", "One year", "/products/gic/cashable_gic.html", "Offers a fixed interest rate, and is redeemable at any time with interest paid if held 30 days or longer.", "<ul><li>Flexibility - access to funds at any time</li><li>Security of guaranteed rate of return</li></ul>", "<ul><li>Monthly</li><li>Semi-annually</li><li>At maturity</li><li>At time of redemption if held 30 days or longer</li></ul>","Non-Registered only"));
	cards.push(new Card("p08_rateadvantage", "RateAdvantage GIC<sup>&reg;</sup>", "Guaranteed-return", "0", "-99","10","5","8", "10","10", "-99","10", "-99","10","10", "No", "$1,000", "<ul><li>Two years,</li><li>three years,</li><li>five years</li></ul>", "/products/gic/rateadvantage_gic.html", "Offers guaranteed interest rates that increase on each anniversary date over the term of the product; cashable version is fully or partially cashable on each anniversary date.", "<ul><li>An escalator or step-rate type GIC with competitive rates that are guaranteed to increase each year</li></ul>", "<ul><li>Annually</li><li>At maturity (interest compounded annually)</li></ul>","Non-Registered only"));
	cards.push(new Card("p09_cashable_rateadvantage", "Cashable RateAdvantage GIC<sup>&reg;</sup>", "Guaranteed-return", "0", "-99","10","5","6", "10","10", "5","-99", "-99","10","10", "Yes. Funds are accessible on each anniversary date", "$1,000", "<ul><li>Two years,</li><li>three years,</li><li>five years</li></ul>", "/products/gic/rateadvantage_gic.html", "Offers guaranteed interest rates that increase on each anniversary date over the term of the product; cashable version is fully or partially cashable on each anniversary date.", "<ul><li>An escalator or step-rate type GIC with competitive rates that are guaranteed to increase each year</li><li>Flexibility to access funds on each anniversary date</li></ul>", "<ul><li>Annually</li></ul>","Non-Registered only"));
	cards.push(new Card("p10_canfundlinked_gic", "RBC Canadian Dividend Fund-Linked GIC", "RBC Market Access", "0", "-99","5","-99","10", "10","10", "-99","10", "-99","9","10", "No", "$1,000", "Three or five years", "/products/gic/dividendlinked.html", "Offers a variable return based on the performance of the RBC Canadian Dividend Fund.", "<ul><li>Potential to earn higher rates of return</li><li>Security of guaranteed principal</li></ul>", "<ul><li>Return, if any, paid at maturity</li></ul>","Non-Registered only"));
	cards.push(new Card("p11_intlfundlinked_gic", "RBC O'Shaughnessy International Equity Fund-Linked GIC", "RBC Market Access", "0", "-99","5","-99","10", "10","10", "-99","10", "-99","9","10", "No", "$1,000", "Three or five years", "/products/gic/equitylinked.html", "Offers a variable return based on the performance of the RBC O'Shaughnessy International Equity Fund.", "<ul><li>Potential to earn higher rates of return</li><li>Security of guaranteed principal</li></ul>", "<ul><li>Return, if any, paid at maturity</li></ul>","Non-Registered only"));
	cards.push(new Card("p12_usdollarterm_gic", "U.S. Dollar Term Deposits GIC", "Guaranteed-return", "0", "-99","-99","-99","-99", "-99","-99", "-99","-99", "-99","-99","-99", "No", "<ul><li>$1,000 (1 to 5 years)</li><li>$5,000 (30 to 364 days)</li><li>$100,000 (less than 30 days)</li></ul>", "<ul><li>1 - 364 days</li><li>1 - 5 years</li></ul>", "/products/gic/us-dollar-term-deposits.html", "", "<ul><li>Both the original investment and interest payments are guaranteed</li><li>Competitive Interest Rates - Guaranteed for the full term of the investment</li></ul>", "<ul><li>For terms less than one year, interest is paid at maturity</li><li>For terms of one year or more, interest is paid annually</li></ul>","Non-Registered only"));
}
//Takes out "$", ",", "N/A", "n/a" from string to make it a valid number
function convertToNumber(str){
	var number = 0;
	number = str.replace(/\$/, "");
	number = number.replace(/,/, "");
	number = number.replace(/N\/A/, "");
	number = number.replace(/n\/a/, "");
	number = number.replace(" ", "");
		
	if (number == '') number = 0.00;
	
	return Number(number);
}
//Retrieves card object with specific id
function getCardObjectById(cid) {
	var temp;
	for (var x=0; x< cards.length; x++) {
		temp = cards[x].id;
		if (cid == temp) return cards[x];
	}
	
	return null;
}
//Retrieves specified parameter from URL string
function getURLParam(strParamName) {	
	// GetURL Params value from querystring
	var qs = location.search.split('?');
	if (qs.length > 1) {
	var pairs = qs[1].split("&");
		for (var i=0; i<pairs.length; i++) {
			var namevalue = pairs[i].split("=", 2);
			var name = unescape(namevalue[0]);
			var value = unescape(namevalue[1]);
			if (name.toUpperCase() == strParamName.toUpperCase()) {
				return value;
				//break;
			}
		}
	}
	return null;
}
