
/**
 * @author kristiaan.thivessen
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 */

WebFontConfig = {
    google: {
        families: ['Droid+Sans:400,700)']
    }
};
(function(){
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
})();

$(function () {
    /* 
    * Various helper functions
    */
    Helpers = {
        /*
        * Give marked elements an equal min-height
        */
        equalizeHeight: function (els) {
            if (!els) els = $('.equalize');
            els.each(function () {
                var max = 0;
                var children = $('.equal', this);
                children.each(function () {
                    var h = $(this).outerHeight();
                    if (h > max) max = h;
                });
                children.each(function () {
                    var a = $(this);
                    var val = max - (a.outerHeight() - a.height());
                    a.css({ minHeight: val + 'px' });
                });
            });
        },
        /*
        * Manage placeholder text on INPUTs and TEXTAREAa
        */
        doPlaceHolderTexts: function (els) {
            if (!els) els = $('input[type=text][title], textarea[title]');
            var setText = function (el) {
                var v = el.val();
                if (v == '' || v == el.attr('title')) {
                    el.val(el.attr('title'));
                    el.addClass('placeholder');
                } else el.removeClass('placeholder');
            }
            els.each(function () {
                $(this).bind('blur', function () {
                    setText($(this));
                }).bind('focus', function () {
                    if ($(this).val() == $(this).attr('title')) $(this).val('');
                    $(this).removeClass('placeholder');
                });
                setText($(this));
            });
        },
        /*
        * Make entire elements clickable and redirect to the HREF of the first occurring anchor
        */
        doClickables: function () {
            var doClick = function (e) {
                if (e.target.tagName.toUpperCase() != "A") {
                    var href = $('a', this).eq(0).attr('href');
                    document.location = href;
                }
            };
            $(document).delegate('.clickable', 'click', doClick);
        },
        /*
        * Fill and place tooltips
        */
        doTooltips: function () {
            var tooltip = $('.tooltip');
            var hideTooltipDelayed;
            if (tooltip.length == 0) {
                tooltip = $('<div class="tooltip"><div class="tooltip_top">&#160;</div><div class="tooltip_contents"></div><a class="more">sluiten</a></div>');
                tooltip.bind('mouseenter', function (e) {
                    clearTimeout(hideTooltipDelayed);
                });
                tooltip.bind('mouseleave', function (e) {
                    delayedTooltipHiding();
                });
                $('body').append(tooltip);
                delayedTooltipHiding = function () {
                    hideTooltipDelayed = setTimeout(function () { tooltip.hide(); }, 1000);
                }
                tooltip.find('a.more').click(function () {
                    clearTimeout(hideTooltipDelayed);
                    tooltip.hide();
                });
            }
			var title;
            var showTip = function (e) {
                clearTimeout(hideTooltipDelayed);
                var tip = $(this);
				
                title = tip.attr('title');
				if(title == 'undefined') return;
				tip.attr('title', '');
				
                tip.css('cursor', 'help');
                tooltip.children('.tooltip_contents').html(title);
                tooltip.css({
                    'top': tip.offset().top - tip.innerHeight() - tooltip.innerHeight() - 4,
                    'left': tip.offset().left + tip.innerWidth() - (tooltip.innerWidth() / 2) + 1
                });
                tooltip.show();
            };
            var hideTip = function (e) {
                var tip = $(this);		
				tip.attr('title', title);		
                delayedTooltipHiding();
            }
            $(document).delegate('a.tip', 'mouseenter', showTip);
            $(document).delegate('a.tip', 'mouseleave', hideTip);
        },
        /*
        * Collapsible items (like FAQs)
        */
        Collapsibles: {
            init: function (els) {
                var self = this;
                this.duration = 100;
                // collapse deeplinked item
                var hash = document.location.hash;
                if (hash && hash != '#') {
                    var el = $(hash);
                    if (el.hasClass('collapse-item')) {
                        var group = el.parents('.collapsible').eq(0);
                        el.addClass('current');
                    }
                }
                this.initAll()
                if (!els) els = $('.collapsible');
                els.bind('click', function (e) {
                    var t = $(e.target);
                    if (t.hasClass('collapse-trigger')) {
                        var item = t.parents('.collapse-item').eq(0);
                        var ul = item.parent();
                        // this is set in F59 Product tabbladen.xslt
                        if (ul.hasClass('ga_product_faq_list')) {
                            // don't trigger google event if they are collapsing the question
                            if (!item.hasClass('current')) {
                                var ga_category = ul.attr('ga_category');
                                var ga_question = t.html();
                                _gaq.push(['_trackEvent', ga_category, 'Veelgestelde-vragen', 'FAQ-' + ga_question]);
                            }
                        }
                        self.toggle(item);
                        e.preventDefault();
                    }
                });
            },
            toggle: function (item) {
                if (item.hasClass('current')) {
                    $('.collapse-body', item).slideUp(this.duration, function () {
                        item.removeClass('current');
                    });
                } else {
                    // close all items in the group if set to do so
                    var group = item.parents('.collapsible').eq(0);
                    if (group.hasClass('collapse-single')) this.closeAll(group);
                    item.addClass('current');
                    $('.collapse-body', item).slideDown(this.duration);
                }
            },
            closeAll: function (group) {
                var self = this;
                $('.collapse-item', group).each(function () {
                    var u = $(this);
                    $('.collapse-body', u).slideUp(self.duration, function () {
                        u.removeClass('current');
                    });
                });
            },
            initAll: function () {
                // prepare all non-open items for animated opening
                $('.collapse-item').each(function () {
                    var u = $(this);
                    if (!u.hasClass('current')) $('.collapse-body', u).slideUp(0);
                });
            }
        }
    };

    window.setTimeout(function () { Helpers.equalizeHeight(); Helpers.equalizeHeight($('.ribbon'));}, 1);
    Helpers.doPlaceHolderTexts();
    Helpers.doClickables();
    Helpers.doTooltips();
    Helpers.Collapsibles.init();

    initSearchOnEnter('#su_search input.text, .search input.text');

    $(document).delegate('a[rel*=external]', 'click', function (e) {
        if (e.which > 1) return;
        e.preventDefault();
        window.open(this.href, '');
    });

    // alternative wishes carousel
    var u = $('#altwishes');
    if (u.length > 0 && u.carousel) {
        $('#altwishes').carousel({
            slides: 'li',
            navprev: $('#previous'),
            navnext: $('#next'),
            maxslides: 4
        });
    }

    $('body').addClass('jsactive').removeClass('jsinactive');


    closeLightboxLinks();

    toggleOptionPanels(); /* ... */

    insuranceApplicants();

    datePicker();

    radioListActivation();

    shadowboxInit();

    colorCheckboxErrorLabels();

    // Init na AJAX load
    if (typeof (Sys) != "undefined" && typeof (Sys.Application) != "undefined") {
        Sys.Application.add_load(function () {
            Helpers.equalizeHeight();

            radioListActivation();
            closeLightboxLinks();

            if (typeof (Shadowbox) != "undefined") {
                Shadowbox.setup();
            }
        });
    }

    new requestPanelTogglerGroup($('.insurance_request_holder'));

    pasteProtection.init();

    var rules = [{
        selection: 'maandag',
        options: ['9tot11', '11tot13', '13tot15', '15tot17', '17tto19', '19tot21']
    }, {
        selection: 'dinsdag',
        options: ['9tot11', '11tot13', '13tot15', '15tot17', '17tto19', '19tot21']
    }, {
        selection: 'woensdag',
        options: ['9tot11', '11tot13', '13tot15', '15tot17', '17tto19', '19tot21']
    }, {
        selection: 'donderdag',
        options: ['9tot11', '11tot13', '13tot15', '15tot17', '17tto19', '19tot21']
    }, {
        selection: 'vrijdag',
        options: ['9tot11', '11tot13', '13tot15', '15tot17', '17tto19', '19tot21']
    }, {
        selection: 'zaterdag',
        options: ['11tot13', '13tot15']
    }];
    new DependantSelects($('.call_me_day'), $('.call_me_time'), rules);

    new maidenNameFormChanger($('#field_aanhef'), $('#field_burgerlijkestaat'), $('#field_achternaam'), $('#field_meisjesnaam'), $('#field_partnernaam'));
    new maidenNameFormChanger($('#field_aanhef_partner'), $('#field_burgerlijkestaat_partner'), $('#field_achternaam_partner'), $('#field_meisjesnaam_partner'), $('#field_partnernaam_partner'));

    toggleSubforms.init();

    var u = $('a.listen')
    if (u.length > 0) u.audioPlayer('/swf/audio-player.swf');

    // Because of a browserbug in Safari 5.1 for Mac where the page is being refreshed when clicking on a selectbox,
    // the font-face font on the selectboxes is temporarily being replaced by a webfont in all Safari browsers:
    if (jQuery.browser.webkit && jQuery.browser.safari) jQuery('select').css('font-family', 'Arial, sans-serif');

    $('body').toggleClass('tickle');

	if(isNaN(parseInt(window.pushboxInterval))) window.pushboxInterval = 5;
	var pbox = new Pushbox($('.pushbox .slides li'), {
		navigation	: $('.pushbox .nav li'),
		transition	: 'fade',
		interval	: window.pushboxInterval
	});

	// read initial slide number for pushbox from url hash '#slide', if present
	var intPbHash = location.hash.indexOf('#slide');
	if(intPbHash != -1) {
		pbox.showSlide(parseInt(location.hash.substr(intPbHash + 6, 1)) - 1);
	}


});

	 
/**
 * Bind method to put callback functions in the correct scope *
 * @author Kristiaan Thivessen. <kristiaan.thivessen@efocus.nl>
 * @since 3 may 2011
 * @param scope: most of the time 'this'
 */
