////////////////////////////////////////////////
//Author : Damien Malone
//
///Date   : 16/06/2006
////////////////////////////////////////////////

function getXMLHttpRequest()
{
	var xmlReq = null 

   	if (typeof window.ActiveXObject != 'undefined' ) 
   	{ 
       xmlReq = new ActiveXObject("Microsoft.XMLHTTP"); 
   	} 

   	else 
  	{ 
       xmlReq = new XMLHttpRequest(); 
   	} 

	return xmlReq;
}

//used to send the login credentials from 
//self service to the portal
//
//This should be called from a page already sitting on https
//This method uses ajax to connect to the portal login command
//and the next time the user selects the portal from the window
//this was called from, it will remember their details as its 
//in the same session
function logIntoPortal()
{
	var xmlReq = getXMLHttpRequest()

	var tempName = document.getElementById("loginForm:username").value;
	var tempPassword=document.getElementById("loginForm:password").value;
	
	var str = "userName=" + tempName + "&password=" +tempPassword; 
	var url = "../../../personalise/controller/Login";// No question mark needed 
	xmlReq.open("POST",url,true); 
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	
	xmlReq.send(str);
	
}

//used to send the login credentials from 
//self service to the portal
//
//This should be called from a page already sitting on https
//This method uses ajax to connect to the portal login command
//and the next time the user selects the portal from the window
//this was called from, it will remember their details as its 
//in the same session
function logIntoPortalfromRequest()
{
	var xmlReq = getXMLHttpRequest()

	var tempName = document.getElementById("requestForm:username").value;
	var tempPassword=document.getElementById("requestForm:password").value;
	
	var str = "userName=" + tempName + "&password=" +tempPassword; 
	var url = "../../../personalise/controller/Login";// No question mark needed 
	xmlReq.open("POST",url,true); 
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	
	xmlReq.send(str);
	
}

function logIntoSelfServiceWithPass1() {
	var tempName = document.getElementById("userName").value;
	var pass1=document.getElementById("password1").value;
	var pass2=document.getElementById("password2").value;
	if (pass1 == pass2) {
		parent.frames["fr2"].doit(tempName,pass1);
	}
}

//called from the portal, used to call a method is the hidden frame to 
//pass the user credentails into self service. These will be stored in 
//the session so when the user goes to self service 
function logIntoSelfService()
{

	var tempName = document.getElementById("userName").value;
	var tempPassword=document.getElementById("password").value;
	parent.frames["fr2"].doit(tempName,tempPassword);
	
}


//Because one frame cannot submit a form in another, it can only call
//methods in other frames, this is the method called to submit the details
//to self service
function doit(username,password)
{

	document.getElementById("ssusername").value = username;
	document.getElementById("sspassword").value = password;	
	
	document.getElementById("loginForm").submit();
}

//Called when a page is being unloaded, used to determine last time a 
//user left SS, so we can determine if we should kill the session or not
//
function sendOnClose()
{
	var xmlReq = getXMLHttpRequest()

	var url = "/selfservice/ExitingServlet";// No question mark needed 
	xmlReq.open("POST",url,true); 
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlReq.send();
	
}


//called from the portal, used to call a method in the hidden frame to 
//log out of SS
function logOutOfSelfService()
{
	parent.frames["fr2"].logout();
	
}


//Because one frame cannot submit a form in another, it can only call
//methods in other frames, this is the method called to submit the 
//logout call to SS
function logout()
{
	document.getElementById("logoutForm").submit();
}

