

var SendRT = "/wp-content/plugins/report-this/report-this.php?rt=true";

function initRT() {
	// initiates the object for sending and receiving data
	httpRT = rt_getHTTPObject();
	oRemovedNode = document.getElementById("rtBlock");
	oRemovedNode.parentNode.removeChild(oRemovedNode);
	document.body.appendChild(oRemovedNode);
	
	rtLnk = document.getElementById('rtLink');
	rtfrm = document.getElementById('rtForm').innerHTML;
	if(rtLnk) {
		rtLnk.onclick = function() {
			document.getElementById('rtUrl').value = document.URL;
			document.getElementById('rtBlock').style.display = 'block';
//			document.getElementById('rtBlock').style.visibility = 'visible';
			ws = rt_windowsize();
			w = parseInt(document.getElementById('rtBlock').offsetWidth);
			h = parseInt(document.getElementById('rtBlock').offsetHeight);
			rtTopOffset =0;
			if(document.body.scrollTop) {
				rtTopOffset = document.body.scrollTop;
			} else if(document.documentElement.scrollTop){ 
				rtTopOffset = document.documentElement.scrollTop;
			}
			document.getElementById('rtBlock').style.top =  (rtTopOffset + ((ws.y/2)-(h/2)))+"px" ;
			document.getElementById('rtBlock').style.left =  ((ws.x/2)-(w/2))+"px";
			return false;
		}
	}
}


function rt_Close() {
	document.getElementById('rtBlock').style.display = 'none';
//	document.getElementById('rtBlock').style.visibility = 'hidden';		
	return false;
}
function rt_Reset() {

	document.getElementById('rtBlock').style.display = 'none';
//	document.getElementById('rtBlock').style.visibility = 'hidden';	
	document.getElementById('rtForm').innerHTML = rtfrm;
}
function rt_Error(rtErrorArr) {
	document.getElementById('rtLblFromName').style.color = "inherit";
	document.getElementById('rtLblFromMail').style.color = "inherit";
	document.getElementById('rtLblReason').style.color = "inherit";
	
	for(i = 0; i < rtErrorArr.length; i++) {
		document.getElementById(rtErrorArr[i]).style.color = '#ff0000';
	}
	
}

function rt_Submit() {
	if (httpRT.readyState == 4 || httpRT.readyState == 0) {
		httpRT.open("POST", SendRT, true);
		httpRT.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  		params = 'url='+document.getElementById('rtUrl').value;
		params+= '&fromname='+document.getElementById('rtFromName').value;
		params+= '&frommail='+document.getElementById('rtFromMail').value;
		params+= '&toname='+document.getElementById('rtToName').value;
		params+= '&tomail='+document.getElementById('rtToMail').value;
		params+= '&reason='+document.getElementById('rtReason').value;
		params+= '&protectwebformcode='+document.getElementById('rtCaptcha').value;
		httpRT.send(params);
		httpRT.onreadystatechange = function () {
			if (httpRT.readyState == 4) {
				results = httpRT.responseText;
				if(results.substring(0,5) == "Array") {
					results = eval(results);
					rt_Error(results);
				} else {
					document.getElementById("rtForm").innerHTML = rt_confirmtext;
					setTimeout('rt_Reset()', 1000);
				}
    		}
		}
  	} else {
  	    setTimeout('rt()', 400)
  	}
	
	return false;
}

//returns the window size 
function rt_windowsize() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	retval = new Object;
	retval.x = x;
	retval.y = y; 
	return retval;
}
//initiates and handles the XMLHttpRequest object
//as found here: http://www.webpasties.com/xmlHttpRequest

function rt_getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}


// brothercake's generic onload
// http://www.brothercake.com/site/resources/scripts/onload/

if(typeof window.addEventListener != 'undefined')
{
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', initRT, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', initRT, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', initRT);
}