Function.prototype.bind = function(scope){
	var method = this;
	return function(){
		return method.apply(scope, arguments);
	};
};

/**
 * Throw a document.location on enter in a search field
 */
function initSearchOnEnter(inputs){
    $(inputs).each(function () {

        input = $(this);
        var submitBtn = input.siblings('a.submit');
        var term = '';

        if (input.attr('title') != input.val()) {
            term = input.val();
        };
		if (submitBtn.attr('href')) {
			var query = submitBtn.attr('href').split('?q=');
			submitBtn.attr({ href: query[0] + '?q=' + term });

			if (submitBtn.length != 0) {
				submitBtn.click(function (e) {
					e.preventDefault();
					document.location = $(this).attr('href');
				});
			}

			input.keyup(function (e) {
				var submitBtn = $(this).siblings('a.submit');
				if (e.keyCode == '13') {
					e.preventDefault();
					submitBtn.trigger('click');
				} else {
					var term = $(this).val();
					var query = submitBtn.attr('href').split('?q=');
					submitBtn.attr({ href: query[0] + '?q=' + term });
				}
			});
		}
    });
} 

/**
 * Is a string inside an array?
 */
function valueInArray(val, array) {
	for(i in array) {
		if(array[i] == val) return true;
		return false;
	}	
};

