﻿// Beeline jQuery plugins/extensions

$.fn.clearSelect = function(label) {
	return this.each(function() {
		if (this.tagName == 'SELECT')
			this.options.length = 0;
		if (label) {
			var dropdownList = this;
			var option = new Option(label, null);
			if ($.browser.msie) {
				dropdownList.add(option);
			}
			else {
				dropdownList.add(option, null);
			}
		}
	});
}

$.fn.fillSelect = function(data, label) {
	return this.clearSelect(label).each(function() {
		if (this.tagName == 'SELECT') {
			var dropdownList = this;
			$.each(data, function(index, optionData) {

				var option = new Option(optionData.Text, optionData.Value);

				if ($.browser.msie) {
					dropdownList.add(option);
				}
				else {
					dropdownList.add(option, null);
				}
			});
		}
	});
}

/*
*  Dev One (http://www.dev-one.com)
*  Watermark jQuery plug-in
*
*/

$.fn.watermark = function(css, text) {
	$(this).unbind('focus');
	$(this).focus(function() {
		$(this).filter(function() {
			return $(this).val() == "" || $(this).val() == text
		}).removeClass(css).val("");
	});

	$(this).unbind('blur');
	$(this).blur(function() {
		$(this).filter(function() {
			return $(this).val() == ""
		}).addClass(css).val(text);
	});

	var input = $(this);
	$(this).closest("form").unbind('submit');
	$(this).closest("form").submit(function() {
		input.filter(function() {
			return $(this).val() == text
		}).val("");
	});

	// Only add the Watermark if there's nothing in there already or if it's being cleared
	if ($(this).val() == "") {
		$(this).addClass(css).val(text);
	}
};

$.fn.valToInt = function() {
	var v = this.val();
	if (v)
		return v;

	return 0;
}

if (!String.prototype.trim) {
	String.prototype.trim = function() {	
		return this.replace(/^\s+|\s+$/g, "");
	}
}

/** Fancy Box **/
function FancyBoxInit() {
	
	var fullPath = window.location.pathname.toLowerCase();
	var matches = fullPath.match("/([^/]*)/?([^/]*?)(\.aspx)?$");

	var lastFolder = '';
	var filename = 'default';
	if (matches != undefined) {
		if (matches.length > 1) {
			lastFolder = matches[1];
		}
		if (matches.length > 2) {
			if (matches[2] != '') {
				filename = matches[2];
			}
		}
	}

	var options = {
		'autoScale': false,
		'titleShow': true,
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'type': 'iframe',
		'width': '35%',
		'height': '50%',
		'titlePosition': 'float',
		onStart: function () {
				dcsMultiTrack('DCS.dcsuri', "/" + lastFolder + "/" + filename + "/PopupOpened.html", 'WT.si_n', 'Compliance Popup Scenario', 'WT.si_p', 'PopupOpened');			
			},
			onCancel: function () {
				dcsMultiTrack('DCS.dcsuri', "/" + lastFolder + "/" + filename + "/PopupClosed.html", 'WT.si_n', 'Compliance Popup Scenario', 'WT.si_p', 'PopupClosed');			
			},
			onComplete: function () {
			},
			onCleanup: function () {
			},
			onClosed: function () {
				dcsMultiTrack('DCS.dcsuri', "/" + lastFolder + "/" + filename + "/PopupClosed.html", 'WT.si_n', 'Compliance Popup Scenario', 'WT.si_p', 'PopupClosed');			
		}
	};

	$("a.fancybox").fancybox(options);
}

/****/
