function xmlhttpPost(strURL) {
	updatepage('<img src="images/loader.gif" width="13" height="16">', 'icon');
  	
 document.getElementById("registerBut").disabled="1";
 document.getElementById("submitBut").disabled="1";  
  var xmlHttpReq = false;
  
  var self = this;
  // Mozilla/Safari
  if (window.XMLHttpRequest) {
      self.xmlHttpReq = new XMLHttpRequest();
  }
  // IE
  else if (window.ActiveXObject) {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  self.xmlHttpReq.open('POST', strURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4) {
		if (self.xmlHttpReq.responseText=='successLogin'){			
			var icode = getCookie('SFicode');
			openWindow('https://integration.fellowshipone.com/integration/contribution/onlinecontribution.aspx?cCode=PWiti42THTnv4f7cRk2t2w==&iCode='+icode, '600', '600');
			document.getElementById('pWord').value='';
			updatepage('', 'results');
  			document.getElementById("registerBut").disabled="";
  			document.getElementById("submitBut").disabled="";
			updatepage('<img src="images/lock.gif" width="13" height="16">', 'icon');
		}
		else
			updatepage(self.xmlHttpReq.responseText, 'results');
			updatepage('<img src="images/lock.gif" width="13" height="16">', 'icon');
  			document.getElementById("registerBut").disabled="";
  			document.getElementById("submitBut").disabled="";
		
    }
  }

	//get the form variables
  username=document.getElementById("uName").value;
			//alert(username);
  password=document.getElementById("pWord").value;
	
	//check for blanks
		if (username == "" || password == ""){
			
			updatepage('You forgot some info!<br/><br />Maybe you need to <a href="javascript:" onclick="javascript:openWindow(\'https://integration.fellowshipone.com/integration/newuser.aspx?cCode=PWiti42THTnv4f7cRk2t2w==\', \'600\', \'600\'); return false;" target="_blank">register</a>?<br />Maybe you need <a href="javascript:" onclick="javascript:openWindow(\'https://integration.fellowshipone.com/integration/loginhelp.aspx?cCode=PWiti42THTnv4f7cRk2t2w==\', \'600\', \'600\'); return false;" target="_blank">help</a>?', 'results');
			
  			document.getElementById("registerBut").disabled="";
  			document.getElementById("submitBut").disabled="";
			updatepage('<img src="images/lock.gif" width="13" height="16">', 'icon');
			return(false);
		}
		
	//
  qstr = 'username='+username+'&password='+password;
  //alert(qstr);

  self.xmlHttpReq.send(qstr);
}


function updatepage(str, div){
  document.getElementById(div).innerHTML=str;
}
      
function handleEnter(field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			xmlhttpPost('SFlogin.php');
			return false;
		} 
		else
		return true;
} 


function openWindow(pageRef, width, height) {
	window.open (pageRef,"StarfishKenya","menubar=1,scrollbars=1,resizable=1,width="+width+",height="+height);
}


function getCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
		//return cookies.substring(startpos,endpos);
	}
	else
	{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
}