﻿function Register()
{
    //Check where the enter is coming from
    if(document.getElementById("WhichControl").value == "Login")
    {
        document.getElementById("Login_btn_Login").submit();
        return true;
    }
    if(document.getElementById("WhichControl").value == "LogOut")
    {
        document.getElementById("Login_btn_LogOut").submit();
        return true;
    }   
    if(document.getElementById("WhichControl").value == "QuickSearch")
    {

        return true;
    }   
    if(document.getElementById("WhichControl").value == "RegisterLogin")
    {
         //Make sure all css classes are back to default
        ClearAll();
        
        //Email login
        if(document.getElementById("Body_txt_LoginEmail").value == "")
        {
            ShowRegError(8);
            document.getElementById("Body_txt_LoginEmail").focus()
            return false;
         }  
         
        //Valid Email address
        if(!validateEmail(document.getElementById("Body_txt_LoginEmail").value))
         {
            ShowRegError(8);
            document.getElementById("Body_txt_LoginEmail").focus()
            return false;
         } 
     
             //PAssword login
        if(document.getElementById("Body_txt_LoginPassword").value == "")
        {
            ShowRegError(9);
            document.getElementById("Body_txt_LoginPassword").focus()
            return false;
         }  
         
            document.forms[0].submit();
            return true; 
    
    }      
    if(document.getElementById("WhichControl").value == "RegisterForgottenEmail")
    {
    
        ClearAll();
    
        if(document.getElementById("Body_txt_EmailForgottenEmail").value == "")
        {
            ShowRegError(10);
            document.getElementById("Body_txt_EmailForgottenEmail").focus()
            return false;
         } 
        //Valid Email address
        if(!validateEmail(document.getElementById("Body_txt_EmailForgottenEmail").value))
         {
            ShowRegError(10);
            document.getElementById("Body_txt_EmailForgottenEmail").focus()
            return false;
         } 
         
        document.forms[0].submit();
        return true; 
    
    }   


    //Make sure all css classes are back to default
    ClearAll();
    document.getElementById("Label7").style.display ="";

    //FirstName
    if(document.getElementById("Body_txt_FirstName").value == "")
    {
        ShowRegError(1);
        document.getElementById("Body_txt_FirstName").focus();
        return false;
     }       
    //LastName
    if(document.getElementById("Body_txt_LastName").value == "")
    {
        ShowRegError(2);
        document.getElementById("Body_txt_LastName").focus()
        return false;
     }       

    //Email
    if(document.getElementById("Body_txt_EmailAddress").value == "")
     {
        ShowRegError(3);
        document.getElementById("Body_txt_EmailAddress").focus()
        return false;
     }       
     
     //Valid Email address
    if(!validateEmail(document.getElementById("Body_txt_EmailAddress").value))
     {
        ShowRegError(3);
        document.getElementById("Body_txt_EmailAddress").focus()
        return false;
     } 
    //PublicName
    if(document.getElementById("Body_txt_PublicName").value == "")
     { 
        ShowRegError(4);
        document.getElementById("Body_txt_PublicName").focus()
        return false;
     }       

    //Password
    if(document.getElementById("Body_txt_Password").value == "")
     {
        ShowRegError(5);
        document.getElementById("Body_txt_Password").focus()
        return false;
     }       

    //Passwords not equal
    if(document.getElementById("Body_txt_Password").value != document.getElementById("Body_txt_RetypePassword").value)
     {
        ShowRegError(6);
        document.getElementById("Body_txt_RetypePassword").focus()
        return false;
     }       
     
    if(document.getElementById("Body_img_AcceptConditions").src.search("Un") != -1)
    {
        document.getElementById("Label7").style.display ="block";
        return false;
    }      
    
    document.getElementById("WhichControl").value = "Registration";
    document.forms[0].submit();          
}
function ClearAll()
{
    //Make sure all css classes are back to default
    for(var i = 1 ; i < 7 ; i++)
    {
        document.getElementById("Body_Label" + i).style.display ="";
        document.getElementById("Left" + i).className = "TextbarLeft";
        document.getElementById("Middle" + i).className = "TextsearchbarMiddleLong";
        document.getElementById("Right" + i).className = "TextbarRight";
    }
    
    if(document.getElementById("WhichControl").value != "Register")
    {
        for(var i = 8 ; i < 11 ; i++)
        {
            document.getElementById("Body_Label" + i).style.display ="";
            document.getElementById("Left" + i).className = "TextbarLeft";
            document.getElementById("Middle" + i).className = "TextsearchbarMiddleLong";
            document.getElementById("Right" + i).className = "TextbarRight";
        }
    }
}
function ShowRegError (p_Item)
{    
    document.getElementById("Body_Label" + p_Item).style.display ="block";
    document.getElementById("Left" + p_Item).className = "TextbarErrorLeft";
    document.getElementById("Middle" + p_Item).className = "TextsearchbarErrorMiddleLong";
    document.getElementById("Right" + p_Item).className = "TextbarErrorRight";
}
function ResendPassword()
{
        //Check where the enter is coming from
    if(document.getElementById("WhichControl").value == "Login")
    {
        document.getElementById("Login_btn_Login").submit();
        return true;
    }
    if(document.getElementById("WhichControl").value == "LogOut")
    {
        document.getElementById("Login_btn_LogOut").submit();
        return true;
    }   
    if(document.getElementById("WhichControl").value == "QuickSearch")
    {
        return true;
    }   
    
    document.getElementById("Body_Label1").style.display ="";
    document.getElementById("Left1").className = "TextbarLeft";
    document.getElementById("Middle1").className = "TextsearchbarMiddleLong";
    document.getElementById("Right1").className = "TextbarRight";
    
    //FirstName
    if(document.getElementById("Body_txt_FirstName").value == "")
    {
        ShowRegError(1);
        document.getElementById("Body_txt_FirstName").focus();
        return false;
     }  
     
     //Valid Email address
    if(!validateEmail(document.getElementById("Body_txt_FirstName").value))
     {
        ShowRegError(1);
        document.getElementById("Body_txt_FirstName").focus()
        return false;
     } 
     
    document.getElementById("Body_btn_Submit").click();
    return true; 
}

function RegisterLoginClick()
{
    SetControl('RegisterLogin');
    Register();
}
function RegisterForgotPassClick()
{
    SetControl('RegisterForgottenEmail');
    Register();
}
function RegisterClick()
{
    SetControl('Register');
    Register();
}
