﻿var galleriaKeyBoard = 0;

function getSiteBaseUrl() { return $('#hidSiteBaseUrl').val(); }
function SelectAll(chk) {
    var chks = $(":checkbox");    
    if (chk) {
        if (chk.className == 'lkcheck') {
            chk.className = 'lkcheck2';
            chk = true;
        }
        else {
            chk.className = 'lkcheck';
            chk = false;
        }
    }
    for (var i = 0; i < chks.length; i++) {
        if (chks[i]) {
            chks[i].checked = chk;
        }
    }
}
function pagerBack(a) {
    var index = parseInt($('#PagerIndex').val());
    if (index == 1) {
        $('.pagerBack').hide('slow');
        return; // alert('You are at the first page'); //already on the 1st page
    }
    index--;
    if (isNaN(index) || index < 1) index = 1;
    $('#PagerIndex').val(index);
    $('form[enctype!="multipart/form-data"]').submit();
}
function pagerNext(a) {
    var total = 0;
    var toRecord = 0;
    if (!isNaN($('#hidPagerTotalRecord').val())) {
        total = parseInt($('#hidPagerTotalRecord').val());
        if (!isNaN($('#hidPagerToRecord').val())) {
            toRecord = parseInt($('#hidPagerToRecord').val());
            if (toRecord >= total) {
                $('.pagerNext').hide('slow');
                return;// alert('You are at the last page');//already on the last page  
            }
        }
    }
    var index = parseInt($('#PagerIndex').val());
    index++;
    if (isNaN(index) || index < 1) index = 1;
    $('#PagerIndex').val(index);     
    $('form[enctype!="multipart/form-data"]').submit();
}
function pagerIndexChanged(t) {
    var index = parseInt($('#PagerIndex').val());
    var pagerSize = parseInt($('#PagerSize').val());

    if (isNaN(index) || index < 1) {        
        $('#PagerIndex').val(1);
        return;
    }
    if (index * pagerSize > parseInt($('#hidPagerTotalRecord').val())) {
        $('#PagerIndex').val(1);
    }
    $('form[enctype!="multipart/form-data"]').submit();
}
function pagerKeyPress() {
    var index = $('#PagerIndex').val();
    if (index == '') return;
    if (isNaN(index) || parseInt(index) < 1) {$('#PagerIndex').val(1);}
}
function startSlideShow(idx) {
    $('#body').hide();
//    $('#loading').width($(window).width());
//    $('#loading').height($(window).height());
    $('#loading').show();
    if (!idx) idx = 0;
    setTimeout('loadSlideShow(' + idx + ')', 1000);
}
function loadSlideShow(idx) {
    var c = $('#gallery');
    c.html('');
    c.show();
//    c.width($(window).width());
    //    c.height($(window).height());
    c.galleria({
        data_config: function (img) {
            return {
                thumb: $(img).attr('src'),
                image: $(img).attr('image'),
                title: $(img).attr('title'),
                description: $(img).attr('alt')
            }
        }
            , data_source: '#gallerysource'
            , keep_source: true
            , debug: false
            , transition: 'slide'
            , show: idx
            , maxScaleRatio: 1
            //,carouselFollow: true
        //, autoplay: true
    });
    //var total = Galleria.get().length;
    //var gal = Galleria.get(total - 1);
    if (galleriaKeyBoard < 1) {
        Galleria.get(0).attachKeyboard({
            LEFT: function () { Galleria.get(0).prev(); }
        , RIGHT: function () { Galleria.get(0).next() }
        , RETURN: function () { Galleria.get(0).play(3000); }
        , ESCAPE: function () { closeGallery(); }
        });
        galleriaKeyBoard = 1;
    }   
    
    $('#loading').hide();
}
function closeGallery() {
    Galleria.ClearGalleries();
    $('#gallery').hide();
    $('#body').show();   
}

jQuery.fn.ForceNumericOnly =
function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        })
    })
};
function newTimeString() {
    var d = new Date();
    return d.getHours() + '.' + d.getMinutes() + '.' + d.getSeconds();
}
/*function showcount(c, l) { $(event.srcElement).next('[class=""]').text('[' +(l - c) +' key:'+ event.keyCode + ' char left]');} //.parent().find('span').text(l - c);}*/

/*
* jQuery.fn.textLimit( limit, callback );
*
* Add a limit to your textarea and inputfields.
*
* $('.element').textLimit( 100 );
*
* Version 1.0.0
* www.labs.skengdon.com/textLimit
* www.labs.skengdon.com/textLimit/js/textLimit.min.js
*/
/*; (function ($) { $.fn.clearTextLimit = function () { return this.each(function () { this.onkeydown = this.onkeyup = null; }); }; $.fn.textLimit = function (limit, callback) { if (typeof callback !== 'function') var callback = function () { }; return this.each(function () { this.limit = limit; this.callback = callback; this.onkeydown = this.onkeyup = function () { if (event.keyCode == 13 || event.keyCode == 36 || event.keyCode == 39) { return true; } this.value = this.value.substr(0, this.limit); this.reached = this.limit - this.value.length; showcount(this.value.length, this.limit); this.reached = (this.reached == 0) ? true : false; return this.callback(this.value.length, this.limit, this.reached); } }); }; })(jQuery);*/

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
};
function shadowText(ctrl, text) {    
    if (typeof (ctrl) == 'string') {
        ctrl = $('#' + ctrl);
    }

    ctrl.val(text)
    .css('color', '#ccc')
    .focus(function () {
        if (ctrl.val() == text) ctrl.val('');
        ctrl.css('color', '#333')
    })
    .blur(function () {
        if (ctrl.val() == '') { ctrl.val(text); ctrl.css('color', '#ccc') }
        else { ctrl.css('color', '#333'); }
    });
}
jQuery.fn.accordian = function () { $(this).click(function () { $(this).toggleClass('lkaccordup lkaccorddown'); $(this).parent().next().slideToggle(); }); }
function dragStart(event, ui) {if (event.target) {/*ff*/if (event.originalEvent.target.className == 'jqmWindowTitle') return true;}else if (event.srcElement.className == 'jqmWindowTitle') return true;return false;}
function PopShare(type, url, title) {
    if (type == 'fb') {
        window.open('http://www.facebook.com/sharer.php?u=' + url + '&t=' + title, 'fpeShare', 'location=0,status=0,menubar=0,toolbar=0,height=500,width=600', 1);
    }
    else if (type == 'tw') {
        window.open('http://twitter.com/home?status=Currently looking at ' + url + '&source=http://www.freepiceditor.com&t=' + title, 'fpeShare', 'location=0,status=0,menubar=0,toolbar=0,height=500,width=600', 1);
    }
}
function selectAllText(c) { c.focus(); c.select(); }
jQuery.fn.outer = function () {
    return $($('<div></div>').html(this.clone())).html();
}
$(document).ready(function () {
    $('.lkaccordup').accordian();
    $('.lkaccorddown').accordian();
});
