﻿$(document).ready(function() {

    //strips all html tags
    $(".plainTextBoxes").live("keyup", function(key) {

        var strInputCode = $(this).html();

        /* 
        This line is optional, it replaces escaped brackets with real ones, 
        i.e. &lt; is replaced with < and &gt; is replaced with >
        */
        strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
        $(this).val(strTagStrippedText);

    });

});

jQuery.fn.center = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

function EnsureInputNumericValuesOnly() {
    if (!(event.keyCode == 45 || event.keyCode == 46 || event.keyCode == 48 || event.keyCode == 49 || event.keyCode == 50 || event.keyCode == 51 || event.keyCode == 52 || event.keyCode == 53 || event.keyCode == 54 || event.keyCode == 55 || event.keyCode == 56 || event.keyCode == 57)) {
        event.returnValue = false;
    }
}


function ClearOnFocus(selector) {
    $(selector).focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (this.value.length == 0) {
            this.value = this.defaultValue;
        }
    });
}

function ResetFormFields(formId) {
    setTimeout(
        function() {
            document.getElementById(formId).reset();
        },
        5
    );
}


var questionId = 0;

function loadFaqAnswer(id, question, contentFullPath) {
    var data =
        {
            AnswerId: id
        };

    questionId = question;

    try {
        $.getJSON(contentFullPath, data, answerCallBack);
    }
    catch (err) {
        alert("error");
    }

}


function answerCallBack(answer) {

    $("div[id^=Answer]").each(function() {
        $(this).html('');
        $(this).removeClass();
    });

    $('#Answer' + questionId).addClass("AnswerBar");
    $('#Answer' + questionId).html(answer);

}


function populateSubjects(contentFullPath) {
    
    var data =
        {
            ContactUsDetailId: $('#contactUs_QueryType').val()
        };

    try {
        $.getJSON(contentFullPath, data, populateSubjectsCallBack);
    }
    catch (err) {
        alert("error");
    }

}

function populateSubjectsCallBack(subjects) {

    var options = '';
    
    for (var i = 0; i < subjects.length; i++) {
        options += '<option value="' + subjects[i].Id + '">' + subjects[i].Subject + '</option>';
    }
    $("select#contactUs_Subject").html(options);

}

function showhide(showId, hideId) {
    if (document.getElementById) {

        var showObj = document.getElementById(showId);
        var hideObj = document.getElementById(hideId);

        showObj.style.display = "";
        hideObj.style.display = "none";
    }
}

function showDiv(showId) {
    if (document.getElementById) {
        var showObj = document.getElementById(showId);
        showObj.style.display = "";
    }
}

function hideDiv(hideId) {
    if (document.getElementById) {
        var hideObj = document.getElementById(hideId);
        hideObj.style.display = "none";
    }
}


function moreAboutUs() {  
    $('#moreAboutUsLightbox').css({
        'height': $(document).height(),
        'filter': 'alpha(opacity=60)'
    })

    $('#moreAboutUs_outer_container').center()

    $('#moreAboutUsLightbox').fadeIn('slow');
    $('#moreAboutUs_form').fadeIn('slow');
    return false;
}


function closeMoreAboutUs() {
    $('#moreAboutUsLightbox').fadeOut('slow');
    $('#moreAboutUs_form').fadeOut('slow');
}

/*  
===============================================================================
WResize is the jQuery plugin for fixing the IE window resize bug
...............................................................................
Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/
===============================================================================
*/

(function($) {

    $.fn.wresize = function(f) {
        version = '1.1';
        wresize = { fired: false, width: 0 };

        function resizeOnce() {
            if ($.browser.msie) {
                if (!wresize.fired) {
                    wresize.fired = true;
                }
                else {
                    var version = parseInt($.browser.version, 10);
                    wresize.fired = false;
                    if (version < 7) {
                        return false;
                    }
                    else if (version == 7) {
                        //a vertical resize is fired once, an horizontal resize twice
                        var width = $(window).width();
                        if (width != wresize.width) {
                            wresize.width = width;
                            return false;
                        }
                    }
                }
            }

            return true;
        }

        function handleWResize(e) {
            if (resizeOnce()) {
                return f.apply(this, [e]);
            }
        }

        this.each(function() {
            if (this == window) {
                $(this).resize(handleWResize);
            }
            else {
                $(this).resize(f);
            }
        });

        return this;
    };

})(jQuery);