﻿$(document).ready(function() {


    // rounded corners
    $(".step").corner();


    // dropdown list
    $("#new_nav_list").droppy();
    

    // load FAQ content into Accordion control
    jQuery('#faq_list').accordion({
        alwaysOpen: false,
        autoHeight: false

    });


    // FAQ links

    // Usage:  use these links to expand individual FAQ panels.
    // Input:  The index of the accordion element 0-11 for now

    $("#faq_service").click(function() 
    {

        jQuery("#faq_list").accordion('activate', 2)

    })


    $("a.faq_pass").click(function() {

        jQuery("#faq_list").accordion('activate', 11)

    })



    function promptFocus() {

        $("#txtUserName").focus();

    }


    // check for blank login fields
    $('#submit_link').click(function() {

        if ($('#txtUserName').val() == "") {

            //alert("user name is required");  prompt is a styled replacement for JavaScript Alerts
            $.prompt('User Name is required', { show: 'slideDown' }, { callback: promptFocus });

            $("#txtUserName").focus();

            return false;

        }

        if ($('#txtPassword').val() == "") {

            //alert("password is required");
            $.prompt('Password is required');
            return false;

        }

    });

    //style our table rows automatically 
    //$('#frmTable tbody tr:odd').addClass('odd');

    // IE doesn't do input:focus - let's fix that
    if (jQuery.browser.msie === true) {

        jQuery('input')
                    .bind('focus', function() {
                        $(this).addClass('ieFocusHack');
                    }).bind('blur', function() {
                        $(this).removeClass('ieFocusHack');
                    });
    }

    // Mark current page on left nav control:
    if ($("#sub_box").length > 0) {   // if the sub_box div exists

        var scriptname = GetUrlScriptname();
        $('ul.category li a[href$="' + scriptname + '"]').parent().addClass('navselected');

    }

    //Mark current page on top nav control:
    if (GetUrlScriptname) {

        var topscriptname = GetUrlScriptname();

        // Mark current page on top nav
        $('#new_nav ul#new_nav_list li.top a[href$="' + topscriptname + '"]').addClass('selected');


        // Don't style dropdown subnav for current page
        $('#new_nav ul#new_nav_list li.top ul.subnav li a[href$="' + topscriptname + '"]').removeClass('selected');

    }

    // remove trailing nav divider
    $("html ul#new_nav_list li a:last").removeClass('list');
    $("html ul#new_nav_list li a:last").addClass('list_end');


});


// document.ready (above) = when the DOM has loaded.  (window).load = when all page elements have loaded.

$(window).load(
    function() {


        $("#login_box").show();

        // drop shadow on left nav and sign up button
        $("#sub_box").dropShadow();
        $("#front_how_it_works").dropShadow();
        $("#btn_signup").dropShadow();
        // $("#btn_partnering").dropShadow();
        // $("#btn_front_started").dropShadow();

        // login tabs functionality
        var tabContainers = $('div.tabs > div');
        tabContainers.hide().filter(':first').show();
        // tabContainers.hide().filter(':first').children("input").filter(':first').focus();
        tabContainers.hide().filter(':first').addClass('selected');


        $('div.tabs ul.tabNavigation a').click(function() {
            tabContainers.hide();
            //tabContainers.filter(this.hash).fadeIn('slow');
            tabContainers.filter(this.hash).show();
            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');

            //$("#partnerUserName").focus();
            //$("#txtUserName").focus();

            return false;
        }).filter(':first').click();


        // Add Google Maps to map page

        if (GetUrlScriptname() == "map.aspx") {

            var map = new GMap2(document.getElementById("map"));    
            map.setCenter(new GLatLng(45.5025, -122.6749), 14);
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.openInfoWindowHtml(map.getCenter(),
    					("<b>Giftango Corporation</b><br />2828 SW Corbett Ave. #216  <br />Portland, OR 97201"));

        }

        if (GetUrlScriptname() == "signup.aspx") 
        {
            var txtSaveForLater = document.getElementById("ctl00_ContentPlaceHolder1_txtSaveForLaterLink");
            
            if (txtSaveForLater != null)
            {
                txtSaveForLater.focus();
                txtSaveForLater.select();
            }
        }

    }
);

function GetUrlScriptname() 
{
    var rex = new RegExp("\\/[^\\/]+\\.\\w+($|\\?)");
    var match = rex.exec(location.pathname);

    if (match == null) {

        return "index.aspx";

    } else {

        return match[0].substring(1);
            
    }
}

/*************************************/
/* Function: ValidateDataForSaving()
/* Desc.: Validate data prior to saving
/*        the signup form
/*************************************/
function ValidateDataForSaving(objForm) 
{
    if (objForm.ctl00_ContentPlaceHolder1_txtLegalName.value == "") 
    {
        alert("Business Legal Name is required prior to saving form for later.");
        objForm.ctl00_ContentPlaceHolder1_txtLegalName.focus();
        return false;
    }

    if (objForm.ctl00_ContentPlaceHolder1_txtRandomCode.value == "") {
    
        alert("Security code is required prior to saving form for later.");
        objForm.ctl00_ContentPlaceHolder1_txtRandomCode.focus();
        return false;
    }

    return true;
}