﻿/// <reference path="jquery-1.4.1.min-vsdoc.js" /> 

$.fn.clearSelect = function() {
    return this.each(function() {
        if (this.tagName == 'SELECT')
            this.options.length = 0;
           
    });
}

$.fn.fillSelect = function(data, getOption) {
    return this.clearSelect().each(function() {
        if (this.tagName == 'SELECT' && getOption) {
            var dropdownList = this;
            $.each(data, function(index, dataObject) {
                var option = getOption(dataObject);
                if ($.browser.msie) {
                    dropdownList.add(option);
                }
                else {
                    dropdownList.add(option, null);
                }
            });
        }
    });
}

// globalization support in javascript
// see files globalization/fr-CA.js, globalization/en-US.js
jQuery.extend({
    getResource: function(name) {
        try {
            var res = eval('$.fn._resources.' + name);
        }
        catch (ex) {
            return null;
        }
        return res;
    }
});

$(document).ready(function() {
    $("table.list tr:even td").each(function() {
        $(this).addClass("even");
    });
});

Number.prototype.format = function(format) {
if (typeof format != 'string') { return; } // sanity check
 
	var hasComma = -1 < format.indexOf(','),
		psplit = format.stripNonNumeric().split('.'),
		that = this;
 
	// compute precision
	if (1 < psplit.length) {
		// fix number precision
		that = that.toFixed(psplit[1].length);
	}
	// error: too many periods
	else if (2 < psplit.length) {
		throw('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
	}
	// remove precision
	else {
		that = that.toFixed(0);
	}
 
	// get the string now that precision is correct
	var fnum = that.toString();
 
	// format has comma, then compute commas
	if (hasComma) {
		// remove precision for computation
		psplit = fnum.split('.');
 
		var cnum = psplit[0],
			parr = [],
			j = cnum.length,
			m = Math.floor(j / 3),
			n = cnum.length % 3 || 3; // n cannot be ZERO or causes infinite loop
 
		// break the number into chunks of 3 digits; first chunk may be less than 3
		for (var i = 0; i < j; i += n) {
			if (i != 0) {n = 3;}
			parr[parr.length] = cnum.substr(i, n);
			m -= 1;
		}
 
		// put chunks back together, separated by comma
		fnum = parr.join(',');
 
		// add the precision back in
		if (psplit[1]) {fnum += '.' + psplit[1];}
	}
 
	// replace the number portion of the format with fnum
	return format.replace(/[d,?.?]+/, fnum);
};
function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function checkForBrowserSupport(browserSupportWarningId) {
    if ($.browser.msie && $.browser.version <= 6) {
        $(browserSupportWarningId).show();
    }
    else {
        $(browserSupportWarningId).hide();
    }
}

function checkForCookieSupport(cookieWarningID) {
    ///<summary>
    /// Validates whether the browser supports cookies or not 
    /// and shows or hide the cookie warning.
    ///</summary>
    document.cookie = "CookieTest";
    var cookieEnabled = false;
    if (document.cookie == "") {
        $(cookieWarningID).show();
    }
    else {
        $(cookieWarningID).hide();
        cookieEnabled = true;
    }
    return cookieEnabled;
}

