﻿var g_strSignInAction;

function InitSignIn(strSignInAction, bSignedIn)
{
  g_strSignInAction=strSignInAction;
  
  var strCurrentURL = window.location.href;
  
  if(strCurrentURL.indexOf("SignIn=Fail")!=-1)
  {
    Welcome(false);
    
    alert("Your username or password was not recognised. Please check and re-enter them.")
    document.getElementById("txtSignInUsername").focus();
  }
  else if(strCurrentURL.indexOf("SignIn=Success")!=-1)
  {
    document.getElementById("elmWelcomeBox").style.backgroundColor="#79B2B2";
    document.getElementById("elmWelcomeBox").style.backgroundImage="url('../../Images/Common/SignedInFormFooter.jpg')";
    
    var arrPTags=document.getElementById("elmWelcomeBox").getElementsByTagName("p");
    for(var nIndex=0; nIndex<arrPTags.length; nIndex++)
    {
      arrPTags[nIndex].style.backgroundColor="#79B2B2";
    }
    
    Welcome(true);
  }
  else if(strCurrentURL.indexOf("SignIn=Required")!=-1)
  {
    Welcome(false);
    
    alert("The area you are trying to access is restricted to COWRIE members only. Please sign in.")
    document.getElementById("txtSignInUsername").focus();
  }
  else
  {
    Welcome(bSignedIn);
  }
}

function Welcome(bShow)
{
  if(bShow)
  {
    document.getElementById("elmSignInBox").style.display="none";
    document.getElementById("elmWelcomeBox").style.display="block";
  }
  else
  {
    document.getElementById("elmSignInBox").style.display="block";
    document.getElementById("elmWelcomeBox").style.display="none";
  }
}

function SignIn()
{
  if(document.getElementById("txtSignInUsername").value=="")
  {
    alert("Please enter your username");
    document.getElementById("txtSignInUsername").focus();
  }
  else if(document.getElementById("txtSignInPassword").value=="")
  {
    alert("Please enter your password");
    document.getElementById("txtSignInPassword").focus();
  }
  else
  {
    document.forms[0].action=g_strSignInAction;
    document.forms[0].onsubmit="";
    document.forms[0].submit();	          	          
  }
  
  return;
}

function trySignIn(e)
{
  e=e||window.event;
  var code=e.keyCode||e.which;
  
  if(code==13)
  {
    SignIn();
    
    return false;
  }
  else
  {
    return true;
  }
}

