﻿var WebImageRoot = "/123/Image/";

var loading = true;
var navTabs = new Array();
var activeTab = null;

//-----------------------------------------------

function PageOnload( sender )
{
    navTabs[0] = document.getElementById( "tabOverview" );
    navTabs[0].imageSrc = "NavTabOverview";
    navTabs[1] = document.getElementById( "tabFeatures" );
    navTabs[1].imageSrc = "NavTabFeatures";
    navTabs[2] = document.getElementById( "tabFreeTrial" );
    navTabs[2].imageSrc = "NavTabFreeTrial";
    navTabs[3] = document.getElementById( "tabLogin" );
    navTabs[3].imageSrc = "NavTabLogin";

    // activeTabName is in master page.
    activeTab = document.getElementById( activeTabName );
    loading = false;
}

//-----------------------------------------------

function NavTabOnOver( sender, imgSrc )
{
    if ( loading == false )
    {
        if ( sender.id != activeTab.id )
        {
            sender.src = WebImageRoot + sender.imageSrc + "Over.gif";
        }  
    }
}

//-----------------------------------------------

function NavTabOnOut( sender, imgSrc )
{
    if ( loading == false )
    {
        if ( sender.id != activeTab.id )
        {
            sender.src = WebImageRoot + sender.imageSrc + ".gif";
        }
    }
}

//-----------------------------------------------

function NavTabClick( sender )
{
    if ( activeTab.id == sender.id )
    {
        return;
    }
    
    if ( sender.id == "tabFeatures" )
    {
        ShowFeaturePage();
        return;
    }

    var requireSSL = false;    
    var page = "";
    switch ( sender.id )
    {
        case "tabOverview":
        page = "/Default.aspx?tab=tabOverview";
        break;
        
        case "tabFreeTrial":
        page = "/FreeTrial.aspx?tab=tabFreeTrial";
        break;
        
        case "tabLogin":
        page = "/123Secure/AppLogin.aspx?tab=tabLogin";
        requireSSL = true;
        break;
    }
    
    window.location.href = GetHostURL( requireSSL ) + page;
}

//-----------------------------------------------

function ValidateFreeTrialAppForm( theForm )
{   
    if ( loading )
    {
        return false;
    }
    
    var msg = "";

    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtFirstName.value ) )
    {
        msg = " * First Name\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtLastName.value ) )
    {
        msg += " * Last Name\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtEmail.value ) )
    {
        msg += " * E-mail\n";
    }
    else
    {
        if ( ! IsValidEmailAddress( theForm.ctl00$ContentPlaceHolder1$txtEmail.value ) )
        {
            msg += " * E-mail address is not valid.\n";
        }
    }
    
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtPhone.value ) )
    {
        msg += " * Phone Number\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtCompany.value ) )
    {
        msg += " * Company Name\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$drpEmployees.options[
    theForm.ctl00$ContentPlaceHolder1$drpEmployees.selectedIndex ].value ) )
    {
        msg += " * Employees\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$drpCountry.options[
    theForm.ctl00$ContentPlaceHolder1$drpCountry.selectedIndex ].value ) )
    {
        msg += " * Country\n";
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$drpSource.options[
    theForm.ctl00$ContentPlaceHolder1$drpSource.selectedIndex ].value ) )
    {
        msg += " * How did you hear about us\n";
    }
    
    if ( msg != "" )
    {
        window.alert( "Please enter information for the following fields:\n" + msg );
    }
    
    if ( msg == "" )
    {
        loading = true;
        return true;
    }
    else
    {
        return false;
    }
}

//-----------------------------------------------

function ValidateAppLoginForm( theForm )
{   
    if ( loading )
    {
        return false;
    }
    
    var msg = "";
    var obj = null;
    
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtPassword.value ) )
    {
        msg = " * Password\n";
        obj = theForm.ctl00$ContentPlaceHolder1$txtPassword;
    }
    if ( IsBlank( theForm.ctl00$ContentPlaceHolder1$txtUserID.value ) )
    {
        msg = " * User ID\n" + msg;
        obj = theForm.ctl00$ContentPlaceHolder1$txtUserID;
    }
    else if ( theForm.ctl00$ContentPlaceHolder1$txtUserID.value.indexOf( "@" ) == -1 )
    {
        //msg = " * Invalid User ID\n" + msg;
        //obj = theForm.ctl00$ContentPlaceHolder1$txtUserID;
    }
    
    
    if ( msg != "" )
    {
        window.alert( "Please enter information for the following fields:\n" + msg );
    }
    
    if ( msg == "" )
    {
        loading = true;
        return true;
    }
    else
    {
        obj.focus();
        return false;
    }
}

//-----------------------------------------------

function ShowHomePage()
{
    window.location.href = GetHostURL( false ) + "/Default.aspx";
}

//-----------------------------------------------

function ShowFeaturePage()
{
    window.location.href = GetHostURL( false ) + "/Features.aspx?tab=tabFeatures&divHeight=1160";
}

//-----------------------------------------------

function FeatureDrillDown( featureID )
{
    window.location.href = GetHostURL( false ) + "/FeatureDetails.aspx?tab=tabFeatures&divHeight=730&itemID=" + featureID;
}

//-----------------------------------------------

function ShowFullSizePic( img )
{
    window.location.href = GetHostURL( false ) + "/ScreenShot.aspx?tab=tabFeatures&divHeight=730&imgSrc=" + img;
}

//-----------------------------------------------

function GetHostURL( requireSSL )
{
    return "";
    /*
    var retVal = "";
    if ( requireSSL )
    {
        retVal = "https://sys.123erp.net";
    }
    else
    {
        retVal = "http://" + window.location.hostname; 
    }
    return retVal;
    */
}

//-----------------------------------------------