var calculator = {
	d: document,
	node: null,
	so: null,
	versions: { SK:'2', DE:'2', BL:'2' },
	init: function(){
		this.node = document.getElementById("dialog-wrapper");
	},
	getflash: function(version) {
		version = version || '1';
		this.so = new SWFObject('/_flash/'+STR_LANG+'/'+version+'/kreditrechner.swf', 'website', '499', '302', '9.0.0', '#FFFFFF');
	    this.so.useExpressInstall('/_flash/expressinstall.swf');
		this.so.addParam('menu', 'false');
		this.so.addParam('scale', 'noscale');
		this.so.addParam('salign', 'lt');
		this.so.addVariable('xml_data', '/_xml/'+STR_LANG+'/'+version+'/data.xml');
	},
	render: function(mode){
		html = '<div id="dialog-shadow"></div>';
		html += '<div id="dialog" class="dialog-calculator">';
		html += '<div class="dialog-top"><a href="#" onclick="calculator.onCloseClick();" title="'+STR_CLOSE+'"></a></div>';
		html += '<div class="dialog-header">';
		if (mode == "DE")
			html += STR_CALCULATOR_TITLE_DE;
		else if (mode == "BL")
			html += STR_CALCULATOR_TITLE_BL;
		else
			html += STR_CALCULATOR_TITLE_SK;
		html += '</div>'
		html += '<div class="dialog-content">';
		html += '<div class="hr hr-bottom"></div>';
		html += '<p>';
		if (mode == "DE")
			html += STR_CALCULATOR_CONTENT_DE;
		else if (mode == "BL")
			html += STR_CALCULATOR_CONTENT_BL;
		else
			html += STR_CALCULATOR_CONTENT_SK;
		html += '</p>';
		html += '<div id="flash-calculator">';
		html += STR_CALCULATOR_FLASH_ALT;
		html += '</div>';
		html += '<div class="hr"></div>';
		html += '</div>';
		html += '<div class="dialog-footer">';
		html += '<a id="dialog-apply-online" class="btn-online" href="https://webantrag.standardchartered.de/';
		if (mode == "DE")
			html += 'dispoeasy';
		else if (mode == "BL")
			html += 'businessline';
		else
			html += 'sofortkredit';

		if (YAHOO) {
			var camp = YAHOO.util.Cookie.get("camp_id");
			var sid = YAHOO.util.Cookie.get("sid");
			var kb = YAHOO.util.Cookie.get("kb");
			var lz = YAHOO.util.Cookie.get("lz");
			var params = [];
			if (camp != "" && camp != null)
				params.push("camp_id="+camp);
			if (sid != "" && sid != null)
				params.push("s_id="+sid);
			if (kb != "" && kb != null)
				params.push("kb="+kb);
			if (lz != "" && lz != null)
				params.push("lz="+lz);
			var paramstr = params.join('&');

			if (paramstr != '') {
				html += "?"+paramstr;
			}
		}
		
		html += '" target="_blank">'+STR_DIALOG_BUTTON_ONLINE+'</a>';
		html += '<a class="btn-pdf" href="/_pdf/antrag_';
		if (mode == "DE")
			html += 'dispoeasy';
		else if (mode == "BL")
			html += 'businessline';
		else
			html += 'sofortkredit';
		html += '.pdf" target="_blank">'+STR_DIALOG_BUTTON_PDF+'</a>';
		html += '<a class="btn-contact" href="/contact/'+STR_LANG+'/">'+STR_DIALOG_BUTTON_QUESTION+'</a>';
		html += '</div>';
		html += '<div class="dialog-bottom"></div>';
		html += '</div>';
		if (this.node)
			this.node.innerHTML = html;
	},
	show: function(mode){
		mode = mode || "SK";
		if (this.node){
			this.getflash(this.versions[mode]);
			this.render(mode);
			this.node.style.display = "block";
			this.so.addVariable('calc_type', mode);
			this.so.write('flash-calculator');
		}
	},
	hide: function(){
		if (this.node){
			delete this.so;
			this.so = null;

			this.node.style.display = "none";
			this.node.innerHTML = "";
		}
	},
	onCloseClick: function(){
		this.hide();
	}
};

$("dialog-wrapper").ready(function(){
	calculator.init();
}); 