/**
 * Parse a block of HTML and give back an object with hcard data
 */
function extractVcard(vcard){
	var obj = new Object;
	obj = {
	    org: $('.org', vcard).text(),
	    photo: $('.photo', vcard).attr('src'),
	    address: {
	        streetAddress: $('.street-address', vcard).text(),
	        postalCode: $('.postal-code', vcard).text(),
	        locality: $('.locality', vcard).text(),
	        region: $('.region', vcard).text()
	    },
	    geo: {
	        latitude: $('.latitude', vcard).text(),
	        longitude: $('.longitude', vcard).text()
	    },
	    tel: $('.tel', vcard).text(),
	    email: $('.email', vcard).text(),
	    url: $('.url', vcard).attr('href')
	};

	return obj;
}

/**
 * Clicking on specific links closes the lightbox
 */
function closeLightboxLinks() {
	$('.lightbox_close').click(function(e){
		e.preventDefault();
		window.parent.parent.Shadowbox.close();
	});
}

/**
 * Clicking on specific links closes the lightbox
 */
function injectLightboxCloseLink() {
	$('#sb-title-inner').append('<a class="more lightbox_close">sluiten</a>');
	$('.lightbox_close').click(function(e){
		e.preventDefault();
		window.parent.parent.Shadowbox.close();
	});
}

/**
 * Selecting options will toggle a panel with more information
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 * @returns void
 */
