function include(fileName) {
  document.write('<script type="text/javascript" src="'+fileName+'"><\/script>');
}

var Utils = {
  updater: function(updateId, url) {
    new Ajax.Updater(updateId, url, {asynchronous:true, evalScripts:true});
    $(updateId).innerHTML = 
      "<div align='center' style='margin:2em'><img src='/img/loading.gif'></div>";
  },
  
  submit: function(updateId, url, formId) {
	new Ajax.Updater(updateId, url, {parameters:Form.serialize(formId), 
	  asynchronous:true, evalScripts:true});
	$(updateId).innerHTML = 
	  "<div align='center' style='margin:2em'><img src='/img/loading.gif'></div>";
  },
  
  cssWindow: function(url, t, w, h, c, m) {
	t = (t)? t : "&nbsp;";
	w = (w)? w : 700;
	h = (h)? h : 450;
	c = (c)? c : "mac_os_x";
	m = (m)? false : true;
	win = new Window({className:c, title:t, width:w, height:h, destroyOnClose:true, showEffect:Element.show, hideEffect:Element.hide, maxWidth:800, maxHeight:550});
	win.setAjaxContent(url, {asynchronous:true, evalScripts:true});
	win.showCenter(m);
  },
  
  cssDialog: function(URL, w, h) {
  	w = (w)? w : 400;
	h = (h)? h : 300;
  	Dialog.info({url:URL}, {width:w, height:h, showProgress: true});
  }, 
  
  openWindow: function(url, w, h) {
	w = (w)? w : 700;
	h = (h)? h : 450;
	win = window.open(url, "pop", "width="+w+",height="+h+",scrollbars=yes,resizable=yes");
	win.focus();
  },
  
  onToggle: function(a, toggleId, url, showLabel, hideLabel) {
	showLabel = (showLabel)? showLabel : "<img src='/img/toggle_down.jpg' title='show' />";
	hideLabel = (hideLabel)? hideLabel : "<img src='/img/toggle_up.jpg' title='hide' />";
	if ($(toggleId).visible()) {
	  a.innerHTML = showLabel;
	} else {
	  a.innerHTML = hideLabel;
	  if (url) {
	  	updater(toggleId, url);
	  }
	}
	Effect.toggle(toggleId);
  },
  
  autocomplete: function(textboxId, spinId, autocompleteId, url, callbackId) {
  	new Ajax.Autocompleter(textboxId, autocompleteId, url, 
  	  {indicator:spinId, afterUpdateElement:autocompleteCallback});
	function autocompleteCallback(text, li) {
	  $(callbackId).value = li.id;
	}
  },
  
  unset: function(id) {
    $(id).value = '';
  },
  
  contact: function() {
  	Utils.cssWindow('/home/contact', 'Contact');	
  },
  
  selectAll: function(checkboxObj, checkboxesObj) {
	if (checkboxObj.checked == true) {
  		for (i=0; i<checkboxesObj.length; i++) {
  			checkboxesObj[i].checked = true;		
  		}
  	} else {
  		for (i=0; i<checkboxesObj.length; i++) {
  			checkboxesObj[i].checked = false;		
  		}
  	}
  }  
}

var Welcome = {
	webinarSupport: function() {
		Utils.cssWindow('/home/webinarSupport', 'Webinar Support');
	},
		
	examplesChart: function(symbol) {
		Utils.cssWindow('/home/examplesChart/'+symbol, 'Trading Examples');
	},
		
	backtesting: function(symbol) {
		Utils.cssWindow('/home/backtesting/'+symbol, 'BackTesting Report');
	},
		
	faqs: function(faq) {
		Utils.cssWindow('/home/faqs/'+faq, 'FAQs');
	},
		
	cta: function() {
		Utils.cssWindow('/home/cta', 'CTA');
	},
		
	skypeHelp: function() {
		Utils.cssWindow('/home/skypeHelp', 'Skype');
	},
		
	solution: function(style, market) {
		Utils.cssWindow('/home/solution/'+style+'/'+market, 'Trading Solution');
	},
		
	audioPlayer: function(fileName) {
		Utils.cssWindow('/home/audioPlayer/'+fileName, 'Player', 400, 150);
	},
		
	reasons: function(key) {
		Utils.cssWindow('/home/reasons/'+key, '');
	},
		
	onWebinar: function() {
		$('webinarImg').src = '/img/home/free_daily_webinars_on.gif';
	},
		
	outWebinar: function() {
		$('webinarImg').src = '/img/home/free_daily_webinars_off.gif';
	}
}

var Products = {
	abletrendFeatures: function(feature) {
		Utils.cssWindow('/products/abletrendFeatures/'+feature, 'AbleTrend Feature');
	},
		
	asctrendFeatures: function(feature) {
		Utils.cssWindow('/products/asctrendFeatures/'+feature, 'ASCTrend Feature');
	},
		
	wintickFeatures: function(feature) {
		Utils.cssWindow('/products/wintickFeatures/'+feature, 'WinTick Feature');
	},
		
	chartDemo: function() {
		Utils.cssWindow('/products/chartDemo', 'Example');
	},
		
	definition:function(key) {
		Utils.cssWindow('/products/definition/'+key, '', 300, 200);
	}
}

var Orders = {
	agree: function() {
		if ($('agreeCheckBox').checked) {
			$('agree').style.background = 'white';
			return true;
		}
		$('agree').style.background = 'yellow';
		return false;
	},
		
	placeOrder: function() {
		if (Orders.agree()) {
			Utils.updater('OrderCheckout', '/orders/placeOrder');
		} else {
			alert('Please check the agreement checkbox');
		}
	},
		
	abletrendDetail: function(pid) {
		Utils.cssWindow('/orders/abletrendDetail/'+pid, 'AbleTrend');
	},
		
	productLists: function(orderId) {
		Utils.cssWindow('/orders/productLists/'+orderId, 'Details');
	}
}

var Users = {
	changeCountry: function(country) {
		if (country == 'US') {
			Element.show('State');
			Element.hide('Province');
		} else {
			Element.show('Province');
			Element.hide('State');
		}
	},
		
	retrievePassword: function() {
		Utils.cssWindow('/users/retrievePassword', 'Retrieve Password', '500', '200');
	},
		
	editAddress: function(retURL) {
		Utils.cssWindow('/users/editAddress/'+retURL, 'Personal Info');
	},
		
	editPayment: function(retURL) {
		Utils.cssWindow('/users/editPayment/'+retURL, 'Payment Info');
	},
		
	editEmail: function(retURL) {
		Windows.closeAll();
		Utils.cssWindow('/users/editEmail/'+retURL, 'Email');
	},
		
	editPassword: function(retURL) {
		Windows.closeAll();
		Utils.cssWindow('/users/editPassword/'+retURL, 'Password');
	},
		
	loginIssues: function(retURL) {
		Utils.cssWindow('/users/loginIssues/'+retURL, '', '500', '200');
	}
}

var Options = {
	pricing: function(model, marketType) {
		window.location='/optionspricing/index/'+model+'/'+marketType;
	}
}

var Vocabularies = {
	showEnglish: function(vocabularyId) {
		Utils.cssWindow('/vocabularies/showEnglish/'+vocabularyId, '', '500', '100');
	},
	
	deleteVocabulary: function (vocabularyId, start) {
		if (confirm('Are you sure?')) {
			window.location = '/vocabularies/delete/'+vocabularyId+'/'+start;
		} else {
			return false;
		}
	}
}