//****
//Homepage article transitions
//****
var nCurrentLead = 0;
var nFadeOutOpacity = 100;
var nFadeInOpacity = 0;
var nClickedArticleLeadLink = -1;
var timerArticleLeads;

function initLeads()
{
    //set the first article to display
    nClickedArticleLeadLink = 0;

    //initiate the change
    changeLeads();              
}

// move to the previous article
function changeLeads_Prev()
{
    // stop moving at the first article
    if(nCurrentLead == 0)
    {
        nClickedArticleLeadLink = 0;
    }
    else
    {
        nClickedArticleLeadLink = nCurrentLead - 1;
    }
    
    // clear the timer
    clearTimeout(timerArticleLeads);
    
    //initiate the change
    changeLeads();
}

// move to the next article
function changeLeads_Next()
{
    // stop moving at the last article
    if(nCurrentLead == 4)
    {
        nClickedArticleLeadLink = 4;
    }
    else
    {
        nClickedArticleLeadLink = nCurrentLead + 1;
    }
    
    // clear the timer
    clearTimeout(timerArticleLeads);
    
    // initiate the change
    changeLeads();
}

// move to the selected article
function changeLeads_onClick(nArticleLeadLink)
{
    // adjust the story number for the array
    nClickedArticleLeadLink = nArticleLeadLink;

    // clear the timer
    clearTimeout(timerArticleLeads);
    
    // initiate the change
    changeLeads();
}

// change the article
function changeLeads()
{
    // set the previous article to the last current
    var nPreviousLead = nCurrentLead;

    // if a change has been initated outside of time
    if(nClickedArticleLeadLink >= 0)
    {
        nCurrentLead = nClickedArticleLeadLink; // set the current to the selected
        nClickedArticleLeadLink = -1; // clear out the selected for next time
    }
    else
    {
        if(nCurrentLead != 4) // determine if we reached the end
        {nCurrentLead = nCurrentLead + 1;} // if not continue to the next article
        else 
        {nCurrentLead = 0;} // or move to the first article
    }
    
    // change the selected story number
    for(i=0;i<=4;i++) {
        document.getElementById("article_lead_" + i).style.display = "none";
        document.getElementById("article_lead_" + i + "_link").className = "story"; // set all to normal
    }

    document.getElementById("article_lead_" + nCurrentLead).style.display = "block";
    document.getElementById("article_lead_" + nCurrentLead + "_link").className = "story selected"; // select the current lead aricle link
    
    timerArticleLeads = setTimeout("changeLeads()", 10000); // initate the time to change automatically
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) 
{
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot = str.indexOf(dot);
    
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail Address");
        return false;
    }

    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail Address");
        return false;
    }

    return true;
}

function ValidateForm() {

    var emailID = document.getElementById("txtEmail");

    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID");
        emailID.focus();
        return false;
    }
    if (echeck(emailID.value)==false){
        emailID.value="";
        emailID.focus();
        return false;
    }
    
    return true
}

function submitNewsletter() 
{
    var bValid = ValidateForm();

    if (bValid) {
        window.open('', 'newsletter', 'menubar=1,resizable=1,width=350,height=250');

        var newsletterForm = document.getElementById('aspnetForm');
        newsletterForm.action = 'http://www.robbreportcollection.com/code/newsletter.asp';
        newsletterForm.target = 'newsletter';
        newsletterForm.submit();
        newsletterForm.action = '';
        newsletterForm.target = '_self';
    }

    return false;
}
