﻿function ConfigureClaimBox(control)
{
    if (control.getAttribute("IsEmpty") == "true")
     {
        control.setAttribute("IsEmpty", "false");
        control.style.backgroundImage = 'none';
    }

    if (control.value == "")
     {
        control.setAttribute("IsEmpty", "true");
        control.style.backgroundImage = 'url(../images/enter_code.png)';
    }
}

function ValidateOnInput(mode, control, e)
 {
    var key;
    var isCtrl;

    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    // check for backspace or delete, or if Ctrl was pressed
    //
    if (key == 8 || isCtrl || key == null)
    {
        return true;
    }

    // Numeric
    //
    var regExpression = /\D/;

    switch (mode.toLowerCase()) {
        // Alpha  
        // 
        case "a":
            {
                regExpression = /[^A-Za-z]/;
                break;
            }
            // Alpha with spaces
            //
        case "as":
            {
                regExpression = /[^A-Za-z .]/;
                break;
            }
            // Alpha numeric with no dash (minus)
            //
        case "an":
            {
                regExpression = /[^A-Za-z0-9]/;
                break;
            }
            // Alpha numeric with dash (minus)
            //
        case "an-":
            {
                regExpression = /[^A-Za-z-0-9]/;
                break;
            }

            // Alpha numeric with spaces
            //
        case "ans":
            {
                regExpression = /[^A-Za-z-0-9 ]/;
                break;
            }
            //Decimal
            //
        case "d":
            {
                regExpression = /[^-0-9.]/;
                break;
            }
    }

    keychar = String.fromCharCode(key);

    if (regExpression.test(keychar)) {
        return false;
    }

    return true;
}

function CheckForCode()
{

    if ($('#tbClaimCode').val() != "KLH4-GZP49")
    {
        $("<p><font color='#ffd241'>There seems to be a problem with your claim code.<br /><br />Please enter a valid claim code and try again.</font></p>").dialog(
                                                           {
                                                            modal: true,
                                                            title: "<img src='../images/photo/dialog_logo.png' height='24px'  style='margin-top:6px'  />&nbsp;&nbsp;<label style='position:relative; top:-6px'>Invalid Claim Code</label>",
                                                            width: 520,
                                                            
                                                            resizable: false,
                                                            draggable: false,
                                                            dialogClass: 'popupDialog'
                                                           }
                                                          );
    }
    else
    {
        var claimCode = $('#tbClaimCode').val();

        $('#tbClaimCode').val('');

        window.location = "ViewPhoto.aspx?id=" + claimCode; 
    }
}


function GetFacebookPublishControlID(name)
{
    var x = $("[id$='" + name + "']").attr('id');

    return x;
}

function ShareSuccessful()
{
    $('body').css('overflow', 'hidden');
    $("<p><font color='#ffd241'>You have successfully shared this photo strip on Facebook.</font></p>").dialog(
        {
            modal: true,
            title: "<img src='../images/photo/dialog_logo.png' height='24px'  style='margin-top:6px'  />&nbsp;&nbsp;<label style='position:relative; top:-6px'>Photo Strip Shared</label>",
            width: 580,
            resizable: false,
            draggable: false,
            dialogClass: 'popupDialog',
            close: function () { $('body').css('overflow', 'auto'); }
        }
        );
}

                                                       
function ShareNotSuccessful()
{
    $('body').css('overflow', 'hidden');
    $("<p><font color='#ffd241'>This photo strip was not shared on Facebook.</font></p>").dialog(
        {
            modal: true,
            title: "<img src='../images/photo/dialog_logo.png' height='24px' style='margin-top:6px' />&nbsp;&nbsp;<label style='position:relative; top:-6px'>Photo Strip Not Shared</label>",
            width: 580,
            resizable: false,
            draggable: false,
            dialogClass: 'popupDialog',
            close: function () { $('body').css('overflow', 'auto'); }
        }
        );
}

function DisplayDemoMessage()
{
    $('body').css('overflow', 'hidden');
    $("<p><font color='#ffd241'>Sorry, this is a demo. Try the Facebook button on the photo strip.</font></p>").dialog(
        {
            modal: true,
            title: "<img src='../images/photo/dialog_logo.png' height='24px'  style='margin-top:6px'  />&nbsp;&nbsp;<label style='position:relative; top:-6px'></label>",
            width: 360,
            resizable: false,
            draggable: false,
            dialogClass: 'popupDialog',
            close: function () { $('body').css('overflow', 'auto'); }
        }
        );    
}


function preloadImage(width, height, imagePath)
{
  pic = new Image(width, height);
  pic.src = imagePath;
}

function PreloadViewPage()
{
    if (document.images)
    {
        preloadImage(47, 39, "images/photo/facebook.png");
        preloadImage(47, 39, "images/photo/facebook_hover.png");

        preloadImage(47, 39, "images/photo/edit.png");
        preloadImage(47, 39, "images/photo/edit_hover.png");

        preloadImage(47, 39, "images/photo/youtube.png");
        preloadImage(47, 39, "images/photo/youtube_hover.png");

        preloadImage(988, 182, "images/photo/stripview_logo.png");
        preloadImage(988, 637, "images/photo/stripview.png");

        preloadImage(179, 470, "images/photo/ad.jpg");

        preloadImage(72, 72, "images/photo/btn_play_video.png");
        preloadImage(72, 72, "images/photo/btn_play_video_hover.png");
    }
}                  