function toggleOptionPanels() {
	var fields = $('.insurance_options .field');
	var txtShow = 'toon details';
	var txtHide = 'verberg details';

	$(fields).each(function(index, field){
		if ($(field).find('.insurance_applicants_panel').length != 0) {
			$(field).find('.insurance_applicants_panel').data('height', $(field).find('.insurance_applicants_panel').height());
			$(field).find('.insurance_applicants_panel').css('height', 0);
		}

		var closePanel = function(field){
			$(field).find('.toggler').html(txtShow);
			$(field).find('.insurance_applicants_panel').animate({'height': 0});
		}

		var openPanel = function(field){
			$(field).find('.toggler').html(txtHide);
			$(field).find('.insurance_applicants_panel').animate({'height': $(field).find('.insurance_applicants_panel').data('height')}, 
				function(){
					$(field).find('.insurance_applicants_panel').css('height', 'auto');
				}
			);
		}

		var denyPanel = function(field){
			if (!$(field).find('li.option:first').children('input[type=radio]').is(':checked')) $(field).removeClass('confirmed');
		}

		var recalculatePanelHeight = function(field){
			if ($(field).find('.insurance_applicants_panel').height() != $(field).find('.insurance_applicants_panel').data('height')) {
				$(field).find('.insurance_applicants_panel').data('height', $(field).find('.insurance_applicants_panel').height());
			}
		}

		var closeInactivePanels = function(field){
			$(fields).not($(field)).each(function(){
				$(this).removeClass('open');
				denyPanel(this);
				closePanel(this);
			});
		}

		var checkRadio = function(label) {
			var radio = $(label).prev('input[type=radio]');
			if ($(radio).hasClass('checked')) {
				$(radio).removeClass('checked');
			} else {
				$(radio).addClass('checked');
			}
			$(radio).trigger('click');
		}
		
		if ($(field).find('li.option').length != 0) {
			$(field).find('li.option:not(:first)').children().each(function(){
				$(this).click(function(){
					$(fields).each(function(){
						if ($(this).hasClass('open')) {
							$(this).removeClass('open');
							closePanel(this);
						}
						denyPanel(this);
					});
				});
			});
			$(field).find('li.option:first').children().each(function(){
				if ($(this).get(0).tagName.toLowerCase() == 'input') {
					if ($(this).is(':checked')) $(field).addClass('confirmed');
					$(field).find('.toggler').html(txtShow);
				}
				$(this).click(function(e){
					if ($(this).get(0).tagName.toLowerCase() == 'input') closeInactivePanels(field);
					if ($(this).get(0).tagName.toLowerCase() == 'label') {
						e.preventDefault();
						checkRadio(this);
					}
					if (!$(field).hasClass('open')) openPanel(field);
					$(field).addClass('open');
					$(field).addClass('confirmed');
				});
			});
		}
		if ($(field).find('.toggler').length != 0) {
			$(field).find('.toggler').click(function(e){
				e.preventDefault();
				$(field).toggleClass('open');
				if ($(field).hasClass('open')) {
					closeInactivePanels(field);
					openPanel(field);
				} else {
					closePanel(field);
				}
			});
		}
	});
}

/**
 * Selecting applications will toggle a panel with more information
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 * @returns void
 */
function insuranceApplicants() {
    $('.insurance_applicants ul > li').each(function (index, item) {
        $(item).find('input[type=checkbox]').each(function () {
            if ($(this).is(':checked')) $(item).addClass('active');
        });

        $(item).find('input[type=checkbox], label').click(function () {
            var input = ($(this).get(0).tagName.toLowerCase() == 'label') ? $(this).prev() : $(this);
            if ($(input).is(':checked')) {
                $(item).addClass('active');
            } else {
                $(item).removeClass('active');
            }

            $(item).parents('.insurance_applicants_panel').data('height', $(item).parents('.insurance_applicants_panel').height());

        });
    });
}

/**
 * Adds an icon triggering a Dutch localized calendar as a datepicker
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 * @returns void
 */
function datePicker() {
	if ($.datepicker == undefined) return false;

	$('.datepicker').datepicker(
		{
			showOn:				'button',
			buttonImage:		'/img/dela/icons/calendar.png',
			buttonImageOnly:	true,
			buttonText:			'toon kalender'
		},
		$.datepicker.regional['nl']
	);
}

/**
 * Adds an "active" class to the parent of the selected radiobutton.
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 * @returns void
 */
