﻿$.fn.checkIE6 = function() {
    var isIE6 = false;
    if ($.browser.msie) {
        if (parseInt($.browser.version) <= 6) {
            isIE6 = true;
        }
    }
    return isIE6;
};

$.fn.textFieldFocus = function(param) {
    $(this).each(function() {
        if ($(this).val() == '' || $(this).val() == param) { $(this).val(param).addClass('inactive'); }

        $(this).focus(function(ev) {
            if ($(this).val() == param) {
                $(this).val('').select().removeClass('inactive');

            }
        }).blur(function(ev) {
            if ($(this).val() == '') {
                $(this).val(param).addClass('inactive');
            }
        })
    })
};

$.fn.changeDropDownStyle = function(isIE6) {
    if (!isIE6) {
        $('#content select').wrap('<div class="select-wrapper"></div>')

        $('#content select').selectbox({
            inputClass: 'frmTxtSelect frmTxt', //css class for the input which will replace the select tag, display the background image
            containerClass: 'popout', // The list container class (a div element)
            hoverClass: 'current', // css class for the current element
            currentClass: 'selected' // css class for the selected element
        }).each(function() {
            $(this).parent().find('input').addClass($(this).attr('class'));
        });
    }
};

//******************************************************
/** function to replace the query string parameter with the given value
**/
$.fn.replaceQueryStringParam = function(url, param, value) {

    var tempUrl = url.toString();
    var qs = getQueryString(tempUrl);  //window.location.search.toString();

    //replace the parameter in the query string
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
    if (tempUrl.match(re))
        tempUrl = tempUrl.replace(re, '$1' + param + "=" + value + '$2');
    else if (qs == '?')
        tempUrl = tempUrl + param + "=" + value;
    else if (qs.length == 0)
        tempUrl = tempUrl + "?" + param + "=" + value;
    else
        tempUrl = tempUrl + "&" + param + "=" + value;

    //return the url
    return tempUrl;

};

//******************************************************
/** function to remove the parameter from query string
**/
$.fn.removeQueryStringParam = function(url, param) {
  return removeQueryParam(url, param);
};

//******************************************************
/** function to remove the parameter from query string
**/
function removeQueryParam(url, param) {
    var tempUrl = url.toString();
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
    if (tempUrl.match(re)) {
        tempUrl = tempUrl.replace(re, '$1');    //alert(tempUrl );
        //alert(tempUrl.charAt(tempUrl.length -1));
        if (tempUrl.length > 0 && tempUrl.charAt(tempUrl.length - 1) == '&') {
            tempUrl = (tempUrl.substr(0, tempUrl.length - 1));
        }
    }
    return tempUrl;
};

function getQueryString(url) {

    var items = url.toString().split('?');
    return items.length > 1 ? items[1] : '';
};

function urlEncode(value) {
    if (null != value && value.length > 0)
        return escape(value);
    else
        return value;
};

//***********
// converts the toggle element with show and hide panel
//*****
$.fn.hideshow = function(toggleElement, toggleContainerClass) {
    $(this).each(function(counter) {
        var hideMain = $(this);

        $(this).find(toggleElement).wrapInner('<a href="#"></a>');
        $(this).prepend('<a href="#" class="lnk-hide-show">Show</a>')

        $(this).find(toggleElement + ' a, .lnk-hide-show').click(function() {
            hideMain.toggleClass('closed');

            if (hideMain.hasClass('closed')) {
                hideMain.children('.lnk-hide-show').html('Show');
                hideMain.children(toggleContainerClass).hide('fast');
            }
            else {
                hideMain.children('.lnk-hide-show').html('Hide');
                hideMain.children(toggleContainerClass).show('fast');
            }
            return false;
        })
    })
};

