// ==UserScript==
// @name		Customize Gaia
// @namespace	http://alloscomp.com/customizegaia.user.js
// @description	General GaiaOnline customizations.	
// @include	*.gaiaonline.com*
// ==/UserScript==

(function () {
	var faviconURL = 'http://www.gaiaonline.com/favicon.ico';

	//Apply favicon in Firefox... needed for me
	var eLink = document.createElement('link');
	eLink.setAttribute('rel', 'shortcut icon');
	eLink.setAttribute('href', faviconURL);
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(eLink);
	
	// Auto set 14 days buy-only
	if(location.href.indexOf(".gaiaonline.com/marketplace/mystore/sell") > -1) {
		var sType = document.getElementsByName('vend_type')[0];
		var sDays = document.getElementsByName('days')[0];
		var sMinutes = document.getElementsByName('minutes')[0];
		if(sType)
			sType.value = '3';
		if(sDays)
			sDays.value = '14';
		if(sMinutes)
			sMinutes.value = '0';
	}
	
	// Put tax indicator in selling confirmation box
	if(location.href.indexOf(".gaiaonline.com/marketplace/mystore/sell/?step=confirm") > -1) {
		var sBody = document.body.innerHTML;
		var arr = sBody.match(/\s*<td align="right">\s*<strong>Buy Now Price:<\/strong>\s*<\/td>\s*<td align="left">\s*([0-9,]+)g\s*<\/td>/);
		var total = arr[1].replace(/\,/g,'');
		var iTax = Math.round(total*.02);
		var table = document.getElementById('sellItemDiv').getElementsByTagName('table')[0];
		var eTr = document.createElement('tr');
		var eTdDesc = document.createElement('td');
		var oStrong = document.createElement('STRONG');
		oStrong.appendChild(document.createTextNode('Tax:'));
		eTdDesc.appendChild(oStrong);
		eTdDesc.setAttribute('align','right');
		var eTdCont = document.createElement('td');
		eTdCont.appendChild(document.createTextNode(iTax+'g'));
		eTdCont.setAttribute('align','left');
		eTr.appendChild(eTdDesc);
		eTr.appendChild(eTdCont);
		table.tBodies[0].appendChild(eTr);
	}
})();