	/* Ajax functions (xmlhttp)*/
	var $xArray=new Array();
	function postHttpDoc(url,data,callBackFunction)
	{
	    //data format: "name1=value1&name2=value2..."
	    var xmlhttp = getxObject(callBackFunction);
	    if (xmlhttp)
	    {
	    	xmlhttp.open("POST",url,true);
	        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    xmlhttp.setRequestHeader("Content-Length",data.length);
		    xmlhttp.send(data);
	    }
	}
	function getxObject(callBackFunction)
	{
	    var xmlhttp = null;
	    if (window.XMLHttpRequest)
	       xmlhttp=new XMLHttpRequest();
	    else if (window.ActiveXObject)
	       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	    if (xmlhttp)
	    {
	       var ind = $xArray.length;
	       $xArray[ind] = xmlhttp;
	       if(!callBackFunction)
	          callBackFunction ="xDummyCallback"
	       xmlhttp.onreadystatechange=new Function("xHttpChange("+ind+",'" + escape(callBackFunction) + "')");
	    }
	    return  xmlhttp;
	}
	function xHttpChange(ind,callBackFunction)
	{
	  callBackFunction = unescape(callBackFunction)
	  var  xmlhttp = $xArray[ind]
	  if(!xmlhttp)
	     return
	  if (xmlhttp.readyState==4)
	  {
	    if (xmlhttp.status==200)
	    {
	       if(callBackFunction.indexOf(")")  > -1)
	       {
	          var str = "xmlhttp)"
	          if(callBackFunction.indexOf("(") < callBackFunction.length-2)
	              str = "," + str
	          callBackFunction  = callBackFunction.substring(0,callBackFunction.length-1)+str
	       }
	       else
	          callBackFunction += "(xmlhttp)"
	       eval(callBackFunction);
	    }
	    else
	    {
			setLoadingDataDiv("none");
  	        alert("There was a problem while retrieving XML data (XMLHTTP status : "+xmlhttp.status+")");
		}	       
	    $xArray[ind] = null;
	  }
	}
	function xDummyCallback(xmlhttp)
	{
	}
	function executeScripts(target)
	{
	    var scriptElements = target.getElementsByTagName("SCRIPT")
	    for(var i =0; i <  scriptElements.length; i++)
	    {
	        var scriptEl =  scriptElements[i];
	        var scr =  scriptEl.innerHTML.replace("<!--","").replace("-->","")
	        try
	        {
	           eval(scr)
	        }
	        catch(error)
	        {
	           setLoadingDataDiv("none");
	           alert("There was a problem while executing the scripts (ERROR : "+error+")");
	        }
	    }
	}
	function loadData()
	{
		// check the useAjax flag, call the relavant method to invoike the request
			var form = document.loginForm;
			if(!form)
				return;
			var formFields="task=checklogin";
			for(var i=0; i < form.elements.length; i++)
			{
				var field=form.elements[i];
				formFields+="&"+field.name+"="+field.value;
			}
			var callBackFunction = "ahaCallback()"
			postHttpDoc("ajaxLogin.jsp",formFields,callBackFunction);
	}
	function ahaCallback(xmlhttp)
	{
	    var element=document.getElementById('content');
	    if(element)
	    {
	       element.innerHTML=xmlhttp.responseText;
	       executeScripts(element);
	    }
	}
	function checkAutoLogin(){
		// ignore request if we are already logged in
		ssoCookieId = document.getElementById('SSO_COOKIE_ID').value;
		formFields = "SSO_COOKIE_ID="+ssoCookieId+"&task=checkAutoLogin";
		var callBackFunction = "ahaCallback()"
		postHttpDoc("ajaxLogin.jsp",formFields,callBackFunction);
	}
	
	function logout(){
		ssoCookieId = document.getElementById('SSO_COOKIE_ID').value;
		formFields = "SSO_COOKIE_ID="+ssoCookieId+"&task=logout";
		var callBackFunction = "ahaCallback()"
		postHttpDoc("ajaxLogin.jsp",formFields,callBackFunction);
	}

	function handleKeyPress(e,form) { 
		var key=e.keyCode; 
		if (key==13){ 
			loadData(); 
		} 
	} 
	function changeAutoLogin(){
                if(document.getElementById('rememberPassword').checked){
                        document.getElementById('autoLogin').value = 'true';
                } else {
                        document.getElementById('autoLogin').value = 'false';
                }
        }

