﻿$(document).ready(function () {

	// Validation
	// Add our force invalid validator method
	$.validator.addMethod("forceinvalid", function (value, element) {
		return false;
	}, "INVALID!!!");

	// Make stuff pretty and rounded
	$('div.divRounded').wrap('<div class="divRoundedOuter"></div>');
	$("div.divRounded").corner("round 8px").parent().css('padding', '4px').corner("round 10px");
	$('div.divRoundedWhite').wrap('<div class="divRoundedOuter"></div>');
	$("div.divRoundedWhite").corner("round 8px").parent().css('padding', '4px').corner("round 10px");
	$('div.divRoundedHeader').wrap('<div class="divRoundedHeaderOuter"></div>');
	$("div.divRoundedHeader").corner("round 8px").parent().css('padding', '4px').corner("round 10px");


	// Set up our helper tooltips
	$("a.helpExpander").qtip({

		content: {
			text: function (api) {
				// Retrieve content from custom attribute of the $('.selector') elements.
				return $(this).next("div.helpExpanderContent").html(); //.attr('qtip');
			},
			title: {
				text:
				function (api) {
					// Get the titlebark
					var s = $(this).next("div.helpExpanderContent").attr("title");
					if (null == s || s.length == 0) { s = "Help"; }
					return s;
				},
				button: true // ...and buttons get styled by ThemeRoller!
			}
		},

		position: {
			at: 'top center', // Position the tooltip above the link
			my: 'bottom left',
			viewport: $(window) // Keep the tooltip on-screen at all times
		},
		show: {
			event: 'click',
			solo: true // Only show one tooltip at a time
		},
		hide: 'unfocus',
		style: {
			classes: 'ui-tooltip-shadow', // Optional shadow...
			tip: 'bottom left', // Tips work nicely with the styles too!

			/*
			* The important part: style.widget property
          
			* This tells qTip to apply the ui-widget classes to
			* the main, titlebar and content elements of the qTip.
			* Otherwise they won't be applied and ThemeRoller styles
			* won't effect this particular tooltip.
			*/
			widget: true
		}
	});

});


function ForceInvalid(element, msg) {

	// Copy our old rules
	var oldRules = element.rules();
	// Apply new invalid rule
	element.rules("add", {
		forceinvalid: true,
		messages: {
			forceinvalid: msg
		}
	});
	// Run that rule
	element.closest('form').validate().element(element);
	// Restore old rules
	element.rules("remove");
	element.rules("add", oldRules);

}

