

var SendStaf = "/wp-content/plugins/sendtoafriend/sendtoafriend.php?staf=true";

function initStaf() {
	if(document.getElementById('send-a-friend') ) {
		// initiates the object for sending and receiving data
		httpStaf = staf_getHTTPObject(); 
		
		stafLnk = document.getElementById('send-a-friend-link');
		staffrm = document.getElementById('send-a-friend-form').innerHTML;
		if(stafLnk) {
			stafLnk.onclick = function() {
				if(document.getElementById('send-a-friend').style.display != 'block') {
					document.getElementById('send-a-friend-url').value = document.URL;
					document.getElementById('send-a-friend').style.display = 'block'; 
					document.getElementById('entry-meta-data').className = 'entry-meta-data open';
					document.getElementById('entry-tools-saf').className = 'open'; 
				}
				else {
					document.getElementById('send-a-friend').style.display = 'none';
					document.getElementById('entry-meta-data').className = 'entry-meta-data'
					document.getElementById('entry-tools-saf').className = ''; 
				}
				return false;
			}
		}
	}
}


function staf_Close() {
	document.getElementById('send-a-friend').style.display = 'none'; 	
	return false;
}
function staf_Reset() {

	document.getElementById('send-a-friend').style.display = 'block';
//	document.getElementById('send-a-friend').style.visibility = 'hidden';
}
function staf_Error(stafErrorArr) {
	document.getElementById('send-a-friend-error').innerHTML = "U heeft niet alle gegevens correct ingevuld.";
	
}

function staf_Submit() {
	if (httpStaf.readyState == 4 || httpStaf.readyState == 0) {
		httpStaf.open("POST", SendStaf, true);
		httpStaf.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  		params = 'url='+document.getElementById('send-a-friend-url').value;
		params+= '&fromname='+document.getElementById('send-a-friend-from').value;
		params+= '&frommail='+document.getElementById('send-a-friend-email-from').value;
		params+= '&toname='+document.getElementById('send-a-friend-to').value;
		params+= '&tomail='+document.getElementById('send-a-friend-email-to').value;
		params+= '&site='+document.getElementById('send-a-friend-site').value;
		httpStaf.send(params);
		httpStaf.onreadystatechange = function () {
			if (httpStaf.readyState == 4) {
				results = httpStaf.responseText;
				if(results.substring(0,5) == "Array") {
					results = eval(results);
					staf_Error(results);
				} else {
					document.getElementById("send-a-friend").innerHTML = "<p class=\"saf-sent\"><strong>Verstuurd</strong><br/>Het artikel is doorgestuurd naar " + document.getElementById('send-a-friend-to').value + ".</p>";
					pageTracker._trackPageview("/sendafriend/" + (document.URL).substr(7));
					//document.getElementById("send-a-friend").innerHTML += '<p><a href="javascript:staf_Reset()">Stuur nog eens door</a></p>';
					//setTimeout('staf_Reset()', 1000);
				}
    		}
		}
  	} else {
  	    setTimeout('staf()', 400)
  	}
	
	return false;
}

//returns the window size 
function staf_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 staf_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', initStaf, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', initStaf, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', initStaf);
}
