var sCode = "";
var attempts = 0;

function get_random()
{

    var ranNum= Math.floor(Math.random()*29);
    return ranNum;
}

function getRandomImage()
{

    var sImg = "";

    var rVal = get_random();

    switch(rVal)
    {
        case 0:
            sImg = "";
            break;
        case 1:
            sImg = "<img src='images/alpha.gif' height=50 width=50>";
            sCode = sCode + "a";
            break;
        case 2:
            sImg = "<img src='images/bravo.gif' height=50 width=50>";
            sCode = sCode + "b";
            break;
        case 3:
            sImg = "<img src='images/charlie.gif' height=50 width=50>";
            sCode = sCode + "c";
            break;
        case 4:
            sImg = "<img src='images/delta.gif' height=50 width=50>";
            sCode = sCode + "d";
            break;
        case 5:
            sImg = "<img src='images/echo.gif' height=50 width=50>";
            sCode = sCode + "e";
            break;
        case 6:
            sImg = "<img src='images/foxtrot.gif' height=50 width=50>";
            sCode = sCode + "f";
            break;
        case 7:
            sImg = "<img src='images/gulf.gif' height=50 width=50>";
            sCode = sCode + "g";
            break;
        case 8:
            sImg = "<img src='images/hotel.gif' height=50 width=50>";
            sCode = sCode + "h";
            break;
        case 9:
            sImg = "<img src='images/india.gif' height=50 width=50>";
            sCode = sCode + "i";
            break;
        case 10:
            sImg = "<img src='images/juliet.gif' height=50 width=50>";
            sCode = sCode + "j";
            break;
        case 11:
            sImg = "<img src='images/kilo.gif' height=50 width=50>";
            sCode = sCode + "k";
            break;
        case 12:
            sImg = "<img src='images/lima.gif' height=50 width=50>";
            sCode = sCode + "l";
            break;
        case 13:
            sImg = "<img src='images/michael.gif' height=50 width=50>";
            sCode = sCode + "m";
            break;
        case 14:
            sImg = "<img src='images/november.gif' height=50 width=50>";
            sCode = sCode + "n";
            break;
        case 15:
            sImg = "<img src='images/oscar.gif' height=50 width=50>";
            sCode = sCode + "o";
            break;
        case 16:
            sImg = "<img src='images/papa.gif' height=50 width=50>";
            sCode = sCode + "p";
            break;
        case 17:
            sImg = "<img src='images/quebec.gif' height=50 width=50>";
            sCode = sCode + "q";
            break;
        case 18:
            sImg = "<img src='images/romeo.gif' height=50 width=50>";
            sCode = sCode + "r";
            break;
        case 19:
            sImg = "<img src='images/serria.gif' height=50 width=50>";
            sCode = sCode + "s";
            break;
        case 20:
            sImg = "<img src='images/tango.gif' height=50 width=50>";
            sCode = sCode + "t";
            break;
        case 21:
            sImg = "<img src='images/uniform.gif' height=50 width=50>";
            sCode = sCode + "u";
            break;
        case 22:
            sImg = "<img src='images/victor.gif' height=50 width=50>";
            sCode = sCode + "v";
            break;
        case 23:
            sImg = "<img src='images/xray.gif' height=50 width=50>";
            sCode = sCode + "x";
            break;
        case 24:
            sImg = "<img src='images/yankee.gif' height=50 width=50>";
            sCode = sCode + "y";
            break;
        case 25:
            sImg = "<img src='images/one.gif' height=50 width=50>";
            sCode = sCode + "1";
            break;
        case 26:
            sImg = "<img src='images/two.gif' height=50 width=50>";
            sCode = sCode + "2";
            break;
        case 27:
            sImg = "<img src='images/four.gif' height=50 width=50>";
            sCode = sCode + "4";
            break;
        case 28:
            sImg = "<img src='images/five.gif' height=50 width=50>";
            sCode = sCode + "5";
            break;
    };

    return(sImg);

}



function getRandomSecureVal(nValues)
{
var sImage = "";
  for (i=0; i < nValues; i++)
  {
    sImage = getRandomImage();
    document.write(sImage);
  }
}


function validate(usercode,useremail)
{

    var bTest;
    bTest = validateEmail(useremail);

    if (bTest == false)
    {
        attempts++;
        var tries1 = 3 - attempts;
        if (tries1 == 0)
        {
             alert("Email Address Incorrect. Due to security you will be redirected to the home page.\nPlease contact us by email or phone if this problem persists.\nSorry for the inconvenience.");
            location.href='http://www.littlebighorngc.com/index.html';
        }
        else
        {
            alert("Incorrect Email Address, please try again. You have " + tries1 + " attempts left.");
            document.contactus.securid.value = "";
            document.contactus.Email.value = "";
            document.contactus.Email.focus();
        }
        return false;
    }

    usercode = usercode.toLowerCase();
    if (usercode == sCode)
    {
        //alert("you passed!");
        return true;
    }
    else
    {
        attempts++;
        var tries = 3 - attempts;
        if (tries == 0)
        {
            alert("Password Incorrect. Due to security you will be redirected to the home page.\nPlease contact us by email or phone if this problem persists.\nSorry for the inconvenience.");
            location.href='http://www.littlebighorngc.com/index.html';

        }
        else
        {
            alert("Incorrect Password, please try again. You have " + tries + " attempts left.");
            document.contactus.securid.value = "";
            document.contactus.securid.focus();
        }
    }

    return false;
}



function validateEmail(elementValue)
{

    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
}


