

var Sendcontacto = "/wp-content/plugins/contacto/contacto.php?contacto=true";

function initcontacto() {
	// initiates the object for sending and receiving data
	httpcontacto = contacto_getHTTPObject();
	oRemovedNode = document.getElementById("contactoBlock");
	oRemovedNode.parentNode.removeChild(oRemovedNode);
	document.body.appendChild(oRemovedNode);
	
	contactoLnk = document.getElementById('contactoLink');
	contactofrm = document.getElementById('contactoForm').innerHTML;
	if(contactoLnk) {
		contactoLnk.onclick = function() {
			document.getElementById('contactoUrl').value = document.URL;
			document.getElementById('contactoBlock').style.display = 'block';
//			document.getElementById('contactoBlock').style.visibility = 'visible';
			ws = contacto_windowsize();
			w = parseInt(document.getElementById('contactoBlock').offsetWidth);
			h = parseInt(document.getElementById('contactoBlock').offsetHeight);
			contactoTopOffset =0;
			if(document.body.scrollTop) {
				contactoTopOffset = document.body.scrollTop;
			} else if(document.documentElement.scrollTop){ 
				contactoTopOffset = document.documentElement.scrollTop;
			}
			document.getElementById('contactoBlock').style.top =  (contactoTopOffset + ((ws.y/2)-(h/2)))+"px" ;
			document.getElementById('contactoBlock').style.left =  ((ws.x/2)-(w/2))+"px";
			return false;
		}
	}
}


function contacto_Close() {
	document.getElementById('contactoBlock').style.display = 'none';
//	document.getElementById('contactoBlock').style.visibility = 'hidden';		
	return false;
}
function contacto_Reset() {

	document.getElementById('contactoBlock').style.display = 'none';
//	document.getElementById('contactoBlock').style.visibility = 'hidden';	
	document.getElementById('contactoForm').innerHTML = contactofrm;
}
function contacto_Error(contactoErrorArr) {
	document.getElementById('contactoLblFromName').style.color = "inherit";
	document.getElementById('contactoLblFromMail').style.color = "inherit";
	document.getElementById('contactoLblToName').style.color = "inherit";
	document.getElementById('contactoLblToMail').style.color = "inherit";
	
	for(i = 0; i < contactoErrorArr.length; i++) {
		document.getElementById(contactoErrorArr[i]).style.color = '#ff0000';
	}
	
}

function contacto_Submit() {
	if (httpcontacto.readyState == 4 || httpcontacto.readyState == 0) {
		httpcontacto.open("POST", Sendcontacto, true);
		httpcontacto.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  		params = 'url='+document.getElementById('contactoUrl').value;
		params+= '&fromname='+document.getElementById('contactoFromName').value;
		params+= '&frommail='+document.getElementById('contactoFromMail').value;
		params+= '&frommessage='+document.getElementById('contactoFromMessage').value;
		httpcontacto.send(params);
		httpcontacto.onreadystatechange = function () {
			if (httpcontacto.readyState == 4) {
				results = httpcontacto.responseText;
				if(results.substring(0,5) == "Array") {
					results = eval(results);
					contacto_Error(results);
				} else {
					document.getElementById("contactoForm").innerHTML = contacto_confirmtext;
					setTimeout('contacto_Reset()', 3000);
				}
    		}
		}
  	} else {
  	    setTimeout('contacto()', 400)
  	}
	
	return false;
}

//returns the window size 
function contacto_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 contacto_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', initcontacto, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', initcontacto, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', initcontacto);
}