function radioListActivation() {
	var arrHolders = $('ul.insurance_selection > li');
	
	var activateHolder = function(elHolder) {
		$(arrHolders).removeClass('active');
		$(elHolder).addClass('active');
	}

	$(arrHolders).each(function(index, elHolder){
		$(elHolder).find('input[type=radio]').each(function(){
			if ($(this).is(':checked')) {
				activateHolder(elHolder);
			}
		});

		$(elHolder).find('input[type=radio]').click(function(){
			activateHolder(elHolder);
		});
	});
}

/**
 * Toggles form panels.
 * @author Kristiaan Thivessen
 * requestPanelTogglerGroup: instance manages a group of panel instances
 * requestPanelToggler: instance manages a panel
 */
function requestPanelTogglerGroup(els) {
	var self = this;
	this.elements = new Array();
	els.each(function(i) {
		self.elements[i] = new requestPanelToggler($(this), self);
	});	
}
requestPanelTogglerGroup.prototype = {
	// close all panels in group
	close: function(exception) {
		for(var i in this.elements) {
			var el = this.elements[i];
			if(el.root != exception) el.close(true);
		}
	}	
}
function requestPanelToggler(el, group) {
	var self = this;

	// internal vars
	this.root = el;
	this.group = group;
	this.status;
	this.panel = $('.insurance_request_panel_holder', this.root);
	this.togglerAnchor = $('.toggler', this.root);
	this.togglerAnchorText = {
		nl: {
			open: 'verberg details',
			closed: 'toon details'	
		}
	}
	this.lang = $('html').attr('lang');
	this.togglerOption = $('.insurance_request_toggler input:checkbox, .insurance_request_toggler input:radio', this.root).eq(0);
	
	// set initial state
	var cbStatus = this.togglerOption.attr('checked');
	var containsErrors = ($('.errors', this.root).length > 0);
	if(this.root.hasClass('closed') && cbStatus != true && !containsErrors) {
		this.status = 'closed'
		this.close();
	} else this.status = 'open';
	if(this.togglerOption.length && cbStatus == false) this.root.addClass('disabled');
	else this.root.removeClass('disabled');
	this.updateTogglers();
	
	// bind events
	this.togglerAnchor.bind('click', function(e) {
		e.preventDefault();
		if(self.status == 'closed') self.open(true);
		else self.close(true);
	});
	this.togglerOption.bind('change', function(e) {	
		if($(this).attr('checked')) {
			self.open(true, true);	
			self.root.removeClass('disabled');
		} else {
			self.close(true);
			self.root.addClass('disabled');
		}
	});
}
requestPanelToggler.prototype = {
	// open panel
	open: function(animateBool, closeGroupBool) {
		var self = this;
		var callback = function() {
			self.root.removeClass('closed');
			self.status = 'open';
			self.updateTogglers();
		}
		if(animateBool) {
			this.panel.slideDown('fast', callback);
			if(this.group && closeGroupBool) this.group.close(this.root);
		}
		else callback();	
	},
	// close panel
	close: function(animateBool) {	
		var self = this;
		var callback = function() {
			self.root.addClass('closed');
			self.status = 'closed';
			self.panel.hide();
			self.updateTogglers();
		}
		if(animateBool) this.panel.slideUp('fast', callback);
		else callback();
	},
	// update toggler text
	updateTogglers: function() {
		if(this.status == 'closed') var t = this.togglerAnchorText[this.lang].closed;
		else var t = this.togglerAnchorText[this.lang].open;
		this.togglerAnchor.text(t);
	}
}

/**
 * Paste protection (shortcut, contextmenu or rightclick)
 * @author Ralph Meeuws <ralph.meeuws[AT]efocus.nl>
 * @returns void
 */
pasteProtection = {
	init: function(els) {
		var self = this;
		if(!els) els = $('.pasteprotected');
		els.bind('contextmenu keydown', self.prevent);
	},
	prevent: function(e) {
		if(e.type == 'contextmenu' || ((e.ctrlKey || e.cmndKey) && e.keyCode == 86)) {
			e.preventDefault();
			var text = $(this).attr('data-pasteprotected');
			if(text && text != '') alert(text);
		}
	}			
}

