﻿// JScript File
var emailCounter = 0;

function incrEmailCount() {
    if (emailCounter >= 9)
        return false;
    emailCounter++;
    return true;
}

function validateEmailCounter(sender, args) {
    if (args.Value != '') {
        var email = args.Value;
        if (!validateEmail(email)) {
            args.IsValid = false;
            if (incrEmailCount())
                return;
            else {
                args.IsValid = false;
                $get(sender.controltovalidate).disabled = true;
                return;
            }
        }
    }

    args.IsValid = true;
}

function validateEmail(email) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (email.match(emailRegEx))
        return true;
    else
        return false;
}

function validatePrivacy(sender, args) {
    if (args.value != '')
        args.IsValid = true;
    else
        args.IsValid = false;

    return;
}
function CloseDiv(div) {
    document.getElementById(div).style.visibility = "hidden";
}

function HideModalPopup(modelId) {
    var modal = $find(modelId);
    modal.hide();
}

function loadNewWindow(URL, newWinName, newWinWidth, newWinHeight, scrollbars) {
    winRef = window.open(URL, newWinName, 'toolbar=0,location=0,directories=0 ,status=0,menubar=0,scrollbars=' + scrollbars + ',resizable=1,width=' + newWinWidth + ',height=' + newWinHeight + ',top=300,left=300');
    winRef.focus();
}

function imposeMaxLength(evt, Object, MaxLen) {
    var returnVal = true;
    try {
        var characterCode; //literal character code will be stored in this variable

        if (window.event)
            characterCode = evt.keyCode;
        else
            characterCode = evt.which;

        if (Object.value.length <= MaxLen) {
            returnVal = true;
        }
        else {
            if ((characterCode == 8) || (characterCode == 127))
                returnVal = true;
            else
                returnVal = false;
        }
    }
    catch (ex) {
        alert(ex);
        returnVal = false;
    }
    return returnVal;
}

/* ex: onkeypress="checkEnter(event)" */
function checkEnter(evt) { //e is event object passed from function invocation
    try {
        var characterCode; //literal character code will be stored in this variable

        if (window.event)
            characterCode = evt.keyCode;
        else
            characterCode = evt.which;

        if (characterCode == 13) //if generated character code is equal to ascii 13 (if enter key)
            return true;
        else
            return false;
    }
    catch (ex) {
        //alert(ex);
    }
}


function showFeedbackForm() {
    $("#feedbackFormWrapper").show();
    $("#feedbackButton").hide();
}
function hideFeedbackForm() {
    $("#feedbackButton").show();
    $("#feedbackFormWrapper").hide();
}



/*Character Counts for inputs
Looks for an element with an id of charcounter, if found, looks for all elements with either a maxlength or charcount attribute.
(charcount was for textareas)
*/

function hookupCounter(id, maxlength) {
    if (maxlength != null && maxlength != '2147483647') {//ie defaults to 2147483647
        $("#" + id).charCounter(maxlength, {
            container: "#charcounter"
        });
        $("#" + id).mouseout(function() {
            $('#charcounter').html('&nbsp;');
        });
        $("#" + id).focus(function() {
            $('#charcounter').show();
        });
    }
}

function hookupCharacterCounters() {
    if ($.fn.charCounter && $('#charcounter')) {
        //$('#charcounter').hide(); //hide counter msg
        $('[maxlength],[charcount]').each(function() {
            if (this.getAttribute('type') == 'text' || this.tagName == 'TEXTAREA') {
                //var charcount = this.getAttribute('charcount');
                var maxlength = this.getAttribute('maxlength');
                if (maxlength == null)
                    maxlength = this.getAttribute('charcount');

                hookupCounter(this.id, maxlength);
            }
        });
    }
}

function setupPage() {
    hookupCharacterCounters(); //setup charactercounts
    if ($.fn.tablesorter != undefined) {
        $("#sortableTable").tablesorter(
    {
        textExtraction: function(node) {
            // if there is a link, return the content of the link
            if (node.getElementsByTagName('a')[0]) {
                return node.getElementsByTagName('a')[0].innerHTML;
            }
            return node.innerHTML;
        }
    });
    }
}

//setup carousels
$(function() {
    if ($.fn.carousel != undefined)
        $('.carousel').carousel({ placeholder: "/images/loading-lg.gif" });
});

// setup my carousel
//$(function() {
//    if ($.fn.mycarousel != undefined)
//        $('.mycarousel').mycarousel({ placeholder: "/images/loading-lg.gif" });
//});

//setup lightbox for my carousel
$(function() {
    if ($.fn.lightBox != undefined)
        $('.mycarousel a').lightBox({
            maxHeight: 500,
            maxWidth: 700,
            imageLoading: '/skins/2008/images/lightbox/lightbox-ico-loading.gif',
            imageBtnPrev: '/skins/2008/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/skins/2008/images/lightbox/lightbox-btn-next.gif',
            imageBtnClose: '/skins/2008/images/lightbox/lightbox-btn-close.gif',
            imageBlank: '/skins/2008/images/lightbox/lightbox-blank.gif'
        });

});

//setup lightbox
$(function() {
    if ($.fn.lightBox != undefined)
        $('.carousel a').lightBox({
            maxHeight: 500,
            maxWidth: 700,
            imageLoading: '/skins/2008/images/lightbox/lightbox-ico-loading.gif',
            imageBtnPrev: '/skins/2008/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/skins/2008/images/lightbox/lightbox-btn-next.gif',
            imageBtnClose: '/skins/2008/images/lightbox/lightbox-btn-close.gif',
            imageBlank: '/skins/2008/images/lightbox/lightbox-blank.gif'
        });

});
//setup references
$(function() {
    if ($.fn.reference != undefined)
        $('.references').reference({});
});
