﻿/// <reference path="jquery-1.6.1.min.js" />

/*
* All elements and parents of specified Table or Div (Specified by JQuery selector; so works for class or ID) will be printed
* Include Print.css in your page, and add any custom styling for your printable element there.
*/
function PrintClean(selector)
{
PrintElementAndParents(selector);
window.print();
}
/*
*This method can be called for multiple selectors consecutively in order to ensure element and all parents have 'print' class 
and will therefore be printed.  
Add Css Class 'noprint' to any children that shouldn't be printed.  
Add Css Class 'mustprint' to any children that have 'hidden' class and aren't displayed on screen, but must be visible for printing.
*/
function PrintElementAndParents(selector) {
    
    jQuery(selector).addClass("print");
    
    var parents = jQuery(selector).parents('*');
        
    for(var i = 0; i < parents.length; i++){
      jQuery(parents[i]).addClass("print");
    }

    //All children that don't have noprint should be printed print
    var children = jQuery(selector).find('*');

    for (var i = 0; i < children.length; i++) {
        if (jQuery(children[i]).hasClass("noprint") == false) {
            jQuery(children[i]).addClass("print");
        }
    }
}

$(document).ready(function() {
    var t = $(".spotlight_window");

    if (t == null || t.length == 0) //No candidate for Jquery.carousel (fader.js) on this page (currently only /default.aspx)
        return;

    $(".spotlight_window").carousel() //Add carousel behavior
    window.onbeforeunload = carousel.Stop;
});

/* ----- Slide Downs ----- */

//below for same address on checkout
//if diff address selected, will slide up
$("input.gcradio-same").click(function() {
    $('#sendtodiff').slideUp('slow');
});

//below for diff address on checkout
$("input.gcradio-diff").click(function() {
    $('#sendtodiff').slideDown('slow');
});

// Add onclick handler to checkbox w/id checkme
$("input.gccheck-gift").click(function() {

    // If checked
    if ($("input.gccheck-gift").is(':checked')) {
        
        $('#sendgift').slideDown("slow");
    
    } else {
        
        $('#sendgift').slideUp("slow");
    }

});


/* ----- Calls for ModalBox ----- */
$(document).ready(function () {
    $("a#addl").fancybox({ 'padding': 0, 'autoScale': false, 'titleShow': false, 'transitionIn': 'fade', 'transitionOut': 'fade', 'speedIn': '200', 'speedOut': '200', 'scrolling': 'no' });
    $("a#gift").fancybox({ 'padding': 0, 'autoScale': false, 'titleShow': false, 'transitionIn': 'fade', 'transitionOut': 'fade' });
    $("a#tella").fancybox({ 'padding': 0, 'autoScale': false, 'titleShow': false, 'transitionIn': 'fade', 'transitionOut': 'fade' });
    $("a.plandet").fancybox({ 'padding': 0, 'autoScale': false, 'titleShow': false, 'transitionIn': 'fade', 'transitionOut': 'fade' });
    $("a#learn-more").fancybox({'padding': 0, 'autoScale': false, 'titleShow': false, 'transitionIn': 'fade', 'transitionOut': 'fade', 'speedIn': '200', 'speedOut': '200', 'scrolling': 'no' });
});

function initializeGallerific(selector) {
    var gallery = $(selector).galleriffic({
        delay: 2500, // in milliseconds
        numThumbs: 2, // The number of thumbnails to show page
        preloadAhead: -1, // Set to -1 to preload all images
        enableTopPager: false,
        enableBottomPager: false,
        maxPagesToShow: 7,  // The maximum number of pages to display in either the top or bottom pager
        imageContainerSel: '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
        controlsContainerSel: '', // The CSS selector for the element within which the slideshow controls should be rendered
        captionContainerSel: '#caption', // The CSS selector for the element within which the captions should be rendered
        loadingContainerSel: '#loading', // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls: false, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls: false, // Specifies whether the slideshow's Next and Previous links should be rendered
        playLinkText: 'Play',
        pauseLinkText: 'Pause',
        prevLinkText: 'Previous',
        nextLinkText: 'Next',
        nextPageLinkText: 'Next &rsaquo;',
        prevPageLinkText: '&lsaquo; Prev',
        enableHistory: false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
        enableKeyboardNavigation: true, // Specifies whether keyboard navigation is enabled
        autoStart: false, // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions: false, // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 900
    });
}

// footer copyright
$(function() {
    var now = new Date()
    $("#footer-copyright").append("&copy;" + now.getFullYear() + "&nbsp;" + "GreatCall. All Rights Reserved.");
});

function addVerisignScriptToPage() {
    $(document).ready(function() {
        var verisignScript = '<script type="text/javascript" src="https://seal.verisign.com/getseal?host_name=www.greatcall.com&amp;size=L&amp;use_flash=NO&amp;use_transparent=NO&amp;lang=en"><\/script>';
        $(".verisign-official-logo").html(verisignScript);
    });
}

function SetClearTimeout(startorder) {
    var timer;
    if (startorder == "true")
        timer = window.setTimeout(function () { window.location.href = '/errorhandling/abouttoexpire.aspx'; }, 1200000);
    else
        window.clearTimeout(timer);
}

/* Text Area Event Handling - START */

//Had to add crazy paste key handling for the text areas due to a bug where paste would allow you to override the values...
$(function () {
    $('.dev-limittextarea').keydown(function (e) { return limitTextArea(e, $(this)); });
    //This is to fix the problem of being able to paste outside the bounds...
    $('.dev-limittextarea').bind('paste', function (e) {
        var textarea = $(this);
        setTimeout(function () { limitText(textarea); }, 100); //Have a 100ms delay to allow the value to get populated, this is a stack overflow fix for this problem...  however I do not like this method, it is the only solution I could find...
    });
});

function limitText(limitTextArea) {
    var limit = limitTextArea.attr('data-limittextarea');
    var value = limitTextArea.val();
    if (value.length >= limit) {
        limitTextArea.val(value.substring(0, limit));
        return false; //To prevent the key press from happening and allowing the extra character.
    }
}

function limitTextArea(event, limitTextArea) {
    var key = event.keyCode;
    if (key != 8 && key != 46) {
        return limitText(limitTextArea);
    }
}

/* Text Area Event Handling - END  */

