﻿var emailPhrase = "Email Address";
var passwordPhrase = "Password";
      
function controlFocus(control, phrase)
{
    if (control.value == phrase)
    {
        control.value = "";            
        control.className = "headerTextBox";    
    }            
}

function controlLostFocus(control, phrase, nextControlID)
{
    if (control.value == "")
    {
        control.value = phrase;
        control.className = "disabledTextBox";
    }
    
    if (nextControlID != null)
    {
        var nextControl = $get(nextControlID);
        
        if (nextControl != null)
            nextControl.focus();    
    }
}

function getSearchText()
{
   return getSearchBox().value;
}

function isReturnKey(e) {
    return e.keyCode == 13;
}

function clickButtonIfEnterKeyPressed(e, buttonToClickID)
{
    if (isReturnKey(e))
    {
        var button = document.getElementById(buttonToClickID);  
           
        if (button != null)
        {            
           e.cancel = true; 
                      
           button.focus();
           
           if (button.dispatchEvent)
           {
                var e = document.createEvent('MouseEvents');
                e.initEvent('click', true, true);
                button.dispatchEvent(e);
           }    
           else
           {
                button.click();
           }     
        }         
            
        return false;
    }
    else
    {
        return true;        
    }
}

function doDisableControl(control)
{
    setTimeout("disableControl('" + control.id + "');", 100);
    return true;
}

function disableControl(controlId)
{
    var element = document.getElementById(controlId);
    if (element != null)
        element.disabled = true;
}


function doTextSearch()
{
    var searchText = getSearchText();
        
    if (searchText == '')
    {
        alert('Please enter a keyword to search for.');
        getSearchBox().focus();
    }
    else
    {
        var url = '../Products/productlist.aspx?type=txt&cp=1&ipp=15&keywords=' + getSearchText();
        document.location = url;
    }
}


function checkForNoRetail(ddl)
{
    if (ddl.selectedIndex == 1)
    {
        if (confirm('As a wholesale supplier, Flappin\' Flags only sells to retailers that carry our products for the public. \n\nIf you are not planning to resell Flappin\' Flag\'s products, please click the \"OK\" button below to find a shop that carries them!\n\nThank you,\n\nFlappin\' Flags.'))
        {
            document.location = '../AboutUs/wheretobuy.aspx';
        }
    }
}
function showCatalogPopup() {
    var loc = window.location + "";
    if (loc.indexOf('Home') > 0) {
        if (shouldShowCatalogPopup()) {
            $.modal('<iframe src="../Catalogs/ViewCatalogPopup.aspx" height="480" width="602" style="border:0" frameborder="0"></iframe>',
        { opacity: 70,
            onOpen: function(dialog) { fadeDialogIn(dialog); },
            closeHTML: "Close",
            containerCss: {
                backgroundColor: "#fff",
                borderColor: "#000000",
                height: 480,
                padding: 0,
                width: 602,
                marginTop: -50
            },
            overlayClose: true
        });
        }
    }
}
function fadeDialogIn(dialog) {
    dialog.overlay.fadeIn('fast', function() {
        dialog.data.hide();
        dialog.container.fadeIn('fast', function() {
            dialog.data.slideDown('fast');
        });
    });
}
function closeDialog() {
    $.modal.close();
}
function setCatalogPopupCookie(value) {
    if (value)
        value = 'true';
    else
        value = 'false';
    var expiredays = 365;
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = "2010NoShow=" + value + ((expiredays == null) ? "" : "expires=" + exdate.toGMTString());
}
function getCatalogPopupCookie() {
    var c_name = "2010NoShow";
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function shouldShowCatalogPopup() {
    var value = getCatalogPopupCookie();
    if (value != null && value != "true")
        return true;
    else
        return false;
}
function wasLogin(dataItems) {
    var foo = "bar";
}