

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

function stafShow(selectedObj)
{
      stafBlock = document.getElementById(selectedObj);
      if(stafBlock)
      {
            stafBlock.style.display = 'block';
            ws = staf_windowsize();
            w  = parseInt(stafBlock.offsetWidth);
            h  = parseInt(stafBlock.offsetHeight);
            stafTopOffset = 0;
            if(document.body.scrollTop) 
            {
                  stafTopOffset = document.body.scrollTop;
            } 
            else if(document.documentElement.scrollTop)
            {
                  stafTopOffset = document.documentElement.scrollTop;
            }
            stafBlock.style.top =  (stafTopOffset + ((ws.y/2)-(h/2)))+"px" ;
            stafBlock.style.left =  ((ws.x/2)-(w/2))+"px";
            return false;
      }
}


function staf_Close(selectedObj) {
	document.getElementById(selectedObj).style.display = 'none';
	return false;
}

function staf_Error(stafErrorArr) {
	document.getElementById('stafLblFromName').style.color = "inherit";
	document.getElementById('stafLblToMail').style.color = "inherit";

	for(i = 0; i < stafErrorArr.length; i++) {
                document.getElementById(stafErrorArr[i]).style.color = '#ff0000';
	}
	
}

function staf_Submit(objID, currentPage) {
	if (httpStaf.readyState == 4 || httpStaf.readyState == 0) {
		httpStaf.open("POST", SendStaf, true);
		httpStaf.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		stafURL = objID.split('stafForm-');
  		params = 'url='+document.getElementById('stafUrl-' + stafURL[1]).value;
		params+= '&fromname='+document.getElementById('stafFromName').value;
		params+= '&tomail='+document.getElementById('stafToMail').value;
		
                staf_form = document.getElementById(objID).innerHTML;
		
                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(objID).innerHTML = staf_confirmtext;
                                        if(currentPage == "home")
                                        {
                                              setTimeout(function()
                                              {
                                                    document.location.href = "http://petsfunky.com";
                                              }, 1500)
                                        }
					elseif(currentPage == "single")
					{
                                              setTimeout(function()
                                              {
                                                    document.getElementById(objID).innerHTML = staf_form;
                                                    document.getElementById("stafBlock-" + stafURL[1]).style.display = 'none';
      	                                            document.getElementById("stafUrl-" + stafURL[1]).value = '';
                                              }, 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;
}