

var Sendreco = "/wp-content/plugins/recommand/recommand.php?reco=true";

function initreco() {
	// initiates the object for sending and receiving data
	httpreco = reco_getHTTPObject();
}

function reco_Error(recoErrorArr) {
	document.getElementById('recoLblFromName').style.color = "inherit";
	document.getElementById('recoLblFromMail').style.color = "inherit";
	document.getElementById('recoLblToName').style.color = "inherit";
	document.getElementById('recoLblToMail').style.color = "inherit";
	
	for(i = 0; i < recoErrorArr.length; i++) {
		document.getElementById(recoErrorArr[i]).style.color = '#ff0000';
	}
	
}

function reco_Submit() {
	if (httpreco.readyState == 4 || httpreco.readyState == 0) {
		httpreco.open("POST", Sendreco, true);
		httpreco.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  		params = 'url='+document.getElementById('recoUrl').value;
		params+= '&fromname='+document.getElementById('recoFromName').value;
		params+= '&frommail='+document.getElementById('recoFromMail').value;
		params+= '&toname='+document.getElementById('recoToName').value;
		params+= '&tomail='+document.getElementById('recoToMail').value;
                params+= '&comment='+document.getElementById('recoComment').value;
		httpreco.send(params);
		httpreco.onreadystatechange = function () {
			if (httpreco.readyState == 4) {
				results = httpreco.responseText;
				if(results.substring(0,5) == "Array") {
					results = eval(results);
					reco_Error(results);
				} else {
					document.getElementById("recoForm").innerHTML = reco_confirmtext;
				}
    		}
		}
  	} else {
  	    setTimeout('reco()', 400)
  	}
	
	return false;
}

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