// ==UserScript==
// @name           Quick Travian Tractor for IE7Pro
// @namespace      QTT
// @version        0.1.0
// @description    Adds a link to the battle reports page that will submit the report to www.traviantractor.com
// @include        http://*.travian.*/berichte.php*
// ==/UserScript==

if (window.location.href.indexOf("berichte.php?") != -1)
	{
	var main, newElement;
	main = document.getElementById('lmid2');
	if (main)
		{
		newElement = document.createElement('a');
		newElement.setAttribute("href","javascript:PostTT()")
		newElement.appendChild(document.createTextNode("Post to Travian Tractor"));
		main.parentNode.insertBefore(newElement, main.nextSibling);
		}
	}

function PostTT()
	{
	var text=document.getElementById('lmid2').innerHTML.replace(/<[^>]*>/g,"").replace(/\r\n[\s]*\r\n/g,"\n").replace(/\r\n(\d)?/g,myReplace).replace(/(&nbsp;)/g,"");
	var form = document.createElement("form");
	form.setAttribute("method","post");
	form.setAttribute("action","http://www.traviantractor.com/index.php/me/enterReport");
	form.setAttribute("target","_QTTWindow");
	form.setAttribute("value", "");
	var hInput = document.createElement("input");
	hInput.setAttribute("type", "hidden");
	hInput.setAttribute("id","report")
	hInput.setAttribute("name","report")
	hInput.setAttribute("value", text);
	form.appendChild(hInput);
	document.body.appendChild(form);
	form.submit();
	document.body.removeChild(form);
	}

function myReplace(myChr)
	{
	return " "+myChr.replace(/\r\n/g,"")
	}