// make a SELECT element's available options depend on another SELECT's value
function DependantSelects(selectSource, selectTarget, rules) {
	var self = this;
	this.selectSource = selectSource;
	this.selectTarget = selectTarget;
	this.rules = rules;
	this.selectTargetOptions = $('option', this.selectTarget).clone();
	this.selectSource.bind('change', function(e) {
		self.parse();
	});
	this.parse();
}
DependantSelects.prototype = {
	parse: function() {
		var self = this;
		var rule;
		// which rule?
		for(var i in this.rules) {
			if(this.rules[i].selection == this.selectSource.val()) rule = this.rules[i];
		}
		this.selectTarget.html('');
		if(rule) {
			// append all options that fit the rule
			this.selectTargetOptions.each(function(i) {
				var val = $(this).attr('value');
				if(rule.options.valueOf().indexOf(val) > -1 || val == '-1') self.selectTarget.append($(this).clone());
			});
		} else {
			// append all options
			this.selectTarget.append(this.selectTargetOptions.clone());
		}
		this.selectTarget.val('-1');
	}	
}

// Form dynamics (DUP/DCS/DLP) for maiden name
function maidenNameFormChanger(genderField, marriedField, lastnameField, maidennameField, partnernameField) {
	var self = this;
	this.genderField = genderField;
	this.marriedField = marriedField;
	this.lastnameField = lastnameField;
	this.maidennameField = maidennameField;
	this.partnernameField = partnernameField;
	this.marriedField.bind('change', function(e) {
		self.update();
	});
	this.genderField.bind('change', function(e) {
		self.update();
	});
	this.update();	
}
maidenNameFormChanger.prototype = {
	update: function() {
		var gender = $('input:checked, input:hidden', this.genderField).val();
		var married = $('input:checked', this.marriedField).val();
		if(gender == 'Vrouw') {
			this.marriedField.show();
			if(married == 'Gehuwd') {
				this.maidennameField.show();
				this.partnernameField.show();
				this.lastnameField.hide();
			} else {
				this.maidennameField.hide();
				this.partnernameField.hide();
				this.lastnameField.show();	
			}
		} else {
			this.marriedField.hide();
			this.maidennameField.hide();
			this.partnernameField.hide();
			this.lastnameField.show();				
		}
	}	
}

// toggles elements on an active checkbox or radio button anywhere on the page
toggleSubforms = {
	init: function(el) {
		var self = this;
		if(!el) el = $('body');
		this.toggles = $('input.toggle:radio, input.toggle:checkbox', el);
		this.toggles.bind('click', function(e) {
			self.toggle($(this));
		});
		this.toggles.each(function() {
			self.toggle($(this));
		});
	},
	toggle: function(el) {
		var t = el.attr('data');
		var status = el.attr('checked');
		if(t && status == false) $(t).hide();
		if(t && status == true) {
			$(t).show();
			// hide associate radios' corresponding elements
			if(el.attr('type') == 'radio') {
				var associates = $(document.getElementsByName(el.attr('name'))).not(el);
				associates.each(function() {
					var u = $(this).attr('data');
					if(u) $(u).hide();
				});
			}	
		}
	}
}

function shadowboxInit() {
    if (typeof (Shadowbox) != "undefined") {
        Shadowbox.init({
            troubleElements: [],
            players: ['html', 'iframe', 'img'],
            skipSetup: false,
            displayNav: false,
            onFinish: function () {
                injectLightboxCloseLink();
            }
        });
    }
}

function showSubmitIndicator() {
    $("#submit_indicator").show();
}

function updateMijnDelaInlog(obj) {
    var value = $("#" + obj).val();
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

    if (emailPattern.test(value)) {
        setTimeout("__doPostBack('" + obj + "','')", 0);
    }
}

function colorCheckboxErrorLabels() {
    $("input[type=checkbox].error, input[type=radio].error").each(function () {
        $("label[for='" + this.id + "']").addClass("error");
    });
}

function disableSubmit(btn) {
    $(btn).addClass('disabled');
    $(btn).parent().find('div.submitprogress').css('display', 'inline-block');
}

function enableSubmit(btn) {
    $(btn).removeClass('disabled');
    $(btn).parent().find('div.submitprogress').css('display', 'none');
}

function ValidateAndSubmit(btn, validationGroup, eventTarget, eventArgument) {
    if ($(btn).hasClass('disabled')) {
        return false;
    }
    if (typeof validationGroup == undefined || validationGroup == null) {
        validationGroup = '';
    }
    Page_ClientValidate(validationGroup);
    if (!Page_IsValid) {
        return false;
    }
    disableSubmit(btn);
    __doPostBack(eventTarget, eventArgument);
}
