﻿function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function LoginFormCheckFields(ln, pw) {
    var lntxt = strtrim(document.getElementById(ln).value);
    var pntxt = strtrim(document.getElementById(pw).value);
    var msg = '';
    if (lntxt.length == 0 || lntxt == 'User Name') {
        document.getElementById("err").innerHTML="Please enter username.";
        document.getElementById(ln).focus;
        return false;
    }
    
    else if (pntxt.length == 0)  {
        document.getElementById("err").innerHTML="Please enter password.";
        document.getElementById(pw).focus;
        return false;
    }
	
    return true;
	
}

function strtrim(string)
{
    //Remove leading spaces
    while(string.charAt(0) == " ")
        string = string.substring(1, string.length);
    //Remove trailing spaces
    while(string.charAt(string.length-1) == " ")
        string = string.substring(string, string.length-1);
    return string;
}

function cleartext(o, emptyval) {
    if (o.value == emptyval) {
        o.value="";
    }
}

function restoretext(o, emptyval) {
    if (o.value == "") {
        o.value=emptyval;
    }
}
var redir;
function makePOST(url, parameters, redurl)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	redir = redurl;
	xmlHttp.onreadystatechange=statusChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}
function statusChanged() 
{ 
if (xmlHttp.readyState==4)
{
	if (xmlHttp.status == 200)
	{
		if(xmlHttp.responseText == '')
		{
			window.location = redir;
			//alert (redir);
		}
		else
		{
			document.getElementById('err').innerHTML=xmlHttp.responseText;
		}
	}
}
}
function login(obj, url) {
	//alert(document.getElementById("login").value);
      var poststr = "username=" + encodeURI( document.getElementById("username").value ) +
                    "&password=" + encodeURI( document.getElementById("password").value )+
                    "&login=" + encodeURI( document.getElementById("h1_LF_LoginBtn").value );
      makePOST('forum2/log.php', poststr, url);
   }